diff --git a/.eslintrc b/.eslintrc index c481eca..e71ebc8 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,6 +2,7 @@ "extends": "react-app", "rules": { "jsx-a11y/href-no-hash": "off", - "no-console": "warn" + "no-console": "warn", + "valid-jsdoc": "warn" } } diff --git a/package.json b/package.json index 1bc7b37..eb26af9 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "highcharts-more": "^0.1.7", "jsonp": "^0.2.1", "lodash.clonedeep": "^4.5.0", + "lodash.isempty": "^4.4.0", "lodash.isequal": "^4.5.0", "module": "^1.2.5", "nprogress": "^0.2.0", @@ -49,10 +50,10 @@ "lint-staged": "^7.2.2", "mockjs": "^1.0.1-beta3", "prettier": "^1.14.2", - "svg-sprite-loader": "^3.9.2", "stylelint": "^9.5.0", "stylelint-config-prettier": "^4.0.0", "stylelint-config-standard": "^18.2.0", + "svg-sprite-loader": "^3.9.2", "umi": "^2.0.3", "umi-plugin-react": "^1.0.3" }, diff --git a/src/components/Layout/Bread.js b/src/components/Layout/Bread.js index ffc9777..df8efdd 100644 --- a/src/components/Layout/Bread.js +++ b/src/components/Layout/Bread.js @@ -23,7 +23,7 @@ const Bread = ({ menu, location }) => { const getPathArray = item => { pathArray.unshift(item) if (item.bpid) { - getPathArray(queryArray(menu, item.bpid, 'id')) + getPathArray(queryArray(menu, 'id', item.bpid)) } } diff --git a/src/components/Layout/Menu.js b/src/components/Layout/Menu.js index 1b287b5..64a67a8 100644 --- a/src/components/Layout/Menu.js +++ b/src/components/Layout/Menu.js @@ -115,7 +115,7 @@ const Menus = ({ result.unshift(String(item['bpid'])) } else { result.unshift(String(item[pid])) - getPath(queryArray(array, item[pid], id)) + getPath(queryArray(array, id, item[pid])) } } } diff --git a/src/components/Layout/Sider.js b/src/components/Layout/Sider.js index c4e1cae..15ef1b4 100644 --- a/src/components/Layout/Sider.js +++ b/src/components/Layout/Sider.js @@ -26,7 +26,7 @@ const Sider = ({
logo - {siderFold ? '' : {config.name}} + {siderFold ? '' : {config.siteName}}
{!siderFold ? ( diff --git a/src/pages/dashboard/components/browser.js b/src/pages/dashboard/components/browser.js index 8374e3c..4f52dbe 100644 --- a/src/pages/dashboard/components/browser.js +++ b/src/pages/dashboard/components/browser.js @@ -1,21 +1,21 @@ import React from 'react' import PropTypes from 'prop-types' import { Table, Tag } from 'antd' -import { color } from 'utils' +import { Color } from 'utils' import styles from './browser.less' const status = { 1: { - color: color.green, + color: Color.green, }, 2: { - color: color.red, + color: Color.red, }, 3: { - color: color.blue, + color: Color.blue, }, 4: { - color: color.yellow, + color: Color.yellow, }, } diff --git a/src/pages/dashboard/components/comments.js b/src/pages/dashboard/components/comments.js index 530c62c..ed3cdc2 100644 --- a/src/pages/dashboard/components/comments.js +++ b/src/pages/dashboard/components/comments.js @@ -1,20 +1,20 @@ import React from 'react' import PropTypes from 'prop-types' import { Table, Tag } from 'antd' -import { color } from 'utils' +import { Color } from 'utils' import styles from './comments.less' const status = { 1: { - color: color.green, + color: Color.green, text: 'APPROVED', }, 2: { - color: color.yellow, + color: Color.yellow, text: 'PENDING', }, 3: { - color: color.red, + color: Color.red, text: 'REJECTED', }, } diff --git a/src/pages/dashboard/components/completed.js b/src/pages/dashboard/components/completed.js index 76249dd..2dc62cd 100644 --- a/src/pages/dashboard/components/completed.js +++ b/src/pages/dashboard/components/completed.js @@ -1,7 +1,7 @@ import React from 'react' import PropTypes from 'prop-types' import classnames from 'classnames' -import { color } from 'utils' +import { Color } from 'utils' import { AreaChart, Area, @@ -46,13 +46,13 @@ function Completed({ data }) { /> diff --git a/src/pages/dashboard/components/cpu.js b/src/pages/dashboard/components/cpu.js index fe3da38..3561555 100644 --- a/src/pages/dashboard/components/cpu.js +++ b/src/pages/dashboard/components/cpu.js @@ -1,6 +1,6 @@ import React from 'react' import PropTypes from 'prop-types' -import { color } from 'utils' +import { Color } from 'utils' import CountUp from 'react-countup' import { LineChart, @@ -47,21 +47,21 @@ function Cpu({ usage = 0, space = 0, cpu = 0, data }) { diff --git a/src/pages/dashboard/components/recentSales.js b/src/pages/dashboard/components/recentSales.js index b06af93..5b034a4 100644 --- a/src/pages/dashboard/components/recentSales.js +++ b/src/pages/dashboard/components/recentSales.js @@ -2,24 +2,24 @@ import React from 'react' import moment from 'moment' import PropTypes from 'prop-types' import { Table, Tag } from 'antd' -import { color } from 'utils' +import { Color } from 'utils' import styles from './recentSales.less' const status = { 1: { - color: color.green, + color: Color.green, text: 'SALE', }, 2: { - color: color.yellow, + color: Color.yellow, text: 'REJECT', }, 3: { - color: color.red, + color: Color.red, text: 'TAX', }, 4: { - color: color.blue, + color: Color.blue, text: 'EXTENDED', }, } diff --git a/src/pages/dashboard/components/sales.js b/src/pages/dashboard/components/sales.js index 6990596..d155239 100644 --- a/src/pages/dashboard/components/sales.js +++ b/src/pages/dashboard/components/sales.js @@ -1,7 +1,7 @@ import React from 'react' import PropTypes from 'prop-types' import classnames from 'classnames' -import { color } from 'utils' +import { Color } from 'utils' import { LineChart, Line, @@ -46,13 +46,13 @@ function Sales({ data }) { /> diff --git a/src/pages/dashboard/components/user.js b/src/pages/dashboard/components/user.js index 34261df..92ed367 100644 --- a/src/pages/dashboard/components/user.js +++ b/src/pages/dashboard/components/user.js @@ -2,7 +2,7 @@ import React from 'react' import PropTypes from 'prop-types' import { Button, Icon } from 'antd' import CountUp from 'react-countup' -import { color } from 'utils' +import { Color } from 'utils' import styles from './user.less' const countUpProps = { @@ -25,13 +25,13 @@ function User({ name, sales = 0, sold = 0 }) {

EARNING SALES

-

+

ITEM SOLD

-

+

diff --git a/src/pages/dashboard/index.js b/src/pages/dashboard/index.js index 7d98dc7..3fcd354 100644 --- a/src/pages/dashboard/index.js +++ b/src/pages/dashboard/index.js @@ -2,7 +2,7 @@ import React from 'react' import PropTypes from 'prop-types' import { connect } from 'dva' import { Row, Col, Card } from 'antd' -import { color } from 'utils' +import { Color } from 'utils' import { Page } from 'components' import { NumberCard, @@ -70,7 +70,7 @@ function Dashboard({ dashboard, loading }) { bodyStyle={{ padding: 0, height: 204, - background: color.blue, + background: Color.blue, }} > diff --git a/src/utils/config.js b/src/utils/config.js index 45c8a6c..de9218e 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -1,9 +1,8 @@ module.exports = { - name: 'AntD Admin', siteName: 'AntD Admin', prefix: 'antdAdmin', footerText: 'Ant Design Admin © 2018 zuiidea', logo: '/logo.svg', - openPages: ['/login'], apiPrefix: '/api/v1', + openPages: ['/login'], } diff --git a/src/utils/index.js b/src/utils/index.js index 1845fe2..f4634d7 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,34 +1,22 @@ -/* global window */ import cloneDeep from 'lodash.clonedeep' export classnames from 'classnames' export config from './config' export request from './request' -export { color } from './theme' +export { Color } from './theme' /** - * @param name {String} - * @return {String} + * 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 queryURL(name) { - let reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`, 'i') - let r = window.location.search.substr(1).match(reg) - if (r != null) return decodeURI(r[2]) - return null -} - -/** - * 数组内查询 - * @param {array} array - * @param {String} id - * @param {String} keyAlias - * @return {Array} - */ -export function queryArray(array, key, keyAlias = 'key') { - if (!(array instanceof Array)) { +export function queryArray(array, key, value) { + if (!Array.isArray(array)) { return null } - const item = array.filter(_ => _[keyAlias] === key) + const item = array.filter(_ => _[key] === value) if (item.length) { return item[0] } @@ -36,12 +24,12 @@ export function queryArray(array, key, keyAlias = 'key') { } /** - * 数组格式转树状结构 - * @param {array} array - * @param {String} id - * @param {String} pid - * @param {String} children - * @return {Array} + * Convert an array to a tree-structured array. + * @param {array} array The Array need to Converted. + * @param {string} id The alias of the unique ID of the object in the array. + * @param {string} pid The alias of the parent ID of the object in the array. + * @param {string} children The alias of children of the object in the array. + * @return {array} Return a tree-structured array. */ export function arrayToTree( array, @@ -49,18 +37,19 @@ export function arrayToTree( pid = 'pid', children = 'children' ) { - let data = cloneDeep(array) - let result = [] - let hash = {} + const result = [] + const hash = {} + const data = cloneDeep(array) + data.forEach((item, index) => { hash[data[index][id]] = data[index] }) data.forEach(item => { - let hashVP = hash[item[pid]] - if (hashVP) { - !hashVP[children] && (hashVP[children] = []) - hashVP[children].push(item) + const hashParent = hash[item[pid]] + if (hashParent) { + !hashParent[children] && (hashParent[children] = []) + hashParent[children].push(item) } else { result.push(item) } diff --git a/src/utils/request.js b/src/utils/request.js index 8b4957b..a8fdd2c 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,5 +1,6 @@ import axios from 'axios' import cloneDeep from 'lodash.clonedeep' +import isEmpty from 'lodash.isempty' import pathToRegexp from 'path-to-regexp' import { message } from 'antd' import qs from 'qs' @@ -31,7 +32,7 @@ export default function request(options) { options.url = method.toLocaleLowerCase() === 'get' - ? `${url}${cloneData ? '?' : ''}${qs.stringify(cloneData)}` + ? `${url}${isEmpty(cloneData) ? '' : '?'}${qs.stringify(cloneData)}` : url return axios(options) diff --git a/src/utils/theme.js b/src/utils/theme.js index c25585c..0a610df 100644 --- a/src/utils/theme.js +++ b/src/utils/theme.js @@ -1,5 +1,5 @@ module.exports = { - color: { + Color: { green: '#64ea91', blue: '#8fc9fb', purple: '#d897eb', diff --git a/yarn.lock b/yarn.lock index 155f385..066906b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6798,6 +6798,10 @@ lodash.isarray@^3.0.0: version "3.0.4" resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" +lodash.isempty@^4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.isempty/-/lodash.isempty-4.4.0.tgz#6f86cbedd8be4ec987be9aaf33c9684db1b31e7e" + lodash.isequal@^4.0.0, lodash.isequal@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"