From 47e7d580bb9387f005da05f5d8e72932968ea7ff Mon Sep 17 00:00:00 2001 From: zuiidea Date: Tue, 14 Mar 2017 20:03:21 +0800 Subject: [PATCH] eslint apply all --- .eslintrc | 25 ++++-- npm-debug.log | 48 +++++++++++ package.json | 2 +- src/components/common/TableBodyWrapper.js | 23 ++--- src/components/dashboard/browser.js | 18 ++-- src/components/dashboard/comments.js | 16 ++-- src/components/dashboard/completed.js | 37 ++++---- src/components/dashboard/cpu.js | 28 +++--- src/components/dashboard/numberCard.js | 6 +- src/components/dashboard/quote.js | 4 +- src/components/dashboard/recentSales.js | 22 ++--- src/components/dashboard/sales.js | 39 +++++---- src/components/dashboard/user.js | 24 +++--- src/components/dashboard/weather.js | 12 +-- src/components/layout/bread.js | 18 ++-- src/components/layout/header.js | 23 ++--- src/components/layout/menu.js | 41 ++++----- src/components/layout/sider.js | 10 +-- src/components/ui/dropOption.js | 10 +-- src/components/ui/ico.js | 4 +- src/components/ui/index.js | 2 +- src/components/ui/layer.js | 3 - src/components/ui/search.js | 10 +-- src/components/users/list.js | 40 ++++----- src/components/users/modal.js | 74 ++++++++-------- src/components/users/search.js | 19 ++-- src/index.js | 2 +- src/models/app.js | 100 +++++++++++----------- src/models/dashboard.js | 90 +++++++++---------- src/models/users.js | 48 +++++------ src/router.js | 26 +++--- src/routes/app.js | 31 +++---- src/routes/dashboard.js | 30 +++---- src/routes/error.js | 6 +- src/routes/login.js | 28 +++--- src/routes/ui/dropOption.js | 50 ++++++----- src/routes/ui/ico.js | 22 ++--- src/routes/ui/layer.js | 31 ++++--- src/routes/ui/search.js | 60 +++++++------ src/routes/users.js | 43 +++++----- src/services/app.js | 6 +- src/services/dashboard.js | 6 +- src/services/users.js | 8 +- src/theme.js | 2 +- src/utils/config.js | 2 +- src/utils/index.js | 24 +++--- src/utils/menu.js | 32 +++---- src/utils/mock.js | 47 ++++++---- src/utils/mockStorge.js | 2 +- src/utils/request.js | 23 +++-- src/utils/theme.js | 4 +- webpack.config.js | 12 +-- 52 files changed, 692 insertions(+), 601 deletions(-) create mode 100644 npm-debug.log diff --git a/.eslintrc b/.eslintrc index 8c43cb5..1572d62 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,18 +1,31 @@ { "extends": "airbnb", "rules": { - "semi": ["error", "never"], - "no-console": "off", - "comma-dangle": ["error", "always"], - "max-len": ["error", 200] + "semi": [2, "never"], + "no-console": 0, + "comma-dangle": [2, "always-multiline"], + "max-len": 0, + "react/jsx-first-prop-new-line": 0, + "space-before-function-paren": [2, "always"], + "no-unused-expressions": [0, { + "allowShortCircuit": true, + "allowTernary": true + }], + "arrow-body-style": [0, "never"], + "func-names": 0, + "prefer-const": 0, + "no-extend-native": 0, + "no-param-reassign": 0, + "no-restricted-syntax": 0, + "no-eval": 0 }, "parser": "babel-eslint", "parserOptions": { "sourceType": "module", "ecmaVersion": 8, "ecmaFeatures": { - "jsx": true, - "experimentalObjectRestSpread": true + "jsx": true, + "experimentalObjectRestSpread": true } } } diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 0000000..a6260eb --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,48 @@ +0 info it worked if it ends with ok +1 verbose cli [ 'D:\\Program Files\\nodejs\\node.exe', +1 verbose cli 'D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', +1 verbose cli 'run', +1 verbose cli 'lint' ] +2 info using npm@3.10.10 +3 info using node@v6.9.5 +4 verbose run-script [ 'prelint', 'lint', 'postlint' ] +5 info lifecycle @~prelint: @ +6 silly lifecycle @~prelint: no script for prelint, continuing +7 info lifecycle @~lint: @ +8 verbose lifecycle @~lint: unsafe-perm in lifecycle true +9 verbose lifecycle @~lint: PATH: D:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;D:\web\antd-admin\node_modules\.bin;D:\Program Files\cmder\bin;D:\Program Files\cmder\vendor\conemu-maximus5\ConEmu\Scripts;D:\Program Files\cmder\vendor\conemu-maximus5;D:\Program Files\cmder\vendor\conemu-maximus5\ConEmu;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows7Master;D:\Program Files\Git\cmd;D:\Program Files\nodejs\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\Program Files (x86)\Yarn\bin;C:\Users\Administrator\AppData\Local\atom\bin;C:\Users\Administrator\AppData\Roaming\npm;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\AppData\Local\Yarn\.bin;D:\Program Files\Git\usr\bin;D:\Program Files\Git\usr\share\vim\vim74;D:\Program Files\cmder\ +10 verbose lifecycle @~lint: CWD: D:\web\antd-admin +11 silly lifecycle @~lint: Args: [ '/d /s /c', 'eslint --ext .js src/' ] +12 silly lifecycle @~lint: Returned: code: 1 signal: null +13 info lifecycle @~lint: Failed to exec lint script +14 verbose stack Error: @ lint: `eslint --ext .js src/` +14 verbose stack Exit status 1 +14 verbose stack at EventEmitter. (D:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:255:16) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at EventEmitter.emit (events.js:191:7) +14 verbose stack at ChildProcess. (D:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at ChildProcess.emit (events.js:191:7) +14 verbose stack at maybeClose (internal/child_process.js:877:16) +14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) +15 verbose pkgid @ +16 verbose cwd D:\web\antd-admin +17 error Windows_NT 10.0.15048 +18 error argv "D:\\Program Files\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "lint" +19 error node v6.9.5 +20 error npm v3.10.10 +21 error code ELIFECYCLE +22 error @ lint: `eslint --ext .js src/` +22 error Exit status 1 +23 error Failed at the @ lint script 'eslint --ext .js src/'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error eslint --ext .js src/ +23 error You can get information on how to open an issue for this project with: +23 error npm bugs +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/package.json b/package.json index ab93e80..93ec541 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "scripts": { "start": "dora --plugins \"proxy,webpack?publicPath=/,webpack-hmr,browser-history?index=/src/index.html\"", "dev": "dora --plugins \"webpack?publicPath=/,webpack-hmr,browser-history?index=/src/index.html\"", - "lint": "eslint --fix --ext .js,.jsx src/components/layout", + "lint": "eslint --fix --ext .js src", "build": "atool-build" }, "theme": "./src/theme.js", diff --git a/src/components/common/TableBodyWrapper.js b/src/components/common/TableBodyWrapper.js index ff85aa1..c59d319 100644 --- a/src/components/common/TableBodyWrapper.js +++ b/src/components/common/TableBodyWrapper.js @@ -6,7 +6,7 @@ const enterAnim = [ opacity: 0, x: 30, backgroundColor: '#fffeee', - duration: 0 + duration: 0, }, { height: 0, duration: 200, @@ -15,28 +15,28 @@ const enterAnim = [ ease: 'easeOutQuad', onComplete: (e) => { e.target.style.height = 'auto' - } + }, }, { opacity: 1, x: 0, duration: 250, - ease: 'easeOutQuad' + ease: 'easeOutQuad', }, { delay: 1000, - backgroundColor: '#fff' - } + backgroundColor: '#fff', + }, ] const leaveAnim = [ { duration: 250, x: -30, - opacity: 0 + opacity: 0, }, { height: 0, duration: 200, - ease: 'easeOutQuad' - } + ease: 'easeOutQuad', + }, ] const TableBodyWrapper = ({ body, page = 1, current }) => { @@ -47,11 +47,12 @@ const TableBodyWrapper = ({ body, page = 1, current }) => { return ( + appear={false} + > {body.props.children} ) @@ -60,7 +61,7 @@ const TableBodyWrapper = ({ body, page = 1, current }) => { TableBodyWrapper.propTypes = { body: PropTypes.element, page: PropTypes.any, - current: PropTypes.number.isRequired + current: PropTypes.number.isRequired, } export default TableBodyWrapper diff --git a/src/components/dashboard/browser.js b/src/components/dashboard/browser.js index 151ba76..1e81858 100644 --- a/src/components/dashboard/browser.js +++ b/src/components/dashboard/browser.js @@ -5,17 +5,17 @@ import { color } from '../../utils' 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, + }, } function Browser ({ data }) { @@ -23,19 +23,19 @@ function Browser ({ data }) { { title: 'name', dataIndex: 'name', - className: styles.name + className: styles.name, }, { title: 'percent', dataIndex: 'percent', className: styles.percent, - render: (text, it) => {text}% - } + render: (text, it) => {text}%, + }, ] return key} dataSource={data} /> } Browser.propTypes = { - data: PropTypes.array + data: PropTypes.array, } export default Browser diff --git a/src/components/dashboard/comments.js b/src/components/dashboard/comments.js index af8acda..55f3721 100644 --- a/src/components/dashboard/comments.js +++ b/src/components/dashboard/comments.js @@ -6,16 +6,16 @@ import { color } from '../../utils' const status = { 1: { color: color.green, - text: 'APPROVED' + text: 'APPROVED', }, 2: { color: color.yellow, - text: 'PENDING' + text: 'PENDING', }, 3: { color: color.red, - text: 'REJECTED' - } + text: 'REJECTED', + }, } function Comments ({ data }) { @@ -25,7 +25,7 @@ function Comments ({ data }) { dataIndex: 'avatar', width: 48, className: styles.avatarcolumn, - render: text => + render: text => , }, { title: 'content', dataIndex: 'content', @@ -36,8 +36,8 @@ function Comments ({ data }) { {status[it.status].text} {it.date} - - } + , + }, ] return (
@@ -47,7 +47,7 @@ function Comments ({ data }) { } Comments.propTypes = { - data: PropTypes.array + data: PropTypes.array, } export default Comments diff --git a/src/components/dashboard/completed.js b/src/components/dashboard/completed.js index d3d9d7a..2477d8a 100644 --- a/src/components/dashboard/completed.js +++ b/src/components/dashboard/completed.js @@ -1,7 +1,8 @@ import React, { PropTypes } from 'react' import styles from './completed.less' -import {color} from '../../utils' -import {AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer} from 'recharts' +import classnames from 'classnames' +import { color } from '../../utils' +import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts' function Completed ({ data }) { return ( @@ -9,24 +10,26 @@ function Completed ({ data }) {
TEAM TOTAL COMPLETED
- { - const { payload } = props - return
    - {payload.map((item, key) =>
  • {item.value}
  • ) } -
- }} /> - + { + const { payload } = prop + return (
    + {payload.map((item, key) =>
  • {item.value}
  • )} +
) + }} + /> + - + { - const list = content.payload.map((item, key) =>
  • {item.name + ':' + item.value}
  • ) + const list = content.payload.map((item, key) =>
  • {`${item.name}:${item.value}`}
  • ) return

    {content.label}

      {list}
    - }} /> - - + }} + /> + +
    @@ -34,7 +37,7 @@ function Completed ({ data }) { } Completed.propTypes = { - data: PropTypes.array + data: PropTypes.array, } export default Completed diff --git a/src/components/dashboard/cpu.js b/src/components/dashboard/cpu.js index 482700d..c51f0f9 100644 --- a/src/components/dashboard/cpu.js +++ b/src/components/dashboard/cpu.js @@ -9,53 +9,53 @@ const countUpProps = { duration: 2.75, useEasing: true, useGrouping: true, - separator: ',' + separator: ',', } function Cpu ({ usage, space, cpu, data }) { - return
    + return (

    usage

    + />

    space

    + />

    cpu

    + />

    - - + + - - + + -
    +
    ) } Cpu.propTypes = { data: PropTypes.array, usage: PropTypes.number, space: PropTypes.number, - cpu: PropTypes.number + cpu: PropTypes.number, } export default Cpu diff --git a/src/components/dashboard/numberCard.js b/src/components/dashboard/numberCard.js index 4b0a245..26c09f8 100644 --- a/src/components/dashboard/numberCard.js +++ b/src/components/dashboard/numberCard.js @@ -5,7 +5,7 @@ import styles from './numberCard.less' function NumberCard ({ icon, color, title, number, countUp }) { return ( - +

    {title || 'No Title'}

    @@ -16,7 +16,7 @@ function NumberCard ({ icon, color, title, number, countUp }) { duration={2.75} useEasing useGrouping - separator=',' + separator="," {...countUp || {}} />

    @@ -30,7 +30,7 @@ NumberCard.propTypes = { color: PropTypes.string, title: PropTypes.string, number: PropTypes.number, - countUp: PropTypes.object + countUp: PropTypes.object, } export default NumberCard diff --git a/src/components/dashboard/quote.js b/src/components/dashboard/quote.js index f7e0c7b..240d244 100644 --- a/src/components/dashboard/quote.js +++ b/src/components/dashboard/quote.js @@ -12,7 +12,7 @@ function Quote ({ name, content, title, avatar }) {

    -{name}-

    {title}

    -
    +
    ) @@ -22,7 +22,7 @@ Quote.propTypes = { name: PropTypes.string, content: PropTypes.string, title: PropTypes.string, - avatar: PropTypes.string + avatar: PropTypes.string, } export default Quote diff --git a/src/components/dashboard/recentSales.js b/src/components/dashboard/recentSales.js index 7ad84b1..6315f81 100644 --- a/src/components/dashboard/recentSales.js +++ b/src/components/dashboard/recentSales.js @@ -6,40 +6,40 @@ import { color } from '../../utils' const status = { 1: { color: color.green, - text: 'SALE' + text: 'SALE', }, 2: { color: color.yellow, - text: 'REJECT' + text: 'REJECT', }, 3: { color: color.red, - text: 'TAX' + text: 'TAX', }, 4: { color: color.blue, - text: 'EXTENDED' - } + text: 'EXTENDED', + }, } function RecentSales ({ data }) { const columns = [ { title: 'NAME', - dataIndex: 'name' + dataIndex: 'name', }, { title: 'STATUS', dataIndex: 'status', - render: text => {status[text].text} + render: text => {status[text].text}, }, { title: 'DATE', dataIndex: 'date', - render: text => new Date(text).format('yyyy-MM-dd') + render: text => new Date(text).format('yyyy-MM-dd'), }, { title: 'PRICE', dataIndex: 'price', - render: (text, it) => ${text} - } + render: (text, it) => ${text}, + }, ] return (
    @@ -49,7 +49,7 @@ function RecentSales ({ data }) { } RecentSales.propTypes = { - data: PropTypes.array + data: PropTypes.array, } export default RecentSales diff --git a/src/components/dashboard/sales.js b/src/components/dashboard/sales.js index 042d483..a9d48b2 100644 --- a/src/components/dashboard/sales.js +++ b/src/components/dashboard/sales.js @@ -1,7 +1,8 @@ import React, { PropTypes } from 'react' import styles from './sales.less' -import {color} from '../../utils' -import {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer} from 'recharts' +import classnames from 'classnames' +import { color } from '../../utils' +import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts' function Sales ({ data }) { return ( @@ -9,25 +10,27 @@ function Sales ({ data }) {
    Yearly Sales
    - { - const { payload } = props - return
      - {payload.map((item, key) =>
    • {item.value}
    • ) } -
    - }} /> - + { + const { payload } = prop + return (
      + {payload.map((item, key) =>
    • {item.value}
    • )} +
    ) + }} + /> + - + { - const list = content.payload.map((item, key) =>
  • {item.name + ':' + item.value}
  • ) + const list = content.payload.map((item, key) =>
  • {`${item.name}:${item.value}`}
  • ) return

    {content.label}

      {list}
    - }} /> - - - + }} + /> + + +
    @@ -35,7 +38,7 @@ function Sales ({ data }) { } Sales.propTypes = { - data: PropTypes.array + data: PropTypes.array, } export default Sales diff --git a/src/components/dashboard/user.js b/src/components/dashboard/user.js index ee663c9..faf8918 100644 --- a/src/components/dashboard/user.js +++ b/src/components/dashboard/user.js @@ -8,14 +8,14 @@ const countUpProps = { duration: 2.75, useEasing: true, useGrouping: true, - separator: ',' + separator: ',', } -function User ({avatar, name, email, sales, sold}) { - return
    +function User ({ avatar, name, email, sales, sold }) { + return (
    -
    +
    {name}

    {email}

    @@ -23,24 +23,24 @@ function User ({avatar, name, email, sales, sold}) {

    EARNING SALES

    -

    + />

    ITEM SOLD

    -

    + />

    - +
    -
    +
    ) } User.propTypes = { @@ -48,7 +48,7 @@ User.propTypes = { name: PropTypes.string, email: PropTypes.string, sales: PropTypes.number, - sold: PropTypes.number + sold: PropTypes.number, } export default User diff --git a/src/components/dashboard/weather.js b/src/components/dashboard/weather.js index a271f59..b11a060 100644 --- a/src/components/dashboard/weather.js +++ b/src/components/dashboard/weather.js @@ -1,19 +1,19 @@ import React, { PropTypes } from 'react' import styles from './weather.less' -function Weather ({city, icon, dateTime, temperature, name}) { - return
    +function Weather ({ city, icon, dateTime, temperature, name }) { + return (

    {name}

    -

    {temperature + '°'}

    +

    {`${temperature}°`}

    {city},{dateTime}

    -
    +
    ) } Weather.propTypes = { @@ -21,7 +21,7 @@ Weather.propTypes = { icon: PropTypes.string, dateTime: PropTypes.string, temperature: PropTypes.string, - name: PropTypes.string + name: PropTypes.string, } export default Weather diff --git a/src/components/layout/bread.js b/src/components/layout/bread.js index 17d72e7..57ff4e4 100644 --- a/src/components/layout/bread.js +++ b/src/components/layout/bread.js @@ -6,15 +6,15 @@ import { menu } from '../../utils' let pathSet = [] const getPathSet = function (menuArray, parentPath) { parentPath = parentPath || '/' - menuArray.map(item => { + menuArray.forEach(item => { pathSet[(parentPath + item.key).replace(/\//g, '-').hyphenToHump()] = { path: parentPath + item.key, name: item.name, icon: item.icon || '', - clickable: item.clickable === undefined + clickable: item.clickable === undefined, } if (item.child) { - getPathSet(item.child, parentPath + item.key + '/') + getPathSet(item.child, `${parentPath}${item.key}/`) } }) } @@ -22,11 +22,11 @@ getPathSet(menu) function Bread ({ location }) { let pathNames = [] - location.pathname.substr(1).split('/').map((item, key) => { + location.pathname.substr(1).split('/').forEach((item, key) => { if (key > 0) { - pathNames.push((pathNames[key - 1] + '-' + item).hyphenToHump()) + pathNames.push((`${pathNames[key - 1]}-${item}`).hyphenToHump()) } else { - pathNames.push(('-' + item).hyphenToHump()) + pathNames.push((`-${item}`).hyphenToHump()) } }) const breads = pathNames.map((item, key) => { @@ -34,7 +34,7 @@ function Bread ({ location }) { item = 'Dashboard' } return ( - + {pathSet[item].icon ? : ''} @@ -46,7 +46,7 @@ function Bread ({ location }) { return (
    - + 主页 {breads} @@ -56,7 +56,7 @@ function Bread ({ location }) { } Bread.propTypes = { - location: PropTypes.object + location: PropTypes.object, } export default Bread diff --git a/src/components/layout/header.js b/src/components/layout/header.js index 2ff7c4f..1d6e56e 100644 --- a/src/components/layout/header.js +++ b/src/components/layout/header.js @@ -1,11 +1,11 @@ -import React, {PropTypes} from 'react' +import React, { PropTypes } from 'react' import { Menu, Icon, Popover } from 'antd' import styles from './main.less' import Menus from './menu' const SubMenu = Menu.SubMenu -function Header ({user, logout, switchSider, siderFold, isNavbar, menuPopoverVisible, location, switchMenuPopover, navOpenKeys, changeOpenKeys}) { +function Header ({ user, logout, switchSider, siderFold, isNavbar, menuPopoverVisible, location, switchMenuPopover, navOpenKeys, changeOpenKeys }) { let handleClickMenu = e => e.key === 'logout' && logout() const menusProps = { siderFold: false, @@ -14,26 +14,27 @@ function Header ({user, logout, switchSider, siderFold, isNavbar, menuPopoverVis handleClickNavMenu: switchMenuPopover, location, navOpenKeys, - changeOpenKeys + changeOpenKeys, } return (
    {isNavbar - ? }> + ? }>
    - +
    :
    } - + - {user.name} < /span>}> - + float: 'right', + }} title={< span > + {user.name} < /span>} + > + 注销 @@ -52,7 +53,7 @@ Header.propTypes = { location: PropTypes.object, switchMenuPopover: PropTypes.func, navOpenKeys: PropTypes.array, - changeOpenKeys: PropTypes.func + changeOpenKeys: PropTypes.func, } export default Header diff --git a/src/components/layout/menu.js b/src/components/layout/menu.js index af79f0f..925bdc5 100644 --- a/src/components/layout/menu.js +++ b/src/components/layout/menu.js @@ -10,25 +10,31 @@ const getMenus = function (menuArray, siderFold, parentPath) { if (item.child) { return ( {item.icon ? : ''}{siderFold && topMenus.indexOf(item.key) >= 0 ? '' : item.name}}> - {getMenus(item.child, siderFold, parentPath + item.key + '/')} + {getMenus(item.child, siderFold, `${parentPath}${item.key}/`)} ) - } else { - return ( - - - {item.icon ? : ''} - {siderFold && topMenus.indexOf(item.key) >= 0 ? '' : item.name} - - - ) } + return ( + + + {item.icon ? : ''} + {siderFold && topMenus.indexOf(item.key) >= 0 ? '' : item.name} + + + ) }) } -function Menus ({ siderFold, darkTheme, location, isNavbar, handleClickNavMenu, navOpenKeys, changeOpenKeys }) { +function Menus ({ siderFold, darkTheme, location, handleClickNavMenu, navOpenKeys, changeOpenKeys }) { const menuItems = getMenus(menu, siderFold) + const getAncestorKeys = (key) => { + const map = { + navigation2: ['navigation'], + } + return map[key] || [] + } + const onOpenChange = (openKeys) => { const latestOpenKey = openKeys.find(key => !(navOpenKeys.indexOf(key) > -1)) const latestCloseKey = navOpenKeys.find(key => !(openKeys.indexOf(key) > -1)) @@ -41,16 +47,10 @@ function Menus ({ siderFold, darkTheme, location, isNavbar, handleClickNavMenu, } changeOpenKeys(nextOpenKeys) } - const getAncestorKeys = (key) => { - const map = { - navigation2: ['navigation'] - } - return map[key] || [] - } // 菜单栏收起时,不能操作openKeys let menuProps = !siderFold ? { onOpenChange, - openKeys: navOpenKeys + openKeys: navOpenKeys, } : {} return ( @@ -59,7 +59,8 @@ function Menus ({ siderFold, darkTheme, location, isNavbar, handleClickNavMenu, mode={siderFold ? 'vertical' : 'inline'} theme={darkTheme ? 'dark' : 'light'} onClick={handleClickNavMenu} - defaultSelectedKeys={[location.pathname.split('/')[location.pathname.split('/').length - 1] || 'dashboard']}> + defaultSelectedKeys={[location.pathname.split('/')[location.pathname.split('/').length - 1] || 'dashboard']} + > {menuItems} ) @@ -72,7 +73,7 @@ Menus.propTypes = { isNavbar: PropTypes.bool, handleClickNavMenu: PropTypes.func, navOpenKeys: PropTypes.array, - changeOpenKeys: PropTypes.func + changeOpenKeys: PropTypes.func, } export default Menus diff --git a/src/components/layout/sider.js b/src/components/layout/sider.js index f43c14c..afe0f9b 100644 --- a/src/components/layout/sider.js +++ b/src/components/layout/sider.js @@ -10,18 +10,18 @@ function Sider ({ siderFold, darkTheme, location, changeTheme, navOpenKeys, chan darkTheme, location, navOpenKeys, - changeOpenKeys + changeOpenKeys, } return (
    - + {'logo'} {siderFold ? '' : {config.logoText}}
    {!siderFold ?
    - 切换主题 - + 切换主题 +
    : ''}
    ) @@ -33,7 +33,7 @@ Sider.propTypes = { location: PropTypes.object, changeTheme: PropTypes.func, navOpenKeys: PropTypes.array, - changeOpenKeys: PropTypes.func + changeOpenKeys: PropTypes.func, } export default Sider diff --git a/src/components/ui/dropOption.js b/src/components/ui/dropOption.js index ab88d16..a1d0eac 100644 --- a/src/components/ui/dropOption.js +++ b/src/components/ui/dropOption.js @@ -1,13 +1,13 @@ -import React, { PropTypes, } from 'react' -import { Dropdown, Button, Icon, Menu, } from 'antd' +import React, { PropTypes } from 'react' +import { Dropdown, Button, Icon, Menu } from 'antd' -const DropOption = ({ onMenuClick, menuOptions = [], buttonStyle, dropdownProps, }) => { +const DropOption = ({ onMenuClick, menuOptions = [], buttonStyle, dropdownProps }) => { const menu = menuOptions.map(item => {item.name}) return ({menu}
    } > - ) diff --git a/src/components/ui/ico.js b/src/components/ui/ico.js index 28dd3a2..f846855 100644 --- a/src/components/ui/ico.js +++ b/src/components/ui/ico.js @@ -1,7 +1,7 @@ -import React, { PropTypes, } from 'react' +import React, { PropTypes } from 'react' import './ico.less' -const Ico = ({ type, }) =>
    { function handleOk () { validateFields((errors) => { @@ -30,7 +30,7 @@ const modal = ({ } const data = { ...getFieldsValue(), - key: item.key + key: item.key, } onOk(data) }) @@ -41,44 +41,44 @@ const modal = ({ visible, onOk: handleOk, onCancel, - wrapClassName: 'vertical-center-modal' + wrapClassName: 'vertical-center-modal', } return (
    - + {getFieldDecorator('name', { initialValue: item.name, rules: [ { required: true, - message: '姓名未填写' - } - ] + message: '姓名未填写', + }, + ], })()} - + {getFieldDecorator('nickName', { initialValue: item.nickName, rules: [ { required: true, - message: '昵称未填写' - } - ] + message: '昵称未填写', + }, + ], })()} - + {getFieldDecorator('isMale', { initialValue: item.isMale, rules: [ { required: true, type: 'boolean', - message: '请选择性别' - } - ] + message: '请选择性别', + }, + ], })( 男 @@ -86,49 +86,49 @@ const modal = ({ )} - + {getFieldDecorator('age', { initialValue: item.age, rules: [ { required: true, type: 'number', - message: '年龄未填写' - } - ] + message: '年龄未填写', + }, + ], })()} - + {getFieldDecorator('phone', { initialValue: item.phone, rules: [ { required: true, - message: '不能为空' - } - ] + message: '不能为空', + }, + ], })()} - + {getFieldDecorator('email', { initialValue: item.email, rules: [ { required: true, - message: '不能为空' - } - ] + message: '不能为空', + }, + ], })()} - + {getFieldDecorator('address', { initialValue: item.address, rules: [ { required: true, - message: '不能为空' - } - ] + message: '不能为空', + }, + ], })()} @@ -140,7 +140,9 @@ modal.propTypes = { form: PropTypes.object.isRequired, visible: PropTypes.bool, type: PropTypes.string, - item: PropTypes.object + item: PropTypes.object, + onCancel: PropTypes.func, + onOk: PropTypes.func, } export default Form.create()(modal) diff --git a/src/components/users/search.js b/src/components/users/search.js index 1708fdd..96c49d0 100644 --- a/src/components/users/search.js +++ b/src/components/users/search.js @@ -9,11 +9,6 @@ const search = ({ onAdd, isMotion, switchIsMotion, - form: { - getFieldDecorator, - validateFields, - getFieldsValue - } }) => { const searchGroupProps = { field, @@ -22,21 +17,21 @@ const search = ({ select: true, selectOptions: [{ value: 'name', name: '姓名' }, { value: 'address', name: '地址' }], selectProps: { - defaultValue: field || 'name' + defaultValue: field || 'name', }, onSearch: (value) => { onSearch(value) - } + }, } return ( -
    + - - - + + + ) @@ -49,7 +44,7 @@ search.propTypes = { field: PropTypes.string, keyword: PropTypes.string, isMotion: PropTypes.bool, - switchIsMotion: PropTypes.func + switchIsMotion: PropTypes.func, } export default Form.create()(search) diff --git a/src/index.js b/src/index.js index 8d34cac..c376dc0 100644 --- a/src/index.js +++ b/src/index.js @@ -10,7 +10,7 @@ const app = dva({ history: browserHistory, onError (error) { console.error('app onError -- ', error) - } + }, }) // 2. Model diff --git a/src/models/app.js b/src/models/app.js index f4ef5ea..29e39f3 100644 --- a/src/models/app.js +++ b/src/models/app.js @@ -1,103 +1,103 @@ -import {login, userInfo, logout} from '../services/app' -import {parse} from 'qs' +import { login, userInfo, logout } from '../services/app' +import { parse } from 'qs' export default { namespace: 'app', state: { login: false, user: { - name: '吴彦祖' + name: '吴彦祖', }, loginButtonLoading: false, menuPopoverVisible: false, siderFold: localStorage.getItem('antdAdminSiderFold') === 'true', darkTheme: localStorage.getItem('antdAdminDarkTheme') !== 'false', isNavbar: document.body.clientWidth < 769, - navOpenKeys: JSON.parse(localStorage.getItem('navOpenKeys') || '[]') + navOpenKeys: JSON.parse(localStorage.getItem('navOpenKeys') || '[]'), }, subscriptions: { - setup ({dispatch}) { - dispatch({type: 'queryUser'}) - window.onresize = function () { - dispatch({type: 'changeNavbar'}) + setup ({ dispatch }) { + dispatch({ type: 'queryUser' }) + window.onresize = () => { + dispatch({ type: 'changeNavbar' }) } - } + }, }, effects: { *login ({ - payload - }, {call, put}) { - yield put({type: 'showLoginButtonLoading'}) + payload, + }, { call, put }) { + yield put({ type: 'showLoginButtonLoading' }) const data = yield call(login, parse(payload)) if (data.success) { yield put({ type: 'loginSuccess', payload: { user: { - name: payload.username - } - }}) + name: payload.username, + }, + } }) } else { yield put({ - type: 'loginFail' + type: 'loginFail', }) } }, *queryUser ({ - payload - }, {call, put}) { + payload, + }, { call, put }) { const data = yield call(userInfo, parse(payload)) if (data.success) { yield put({ type: 'loginSuccess', payload: { user: { - name: data.username - } - } + name: data.username, + }, + }, }) } }, *logout ({ - payload - }, {call, put}) { + payload, + }, { call, put }) { const data = yield call(logout, parse(payload)) if (data.success) { yield put({ - type: 'logoutSuccess' + type: 'logoutSuccess', }) } }, *switchSider ({ - payload - }, {put}) { + payload, + }, { put }) { yield put({ - type: 'handleSwitchSider' + type: 'handleSwitchSider', }) }, *changeTheme ({ - payload - }, {put}) { + payload, + }, { put }) { yield put({ - type: 'handleChangeTheme' + type: 'handleChangeTheme', }) }, *changeNavbar ({ - payload - }, {put}) { + payload, + }, { put }) { if (document.body.clientWidth < 769) { - yield put({type: 'showNavbar'}) + yield put({ type: 'showNavbar' }) } else { - yield put({type: 'hideNavbar'}) + yield put({ type: 'hideNavbar' }) } }, *switchMenuPopver ({ - payload - }, {put}) { + payload, + }, { put }) { yield put({ - type: 'handleSwitchMenuPopver' + type: 'handleSwitchMenuPopver', }) - } + }, }, reducers: { loginSuccess (state, action) { @@ -105,65 +105,65 @@ export default { ...state, ...action.payload, login: true, - loginButtonLoading: false + loginButtonLoading: false, } }, logoutSuccess (state) { return { ...state, - login: false + login: false, } }, loginFail (state) { return { ...state, login: false, - loginButtonLoading: false + loginButtonLoading: false, } }, showLoginButtonLoading (state) { return { ...state, - loginButtonLoading: true + loginButtonLoading: true, } }, handleSwitchSider (state) { localStorage.setItem('antdAdminSiderFold', !state.siderFold) return { ...state, - siderFold: !state.siderFold + siderFold: !state.siderFold, } }, handleChangeTheme (state) { localStorage.setItem('antdAdminDarkTheme', !state.darkTheme) return { ...state, - darkTheme: !state.darkTheme + darkTheme: !state.darkTheme, } }, showNavbar (state) { return { ...state, - isNavbar: true + isNavbar: true, } }, hideNavbar (state) { return { ...state, - isNavbar: false + isNavbar: false, } }, handleSwitchMenuPopver (state) { return { ...state, - menuPopoverVisible: !state.menuPopoverVisible + menuPopoverVisible: !state.menuPopoverVisible, } }, handleNavOpenKeys (state, action) { return { ...state, - ...action.payload + ...action.payload, } - } - } + }, + }, } diff --git a/src/models/dashboard.js b/src/models/dashboard.js index 25294ae..6b83c13 100644 --- a/src/models/dashboard.js +++ b/src/models/dashboard.js @@ -1,51 +1,51 @@ -import {myCity, queryWeather, query} from '../services/dashboard' -import {parse} from 'qs' +import { myCity, queryWeather, query } from '../services/dashboard' +import { parse } from 'qs' // zuimei 摘自 http://www.zuimeitianqi.com/res/js/index.js let zuimei = { - ParseActualData: function (actual, air) { + parseActualData (actual) { let weather = { - icon: 'http://www.zuimeitianqi.com/res/icon/' + zuimei.GetIconName(actual.wea, 'big'), - name: zuimei.GetWeatherName(actual.wea), + icon: `http://www.zuimeitianqi.com/res/icon/${zuimei.getIconName(actual.wea, 'big')}`, + name: zuimei.getWeatherName(actual.wea), temperature: actual.tmp, - dateTime: new Date(actual.PTm).format('MM-dd hh:mm') + dateTime: new Date(actual.PTm).format('MM-dd hh:mm'), } return weather }, - GetIconName: function (wea, flg) { + getIconName (wea, flg) { let myDate = new Date() let hour = myDate.getHours() let num = 0 if (wea.indexOf('/') !== -1) { let weas = wea.split('/') if (hour < 12) { - num = zuimei.ReplaceIcon(weas[0]) + num = zuimei.replaceIcon(weas[0]) if (num < 6) { - num = num + '_' + flg + '_night.png' + num = `${num}_${flg}_night.png` } else { - num = num + '_' + flg + '.png' + num = `${num}_${flg}.png` } } else if (hour >= 12) { - num = zuimei.ReplaceIcon(weas[1]) + num = zuimei.replaceIcon(weas[1]) if (hour >= 18) { - num = num + '_' + flg + '_night.png' + num = `${num}_${flg}_night.png` } else { - num = num + '_' + flg + '.png' + num = `${num}_${flg}.png` } } } else { if ((hour >= 18 && hour <= 23) || (hour >= 0 && hour <= 6)) { - num = num + '_' + flg + '_night.png' + num = `${num}_${flg}_night.png` } else { - num = num + '_' + flg + '.png' + num = `${num}_${flg}.png` } } return num }, - ReplaceIcon: function (num) { + replaceIcon (num) { if (num === 21) { num = 7 } else if (num === 22) { @@ -67,19 +67,19 @@ let zuimei = { return num }, - GetWeatherName: function (wea) { + getWeatherName (wea) { let name = '' if (wea.indexOf('/') !== -1) { let weas = wea.split('/') - name = zuimei.GetWeatherByCode(weas[0]) + '转' + zuimei.GetWeatherByCode(weas[1]) + name = `${zuimei.getWeatherByCode(weas[0])}转${zuimei.getWeatherByCode(weas[1])}` } else { - name = zuimei.GetWeatherByCode(wea) + name = zuimei.getWeatherByCode(wea) } return name }, - GetWeatherByCode: function (num) { + getWeatherByCode (num) { let wea = '' if (num === 0) { wea = '晴' @@ -160,7 +160,7 @@ let zuimei = { } return wea - } + }, } export default { @@ -171,11 +171,11 @@ export default { temperature: '5', name: '晴', icon: 'http://www.zuimeitianqi.com/res/icon/0_big.png', - dateTime: new Date().format('MM-dd hh:mm') + dateTime: new Date().format('MM-dd hh:mm'), }, sales: [], quote: { - avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236' + avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236', }, numbers: [], recentSales: [], @@ -184,49 +184,49 @@ export default { browser: [], cpu: {}, user: { - avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236' - } + avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236', + }, }, subscriptions: { - setup ({dispatch}) { - dispatch({type: 'queryWeather'}) - dispatch({type: 'query'}) - } + setup ({ dispatch }) { + dispatch({ type: 'queryWeather' }) + dispatch({ type: 'query' }) + }, }, effects: { *query ({ - payload - }, {call, put}) { + payload, + }, { call, put }) { const data = yield call(query, parse(payload)) - yield put({type: 'queryWeather', payload: {...data}}) + yield put({ type: 'queryWeather', payload: { ...data } }) }, *queryWeather ({ - payload - }, {call, put}) { - const myCityResult = yield call(myCity, {flg: 0}) + payload, + }, { call, put }) { + const myCityResult = yield call(myCity, { flg: 0 }) const myCityData = myCityResult.query.results.json - const result = yield call(queryWeather, {cityCode: myCityData.selectCityCode}) + const result = yield call(queryWeather, { cityCode: myCityData.selectCityCode }) const data = result.query.results.json - const weather = zuimei.ParseActualData(data.data.actual) + const weather = zuimei.parseActualData(data.data.actual) weather.city = myCityData.selectCityName - yield put({type: 'queryWeatherSuccess', payload: { - weather - }}) - } + yield put({ type: 'queryWeatherSuccess', payload: { + weather, + } }) + }, }, reducers: { queryWeatherSuccess (state, action) { return { ...state, - ...action.payload + ...action.payload, } }, queryWeather (state, action) { return { ...state, - ...action.payload + ...action.payload, } - } - } + }, + }, } diff --git a/src/models/users.js b/src/models/users.js index 6384b3f..4d432c1 100644 --- a/src/models/users.js +++ b/src/models/users.js @@ -16,8 +16,8 @@ export default { showQuickJumper: true, showTotal: total => `共 ${total} 条`, current: 1, - total: null - } + total: null, + }, }, subscriptions: { @@ -26,11 +26,11 @@ export default { if (location.pathname === '/users') { dispatch({ type: 'query', - payload: location.query + payload: location.query, }) } }) - } + }, }, effects: { @@ -41,8 +41,8 @@ export default { type: 'querySuccess', payload: { list: data.data, - pagination: data.page - } + pagination: data.page, + }, }) } }, @@ -55,9 +55,9 @@ export default { list: data.data, pagination: { total: data.page.total, - current: data.page.current - } - } + current: data.page.current, + }, + }, }) } }, @@ -71,9 +71,9 @@ export default { list: data.data, pagination: { total: data.page.total, - current: data.page.current - } - } + current: data.page.current, + }, + }, }) } }, @@ -89,30 +89,30 @@ export default { list: data.data, pagination: { total: data.page.total, - current: data.page.current - } - } + current: data.page.current, + }, + }, }) } }, *switchIsMotion ({ - payload - }, {put}) { + payload, + }, { put }) { yield put({ - type: 'handleSwitchIsMotion' + type: 'handleSwitchIsMotion', }) - } + }, }, reducers: { querySuccess (state, action) { - const {list, pagination} = action.payload + const { list, pagination } = action.payload return { ...state, list, pagination: { ...state.pagination, - ...pagination - }} + ...pagination, + } } }, showModal (state, action) { return { ...state, ...action.payload, modalVisible: true } @@ -123,7 +123,7 @@ export default { handleSwitchIsMotion (state) { localStorage.setItem('antdAdminUserIsMotion', !state.isMotion) return { ...state, isMotion: !state.isMotion } - } - } + }, + }, } diff --git a/src/router.js b/src/router.js index 1b731e1..c63d24d 100644 --- a/src/router.js +++ b/src/router.js @@ -1,5 +1,5 @@ import React from 'react' -import {Router} from 'dva/router' +import { Router } from 'dva/router' import App from './routes/app' const cached = {} @@ -10,7 +10,7 @@ const registerModel = (app, model) => { } } -export default function ({history, app}) { +export default function ({ history, app }) { const routes = [ { path: '/', @@ -18,7 +18,7 @@ export default function ({history, app}) { getIndexRoute (nextState, cb) { require.ensure([], require => { registerModel(app, require('./models/dashboard')) - cb(null, {component: require('./routes/dashboard')}) + cb(null, { component: require('./routes/dashboard') }) }, 'dashboard') }, childRoutes: [ @@ -30,7 +30,7 @@ export default function ({history, app}) { registerModel(app, require('./models/dashboard')) cb(null, require('./routes/dashboard')) }, 'dashboard') - } + }, }, { path: 'users', name: 'users', @@ -39,7 +39,7 @@ export default function ({history, app}) { registerModel(app, require('./models/users')) cb(null, require('./routes/users')) }, 'users') - } + }, }, { path: 'ui/ico', name: 'ui/ico', @@ -47,7 +47,7 @@ export default function ({history, app}) { require.ensure([], require => { cb(null, require('./routes/ui/ico')) }, 'ui-ico') - } + }, }, { path: 'ui/search', name: 'ui/search', @@ -55,7 +55,7 @@ export default function ({history, app}) { require.ensure([], require => { cb(null, require('./routes/ui/search')) }, 'ui-search') - } + }, }, { path: 'ui/dropOption', name: 'ui/dropOption', @@ -63,7 +63,7 @@ export default function ({history, app}) { require.ensure([], require => { cb(null, require('./routes/ui/dropOption')) }, 'ui-dropOption') - } + }, }, { path: 'ui/layer', name: 'ui/layer', @@ -71,7 +71,7 @@ export default function ({history, app}) { require.ensure([], require => { cb(null, require('./routes/ui/layer')) }, 'ui-layer') - } + }, }, { path: '*', name: 'error', @@ -79,10 +79,10 @@ export default function ({history, app}) { require.ensure([], require => { cb(null, require('./routes/error')) }, 'error') - } - } - ] - } + }, + }, + ], + }, ] return diff --git a/src/routes/app.js b/src/routes/app.js index d9239e1..f37b075 100644 --- a/src/routes/app.js +++ b/src/routes/app.js @@ -10,14 +10,14 @@ import { Spin } from 'antd' import { classnames } from '../utils' import '../components/layout/common.less' -function App ({children, location, dispatch, app, loading}) { - const {login, loginButtonLoading, user, siderFold, darkTheme, isNavbar, menuPopoverVisible, navOpenKeys} = app +function App ({ children, location, dispatch, app, loading }) { + const { login, loginButtonLoading, user, siderFold, darkTheme, isNavbar, menuPopoverVisible, navOpenKeys } = app const loginProps = { loading, loginButtonLoading, onOk (data) { - dispatch({type: 'app/login', payload: data}) - } + dispatch({ type: 'app/login', payload: data }) + }, } const headerProps = { @@ -28,18 +28,18 @@ function App ({children, location, dispatch, app, loading}) { menuPopoverVisible, navOpenKeys, switchMenuPopover () { - dispatch({type: 'app/switchMenuPopver'}) + dispatch({ type: 'app/switchMenuPopver' }) }, logout () { - dispatch({type: 'app/logout'}) + dispatch({ type: 'app/logout' }) }, switchSider () { - dispatch({type: 'app/switchSider'}) + dispatch({ type: 'app/switchSider' }) }, changeOpenKeys (openKeys) { localStorage.setItem('navOpenKeys', JSON.stringify(openKeys)) dispatch({ type: 'app/handleNavOpenKeys', payload: { navOpenKeys: openKeys } }) - } + }, } const siderProps = { @@ -48,18 +48,18 @@ function App ({children, location, dispatch, app, loading}) { location, navOpenKeys, changeTheme () { - dispatch({type: 'app/changeTheme'}) + dispatch({ type: 'app/changeTheme' }) }, changeOpenKeys (openKeys) { localStorage.setItem('navOpenKeys', JSON.stringify(openKeys)) dispatch({ type: 'app/handleNavOpenKeys', payload: { navOpenKeys: openKeys } }) - } + }, } return (
    {login - ?
    - {!isNavbar ?
    + :
    }
    ) } @@ -81,7 +81,8 @@ App.propTypes = { children: PropTypes.element.isRequired, location: PropTypes.object, dispatch: PropTypes.func, - app: PropTypes.object + app: PropTypes.object, + loading: PropTypes.bool, } -export default connect(({app, loading}) => ({app, loading: loading.models.app}))(App) +export default connect(({ app, loading }) => ({ app, loading: loading.models.app }))(App) diff --git a/src/routes/dashboard.js b/src/routes/dashboard.js index bb31219..fb104f4 100644 --- a/src/routes/dashboard.js +++ b/src/routes/dashboard.js @@ -1,6 +1,6 @@ -import React, {PropTypes} from 'react' -import {connect} from 'dva' -import {Row, Col, Card} from 'antd' +import React, { PropTypes } from 'react' +import { connect } from 'dva' +import { Row, Col, Card } from 'antd' import NumberCard from '../components/dashboard/numberCard' import Quote from '../components/dashboard/quote' import Sales from '../components/dashboard/sales' @@ -12,17 +12,17 @@ import Browser from '../components/dashboard/browser' import Cpu from '../components/dashboard/cpu' import User from '../components/dashboard/user' import styles from './dashboard.less' -import {color} from '../utils' +import { color } from '../utils' const bodyStyle = { bodyStyle: { height: 432, - background: '#fff' - } + background: '#fff', + }, } -function Dashboard ({dashboard}) { - const {weather, sales, quote, numbers, recentSales, comments, completed, browser, cpu, user} = dashboard +function Dashboard ({ dashboard }) { + const { weather, sales, quote, numbers, recentSales, comments, completed, browser, cpu, user } = dashboard const numberCards = numbers.map((item, key) =>
    ) @@ -32,7 +32,7 @@ function Dashboard ({dashboard}) { {numberCards} @@ -43,7 +43,7 @@ function Dashboard ({dashboard}) { @@ -52,7 +52,7 @@ function Dashboard ({dashboard}) { @@ -71,7 +71,7 @@ function Dashboard ({dashboard}) { @@ -87,7 +87,7 @@ function Dashboard ({dashboard}) { - + @@ -96,7 +96,7 @@ function Dashboard ({dashboard}) { } Dashboard.propTypes = { - dashboard: PropTypes.object + dashboard: PropTypes.object, } -export default connect(({dashboard}) => ({dashboard}))(Dashboard) +export default connect(({ dashboard }) => ({ dashboard }))(Dashboard) diff --git a/src/routes/error.js b/src/routes/error.js index 5285478..7c4b8cb 100644 --- a/src/routes/error.js +++ b/src/routes/error.js @@ -1,10 +1,10 @@ import React from 'react' -import {Icon} from 'antd' +import { Icon } from 'antd' import styles from './error.less' -const Error = () =>
    +const Error = () =>
    - +

    404 Not Found

    diff --git a/src/routes/login.js b/src/routes/login.js index 85e6a82..cf5d2b6 100644 --- a/src/routes/login.js +++ b/src/routes/login.js @@ -1,4 +1,4 @@ -import React, {PropTypes} from 'react' +import React, { PropTypes } from 'react' import { Button, Row, Form, Input } from 'antd' import { config } from '../utils' import styles from './login.less' @@ -10,8 +10,8 @@ const login = ({ onOk, form: { getFieldDecorator, - validateFieldsAndScroll - } + validateFieldsAndScroll, + }, }) => { function handleOk () { validateFieldsAndScroll((errors, values) => { @@ -25,7 +25,7 @@ const login = ({ return (
    - + {'logo'} Ant Design
    @@ -34,23 +34,23 @@ const login = ({ rules: [ { required: true, - message: '请填写用户名' - } - ] - })()} + message: '请填写用户名', + }, + ], + })()} {getFieldDecorator('password', { rules: [ { required: true, - message: '请填写密码' - } - ] - })()} + message: '请填写密码', + }, + ], + })()} - @@ -66,7 +66,7 @@ const login = ({ login.propTypes = { form: PropTypes.object, loginButtonLoading: PropTypes.bool, - onOk: PropTypes.func + onOk: PropTypes.func, } export default Form.create()(login) diff --git a/src/routes/ui/dropOption.js b/src/routes/ui/dropOption.js index f3e6171..eede8bc 100644 --- a/src/routes/ui/dropOption.js +++ b/src/routes/ui/dropOption.js @@ -2,24 +2,24 @@ import React from 'react' import { DropOption } from '../../components/ui' import { Table, Row, Col, Card, message } from 'antd' -const DropOptionPage = () =>
    +const DropOptionPage = () =>
    - - + + - - + + - + { + menuOptions={[{ key: '1', name: '编辑' }, { key: '2', name: '删除' }]} + buttonStyle={{ border: 'solid 1px #eee', width: 60 }} + onMenuClick={({ key }) => { switch (key) { case '1': message.success('点击了编辑') @@ -27,63 +27,67 @@ const DropOptionPage = () =>
    case '2': message.success('点击了删除') break + default: + break } }} - /> + /> -

    Props

    +

    Props

    -
    key} +
    key} pagination={false} bordered scroll={{ x: 800 }} columns={[ { title: '参数', - dataIndex: 'props' + dataIndex: 'props', }, { title: '说明', - dataIndex: 'desciption' + dataIndex: 'desciption', }, { title: '类型', - dataIndex: 'type' + dataIndex: 'type', }, { title: '默认值', - dataIndex: 'default' - } + dataIndex: 'default', + }, ]} dataSource={[ { props: 'menuOptions', desciption: '下拉操作的选项,格式为[{name:string,key:string}]', type: 'Array', - default: '必选' + default: '必选', }, { props: 'onMenuClick', desciption: '点击 menuitem 调用此函数,参数为 {item, key, keyPath}', type: 'Function', - default: '-' + default: '-', }, { props: 'buttonStyle', desciption: '按钮的样式', type: 'Object', - default: '-' + default: '-', }, { props: 'dropdownProps', desciption: '下拉菜单的参数,可参考antd的【Dropdown】组件', type: 'Object', - default: '-' - } - ]} /> + default: '-', + }, + ]} + /> diff --git a/src/routes/ui/ico.js b/src/routes/ui/ico.js index 1132e41..1aee521 100644 --- a/src/routes/ui/ico.js +++ b/src/routes/ui/ico.js @@ -5,42 +5,44 @@ import styles from './ico.less' const iconlist = ['Cherry', 'Cheese', 'Bread', 'Beer', 'Beet', 'Bacon', 'Banana', 'Asparagus', 'Apple'] -const IcoPage = () =>
    +const IcoPage = () =>
      {iconlist.map(item =>
    • {item}
    • )}
    -

    Props

    +

    Props

    -
    key} +
    key} pagination={false} bordered scroll={{ x: 800 }} columns={[ { title: '参数', - dataIndex: 'props' + dataIndex: 'props', }, { title: '说明', - dataIndex: 'desciption' + dataIndex: 'desciption', }, { title: '类型', - dataIndex: 'type' + dataIndex: 'type', }, { title: '默认值', - dataIndex: 'default' - } + dataIndex: 'default', + }, ]} dataSource={[ { props: 'type', desciption: '图标类型', type: 'String', - default: '-' - }]} /> + default: '-', + }]} + /> diff --git a/src/routes/ui/layer.js b/src/routes/ui/layer.js index 3eeaaa5..52513e9 100644 --- a/src/routes/ui/layer.js +++ b/src/routes/ui/layer.js @@ -1,48 +1,51 @@ import React from 'react' -import { Layer } from '../../components/ui' +// import { Layer } from '../../components/ui' import { Table, Row, Col, Button, Card } from 'antd' -import styles from './ico.less' +import './ico.less' -const IcoPage = () =>
    +const IcoPage = () =>
    - - + + -

    Props

    +

    Props

    -
    key} +
    key} pagination={false} bordered scroll={{ x: 800 }} columns={[ { title: '参数', - dataIndex: 'props' + dataIndex: 'props', }, { title: '说明', - dataIndex: 'desciption' + dataIndex: 'desciption', }, { title: '类型', - dataIndex: 'type' + dataIndex: 'type', }, { title: '默认值', - dataIndex: 'default' - } + dataIndex: 'default', + }, ]} dataSource={[ { props: 'type', desciption: '图标类型', type: 'String', - default: '-' - }]} /> + default: '-', + }, + ]} + /> diff --git a/src/routes/ui/search.js b/src/routes/ui/search.js index 3474a06..0b68cc5 100644 --- a/src/routes/ui/search.js +++ b/src/routes/ui/search.js @@ -2,87 +2,95 @@ import React from 'react' import { Search } from '../../components/ui' import { Table, Row, Col, Card } from 'antd' -const SearchPage = () =>
    +const SearchPage = () =>
    - + - - + + - - - + + + -

    Props

    +

    Props

    -
    key} +
    key} pagination={false} bordered scroll={{ x: 800 }} columns={[ { title: '参数', - dataIndex: 'props' + dataIndex: 'props', }, { title: '说明', - dataIndex: 'desciption' + dataIndex: 'desciption', }, { title: '类型', - dataIndex: 'type' + dataIndex: 'type', }, { title: '默认值', - dataIndex: 'default' - } + dataIndex: 'default', + }, ]} dataSource={[ { props: 'size', desciption: '设置Search大小,可选值为 【small】 【large】 或者不设', type: 'String', - default: '-' + default: '-', }, { props: 'select', desciption: '设置是否有选择器', type: 'Boolean', - default: 'false' + default: 'false', }, { props: 'selectOptions', desciption: '选择器的选项,格式为[{name:"",value:""}]或者[{value:""}]', type: 'Array', - default: '-' + default: '-', }, { props: 'selectProps', desciption: '选择器的属性,可参考antd的【Select】组件', type: 'Object', - default: '-' + default: '-', }, { props: 'onSearch', desciption: '点击搜索按钮, 按Enter键或者点击清除时的回调', type: 'Function({keyword:string,field:string})', - default: '-' - }]} /> + default: '-', + }, + ]} + /> diff --git a/src/routes/users.js b/src/routes/users.js index 93d2667..bd1ad14 100644 --- a/src/routes/users.js +++ b/src/routes/users.js @@ -16,37 +16,37 @@ function Users ({ location, dispatch, users, loading }) { onOk (data) { dispatch({ type: `users/${modalType}`, - payload: data + payload: data, }) }, onCancel () { dispatch({ - type: 'users/hideModal' + type: 'users/hideModal', }) - } + }, } const userListProps = { dataSource: list, loading, - pagination: pagination, + pagination, location, isMotion, onPageChange (page) { const { query, pathname } = location dispatch(routerRedux.push({ - pathname: pathname, + pathname, query: { ...query, page: page.current, - pageSize: page.pageSize - } + pageSize: page.pageSize, + }, })) }, onDeleteItem (id) { dispatch({ type: 'users/delete', - payload: id + payload: id, }) }, onEditItem (item) { @@ -54,10 +54,10 @@ function Users ({ location, dispatch, users, loading }) { type: 'users/showModal', payload: { modalType: 'update', - currentItem: item - } + currentItem: item, + }, }) - } + }, } const userSearchProps = { @@ -69,30 +69,30 @@ function Users ({ location, dispatch, users, loading }) { pathname: '/users', query: { field: fieldsValue.field, - keyword: fieldsValue.keyword - } + keyword: fieldsValue.keyword, + }, })) : dispatch(routerRedux.push({ - pathname: '/users' + pathname: '/users', })) }, onAdd () { dispatch({ type: 'users/showModal', payload: { - modalType: 'create' - } + modalType: 'create', + }, }) }, switchIsMotion () { - dispatch({type: 'users/switchIsMotion'}) - } + dispatch({ type: 'users/switchIsMotion' }) + }, } const UserModalGen = () => return ( -
    +
    @@ -103,7 +103,8 @@ function Users ({ location, dispatch, users, loading }) { Users.propTypes = { users: PropTypes.object, location: PropTypes.object, - dispatch: PropTypes.func + dispatch: PropTypes.func, + loading: PropTypes.bool, } -export default connect(({users, loading}) => ({users, loading: loading.models.user}))(Users) +export default connect(({ users, loading }) => ({ users, loading: loading.models.user }))(Users) diff --git a/src/services/app.js b/src/services/app.js index e062075..b0c19d1 100644 --- a/src/services/app.js +++ b/src/services/app.js @@ -3,20 +3,20 @@ import { request } from '../utils' export async function login (params) { return request('/api/login', { method: 'post', - data: params + data: params, }) } export async function logout (params) { return request('/api/logout', { method: 'post', - data: params + data: params, }) } export async function userInfo (params) { return request('/api/userInfo', { method: 'get', - data: params + data: params, }) } diff --git a/src/services/dashboard.js b/src/services/dashboard.js index ac549be..bd5e34f 100644 --- a/src/services/dashboard.js +++ b/src/services/dashboard.js @@ -4,7 +4,7 @@ export async function myCity (params) { return request('http://www.zuimeitianqi.com/zuimei/myCity', { method: 'get', cross: true, - data: params + data: params, }) } @@ -12,13 +12,13 @@ export async function queryWeather (params) { return request('http://www.zuimeitianqi.com/zuimei/queryWeather', { method: 'get', cross: true, - data: params + data: params, }) } export async function query (params) { return request('/api/dashboard', { method: 'get', - data: params + data: params, }) } diff --git a/src/services/users.js b/src/services/users.js index e10e1ba..2460eb1 100644 --- a/src/services/users.js +++ b/src/services/users.js @@ -3,27 +3,27 @@ import { request } from '../utils' export async function query (params) { return request('/api/users', { method: 'get', - data: params + data: params, }) } export async function create (params) { return request('/api/users', { method: 'post', - data: params + data: params, }) } export async function remove (params) { return request('/api/users', { method: 'delete', - data: params + data: params, }) } export async function update (params) { return request('/api/users', { method: 'put', - data: params + data: params, }) } diff --git a/src/theme.js b/src/theme.js index a165eab..7a97966 100644 --- a/src/theme.js +++ b/src/theme.js @@ -8,6 +8,6 @@ module.exports = () => { '@border-color-base': '#e5e5e5', '@menu-dark-bg': '#3e3e3e', '@text-color': '#666', - '@font-family': '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", SimSun, sans-serif' + '@font-family': '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", SimSun, sans-serif', } } diff --git a/src/utils/config.js b/src/utils/config.js index 6a71518..15a26f2 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -4,5 +4,5 @@ module.exports = { footerText: 'Ant Design Admin 版权所有 © 2016 由 zuiidea 支持', logoSrc: 'https://t.alipayobjects.com/images/rmsweb/T1B9hfXcdvXXXXXXXX.svg', logoText: 'Antd Admin', - needLogin: true + needLogin: true, } diff --git a/src/utils/index.js b/src/utils/index.js index 075b5a1..549ff48 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -2,13 +2,13 @@ import config from './config' import menu from './menu' import request from './request' import classnames from 'classnames' -import {color} from './theme' +import { color } from './theme' require('./mock.js') // 连字符转驼峰 String.prototype.hyphenToHump = function () { - return this.replace(/-(\w)/g, function () { - return arguments[1].toUpperCase() + return this.replace(/-(\w)/g, (...args) => { + return args[1].toUpperCase() }) } @@ -19,7 +19,7 @@ String.prototype.humpToHyphen = function () { // 日期格式化 Date.prototype.format = function (format) { - var o = { + const o = { 'M+': this.getMonth() + 1, 'd+': this.getDate(), 'h+': this.getHours(), @@ -27,14 +27,14 @@ Date.prototype.format = function (format) { 'm+': this.getMinutes(), 's+': this.getSeconds(), 'q+': Math.floor((this.getMonth() + 3) / 3), - 'S': this.getMilliseconds() + S: this.getMilliseconds(), } - if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length)) } - for (var k in o) { - if (new RegExp('(' + k + ')').test(format)) { - format = format.replace(RegExp.$1, RegExp.$1.length === 1 - ? o[k] - : ('00' + o[k]).substr(('' + o[k]).length)) + if (/(y+)/.test(format)) { + format = format.replace(RegExp.$1, `${this.getFullYear()}`.substr(4 - RegExp.$1.length)) + } + for (let k in o) { + if (new RegExp(`(${k})`).test(format)) { + format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : (`00${o[k]}`).substr(`${o[k]}`.length)) } } return format @@ -45,5 +45,5 @@ module.exports = { menu, request, color, - classnames + classnames, } diff --git a/src/utils/menu.js b/src/utils/menu.js index a5691f3..ae6e080 100644 --- a/src/utils/menu.js +++ b/src/utils/menu.js @@ -2,12 +2,12 @@ module.exports = [ { key: 'dashboard', name: '仪表盘', - icon: 'laptop' + icon: 'laptop', }, { key: 'users', name: '用户管理', - icon: 'user' + icon: 'user', }, { key: 'ui', @@ -17,21 +17,21 @@ module.exports = [ child: [ { key: 'ico', - name: 'Ico 图标' + name: 'Ico 图标', }, { key: 'search', - name: 'Search 搜索' + name: 'Search 搜索', }, { key: 'dropOption', - name: 'DropOption 下拉操作' + name: 'DropOption 下拉操作', }, { key: 'layer', - name: 'Layer 弹层' - } - ] + name: 'Layer 弹层', + }, + ], }, { key: 'navigation', @@ -40,7 +40,7 @@ module.exports = [ child: [ { key: 'navigation1', - name: '二级导航1' + name: '二级导航1', }, { key: 'navigation2', @@ -48,14 +48,14 @@ module.exports = [ child: [ { key: 'navigation21', - name: '三级导航1' + name: '三级导航1', }, { key: 'navigation22', - name: '三级导航2' - } - ] - } - ] - } + name: '三级导航2', + }, + ], + }, + ], + }, ] diff --git a/src/utils/mock.js b/src/utils/mock.js index 621ce71..385e30b 100644 --- a/src/utils/mock.js +++ b/src/utils/mock.js @@ -1,34 +1,43 @@ const Mock = require('mockjs') -const mockData = [require('../../mock/users'), require('../../mock/app'), require('../../mock/dashboard')] +const users = require('../../mock/users') +const app = require('../../mock/app') +const dashboard = require('../../mock/dashboard') +const mockData = [users, app, dashboard] function serialize (str) { let paramArray = str.split('&') let query = {} for (let i in paramArray) { - query[paramArray[i].split('=')[0]] = paramArray[i].split('=')[1] + if (Object.prototype.hasOwnProperty.call(paramArray, i)) { + query[paramArray[i].split('=')[0]] = paramArray[i].split('=')[1] + } } return query } for (let i in mockData) { - for (let key in mockData[i]) { - Mock.mock(eval('/' + key.split(' ')[1].replace(/\//g, '\\\/') + '/'), key.split(' ')[0].toLowerCase(), function (options) { - if (key.split(' ')[0].toLowerCase() == 'get') { - options.query = options.url.split('?')[1] - ? serialize(options.url.split('?')[1]) - : (options.body - ? serialize(options.body) - : {}) + if (Object.prototype.hasOwnProperty.call(mockData, i)) { + for (let key in mockData[i]) { + if (Object.prototype.hasOwnProperty.call(mockData[i], key)) { + Mock.mock(eval(`/${key.split(' ')[1].replace(/\//g, '\\/')}/`), key.split(' ')[0].toLowerCase(), (options) => { + if (key.split(' ')[0].toLowerCase() === 'get') { + if (options.url.split('?')[1]) { + options.query = serialize(options.url.split('?')[1]) + } else { + options.query = options.body ? serialize(options.body) : {} + } + } + let res = {} + let result = {} + res.json = function (data) { + result = data + } + mockData[i][key](options, res) + return result + }) } - let res = {} - let result = {} - res.json = function (data) { - result = data - } - mockData[i][key](options, res) - return result - }) + } } } -Mock.setup({timeout: '200-600'}) +Mock.setup({ timeout: '200-600' }) diff --git a/src/utils/mockStorge.js b/src/utils/mockStorge.js index c4a8487..62bb98d 100644 --- a/src/utils/mockStorge.js +++ b/src/utils/mockStorge.js @@ -7,7 +7,7 @@ export default function mockStorge (name, defaultValue) { ? JSON.parse(localStorage.getItem(key)) : defaultValue !localStorage.getItem(key) && localStorage.setItem(key, JSON.stringify(global[key])) - Watch.watch(global[key], function () { + Watch.watch(global[key], () => { localStorage.setItem(key, JSON.stringify(global[key])) }) return key diff --git a/src/utils/request.js b/src/utils/request.js index 94588b7..566ff54 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -3,18 +3,17 @@ import Ajax from 'robe-ajax' export default function request (url, options) { if (options.cross) { return Ajax.getJSON('http://query.yahooapis.com/v1/public/yql', { - q: "select * from json where url='" + url + '?' + Ajax.param(options.data) + "'", - format: 'json' - }) - } else { - return Ajax.ajax({ - url: url, - method: options.method || 'get', - data: options.data || {}, - processData: options.method === 'get', - dataType: 'JSON' - }).done((data) => { - return data + q: `select * from json where url='${url}?${Ajax.param(options.data)}'`, + format: 'json', }) } + return Ajax.ajax({ + url, + method: options.method || 'get', + data: options.data || {}, + processData: options.method === 'get', + dataType: 'JSON', + }).done((data) => { + return data + }) } diff --git a/src/utils/theme.js b/src/utils/theme.js index 85ed8b4..c25585c 100644 --- a/src/utils/theme.js +++ b/src/utils/theme.js @@ -9,6 +9,6 @@ module.exports = { borderBase: '#e5e5e5', borderSplit: '#f4f4f4', grass: '#d6fbb5', - sky: '#c1e0fc' - } + sky: '#c1e0fc', + }, } diff --git a/webpack.config.js b/webpack.config.js index 919b323..88576a1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,7 +4,7 @@ module.exports = function (webpackConfig, env) { webpackConfig.babel.plugins.push('transform-runtime') webpackConfig.babel.plugins.push(['import', { libraryName: 'antd', - style: true + style: true, }]) // Support hmr @@ -12,22 +12,22 @@ module.exports = function (webpackConfig, env) { webpackConfig.devtool = '#eval' webpackConfig.babel.plugins.push(['dva-hmr', { entries: [ - './src/index.js' - ] + './src/index.js', + ], }]) } else { webpackConfig.babel.plugins.push('dev-expression') - webpackConfig.entry = {index: './src/_index.js'} + webpackConfig.entry = { index: './src/_index.js' } } // Don't extract common.js and common.css - webpackConfig.plugins = webpackConfig.plugins.filter(function (plugin) { + webpackConfig.plugins = webpackConfig.plugins.filter((plugin) => { return !(plugin instanceof webpack.optimize.CommonsChunkPlugin) }) // Support CSS Modules // Parse all less files as css module. - webpackConfig.module.loaders.forEach(function (loader, index) { + webpackConfig.module.loaders.forEach((loader) => { if (typeof loader.test === 'function' && loader.test.toString().indexOf('\\.less$') > -1) { loader.include = /node_modules/ loader.test = /\.less$/