mirror of
https://github.com/zuiidea/antd-admin.git
synced 2024-04-21 12:32:14 +00:00
Optimize the utils function and add JSdoc
Change the variable color to Color. Add package loadsh.isempty.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
"extends": "react-app",
|
||||
"rules": {
|
||||
"jsx-a11y/href-no-hash": "off",
|
||||
"no-console": "warn"
|
||||
"no-console": "warn",
|
||||
"valid-jsdoc": "warn"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ const Sider = ({
|
||||
<div>
|
||||
<div className={styles.logo}>
|
||||
<img alt="logo" src={config.logo} />
|
||||
{siderFold ? '' : <span>{config.name}</span>}
|
||||
{siderFold ? '' : <span>{config.siteName}</span>}
|
||||
</div>
|
||||
<Menus {...menusProps} />
|
||||
{!siderFold ? (
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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 }) {
|
||||
/>
|
||||
<XAxis
|
||||
dataKey="name"
|
||||
axisLine={{ stroke: color.borderBase, strokeWidth: 1 }}
|
||||
axisLine={{ stroke: Color.borderBase, strokeWidth: 1 }}
|
||||
tickLine={false}
|
||||
/>
|
||||
<YAxis axisLine={false} tickLine={false} />
|
||||
<CartesianGrid
|
||||
vertical={false}
|
||||
stroke={color.borderBase}
|
||||
stroke={Color.borderBase}
|
||||
strokeDasharray="3 3"
|
||||
/>
|
||||
<Tooltip
|
||||
@@ -81,20 +81,20 @@ function Completed({ data }) {
|
||||
<Area
|
||||
type="monotone"
|
||||
dataKey="Task complete"
|
||||
stroke={color.grass}
|
||||
fill={color.grass}
|
||||
stroke={Color.grass}
|
||||
fill={Color.grass}
|
||||
strokeWidth={2}
|
||||
dot={{ fill: '#fff' }}
|
||||
activeDot={{ r: 5, fill: '#fff', stroke: color.green }}
|
||||
activeDot={{ r: 5, fill: '#fff', stroke: Color.green }}
|
||||
/>
|
||||
<Area
|
||||
type="monotone"
|
||||
dataKey="Cards Complete"
|
||||
stroke={color.sky}
|
||||
fill={color.sky}
|
||||
stroke={Color.sky}
|
||||
fill={Color.sky}
|
||||
strokeWidth={2}
|
||||
dot={{ fill: '#fff' }}
|
||||
activeDot={{ r: 5, fill: '#fff', stroke: color.blue }}
|
||||
activeDot={{ r: 5, fill: '#fff', stroke: Color.blue }}
|
||||
/>
|
||||
</AreaChart>
|
||||
</ResponsiveContainer>
|
||||
|
||||
@@ -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 }) {
|
||||
<LineChart data={data} margin={{ left: -40 }}>
|
||||
<XAxis
|
||||
dataKey="name"
|
||||
axisLine={{ stroke: color.borderBase, strokeWidth: 1 }}
|
||||
axisLine={{ stroke: Color.borderBase, strokeWidth: 1 }}
|
||||
tickLine={false}
|
||||
/>
|
||||
<YAxis axisLine={false} tickLine={false} />
|
||||
<CartesianGrid
|
||||
vertical={false}
|
||||
stroke={color.borderBase}
|
||||
stroke={Color.borderBase}
|
||||
strokeDasharray="3 3"
|
||||
/>
|
||||
<Line
|
||||
type="monotone"
|
||||
connectNulls
|
||||
dataKey="cpu"
|
||||
stroke={color.blue}
|
||||
fill={color.blue}
|
||||
stroke={Color.blue}
|
||||
fill={Color.blue}
|
||||
/>
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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 }) {
|
||||
/>
|
||||
<XAxis
|
||||
dataKey="name"
|
||||
axisLine={{ stroke: color.borderBase, strokeWidth: 1 }}
|
||||
axisLine={{ stroke: Color.borderBase, strokeWidth: 1 }}
|
||||
tickLine={false}
|
||||
/>
|
||||
<YAxis axisLine={false} tickLine={false} />
|
||||
<CartesianGrid
|
||||
vertical={false}
|
||||
stroke={color.borderBase}
|
||||
stroke={Color.borderBase}
|
||||
strokeDasharray="3 3"
|
||||
/>
|
||||
<Tooltip
|
||||
@@ -81,25 +81,25 @@ function Sales({ data }) {
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="Food"
|
||||
stroke={color.purple}
|
||||
stroke={Color.purple}
|
||||
strokeWidth={3}
|
||||
dot={{ fill: color.purple }}
|
||||
dot={{ fill: Color.purple }}
|
||||
activeDot={{ r: 5, strokeWidth: 0 }}
|
||||
/>
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="Clothes"
|
||||
stroke={color.red}
|
||||
stroke={Color.red}
|
||||
strokeWidth={3}
|
||||
dot={{ fill: color.red }}
|
||||
dot={{ fill: Color.red }}
|
||||
activeDot={{ r: 5, strokeWidth: 0 }}
|
||||
/>
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="Electronics"
|
||||
stroke={color.green}
|
||||
stroke={Color.green}
|
||||
strokeWidth={3}
|
||||
dot={{ fill: color.green }}
|
||||
dot={{ fill: Color.green }}
|
||||
activeDot={{ r: 5, strokeWidth: 0 }}
|
||||
/>
|
||||
</LineChart>
|
||||
|
||||
@@ -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 }) {
|
||||
<div className={styles.number}>
|
||||
<div className={styles.item}>
|
||||
<p>EARNING SALES</p>
|
||||
<p style={{ color: color.green }}>
|
||||
<p style={{ color: Color.green }}>
|
||||
<CountUp end={sales} prefix="$" {...countUpProps} />
|
||||
</p>
|
||||
</div>
|
||||
<div className={styles.item}>
|
||||
<p>ITEM SOLD</p>
|
||||
<p style={{ color: color.blue }}>
|
||||
<p style={{ color: Color.blue }}>
|
||||
<CountUp end={sold} {...countUpProps} />
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -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,
|
||||
}}
|
||||
>
|
||||
<Weather
|
||||
@@ -86,7 +86,7 @@ function Dashboard({ dashboard, loading }) {
|
||||
bodyStyle={{
|
||||
padding: 0,
|
||||
height: 204,
|
||||
background: color.peach,
|
||||
background: Color.peach,
|
||||
}}
|
||||
>
|
||||
<Quote {...quote} />
|
||||
|
||||
+1
-2
@@ -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'],
|
||||
}
|
||||
|
||||
+23
-34
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
color: {
|
||||
Color: {
|
||||
green: '#64ea91',
|
||||
blue: '#8fc9fb',
|
||||
purple: '#d897eb',
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user