diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..710f153 --- /dev/null +++ b/.babelrc @@ -0,0 +1,22 @@ +{ + "presets": [ + "umi/babel" + ], + "plugins": [ + [ + "babel-plugin-module-resolver", + { + "alias": { + "components": "./src/components", + "utils": "./src/utils", + "config": "./src/utils/config", + "enums": "./src/utils/enums", + "services": "./src/services", + "models": "./src/models", + "routes": "./src/routes", + "themes": "./src/themes" + } + } + ] + ] +} diff --git a/.eslintrc b/.eslintrc index 343890d..efb2508 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,5 @@ { - "extends": "airbnb", + "extends": "umi", "rules": { "arrow-body-style": [0, "never"], "comma-dangle": [2, "always-multiline"], @@ -44,17 +44,5 @@ "react/no-danger": 0, "react/jsx-first-prop-new-line": 0, "react/jsx-filename-extension": 0 - }, - "parser": "babel-eslint", - "parserOptions": { - "sourceType": "module", - "ecmaVersion": 8, - "ecmaFeatures": { - "jsx": true, - "experimentalObjectRestSpread": true - } - }, - "settings": { - "import/resolver": "node" - } + } } diff --git a/.gitignore b/.gitignore index 4666114..d1c78d1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ dist node_modules yarn.lock npm-debug.log + # ide .idea @@ -9,3 +10,7 @@ npm-debug.log .DS_Store .AppleDouble .LSOverride + +# umi +.umi +.umi-production diff --git a/.roadhogrc.js b/.roadhogrc.js deleted file mode 100644 index 9b76d6f..0000000 --- a/.roadhogrc.js +++ /dev/null @@ -1,57 +0,0 @@ -const path = require('path') -const { version } = require('./package.json') - -const svgSpriteDirs = [ - path.resolve(__dirname, 'src/svg/'), - require.resolve('antd').replace(/index\.js$/, '') -] - -export default { - entry: 'src/index.js', - svgSpriteLoaderDirs: svgSpriteDirs, - theme: "./theme.config.js", - publicPath: `/${version}/`, - outputPath: `./dist/${version}`, - // 接口代理示例 - proxy: { - "/api/v1/weather": { - "target": "https://api.seniverse.com/", - "changeOrigin": true, - "pathRewrite": { "^/api/v1/weather": "/v3/weather" } - }, - // "/api/v2": { - // "target": "http://192.168.0.110", - // "changeOrigin": true, - // "pathRewrite": { "^/api/v2" : "/api/v2" } - // } - }, - env: { - development: { - extraBabelPlugins: [ - "dva-hmr", - "transform-runtime", - [ - "import", { - "libraryName": "antd", - "style": true - } - ] - ] - }, - production: { - extraBabelPlugins: [ - "transform-runtime", - [ - "import", { - "libraryName": "antd", - "style": true - } - ] - ] - } - }, - dllPlugin: { - exclude: ["babel-runtime", "roadhog", "cross-env"], - include: ["dva/router", "dva/saga", "dva/fetch"] - } -} diff --git a/.roadhogrc.mock.js b/.roadhogrc.mock.js deleted file mode 100644 index fc068f0..0000000 --- a/.roadhogrc.mock.js +++ /dev/null @@ -1,5 +0,0 @@ -const mock = {} -require('fs').readdirSync(require('path').join(__dirname + '/src/mock')).forEach(function(file) { - Object.assign(mock, require('./src/mock/' + file)) -}) -module.exports = mock diff --git a/.umirc.js b/.umirc.js new file mode 100644 index 0000000..5e176d2 --- /dev/null +++ b/.umirc.js @@ -0,0 +1,26 @@ + +export default { + plugins: [ + 'umi-plugin-dva', + [ + 'umi-plugin-routes', + { + exclude: [ + /model\.(j|t)sx?$/, + /service\.(j|t)sx?$/, + /models\//, + /components\//, + /services\//, + /chart\/Container\.js$/, + ], + }, + ], + [ + 'umi-plugin-dll', + { + exclude: [], + include: ["dva", "dva/router", "dva/saga", "dva/fetch", "antd/es"], + }, + ], + ], +} diff --git a/.umirc.mock.js b/.umirc.mock.js new file mode 100644 index 0000000..fb7e6fb --- /dev/null +++ b/.umirc.mock.js @@ -0,0 +1,8 @@ + +export default { + ...require('./mock/common'), + ...require('./mock/dashboard'), + ...require('./mock/menu'), + ...require('./mock/post'), + ...require('./mock/user'), +} diff --git a/.webpackrc.js b/.webpackrc.js new file mode 100644 index 0000000..8b4f277 --- /dev/null +++ b/.webpackrc.js @@ -0,0 +1,32 @@ +import { resolve } from 'path'; + +export default { + theme: "./theme.config.js", + // 接口代理示例 + proxy: { + "/api/v1/weather": { + "target": "https://api.seniverse.com/", + "changeOrigin": true, + "pathRewrite": { "^/api/v1/weather": "/v3/weather" } + }, + // "/api/v2": { + // "target": "http://192.168.0.110", + // "changeOrigin": true, + // "pathRewrite": { "^/api/v2" : "/api/v2" } + // } + }, + alias: { + themes: resolve(__dirname, './src/themes'), + components: resolve(__dirname,"./src/components"), + utils: resolve(__dirname,"./src/utils"), + config: resolve(__dirname,"./src/utils/config"), + enums: resolve(__dirname,"./src/utils/enums"), + services: resolve(__dirname,"./src/services"), + models: resolve(__dirname,"./src/models"), + routes: resolve(__dirname,"./src/routes"), + }, + urlLoaderExcludes: [ + /\.svg$/, + ], + ignoreMomentLocale: true, +} diff --git a/README.md b/README.md index 93cd021..78fc267 100644 --- a/README.md +++ b/README.md @@ -108,8 +108,13 @@ git clone https://github.com/zuiidea/antd-admin.git 进入目录安装依赖: ```bash +<<<<<<< HEAD #开始前请确保没有安装roadhog、webpack到NPM全局目录, 国内用户推荐yarn或者cnpm npm i 或者 yarn install +======= +#开始前请确保没有安装roadhog、webpack到NPM全局目录 +yarn install或者 npm i +>>>>>>> develop ``` 开发: @@ -117,7 +122,7 @@ npm i 或者 yarn install ```bash npm run build:dll #第一次npm run dev时需运行此命令,使开发时编译更快 npm run dev -打开 http://localhost:8000 +打开 http://localhost:8000 #端口在package.json中cross-env后加上 PORT=8000指定 ``` 构建: diff --git a/src/mock/common.js b/mock/common.js similarity index 96% rename from src/mock/common.js rename to mock/common.js index c8b79e9..1d5436d 100644 --- a/src/mock/common.js +++ b/mock/common.js @@ -1,5 +1,5 @@ const Mock = require('mockjs') -const config = require('../utils/config') +const config = require('../src/utils/config') const queryArray = (array, key, keyAlias = 'key') => { if (!(array instanceof Array)) { diff --git a/src/mock/dashboard.js b/mock/dashboard.js similarity index 96% rename from src/mock/dashboard.js rename to mock/dashboard.js index 788bc56..9f31a4a 100644 --- a/src/mock/dashboard.js +++ b/mock/dashboard.js @@ -1,7 +1,7 @@ -import { color } from '../utils/theme' +import { color } from '../src/utils/theme' const Mock = require('mockjs') -const config = require('../utils/config') +const config = require('../src/utils/config') const { apiPrefix } = config diff --git a/src/mock/menu.js b/mock/menu.js similarity index 100% rename from src/mock/menu.js rename to mock/menu.js diff --git a/src/mock/post.js b/mock/post.js similarity index 100% rename from src/mock/post.js rename to mock/post.js diff --git a/src/mock/user.js b/mock/user.js similarity index 99% rename from src/mock/user.js rename to mock/user.js index 6dd8a8f..c3ee292 100644 --- a/src/mock/user.js +++ b/mock/user.js @@ -1,6 +1,6 @@ const qs = require('qs') const Mock = require('mockjs') -const config = require('../utils/config') +const config = require('../src/utils/config') const { apiPrefix } = config diff --git a/package.json b/package.json index 3ce5820..383fd43 100644 --- a/package.json +++ b/package.json @@ -1,74 +1,65 @@ { "private": true, "name": "antd-admin", - "version": "4.3.9", + "version": "5.0.0-beta", "dependencies": { - "antd": "^3.5.1", + "@babel/polyfill": "^7.0.0-beta.44", + "antd": "^3.5.3", "axios": "^0.18.0", - "babel-polyfill": "^6.26.0", "classnames": "^2.2.5", - "cross-env": "^5.0.5", "d3-shape": "^1.2.0", + "draftjs-to-html": "^0.8.4", "draftjs-to-markdown": "^0.5.1", - "dva": "^2.2.3", - "dva-loading": "^2.0.0", + "dva-model-extend": "^0.1.2", "echarts": "^4.1.0", - "echarts-for-react": "^2.0.8", + "echarts-for-react": "^2.0.11", "echarts-gl": "^1.1.1", "echarts-liquidfill": "^2.0.0", - "ejs-loader": "^0.3.0", - "highcharts-exporting": "^0.1.2", - "highcharts-more": "^0.1.2", - "history": "^4.7.2", - "js-beautify": "^1.6.14", + "highcharts-exporting": "^0.1.7", + "highcharts-more": "^0.1.7", "jsonp": "^0.2.1", - "less-vars-to-js": "^1.1.2", - "lodash": "^4.17.4", - "mockjs": "^1.0.1-beta3", + "lodash.clonedeep": "^4.5.0", + "lodash.isequal": "^4.5.0", "nprogress": "^0.2.0", - "path-to-regexp": "^2.1.0", - "prop-types": "^15.5.10", - "qs": "^6.5.0", + "path-to-regexp": "^2.2.0", + "prop-types": "^15.6.1", + "qs": "^6.5.2", "query-string": "^5.1.1", - "rc-tween-one": "^1.7.3", - "react": "^16.3.2", - "react-countup": "^3.0.2", - "react-dom": "^16.3.2", + "rc-tween-one": "^1.7.8", + "react-adsense": "^0.0.5", + "react-countup": "^3.0.3", "react-draft-wysiwyg": "^1.12.13", "react-helmet": "^5.2.0", "react-highcharts": "^16.0.2", "recharts": "^1.0.0-beta.10" }, "devDependencies": { - "babel-eslint": "^8.1.0", "babel-plugin-dev-expression": "^0.2.1", - "babel-plugin-dva-hmr": "^0.4.0", - "babel-plugin-import": "^1.1.1", - "babel-plugin-transform-runtime": "^6.9.0", - "babel-runtime": "^6.9.2", - "copy-webpack-plugin": "^4.0.1", - "draftjs-to-html": "^0.8.1", - "dva-model-extend": "^0.1.1", - "eslint": "^4.1.1", - "eslint-config-airbnb": "^16.1.0", - "eslint-import-resolver-node": "^0.3.1", - "eslint-loader": "^2.0.0", - "eslint-plugin-import": "^2.6.1", - "eslint-plugin-jsx-a11y": "^6.0.2", - "eslint-plugin-react": "^7.1.0", - "html-webpack-plugin": "^3.2.0", - "redbox-react": "^1.2.10", - "roadhog": "1.3.1" + "babel-plugin-module-resolver": "^3.1.0", + "cross-env": "^5.1.6", + "eslint": "^4.19.1", + "eslint-config-umi": "^0.1.4", + "eslint-plugin-flowtype": "^2.47.1", + "eslint-plugin-import": "^2.12.0", + "eslint-plugin-jsx-a11y": "^6.0.3", + "eslint-plugin-react": "^7.8.2", + "js-beautify": "^1.7.5", + "less-vars-to-js": "^1.1.2", + "mockjs": "^1.0.1-beta3", + "svg-sprite-loader": "^3.7.3", + "umi": "^1.3.4", + "umi-plugin-dll": "^0.2.1", + "umi-plugin-dva": "^0.7.3", + "umi-plugin-routes": "^0.1.4" }, "pre-commit": [ "lint" ], "scripts": { - "dev": "cross-env BROWSER=none HOST=0.0.0.0 roadhog server", - "start": "roadhog buildDll && cross-env BROWSER=none HOST=0.0.0.0 roadhog server", + "analyze": "cross-env ANALYZE=1 BABELRC=1 umi build", + "start": "cross-env BABELRC=1 COMPILE_ON_DEMAND=none BROWSER=none HOST=0.0.0.0 umi dev", "lint": "eslint --fix --ext .js src", - "build": "roadhog build", - "build:dll": "roadhog buildDll", - "build:new": "node version && roadhog build" + "build": "cross-env BABELRC=1 umi build", + "test": "umi test" } } diff --git a/src/public/antd/iconfont.eot b/public/public/antd/iconfont.eot similarity index 100% rename from src/public/antd/iconfont.eot rename to public/public/antd/iconfont.eot diff --git a/src/public/antd/iconfont.svg b/public/public/antd/iconfont.svg similarity index 100% rename from src/public/antd/iconfont.svg rename to public/public/antd/iconfont.svg diff --git a/src/public/antd/iconfont.ttf b/public/public/antd/iconfont.ttf similarity index 100% rename from src/public/antd/iconfont.ttf rename to public/public/antd/iconfont.ttf diff --git a/src/public/antd/iconfont.woff b/public/public/antd/iconfont.woff similarity index 100% rename from src/public/antd/iconfont.woff rename to public/public/antd/iconfont.woff diff --git a/src/public/assets/data-1491837999815-H1_44Qtal.jpg b/public/public/assets/data-1491837999815-H1_44Qtal.jpg similarity index 100% rename from src/public/assets/data-1491837999815-H1_44Qtal.jpg rename to public/public/assets/data-1491837999815-H1_44Qtal.jpg diff --git a/src/public/assets/data-1493804606544-r1PBU7D1W.jpg b/public/public/assets/data-1493804606544-r1PBU7D1W.jpg similarity index 100% rename from src/public/assets/data-1493804606544-r1PBU7D1W.jpg rename to public/public/assets/data-1493804606544-r1PBU7D1W.jpg diff --git a/src/public/assets/data-1493804610896-SJoBIXPkW.jpg b/public/public/assets/data-1493804610896-SJoBIXPkW.jpg similarity index 100% rename from src/public/assets/data-1493804610896-SJoBIXPkW.jpg rename to public/public/assets/data-1493804610896-SJoBIXPkW.jpg diff --git a/src/public/iconfont.css b/public/public/iconfont.css similarity index 100% rename from src/public/iconfont.css rename to public/public/iconfont.css diff --git a/src/public/iconfont.eot b/public/public/iconfont.eot similarity index 100% rename from src/public/iconfont.eot rename to public/public/iconfont.eot diff --git a/src/public/iconfont.js b/public/public/iconfont.js similarity index 100% rename from src/public/iconfont.js rename to public/public/iconfont.js diff --git a/src/public/iconfont.svg b/public/public/iconfont.svg similarity index 100% rename from src/public/iconfont.svg rename to public/public/iconfont.svg diff --git a/src/public/iconfont.ttf b/public/public/iconfont.ttf similarity index 100% rename from src/public/iconfont.ttf rename to public/public/iconfont.ttf diff --git a/src/public/iconfont.woff b/public/public/iconfont.woff similarity index 100% rename from src/public/iconfont.woff rename to public/public/iconfont.woff diff --git a/src/public/logo.svg b/public/public/logo.svg similarity index 100% rename from src/public/logo.svg rename to public/public/logo.svg diff --git a/src/components/DataTable/DataTable.js b/src/components/DataTable/DataTable.js index 4b33461..3478a5f 100644 --- a/src/components/DataTable/DataTable.js +++ b/src/components/DataTable/DataTable.js @@ -2,7 +2,8 @@ import React from 'react' import PropTypes from 'prop-types' import { Table } from 'antd' import { request } from 'utils' -import lodash from 'lodash' +import cloneDeep from 'lodash.clonedeep' +import isEqual from 'lodash.isequal' import './DataTable.less' class DataTable extends React.Component { @@ -31,12 +32,12 @@ class DataTable extends React.Component { } } - componentWillReceiveProps (nextProps) { - const staticNextProps = lodash.cloneDeep(nextProps) + UNSAFE_componentWillReceiveProps (nextProps) { + const staticNextProps = cloneDeep(nextProps) delete staticNextProps.columns const { columns, ...otherProps } = this.props - if (!lodash.isEqual(staticNextProps, otherProps)) { + if (!isEqual(staticNextProps, otherProps)) { this.props = nextProps this.fetch() } diff --git a/src/components/Layout/Header.less b/src/components/Layout/Header.less index 9312ad2..9bfde84 100644 --- a/src/components/Layout/Header.less +++ b/src/components/Layout/Header.less @@ -1,92 +1,92 @@ -@import "~themes/vars"; - -.header { - :global { - .ant-menu-submenu-title { - height: 56px; - } - - .ant-menu-horizontal { - line-height: 56px; - - & > .ant-menu-submenu:hover { - color: #1890ff; - background-color: rgba(24, 144, 255, 0.15); - } - } - - .ant-menu { - border-bottom: none; - height: 56px; - } - - .ant-menu-horizontal > .ant-menu-submenu { - top: 0; - margin-top: 0; - } - - .ant-menu-horizontal > .ant-menu-item, - .ant-menu-horizontal > .ant-menu-submenu { - border-bottom: none; - } - - .ant-menu-horizontal > .ant-menu-item-active, - .ant-menu-horizontal > .ant-menu-item-open, - .ant-menu-horizontal > .ant-menu-item-selected, - .ant-menu-horizontal > .ant-menu-item:hover, - .ant-menu-horizontal > .ant-menu-submenu-active, - .ant-menu-horizontal > .ant-menu-submenu-open, - .ant-menu-horizontal > .ant-menu-submenu-selected, - .ant-menu-horizontal > .ant-menu-submenu:hover { - border-bottom: none; - } - } - box-shadow: @shadow-2; - position: relative; - display: flex; - justify-content: space-between; - height: 56px; - z-index: 9; - display: flex; - align-items: center; - background-color: #fff; - - .rightWarpper { - display: flex; - padding-right: 16px; - } - - .button { - width: 56px; - height: 56px; - line-height: 56px; - text-align: center; - font-size: 18px; - cursor: pointer; - transition: @transition-ease-in; - - &:hover { - color: @primary-color; - background-color: fade(@primary-color, 15%); - } - } -} - -.popovermenu { - width: 280px; - margin-left: 6px; - - :global .ant-popover-inner-content { - padding: 0; - - .ant-menu-inline .ant-menu-item, - .ant-menu-vertical .ant-menu-item { - border-right: 0; - } - - .ant-menu-inline .ant-menu-item-selected, - .ant-menu-inline .ant-menu-selected { - border-right: 0; - } - } -} +@import "~themes/vars.less"; + +.header { + :global { + .ant-menu-submenu-title { + height: 56px; + } + + .ant-menu-horizontal { + line-height: 56px; + + & > .ant-menu-submenu:hover { + color: #1890ff; + background-color: rgba(24, 144, 255, 0.15); + } + } + + .ant-menu { + border-bottom: none; + height: 56px; + } + + .ant-menu-horizontal > .ant-menu-submenu { + top: 0; + margin-top: 0; + } + + .ant-menu-horizontal > .ant-menu-item, + .ant-menu-horizontal > .ant-menu-submenu { + border-bottom: none; + } + + .ant-menu-horizontal > .ant-menu-item-active, + .ant-menu-horizontal > .ant-menu-item-open, + .ant-menu-horizontal > .ant-menu-item-selected, + .ant-menu-horizontal > .ant-menu-item:hover, + .ant-menu-horizontal > .ant-menu-submenu-active, + .ant-menu-horizontal > .ant-menu-submenu-open, + .ant-menu-horizontal > .ant-menu-submenu-selected, + .ant-menu-horizontal > .ant-menu-submenu:hover { + border-bottom: none; + } + } + box-shadow: @shadow-2; + position: relative; + display: flex; + justify-content: space-between; + height: 56px; + z-index: 9; + display: flex; + align-items: center; + background-color: #fff; + + .rightWarpper { + display: flex; + padding-right: 16px; + } + + .button { + width: 56px; + height: 56px; + line-height: 56px; + text-align: center; + font-size: 18px; + cursor: pointer; + transition: @transition-ease-in; + + &:hover { + color: @primary-color; + background-color: fade(@primary-color, 15%); + } + } +} + +.popovermenu { + width: 280px; + margin-left: 6px; + + :global .ant-popover-inner-content { + padding: 0; + + .ant-menu-inline .ant-menu-item, + .ant-menu-vertical .ant-menu-item { + border-right: 0; + } + + .ant-menu-inline .ant-menu-item-selected, + .ant-menu-inline .ant-menu-selected { + border-right: 0; + } + } +} diff --git a/src/components/Layout/Layout.less b/src/components/Layout/Layout.less index 0ca5382..7fb56e0 100644 --- a/src/components/Layout/Layout.less +++ b/src/components/Layout/Layout.less @@ -1,188 +1,188 @@ -@import "~themes/vars"; - -:global { - .ant-layout-header { - padding: 0; - } - - .ant-layout-sider { - transition: all 0.3s; - - .ant-menu-root { - height: ~"calc(100vh - 144px)"; - overflow-x: hidden; - border-right: none; - - &::-webkit-scrollbar-thumb { - background-color: transparent; - } - - &:hover { - &::-webkit-scrollbar-thumb { - background-color: rgba(0, 0, 0, 0.2); - } - } - } - - .ant-menu { - .ant-menu-item, - .ant-menu-submenu-title { - overflow: hidden; - white-space: normal; - } - } - } - - .ant-layout-content { - padding: 24px; - } - - .ant-layout-footer { - text-align: center; - padding: 0 24px; - height: 40px; - font-size: 12px; - line-height: 40px; - } - - .ant-back-top { - right: 50px; - } - - .ant-switch.ant-switch-large { - line-height: 24px; - height: 26px; - - &:after, - &:before { - width: 22px; - height: 22px; - } - - &.ant-switch-checked:after, - &.ant-switch-checked:before { - margin-left: -23px; - } - } - - .flex-vertical-center { - display: flex; - align-items: center; - } - - .ant-form-item { - margin-bottom: 12px; - } -} - - - -.logo { - height: 96px; - display: flex; - align-items: center; - justify-content: center; - - img { - width: 40px; - margin-right: 8px; - } - - span { - vertical-align: text-bottom; - font-size: 16px; - text-transform: uppercase; - display: inline-block; - font-weight: 700; - color: @primary-color; - white-space: nowrap; - :local { - animation: fadeLeftIn 500ms linear; - animation-fill-mode: both; - } - } -} - -.switchtheme { - width: 100%; - position: absolute; - bottom: 0; - height: 48px; - background-color: #fff; - border-top: solid 1px #f8f8f8; - display: flex; - justify-content: space-between; - align-items: center; - padding: 0 16px; - overflow: hidden; - z-index: 9; - transition: all 0.3s; - - span { - white-space: nowrap; - overflow: hidden; - font-size: 12px; - } - - :global { - .anticon { - min-width: 14px; - margin-right: 4px; - font-size: 14px; - } - } -} - -.bread { - margin-bottom: 24px; - - :global { - .ant-breadcrumb { - display: flex; - align-items: center; - } - } -} - -.dark { - .switchtheme { - background-color: #000d18; - border-color: #001629; - } -} - -.light { - :global { - .ant-layout-sider { - background: #fff; - } - } -} -@media (max-width: 767px) { - .bread { - margin-bottom: 12px; - } - - :global { - .ant-layout-content { - padding: 12px; - } - - .ant-back-top { - right: 20px; - bottom: 20px; - } - } -} - -@keyframes fadeLeftIn { - 0% { - transform: translateX(5px); - opacity: 0; - } - - 100% { - transform: translateX(0); - opacity: 1; - } -} +@import "~themes/vars.less"; + +:global { + .ant-layout-header { + padding: 0; + } + + .ant-layout-sider { + transition: all 0.3s; + + .ant-menu-root { + height: ~"calc(100vh - 144px)"; + overflow-x: hidden; + border-right: none; + + &::-webkit-scrollbar-thumb { + background-color: transparent; + } + + &:hover { + &::-webkit-scrollbar-thumb { + background-color: rgba(0, 0, 0, 0.2); + } + } + } + + .ant-menu { + .ant-menu-item, + .ant-menu-submenu-title { + overflow: hidden; + white-space: normal; + } + } + } + + .ant-layout-content { + padding: 24px; + } + + .ant-layout-footer { + text-align: center; + padding: 0 24px; + height: 40px; + font-size: 12px; + line-height: 40px; + } + + .ant-back-top { + right: 50px; + } + + .ant-switch.ant-switch-large { + line-height: 24px; + height: 26px; + + &:after, + &:before { + width: 22px; + height: 22px; + } + + &.ant-switch-checked:after, + &.ant-switch-checked:before { + margin-left: -23px; + } + } + + .flex-vertical-center { + display: flex; + align-items: center; + } + + .ant-form-item { + margin-bottom: 12px; + } +} + + + +.logo { + height: 96px; + display: flex; + align-items: center; + justify-content: center; + + img { + width: 40px; + margin-right: 8px; + } + + span { + vertical-align: text-bottom; + font-size: 16px; + text-transform: uppercase; + display: inline-block; + font-weight: 700; + color: @primary-color; + white-space: nowrap; + :local { + animation: fadeLeftIn 500ms linear; + animation-fill-mode: both; + } + } +} + +.switchtheme { + width: 100%; + position: absolute; + bottom: 0; + height: 48px; + background-color: #fff; + border-top: solid 1px #f8f8f8; + display: flex; + justify-content: space-between; + align-items: center; + padding: 0 16px; + overflow: hidden; + z-index: 9; + transition: all 0.3s; + + span { + white-space: nowrap; + overflow: hidden; + font-size: 12px; + } + + :global { + .anticon { + min-width: 14px; + margin-right: 4px; + font-size: 14px; + } + } +} + +.bread { + margin-bottom: 24px; + + :global { + .ant-breadcrumb { + display: flex; + align-items: center; + } + } +} + +.dark { + .switchtheme { + background-color: #000d18; + border-color: #001629; + } +} + +.light { + :global { + .ant-layout-sider { + background: #fff; + } + } +} +@media (max-width: 767px) { + .bread { + margin-bottom: 12px; + } + + :global { + .ant-layout-content { + padding: 12px; + } + + .ant-back-top { + right: 20px; + bottom: 20px; + } + } +} + +@keyframes fadeLeftIn { + 0% { + transform: translateX(5px); + opacity: 0; + } + + 100% { + transform: translateX(0); + opacity: 1; + } +} diff --git a/src/components/Layout/Menu.js b/src/components/Layout/Menu.js index 4d9ad6a..015c27f 100644 --- a/src/components/Layout/Menu.js +++ b/src/components/Layout/Menu.js @@ -5,6 +5,9 @@ import { Link } from 'react-router-dom' import { arrayToTree, queryArray } from 'utils' import pathToRegexp from 'path-to-regexp' +const { SubMenu } = Menu +let openKeysFlag = false + const Menus = ({ siderFold, darkTheme, navOpenKeys, changeOpenKeys, menu, location, }) => { @@ -20,7 +23,7 @@ const Menus = ({ levelMap[item.id] = item.mpid } return ( - {item.icon && } @@ -28,7 +31,7 @@ const Menus = ({ } > {getMenus(item.children, siderFoldN)} - + ) } return ( @@ -62,6 +65,7 @@ const Menus = ({ } const onOpenChange = (openKeys) => { + if (navOpenKeys.length) changeOpenKeys([]), openKeysFlag = true const latestOpenKey = openKeys.find(key => !navOpenKeys.includes(key)) const latestCloseKey = navOpenKeys.find(key => !openKeys.includes(key)) let nextOpenKeys = [] @@ -85,6 +89,7 @@ const Menus = ({ let defaultSelectedKeys for (let item of menu) { if (item.route && pathToRegexp(item.route).exec(location.pathname)) { + if (!navOpenKeys.length && item.mpid && !openKeysFlag) changeOpenKeys([String(item.mpid)]) currentMenu = item break } diff --git a/src/components/Page/Page.less b/src/components/Page/Page.less index 0a8156f..8355fb7 100644 --- a/src/components/Page/Page.less +++ b/src/components/Page/Page.less @@ -1,16 +1,16 @@ -@import "~themes/vars"; - -.contentInner{ - background: #fff; - padding: 24px; - box-shadow: @shadow-1; - min-height: ~"calc(100vh - 198px)"; - position: relative; -} - -@media (max-width: 767px) { - .contentInner { - padding: 12px; - min-height: ~"calc(100vh - 160px)"; - } -} +@import "~themes/vars.less"; + +.contentInner{ + background: #fff; + padding: 24px; + box-shadow: @shadow-1; + min-height: ~"calc(100vh - 198px)"; + position: relative; +} + +@media (max-width: 767px) { + .contentInner { + padding: 12px; + min-height: ~"calc(100vh - 160px)"; + } +} diff --git a/src/global.js b/src/global.js new file mode 100644 index 0000000..33b7c42 --- /dev/null +++ b/src/global.js @@ -0,0 +1 @@ +import '@babel/polyfill' diff --git a/src/index.js b/src/index.js deleted file mode 100644 index e880e17..0000000 --- a/src/index.js +++ /dev/null @@ -1,25 +0,0 @@ -import { message } from 'antd' -import dva from 'dva' -import createLoading from 'dva-loading' -import createHistory from 'history/createBrowserHistory' -import 'babel-polyfill' - -// 1. Initialize -const app = dva({ - ...createLoading({ - effects: true, - }), - history: createHistory(), - onError (error) { - message.error(error.message) - }, -}) - -// 2. Model -app.model(require('./models/app')) - -// 3. Router -app.router(require('./router')) - -// 4. Start -app.start('#root') diff --git a/src/routes/app.js b/src/layouts/app.js similarity index 99% rename from src/routes/app.js rename to src/layouts/app.js index 91bd1a8..adef0b7 100644 --- a/src/routes/app.js +++ b/src/layouts/app.js @@ -10,7 +10,7 @@ import { BackTop, Layout } from 'antd' import { classnames, config } from 'utils' import { Helmet } from 'react-helmet' import { withRouter } from 'dva/router' -import Error from './error' +import Error from '../pages/404' import '../themes/index.less' import './app.less' diff --git a/src/routes/app.less b/src/layouts/app.less similarity index 92% rename from src/routes/app.less rename to src/layouts/app.less index 32023d4..6af0944 100644 --- a/src/routes/app.less +++ b/src/layouts/app.less @@ -1,72 +1,72 @@ -@import "~themes/vars"; - -:global { - #nprogress { - pointer-events: none; - - .bar { - background: @primary-color; - position: fixed; - z-index: 1024; - top: 0; - left: 0; - right: 0; - width: 100%; - height: 2px; - } - - .peg { - display: block; - position: absolute; - right: 0; - width: 100px; - height: 100%; - box-shadow: 0 0 10px @primary-color,0 0 5px @primary-color; - opacity: 1.0; - transform: rotate(3deg) translate(0px,-4px); - } - - .spinner { - display: block; - position: fixed; - z-index: 1031; - top: 15px; - right: 15px; - } - - .spinner-icon { - width: 18px; - height: 18px; - box-sizing: border-box; - border: solid 2px transparent; - border-top-color: @primary-color; - border-left-color: @primary-color; - border-radius: 50%; - - :local { - animation: nprogress-spinner 400ms linear infinite; - } - } - } - - .nprogress-custom-parent { - overflow: hidden; - position: relative; - - #nprogress { - .bar, - .spinner { - position: absolute; - } - } - } -} -@keyframes nprogress-spinner { - 0% { - transform: rotate(0deg); - } - - 100% { - transform: rotate(360deg); - } -} +@import "~themes/vars.less"; + +:global { + #nprogress { + pointer-events: none; + + .bar { + background: @primary-color; + position: fixed; + z-index: 1024; + top: 0; + left: 0; + right: 0; + width: 100%; + height: 2px; + } + + .peg { + display: block; + position: absolute; + right: 0; + width: 100px; + height: 100%; + box-shadow: 0 0 10px @primary-color,0 0 5px @primary-color; + opacity: 1.0; + transform: rotate(3deg) translate(0px,-4px); + } + + .spinner { + display: block; + position: fixed; + z-index: 1031; + top: 15px; + right: 15px; + } + + .spinner-icon { + width: 18px; + height: 18px; + box-sizing: border-box; + border: solid 2px transparent; + border-top-color: @primary-color; + border-left-color: @primary-color; + border-radius: 50%; + + :local { + animation: nprogress-spinner 400ms linear infinite; + } + } + } + + .nprogress-custom-parent { + overflow: hidden; + position: relative; + + #nprogress { + .bar, + .spinner { + position: absolute; + } + } + } +} +@keyframes nprogress-spinner { + 0% { + transform: rotate(0deg); + } + + 100% { + transform: rotate(360deg); + } +} diff --git a/src/layouts/index.js b/src/layouts/index.js new file mode 100644 index 0000000..bcb7310 --- /dev/null +++ b/src/layouts/index.js @@ -0,0 +1,14 @@ +import { LocaleProvider } from 'antd' +import enUS from 'antd/lib/locale-provider/en_US' +import withRouter from 'umi/withRouter' +import App from './app' + +export default withRouter((props) => { + return ( + + + { props.children } + + + ) +}) diff --git a/src/models/app.js b/src/models/app.js index 49ad4ae..89c4c45 100644 --- a/src/models/app.js +++ b/src/models/app.js @@ -44,7 +44,7 @@ export default { type: 'updateState', payload: { locationPathname: location.pathname, - locationQuery: queryString.parse(location.search), + locationQuery: location.query, }, }) }) @@ -113,6 +113,16 @@ export default { }, { call, put }) { const data = yield call(logout, parse(payload)) if (data.success) { + yield put({ type: 'updateState', payload: { + user: {}, + permissions: { visit: [] }, + menu: [{ + id: 1, + icon: 'laptop', + name: 'Dashboard', + router: '/dashboard', + }], + }}) yield put({ type: 'query' }) } else { throw (data) diff --git a/src/routes/error/index.js b/src/pages/404.js similarity index 88% rename from src/routes/error/index.js rename to src/pages/404.js index caa83ee..8b8f870 100644 --- a/src/routes/error/index.js +++ b/src/pages/404.js @@ -1,7 +1,7 @@ import React from 'react' import { Icon } from 'antd' import { Page } from 'components' -import styles from './index.less' +import styles from './404.less' const Error = () => (
diff --git a/src/routes/error/index.less b/src/pages/404.less similarity index 100% rename from src/routes/error/index.less rename to src/pages/404.less diff --git a/src/routes/UIElement/dataTable/index.js b/src/pages/UIElement/dataTable/index.js similarity index 100% rename from src/routes/UIElement/dataTable/index.js rename to src/pages/UIElement/dataTable/index.js diff --git a/src/routes/UIElement/dropOption/index.js b/src/pages/UIElement/dropOption/index.js similarity index 100% rename from src/routes/UIElement/dropOption/index.js rename to src/pages/UIElement/dropOption/index.js diff --git a/src/routes/UIElement/editor/index.js b/src/pages/UIElement/editor/index.js similarity index 100% rename from src/routes/UIElement/editor/index.js rename to src/pages/UIElement/editor/index.js diff --git a/src/routes/UIElement/iconfont/emoji.js b/src/pages/UIElement/iconfont/emoji.js similarity index 100% rename from src/routes/UIElement/iconfont/emoji.js rename to src/pages/UIElement/iconfont/emoji.js diff --git a/src/routes/UIElement/iconfont/index.js b/src/pages/UIElement/iconfont/index.js similarity index 100% rename from src/routes/UIElement/iconfont/index.js rename to src/pages/UIElement/iconfont/index.js diff --git a/src/routes/UIElement/iconfont/index.less b/src/pages/UIElement/iconfont/index.less similarity index 100% rename from src/routes/UIElement/iconfont/index.less rename to src/pages/UIElement/iconfont/index.less diff --git a/src/routes/UIElement/layer/index.js b/src/pages/UIElement/layer/index.js similarity index 100% rename from src/routes/UIElement/layer/index.js rename to src/pages/UIElement/layer/index.js diff --git a/src/routes/UIElement/search/index.js b/src/pages/UIElement/search/index.js similarity index 100% rename from src/routes/UIElement/search/index.js rename to src/pages/UIElement/search/index.js diff --git a/src/routes/chart/Container.js b/src/pages/chart/Container.js similarity index 100% rename from src/routes/chart/Container.js rename to src/pages/chart/Container.js diff --git a/src/routes/chart/Container.less b/src/pages/chart/Container.less similarity index 100% rename from src/routes/chart/Container.less rename to src/pages/chart/Container.less diff --git a/src/routes/chart/ECharts/AirportCoordComponent.js b/src/pages/chart/ECharts/AirportCoordComponent.js similarity index 100% rename from src/routes/chart/ECharts/AirportCoordComponent.js rename to src/pages/chart/ECharts/AirportCoordComponent.js diff --git a/src/routes/chart/ECharts/BubbleGradientComponent.js b/src/pages/chart/ECharts/BubbleGradientComponent.js similarity index 100% rename from src/routes/chart/ECharts/BubbleGradientComponent.js rename to src/pages/chart/ECharts/BubbleGradientComponent.js diff --git a/src/routes/chart/ECharts/CalendarComponent.js b/src/pages/chart/ECharts/CalendarComponent.js similarity index 100% rename from src/routes/chart/ECharts/CalendarComponent.js rename to src/pages/chart/ECharts/CalendarComponent.js diff --git a/src/routes/chart/ECharts/ChartAPIComponent.js b/src/pages/chart/ECharts/ChartAPIComponent.js similarity index 100% rename from src/routes/chart/ECharts/ChartAPIComponent.js rename to src/pages/chart/ECharts/ChartAPIComponent.js diff --git a/src/routes/chart/ECharts/ChartShowLoadingComponent.js b/src/pages/chart/ECharts/ChartShowLoadingComponent.js similarity index 100% rename from src/routes/chart/ECharts/ChartShowLoadingComponent.js rename to src/pages/chart/ECharts/ChartShowLoadingComponent.js diff --git a/src/routes/chart/ECharts/ChartWithEventComponent.js b/src/pages/chart/ECharts/ChartWithEventComponent.js similarity index 100% rename from src/routes/chart/ECharts/ChartWithEventComponent.js rename to src/pages/chart/ECharts/ChartWithEventComponent.js diff --git a/src/routes/chart/ECharts/DynamicChartComponent.js b/src/pages/chart/ECharts/DynamicChartComponent.js similarity index 100% rename from src/routes/chart/ECharts/DynamicChartComponent.js rename to src/pages/chart/ECharts/DynamicChartComponent.js diff --git a/src/routes/chart/ECharts/EchartsComponent.js b/src/pages/chart/ECharts/EchartsComponent.js similarity index 100% rename from src/routes/chart/ECharts/EchartsComponent.js rename to src/pages/chart/ECharts/EchartsComponent.js diff --git a/src/routes/chart/ECharts/GCalendarComponent.js b/src/pages/chart/ECharts/GCalendarComponent.js similarity index 100% rename from src/routes/chart/ECharts/GCalendarComponent.js rename to src/pages/chart/ECharts/GCalendarComponent.js diff --git a/src/routes/chart/ECharts/GaugeComponent.js b/src/pages/chart/ECharts/GaugeComponent.js similarity index 100% rename from src/routes/chart/ECharts/GaugeComponent.js rename to src/pages/chart/ECharts/GaugeComponent.js diff --git a/src/routes/chart/ECharts/GraphComponent.js b/src/pages/chart/ECharts/GraphComponent.js similarity index 100% rename from src/routes/chart/ECharts/GraphComponent.js rename to src/pages/chart/ECharts/GraphComponent.js diff --git a/src/routes/chart/ECharts/LiquidfillComponent.js b/src/pages/chart/ECharts/LiquidfillComponent.js similarity index 100% rename from src/routes/chart/ECharts/LiquidfillComponent.js rename to src/pages/chart/ECharts/LiquidfillComponent.js diff --git a/src/routes/chart/ECharts/LunarCalendarComponent.js b/src/pages/chart/ECharts/LunarCalendarComponent.js similarity index 100% rename from src/routes/chart/ECharts/LunarCalendarComponent.js rename to src/pages/chart/ECharts/LunarCalendarComponent.js diff --git a/src/routes/chart/ECharts/MainPageComponent.js b/src/pages/chart/ECharts/MainPageComponent.js similarity index 100% rename from src/routes/chart/ECharts/MainPageComponent.js rename to src/pages/chart/ECharts/MainPageComponent.js diff --git a/src/routes/chart/ECharts/MapChartComponent.js b/src/pages/chart/ECharts/MapChartComponent.js similarity index 100% rename from src/routes/chart/ECharts/MapChartComponent.js rename to src/pages/chart/ECharts/MapChartComponent.js diff --git a/src/routes/chart/ECharts/ModuleLoadChartComponent.js b/src/pages/chart/ECharts/ModuleLoadChartComponent.js similarity index 100% rename from src/routes/chart/ECharts/ModuleLoadChartComponent.js rename to src/pages/chart/ECharts/ModuleLoadChartComponent.js diff --git a/src/routes/chart/ECharts/MoonComponent.js b/src/pages/chart/ECharts/MoonComponent.js similarity index 100% rename from src/routes/chart/ECharts/MoonComponent.js rename to src/pages/chart/ECharts/MoonComponent.js diff --git a/src/routes/chart/ECharts/SimpleChartComponent.js b/src/pages/chart/ECharts/SimpleChartComponent.js similarity index 100% rename from src/routes/chart/ECharts/SimpleChartComponent.js rename to src/pages/chart/ECharts/SimpleChartComponent.js diff --git a/src/routes/chart/ECharts/ThemeChartComponent.js b/src/pages/chart/ECharts/ThemeChartComponent.js similarity index 100% rename from src/routes/chart/ECharts/ThemeChartComponent.js rename to src/pages/chart/ECharts/ThemeChartComponent.js diff --git a/src/routes/chart/ECharts/TransparentBar3DComPonent.js b/src/pages/chart/ECharts/TransparentBar3DComPonent.js similarity index 100% rename from src/routes/chart/ECharts/TransparentBar3DComPonent.js rename to src/pages/chart/ECharts/TransparentBar3DComPonent.js diff --git a/src/routes/chart/ECharts/TreemapComponent.js b/src/pages/chart/ECharts/TreemapComponent.js similarity index 100% rename from src/routes/chart/ECharts/TreemapComponent.js rename to src/pages/chart/ECharts/TreemapComponent.js diff --git a/src/routes/chart/ECharts/index.js b/src/pages/chart/ECharts/page.js similarity index 98% rename from src/routes/chart/ECharts/index.js rename to src/pages/chart/ECharts/page.js index 120260c..35f2986 100644 --- a/src/routes/chart/ECharts/index.js +++ b/src/pages/chart/ECharts/page.js @@ -2,7 +2,7 @@ import React from 'react' import { Radio } from 'antd' import { Page } from 'components' import EchartsComponent from './EchartsComponent' -import styles from './index.less' +import styles from './page.less' const RadioGroup = Radio.Group diff --git a/src/routes/chart/ECharts/index.less b/src/pages/chart/ECharts/page.less similarity index 100% rename from src/routes/chart/ECharts/index.less rename to src/pages/chart/ECharts/page.less diff --git a/src/routes/chart/ECharts/theme/macarons.js b/src/pages/chart/ECharts/theme/macarons.js similarity index 96% rename from src/routes/chart/ECharts/theme/macarons.js rename to src/pages/chart/ECharts/theme/macarons.js index 73fc10d..64da22d 100644 --- a/src/routes/chart/ECharts/theme/macarons.js +++ b/src/pages/chart/ECharts/theme/macarons.js @@ -1,7 +1,7 @@ (function (root, factory) { - if (typeof define === 'function' && define.amd) { + if (typeof define === 'function' && define.amd) { // eslint-disable-line // AMD. Register as an anonymous module. - define(['exports', 'echarts'], factory) + define(['exports', 'echarts'], factory) // eslint-disable-line } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') { // CommonJS factory(exports, require('echarts')) diff --git a/src/routes/chart/ECharts/theme/shine.js b/src/pages/chart/ECharts/theme/shine.js similarity index 95% rename from src/routes/chart/ECharts/theme/shine.js rename to src/pages/chart/ECharts/theme/shine.js index 027fb4e..9d342ab 100644 --- a/src/routes/chart/ECharts/theme/shine.js +++ b/src/pages/chart/ECharts/theme/shine.js @@ -1,7 +1,7 @@ (function (root, factory) { - if (typeof define === 'function' && define.amd) { + if (typeof define === 'function' && define.amd) { // eslint-disable-line // AMD. Register as an anonymous module. - define(['exports', 'echarts'], factory) + define(['exports', 'echarts'], factory) // eslint-disable-line } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') { // CommonJS factory(exports, require('echarts')) diff --git a/src/routes/chart/Recharts/AreaChartComponent.js b/src/pages/chart/Recharts/AreaChartComponent.js similarity index 100% rename from src/routes/chart/Recharts/AreaChartComponent.js rename to src/pages/chart/Recharts/AreaChartComponent.js diff --git a/src/routes/chart/Recharts/BarChartComponent.js b/src/pages/chart/Recharts/BarChartComponent.js similarity index 100% rename from src/routes/chart/Recharts/BarChartComponent.js rename to src/pages/chart/Recharts/BarChartComponent.js diff --git a/src/routes/chart/Recharts/Container.js b/src/pages/chart/Recharts/Container.js similarity index 100% rename from src/routes/chart/Recharts/Container.js rename to src/pages/chart/Recharts/Container.js diff --git a/src/routes/chart/Recharts/Container.less b/src/pages/chart/Recharts/Container.less similarity index 100% rename from src/routes/chart/Recharts/Container.less rename to src/pages/chart/Recharts/Container.less diff --git a/src/routes/chart/Recharts/LineChartComponent.js b/src/pages/chart/Recharts/LineChartComponent.js similarity index 100% rename from src/routes/chart/Recharts/LineChartComponent.js rename to src/pages/chart/Recharts/LineChartComponent.js diff --git a/src/routes/chart/Recharts/ReChartsComponent.js b/src/pages/chart/Recharts/ReChartsComponent.js similarity index 100% rename from src/routes/chart/Recharts/ReChartsComponent.js rename to src/pages/chart/Recharts/ReChartsComponent.js diff --git a/src/routes/chart/Recharts/index.js b/src/pages/chart/Recharts/page.js similarity index 96% rename from src/routes/chart/Recharts/index.js rename to src/pages/chart/Recharts/page.js index 32a0990..0bd0f9f 100644 --- a/src/routes/chart/Recharts/index.js +++ b/src/pages/chart/Recharts/page.js @@ -2,7 +2,7 @@ import React from 'react' import { Radio } from 'antd' import { Page } from 'components' import ReChartsComponent from './ReChartsComponent' -import styles from './index.less' +import styles from './page.less' const RadioGroup = Radio.Group diff --git a/src/routes/chart/Recharts/index.less b/src/pages/chart/Recharts/page.less similarity index 100% rename from src/routes/chart/Recharts/index.less rename to src/pages/chart/Recharts/page.less diff --git a/src/routes/chart/highCharts/HighChartsComponent.js b/src/pages/chart/highCharts/HighChartsComponent.js similarity index 100% rename from src/routes/chart/highCharts/HighChartsComponent.js rename to src/pages/chart/highCharts/HighChartsComponent.js diff --git a/src/routes/chart/highCharts/HighMoreComponent.js b/src/pages/chart/highCharts/HighMoreComponent.js similarity index 71% rename from src/routes/chart/highCharts/HighMoreComponent.js rename to src/pages/chart/highCharts/HighMoreComponent.js index e8f971c..2f310d4 100644 --- a/src/routes/chart/highCharts/HighMoreComponent.js +++ b/src/pages/chart/highCharts/HighMoreComponent.js @@ -1,10 +1,11 @@ import React from 'react' import ReactHighcharts from 'react-highcharts' -import highchartsMore from 'highcharts-more' -import highchartsExporting from 'highcharts-exporting' +import HighchartsExporting from 'highcharts-exporting' +import HighchartsMore from 'highcharts-more' -highchartsMore(ReactHighcharts.Highcharts) -highchartsExporting(ReactHighcharts.Highcharts) + +HighchartsMore(ReactHighcharts.Highcharts) +HighchartsExporting(ReactHighcharts.Highcharts) const config = { chart: { diff --git a/src/routes/chart/highCharts/HighmapsComponent.js b/src/pages/chart/highCharts/HighmapsComponent.js similarity index 100% rename from src/routes/chart/highCharts/HighmapsComponent.js rename to src/pages/chart/highCharts/HighmapsComponent.js diff --git a/src/routes/chart/highCharts/HighstockComponent.js b/src/pages/chart/highCharts/HighstockComponent.js similarity index 100% rename from src/routes/chart/highCharts/HighstockComponent.js rename to src/pages/chart/highCharts/HighstockComponent.js diff --git a/src/routes/chart/highCharts/mapdata/europe.js b/src/pages/chart/highCharts/mapdata/europe.js similarity index 100% rename from src/routes/chart/highCharts/mapdata/europe.js rename to src/pages/chart/highCharts/mapdata/europe.js diff --git a/src/routes/chart/highCharts/index.js b/src/pages/chart/highCharts/page.js similarity index 96% rename from src/routes/chart/highCharts/index.js rename to src/pages/chart/highCharts/page.js index 7941c2f..06ea85a 100644 --- a/src/routes/chart/highCharts/index.js +++ b/src/pages/chart/highCharts/page.js @@ -2,7 +2,7 @@ import React from 'react' import { Radio } from 'antd' import { Page } from 'components' import HighChartsComponent from './HighChartsComponent' -import styles from './index.less' +import styles from './page.less' const RadioGroup = Radio.Group diff --git a/src/routes/chart/highCharts/index.less b/src/pages/chart/highCharts/page.less similarity index 100% rename from src/routes/chart/highCharts/index.less rename to src/pages/chart/highCharts/page.less diff --git a/src/routes/dashboard/components/browser.js b/src/pages/dashboard/components/browser.js similarity index 100% rename from src/routes/dashboard/components/browser.js rename to src/pages/dashboard/components/browser.js diff --git a/src/routes/dashboard/components/browser.less b/src/pages/dashboard/components/browser.less similarity index 100% rename from src/routes/dashboard/components/browser.less rename to src/pages/dashboard/components/browser.less diff --git a/src/routes/dashboard/components/comments.js b/src/pages/dashboard/components/comments.js similarity index 100% rename from src/routes/dashboard/components/comments.js rename to src/pages/dashboard/components/comments.js diff --git a/src/routes/dashboard/components/comments.less b/src/pages/dashboard/components/comments.less similarity index 100% rename from src/routes/dashboard/components/comments.less rename to src/pages/dashboard/components/comments.less diff --git a/src/routes/dashboard/components/completed.js b/src/pages/dashboard/components/completed.js similarity index 100% rename from src/routes/dashboard/components/completed.js rename to src/pages/dashboard/components/completed.js diff --git a/src/routes/dashboard/components/completed.less b/src/pages/dashboard/components/completed.less similarity index 100% rename from src/routes/dashboard/components/completed.less rename to src/pages/dashboard/components/completed.less diff --git a/src/routes/dashboard/components/cpu.js b/src/pages/dashboard/components/cpu.js similarity index 100% rename from src/routes/dashboard/components/cpu.js rename to src/pages/dashboard/components/cpu.js diff --git a/src/routes/dashboard/components/cpu.less b/src/pages/dashboard/components/cpu.less similarity index 100% rename from src/routes/dashboard/components/cpu.less rename to src/pages/dashboard/components/cpu.less diff --git a/src/routes/dashboard/components/index.js b/src/pages/dashboard/components/index.js similarity index 100% rename from src/routes/dashboard/components/index.js rename to src/pages/dashboard/components/index.js diff --git a/src/routes/dashboard/components/numberCard.js b/src/pages/dashboard/components/numberCard.js similarity index 100% rename from src/routes/dashboard/components/numberCard.js rename to src/pages/dashboard/components/numberCard.js diff --git a/src/routes/dashboard/components/numberCard.less b/src/pages/dashboard/components/numberCard.less similarity index 100% rename from src/routes/dashboard/components/numberCard.less rename to src/pages/dashboard/components/numberCard.less diff --git a/src/routes/dashboard/components/quote.js b/src/pages/dashboard/components/quote.js similarity index 100% rename from src/routes/dashboard/components/quote.js rename to src/pages/dashboard/components/quote.js diff --git a/src/routes/dashboard/components/quote.less b/src/pages/dashboard/components/quote.less similarity index 100% rename from src/routes/dashboard/components/quote.less rename to src/pages/dashboard/components/quote.less diff --git a/src/routes/dashboard/components/recentSales.js b/src/pages/dashboard/components/recentSales.js similarity index 100% rename from src/routes/dashboard/components/recentSales.js rename to src/pages/dashboard/components/recentSales.js diff --git a/src/routes/dashboard/components/recentSales.less b/src/pages/dashboard/components/recentSales.less similarity index 100% rename from src/routes/dashboard/components/recentSales.less rename to src/pages/dashboard/components/recentSales.less diff --git a/src/routes/dashboard/components/sales.js b/src/pages/dashboard/components/sales.js similarity index 100% rename from src/routes/dashboard/components/sales.js rename to src/pages/dashboard/components/sales.js diff --git a/src/routes/dashboard/components/sales.less b/src/pages/dashboard/components/sales.less similarity index 100% rename from src/routes/dashboard/components/sales.less rename to src/pages/dashboard/components/sales.less diff --git a/src/routes/dashboard/components/user-background.png b/src/pages/dashboard/components/user-background.png similarity index 100% rename from src/routes/dashboard/components/user-background.png rename to src/pages/dashboard/components/user-background.png diff --git a/src/routes/dashboard/components/user.js b/src/pages/dashboard/components/user.js similarity index 100% rename from src/routes/dashboard/components/user.js rename to src/pages/dashboard/components/user.js diff --git a/src/routes/dashboard/components/user.less b/src/pages/dashboard/components/user.less similarity index 100% rename from src/routes/dashboard/components/user.less rename to src/pages/dashboard/components/user.less diff --git a/src/routes/dashboard/components/weather.js b/src/pages/dashboard/components/weather.js similarity index 100% rename from src/routes/dashboard/components/weather.js rename to src/pages/dashboard/components/weather.js diff --git a/src/routes/dashboard/components/weather.less b/src/pages/dashboard/components/weather.less similarity index 100% rename from src/routes/dashboard/components/weather.less rename to src/pages/dashboard/components/weather.less diff --git a/src/routes/dashboard/index.js b/src/pages/dashboard/index.js similarity index 100% rename from src/routes/dashboard/index.js rename to src/pages/dashboard/index.js diff --git a/src/routes/dashboard/index.less b/src/pages/dashboard/index.less similarity index 94% rename from src/routes/dashboard/index.less rename to src/pages/dashboard/index.less index ebf4401..ac6c58e 100644 --- a/src/routes/dashboard/index.less +++ b/src/pages/dashboard/index.less @@ -9,7 +9,6 @@ } } .ant-card-body{ - overflow-y: scroll; overflow-x: hidden; } } diff --git a/src/models/dashboard.js b/src/pages/dashboard/model.js similarity index 92% rename from src/models/dashboard.js rename to src/pages/dashboard/model.js index 798377a..0a4c3e7 100644 --- a/src/models/dashboard.js +++ b/src/pages/dashboard/model.js @@ -1,8 +1,8 @@ import { parse } from 'qs' import modelExtend from 'dva-model-extend' -import { query } from 'services/dashboard' -import { model } from 'models/common' -import * as weatherService from 'services/weather' +import { query } from './services/dashboard' +import { model } from 'utils/model' +import * as weatherService from './services/weather' export default modelExtend(model, { namespace: 'dashboard', diff --git a/src/services/dashboard.js b/src/pages/dashboard/services/dashboard.js similarity index 100% rename from src/services/dashboard.js rename to src/pages/dashboard/services/dashboard.js diff --git a/src/services/weather.js b/src/pages/dashboard/services/weather.js similarity index 100% rename from src/services/weather.js rename to src/pages/dashboard/services/weather.js diff --git a/src/entry.ejs b/src/pages/document.ejs similarity index 71% rename from src/entry.ejs rename to src/pages/document.ejs index 2e149a9..de5e243 100644 --- a/src/entry.ejs +++ b/src/pages/document.ejs @@ -1,25 +1,19 @@ -<% htmlWebpackPlugin.options.headScripts = htmlWebpackPlugin.options.headScripts || [] %> - - - - - - - - - antd admin - - <% for (item of htmlWebpackPlugin.options.headScripts) { %> - - <% } %> - - - -
- - - - + + + + + + + + antd admin + + + + +
+ + + diff --git a/src/pages/index.js b/src/pages/index.js new file mode 100644 index 0000000..30f08c2 --- /dev/null +++ b/src/pages/index.js @@ -0,0 +1,3 @@ +import Redirect from 'umi/redirect' + +export default () => diff --git a/src/routes/login/index.js b/src/pages/login/index.js similarity index 100% rename from src/routes/login/index.js rename to src/pages/login/index.js diff --git a/src/routes/login/index.less b/src/pages/login/index.less similarity index 100% rename from src/routes/login/index.less rename to src/pages/login/index.less diff --git a/src/models/login.js b/src/pages/login/model.js similarity index 93% rename from src/models/login.js rename to src/pages/login/model.js index a40576f..4e0ce9e 100644 --- a/src/models/login.js +++ b/src/pages/login/model.js @@ -1,5 +1,5 @@ import { routerRedux } from 'dva/router' -import { login } from 'services/login' +import { login } from './service' export default { namespace: 'login', diff --git a/src/services/login.js b/src/pages/login/service.js similarity index 100% rename from src/services/login.js rename to src/pages/login/service.js diff --git a/src/routes/post/List.js b/src/pages/post/components/List.js similarity index 100% rename from src/routes/post/List.js rename to src/pages/post/components/List.js diff --git a/src/routes/post/List.less b/src/pages/post/components/List.less similarity index 100% rename from src/routes/post/List.less rename to src/pages/post/components/List.less diff --git a/src/routes/post/index.js b/src/pages/post/index.js similarity index 95% rename from src/routes/post/index.js rename to src/pages/post/index.js index 87e39ed..47b87a2 100644 --- a/src/routes/post/index.js +++ b/src/pages/post/index.js @@ -5,7 +5,7 @@ import { Tabs } from 'antd' import { routerRedux } from 'dva/router' import queryString from 'query-string' import { Page } from 'components' -import List from './List' +import List from './components/List' const { TabPane } = Tabs @@ -19,7 +19,6 @@ const Index = ({ post, dispatch, loading, location, }) => { const { list, pagination } = post - location.query = queryString.parse(location.search) const { query, pathname } = location const listProps = { diff --git a/src/models/post.js b/src/pages/post/model.js similarity index 83% rename from src/models/post.js rename to src/pages/post/model.js index 797dcf5..36d764d 100644 --- a/src/models/post.js +++ b/src/pages/post/model.js @@ -1,7 +1,6 @@ import modelExtend from 'dva-model-extend' -import { query } from 'services/posts' -import { pageModel } from 'models/common' -import queryString from 'query-string' +import { query } from './service' +import { pageModel } from 'utils/model' export default modelExtend(pageModel, { @@ -15,7 +14,7 @@ export default modelExtend(pageModel, { type: 'query', payload: { status: 2, - ...queryString.parse(location.search), + ...location.query, }, }) } diff --git a/src/services/posts.js b/src/pages/post/service.js similarity index 100% rename from src/services/posts.js rename to src/pages/post/service.js diff --git a/src/routes/request/index.js b/src/pages/request/index.js similarity index 100% rename from src/routes/request/index.js rename to src/pages/request/index.js diff --git a/src/routes/request/index.less b/src/pages/request/index.less similarity index 100% rename from src/routes/request/index.less rename to src/pages/request/index.less diff --git a/src/routes/user/detail/index.js b/src/pages/user/$id/index.js similarity index 100% rename from src/routes/user/detail/index.js rename to src/pages/user/$id/index.js diff --git a/src/routes/user/detail/index.less b/src/pages/user/$id/index.less similarity index 100% rename from src/routes/user/detail/index.less rename to src/pages/user/$id/index.less diff --git a/src/models/user/detail.js b/src/pages/user/$id/models/detail.js similarity index 100% rename from src/models/user/detail.js rename to src/pages/user/$id/models/detail.js diff --git a/src/routes/user/Filter.js b/src/pages/user/components/Filter.js similarity index 99% rename from src/routes/user/Filter.js rename to src/pages/user/components/Filter.js index 3a02ff9..9b82bad 100644 --- a/src/routes/user/Filter.js +++ b/src/pages/user/components/Filter.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types' import moment from 'moment' import { FilterItem } from 'components' import { Form, Button, Row, Col, DatePicker, Input, Cascader, Switch } from 'antd' -import city from '../../utils/city' +import city from 'utils/city' const { Search } = Input const { RangePicker } = DatePicker diff --git a/src/routes/user/List.js b/src/pages/user/components/List.js similarity index 96% rename from src/routes/user/List.js rename to src/pages/user/components/List.js index 468edb8..2e93d1f 100644 --- a/src/routes/user/List.js +++ b/src/pages/user/components/List.js @@ -4,7 +4,6 @@ import { Table, Modal } from 'antd' import classnames from 'classnames' import { DropOption } from 'components' import { Link } from 'react-router-dom' -import queryString from 'query-string' import AnimTableBody from 'components/DataTable/AnimTableBody' import styles from './List.less' @@ -13,7 +12,6 @@ const { confirm } = Modal const List = ({ onDeleteItem, onEditItem, isMotion, location, ...tableProps }) => { - location.query = queryString.parse(location.search) const handleMenuClick = (record, e) => { if (e.key === '1') { diff --git a/src/routes/user/List.less b/src/pages/user/components/List.less similarity index 92% rename from src/routes/user/List.less rename to src/pages/user/components/List.less index bdc1190..6af6d67 100644 --- a/src/routes/user/List.less +++ b/src/pages/user/components/List.less @@ -16,8 +16,9 @@ :global { .ant-table-tbody > tr > td, .ant-table-thead > tr > th { + // 选择框 <6 会导致换行 &:nth-child(1) { - width: 5%; + width: 6%; } &:nth-child(2) { @@ -49,15 +50,15 @@ } &:nth-child(9) { - width: 17%; + width: 18%; } &:nth-child(10) { - width: 13%; + width: 12%; } &:nth-child(11) { - width: 8%; + width: 7%; } } diff --git a/src/routes/user/Modal.js b/src/pages/user/components/Modal.js similarity index 99% rename from src/routes/user/Modal.js rename to src/pages/user/components/Modal.js index 47141a6..ab760a2 100644 --- a/src/routes/user/Modal.js +++ b/src/pages/user/components/Modal.js @@ -1,7 +1,7 @@ import React from 'react' import PropTypes from 'prop-types' import { Form, Input, InputNumber, Radio, Modal, Cascader } from 'antd' -import city from '../../utils/city' +import city from 'utils/city' const FormItem = Form.Item diff --git a/src/routes/user/index.js b/src/pages/user/index.js similarity index 96% rename from src/routes/user/index.js rename to src/pages/user/index.js index 2969604..89b5310 100644 --- a/src/routes/user/index.js +++ b/src/pages/user/index.js @@ -5,15 +5,14 @@ import { connect } from 'dva' import { Row, Col, Button, Popconfirm } from 'antd' import { Page } from 'components' import queryString from 'query-string' -import List from './List' -import Filter from './Filter' -import Modal from './Modal' +import List from './components/List' +import Filter from './components/Filter' +import Modal from './components/Modal' const User = ({ location, dispatch, user, loading, }) => { - location.query = queryString.parse(location.search) const { query, pathname } = location const { list, pagination, currentItem, modalVisible, modalType, isMotion, selectedRowKeys, diff --git a/src/models/user.js b/src/pages/user/model.js similarity index 90% rename from src/models/user.js rename to src/pages/user/model.js index bcf8468..e51bd61 100644 --- a/src/models/user.js +++ b/src/pages/user/model.js @@ -1,10 +1,9 @@ /* global window */ import modelExtend from 'dva-model-extend' -import queryString from 'query-string' import { config } from 'utils' -import { create, remove, update } from 'services/user' -import * as usersService from 'services/users' -import { pageModel } from './common' +import { create, remove, update } from './services/user' +import * as usersService from './services/users' +import { pageModel } from 'utils/model' const { query } = usersService const { prefix } = config @@ -24,7 +23,7 @@ export default modelExtend(pageModel, { setup ({ dispatch, history }) { history.listen((location) => { if (location.pathname === '/user') { - const payload = queryString.parse(location.search) || { page: 1, pageSize: 10 } + const payload = location.query || { page: 1, pageSize: 10 } dispatch({ type: 'query', payload, diff --git a/src/services/user.js b/src/pages/user/services/user.js similarity index 100% rename from src/services/user.js rename to src/pages/user/services/user.js diff --git a/src/services/users.js b/src/pages/user/services/users.js similarity index 100% rename from src/services/users.js rename to src/pages/user/services/users.js diff --git a/src/plugins/onError.js b/src/plugins/onError.js new file mode 100644 index 0000000..5661d64 --- /dev/null +++ b/src/plugins/onError.js @@ -0,0 +1,8 @@ +import { message } from 'antd' + +export default { + onError (e) { + e.preventDefault() + message.error(e.message) + }, +} diff --git a/src/router.js b/src/router.js deleted file mode 100644 index 1a8b920..0000000 --- a/src/router.js +++ /dev/null @@ -1,101 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' -import { Switch, Route, Redirect, routerRedux } from 'dva/router' -import dynamic from 'dva/dynamic' -import App from 'routes/app' -import { LocaleProvider } from 'antd' -import enUS from 'antd/lib/locale-provider/en_US' - -const { ConnectedRouter } = routerRedux - -const Routers = function ({ history, app }) { - const error = dynamic({ - app, - component: () => import('./routes/error'), - }) - const routes = [ - { - path: '/dashboard', - models: () => [import('./models/dashboard')], - component: () => import('./routes/dashboard/'), - }, { - path: '/user', - models: () => [import('./models/user')], - component: () => import('./routes/user/'), - }, { - path: '/user/:id', - models: () => [import('./models/user/detail')], - component: () => import('./routes/user/detail/'), - }, { - path: '/login', - models: () => [import('./models/login')], - component: () => import('./routes/login/'), - }, { - path: '/request', - component: () => import('./routes/request/'), - }, { - path: '/UIElement/iconfont', - component: () => import('./routes/UIElement/iconfont/'), - }, { - path: '/UIElement/search', - component: () => import('./routes/UIElement/search/'), - }, { - path: '/UIElement/dropOption', - component: () => import('./routes/UIElement/dropOption/'), - }, { - path: '/UIElement/layer', - component: () => import('./routes/UIElement/layer/'), - }, { - path: '/UIElement/dataTable', - component: () => import('./routes/UIElement/dataTable/'), - }, { - path: '/UIElement/editor', - component: () => import('./routes/UIElement/editor/'), - }, { - path: '/chart/ECharts', - component: () => import('./routes/chart/ECharts/'), - }, { - path: '/chart/highCharts', - component: () => import('./routes/chart/highCharts/'), - }, { - path: '/chart/Recharts', - component: () => import('./routes/chart/Recharts/'), - }, { - path: '/post', - models: () => [import('./models/post')], - component: () => import('./routes/post/'), - }, - ] - - return ( - - - - - ()} /> - { - routes.map(({ path, ...dynamics }, key) => ( - - )) - } - - - - - - ) -} - -Routers.propTypes = { - history: PropTypes.object, - app: PropTypes.object, -} - -export default Routers diff --git a/src/tests/models/example-test.js b/src/tests/models/example-test.js deleted file mode 100644 index 8b13789..0000000 --- a/src/tests/models/example-test.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/themes/index.less b/src/themes/index.less index 74582f7..a6f29a4 100644 --- a/src/themes/index.less +++ b/src/themes/index.less @@ -1,135 +1,135 @@ -@import "~themes/vars"; - -body { - height: 100%; - overflow-y: hidden; - background-color: #f8f8f8; -} - -::-webkit-scrollbar-thumb { - background-color: #e6e6e6; -} - -::-webkit-scrollbar { - width: 8px; - height: 8px; -} - -:global { - .ant-breadcrumb { - & > span { - &:last-child { - color: #999; - font-weight: normal; - } - } - } - - .ant-breadcrumb-link { - .anticon + span { - margin-left: 4px; - } - } - - .ant-table { - .ant-table-thead > tr > th { - text-align: center; - } - - .ant-table-tbody > tr > td { - text-align: center; - } - - &.ant-table-small { - .ant-table-thead > tr > th { - background: #f7f7f7; - } - - .ant-table-body > table { - padding: 0; - } - } - } - - .ant-table-pagination { - float: none!important; - display: table; - margin: 16px auto !important; - } - - .ant-popover-inner { - border: none; - border-radius: 0; - box-shadow: 0 0 20px rgba(100, 100, 100, 0.2); - } - - .vertical-center-modal { - display: flex; - align-items: center; - justify-content: center; - - .ant-modal { - top: 0; - - .ant-modal-body { - max-height: 80vh; - overflow-y: auto; - } - } - } - - .ant-form-item-control { - vertical-align: middle; - } - - .ant-modal-mask { - background-color: rgba(55, 55, 55, 0.2); - } - - .ant-modal-content { - box-shadow: none; - } - - .ant-select-dropdown-menu-item { - padding: 12px 16px !important; - } - - .margin-right { - margin-right: 16px; - } - - a:focus { - text-decoration: none; - } -} -@media (min-width: 1600px) { - :global { - .ant-col-xl-48 { - width: 20%; - } - - .ant-col-xl-96 { - width: 40%; - } - } -} -@media (max-width: 767px) { - :global { - .ant-pagination-item, - .ant-pagination-next, - .ant-pagination-options, - .ant-pagination-prev { - margin-bottom: 8px; - } - - .ant-card { - .ant-card-head { - padding: 0 12px; - } - - .ant-card-body { - padding: 12px; - } - } - } -} +@import "~themes/vars.less"; + +body { + height: 100%; + overflow-y: hidden; + background-color: #f8f8f8; +} + +::-webkit-scrollbar-thumb { + background-color: #e6e6e6; +} + +::-webkit-scrollbar { + width: 8px; + height: 8px; +} + +:global { + .ant-breadcrumb { + & > span { + &:last-child { + color: #999; + font-weight: normal; + } + } + } + + .ant-breadcrumb-link { + .anticon + span { + margin-left: 4px; + } + } + + .ant-table { + .ant-table-thead > tr > th { + text-align: center; + } + + .ant-table-tbody > tr > td { + text-align: center; + } + + &.ant-table-small { + .ant-table-thead > tr > th { + background: #f7f7f7; + } + + .ant-table-body > table { + padding: 0; + } + } + } + + .ant-table-pagination { + float: none!important; + display: table; + margin: 16px auto !important; + } + + .ant-popover-inner { + border: none; + border-radius: 0; + box-shadow: 0 0 20px rgba(100, 100, 100, 0.2); + } + + .vertical-center-modal { + display: flex; + align-items: center; + justify-content: center; + + .ant-modal { + top: 0; + + .ant-modal-body { + max-height: 80vh; + overflow-y: auto; + } + } + } + + .ant-form-item-control { + vertical-align: middle; + } + + .ant-modal-mask { + background-color: rgba(55, 55, 55, 0.2); + } + + .ant-modal-content { + box-shadow: none; + } + + .ant-select-dropdown-menu-item { + padding: 12px 16px !important; + } + + .margin-right { + margin-right: 16px; + } + + a:focus { + text-decoration: none; + } +} +@media (min-width: 1600px) { + :global { + .ant-col-xl-48 { + width: 20%; + } + + .ant-col-xl-96 { + width: 40%; + } + } +} +@media (max-width: 767px) { + :global { + .ant-pagination-item, + .ant-pagination-next, + .ant-pagination-options, + .ant-pagination-prev { + margin-bottom: 8px; + } + + .ant-card { + .ant-card-head { + padding: 0 12px; + } + + .ant-card-body { + padding: 12px; + } + } + } +} diff --git a/src/themes/vars.less b/src/themes/vars.less index 69f340e..8b052a4 100644 --- a/src/themes/vars.less +++ b/src/themes/vars.less @@ -1,2 +1,2 @@ -@import "~themes/default"; -@import "~themes/mixin"; +@import "~themes/default.less"; +@import "~themes/mixin.less"; diff --git a/src/utils/config.js b/src/utils/config.js index 5f4ad56..9ce27e9 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -4,10 +4,10 @@ const APIV2 = '/api/v2' module.exports = { name: 'AntD Admin', prefix: 'antdAdmin', - footerText: 'Ant Design Admin © 2017 zuiidea', - logo: '/logo.svg', - iconFontCSS: '/iconfont.css', - iconFontJS: '/iconfont.js', + footerText: 'Ant Design Admin © 2018 zuiidea', + logo: '/public/logo.svg', + iconFontCSS: '/public/iconfont.css', + iconFontJS: '/public/iconfont.js', CORS: [], openPages: ['/login'], apiPrefix: '/api/v1', diff --git a/src/utils/index.js b/src/utils/index.js index dad7e5f..e5c8383 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,9 +1,10 @@ /* global window */ -import classnames from 'classnames' -import lodash from 'lodash' -import config from './config' -import request from './request' -import { color } from './theme' +import cloneDeep from 'lodash.clonedeep' + +export classnames from 'classnames' +export config from './config' +export request from './request' +export { color } from './theme' // 连字符转驼峰 String.prototype.hyphenToHump = function () { @@ -42,11 +43,10 @@ Date.prototype.format = function (format) { /** - * @param {String} + * @param name {String} * @return {String} */ - -const queryURL = (name) => { +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]) @@ -60,7 +60,7 @@ const queryURL = (name) => { * @param {String} keyAlias * @return {Array} */ -const queryArray = (array, key, keyAlias = 'key') => { +export function queryArray (array, key, keyAlias = 'key') { if (!(array instanceof Array)) { return null } @@ -79,8 +79,8 @@ const queryArray = (array, key, keyAlias = 'key') => { * @param {String} children * @return {Array} */ -const arrayToTree = (array, id = 'id', pid = 'pid', children = 'children') => { - let data = lodash.cloneDeep(array) +export function arrayToTree (array, id = 'id', pid = 'pid', children = 'children') { + let data = cloneDeep(array) let result = [] let hash = {} data.forEach((item, index) => { @@ -98,13 +98,3 @@ const arrayToTree = (array, id = 'id', pid = 'pid', children = 'children') => { }) return result } - -module.exports = { - config, - request, - color, - classnames, - queryURL, - queryArray, - arrayToTree, -} diff --git a/src/models/common.js b/src/utils/model.js similarity index 86% rename from src/models/common.js rename to src/utils/model.js index bcd9e46..7999727 100644 --- a/src/models/common.js +++ b/src/utils/model.js @@ -1,6 +1,6 @@ import modelExtend from 'dva-model-extend' -const model = { +export const model = { reducers: { updateState (state, { payload }) { return { @@ -11,7 +11,7 @@ const model = { }, } -const pageModel = modelExtend(model, { +export const pageModel = modelExtend(model, { state: { list: [], @@ -40,9 +40,3 @@ const pageModel = modelExtend(model, { }, }) - - -module.exports = { - model, - pageModel, -} diff --git a/src/utils/request.js b/src/utils/request.js index 31c2a5f..c084688 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -2,7 +2,7 @@ import axios from 'axios' import qs from 'qs' import jsonp from 'jsonp' -import lodash from 'lodash' +import cloneDeep from 'lodash.clonedeep' import pathToRegexp from 'path-to-regexp' import { message } from 'antd' import { YQL, CORS } from './config' @@ -15,7 +15,7 @@ const fetch = (options) => { url, } = options - const cloneData = lodash.cloneDeep(data) + const cloneData = cloneDeep(data) try { let domin = '' diff --git a/version.js b/version.js deleted file mode 100644 index f463575..0000000 --- a/version.js +++ /dev/null @@ -1,82 +0,0 @@ -const fs = require('fs') -const path = require('path') -const beautify = require('js-beautify').js_beautify -const config = require('./package.json') - -const dist = path.join(`${__dirname}/dist`) -const maxVersion = 5 - -const writeVersion = () => new Promise((resolve, reject) => { - const { version } = config - const numbers = version.split('.') - numbers[2] = Number(numbers[2]) + 1 - config.version = numbers.join('.') - - fs.writeFile(path.join(__dirname, 'package.json'), beautify(JSON.stringify(config), { indent_size: 2 }), (err) => { - if (err) { - reject() - } - resolve() - console.log(`version: ${config.version}`) - }) -}) - -const removeFolder = (folderPath) => { - let files = [] - if (fs.existsSync(folderPath)) { - files = fs.readdirSync(folderPath) - files.forEach((file) => { - const curPath = `${folderPath}/${file}` - if (fs.statSync(curPath).isDirectory()) { - removeFolder(curPath) - } else { - fs.unlinkSync(curPath) - } - }) - fs.rmdirSync(folderPath) - } -} - -const start = async () => { - const files = fs.readdirSync(dist) - const promises = files.map(file => new Promise((resolve, reject) => { - fs.stat(`${dist}/${file}`, (err, stats) => { - if (err) { - reject() - } else { - resolve(!stats.isFile() - ? file - : null) - } - }) - })) - - const result = await Promise.all(promises) - - const folders = result.filter((item) => { - if (item) { - return item.split('.').length === 3 - } - return false - }).sort((a, b) => { - const an = a.split('.').map(_ => Number(_)) - const bn = b.split('.').map(_ => Number(_)) - if (an[0] === bn[0]) { - if (an[1] === bn[1]) { - return an[2] < bn[2] - } - return an[1] < bn[1] - } - return an[0] < bn[0] - }).filter((item, index) => { - return index > (maxVersion - 1) - }) - - for (const item of folders) { - await removeFolder(`${dist}/${item}`) - } - - await writeVersion() -} - -start() diff --git a/webpack.config.js b/webpack.config.js index 2abc96f..ac4f22d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,59 +1,13 @@ -const HtmlWebpackPlugin = require('html-webpack-plugin') -const CopyWebpackPlugin = require('copy-webpack-plugin') -const webpack = require('webpack') -module.exports = (webpackConfig, env) => { - const production = env === 'production' - // FilenameHash - webpackConfig.output.chunkFilename = '[name].[chunkhash].js' - - if (production) { - if (webpackConfig.module) { - // ClassnameHash - webpackConfig.module.rules.map((item) => { - if (String(item.test) === '/\\.less$/' || String(item.test) === '/\\.css/') { - item.use.filter(iitem => iitem.loader === 'css')[0].options.localIdentName = '[hash:base64:5]' - } - return item - }) - } - webpackConfig.plugins.push( - new webpack.LoaderOptionsPlugin({ - minimize: true, - debug: false, - }) - ) - } - - webpackConfig.plugins = webpackConfig.plugins.concat([ - new CopyWebpackPlugin([ +export default function (webpackConfig) { + webpackConfig.module.rules.push({ + test: /\.svg$/i, + use: [ { - from: 'src/public', - to: production ? '../' : webpackConfig.output.outputPath, + loader: require.resolve('svg-sprite-loader'), }, - ]), - new HtmlWebpackPlugin({ - template: `${__dirname}/src/entry.ejs`, - filename: production ? '../index.html' : 'index.html', - minify: production ? { - collapseWhitespace: true, - } : null, - hash: true, - headScripts: production ? null : ['/roadhog.dll.js'], - }), - ]) - - // Alias - webpackConfig.resolve.alias = { - components: `${__dirname}/src/components`, - utils: `${__dirname}/src/utils`, - config: `${__dirname}/src/utils/config`, - enums: `${__dirname}/src/utils/enums`, - services: `${__dirname}/src/services`, - models: `${__dirname}/src/models`, - routes: `${__dirname}/src/routes`, - themes: `${__dirname}/src/themes`, - } + ], + }) return webpackConfig -} +};