Optimization and rewriting PrimaryLayout.

This commit is contained in:
zuiidea
2018-09-18 22:04:30 +08:00
parent 5aa187334a
commit 4e7795ec7c
22 changed files with 503 additions and 786 deletions
+3 -7
View File
@@ -3,17 +3,13 @@
* @param {array} array An array where all values are objects, like [{key:1},{key:2}].
* @param {string} key The key of the object that needs to be queried.
* @param {string} value The value of the object that needs to be queried.
* @return {object|null} Return frist object when query success.
* @return {object|undefined} Return frist object when query success.
*/
export function queryArray(array, key, value) {
if (!Array.isArray(array)) {
return null
return
}
const item = array.filter(_ => _[key] === value)
if (item.length) {
return item[0]
}
return null
return array.filter(_ => _[key] === value)
}
export const Constant = {
-69
View File
@@ -1,69 +0,0 @@
const Mock = require('mockjs')
const config = {
apiPrefix: '/api/v1',
}
/**
* Query objects that specify keys and values in an array where all values are objects.
* @param {array} array An array where all values are objects, like [{key:1},{key:2}].
* @param {string} key The key of the object that needs to be queried.
* @param {string} value The value of the object that needs to be queried.
* @return {object|null} Return frist object when query success.
*/
export function queryArray(array, key, value) {
if (!Array.isArray(array)) {
return null
}
const item = array.filter(_ => _[key] === value)
if (item.length) {
return item[0]
}
return null
}
const NOTFOUND = {
message: 'Not Found',
documentation_url: 'http://localhost:8000/request',
}
let postId = 0
const posts = Mock.mock({
'data|100': [
{
id() {
postId += 1
return postId + 10000
},
'status|1-2': 1,
title: '@title',
author: '@last',
categories: '@word',
tags: '@word',
'views|10-200': 1,
'comments|10-200': 1,
visibility: () => {
return Mock.mock(
'@pick(["Public",' + '"Password protected", ' + '"Private"])'
)
},
date: '@dateTime',
image() {
return Mock.Random.image(
'100x100',
Mock.Random.color(),
'#757575',
'png',
this.author.substr(0, 1)
)
},
},
],
}).data
module.exports = {
queryArray,
NOTFOUND,
Mock,
posts,
config,
}
+2 -2
View File
@@ -87,11 +87,11 @@ const database = [
name: 'Rechartst',
icon: 'area-chart',
route: '/chart/Recharts',
},
}
]
module.exports = {
[`GET ${ApiPrefix}/menus`](req, res) {
[`GET ${ApiPrefix}/routes`](req, res) {
res.status(200).json(database)
},
}