Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca1d182795 | ||
|
|
4042d5ba3a | ||
|
|
da4abc2293 | ||
|
|
13c13961c7 | ||
|
|
0d1c4f23e9 | ||
|
|
f3c6ccf7b2 | ||
|
|
a18c9bcb7e | ||
|
|
12eab5f5c7 | ||
|
|
1dbeb05005 | ||
|
|
a0000d7371 | ||
|
|
b0cb27712d | ||
|
|
0bb381f419 | ||
|
|
8c01bc1488 | ||
|
|
d8baaad3b1 | ||
|
|
e32a19fe3b | ||
|
|
c6382c6221 | ||
|
|
02280fbed9 | ||
|
|
d897eb205d | ||
|
|
b1f290ea32 | ||
|
|
0e36b6b7a0 | ||
|
|
d92f121cf4 | ||
|
|
0a73ba0f12 | ||
|
|
9e4e0efbab | ||
|
|
524dff07d2 | ||
|
|
8b3e5c08f7 | ||
|
|
c17444f5d6 | ||
|
|
df85ecdfff | ||
|
|
b8824141d6 | ||
|
|
aedd2ec3db | ||
|
|
5abad21082 | ||
|
|
1ae41c7ae5 | ||
|
|
e41671dbf9 | ||
|
|
eaeb9092e4 | ||
|
|
2f3ca0a006 | ||
|
|
1b65351be4 | ||
|
|
0422f6d51e | ||
|
|
8d050d4040 | ||
|
|
82b3a4b384 | ||
|
|
d2f391a881 | ||
|
|
9e778487d9 | ||
|
|
7938d71f2f | ||
|
|
422a6fed30 | ||
|
|
c6ea0454b3 | ||
|
|
467767a6c5 | ||
|
|
cf795c512a | ||
|
|
18b499030d | ||
|
|
d800d6f3ce | ||
|
|
185f706107 | ||
|
|
5a4661cdad | ||
|
|
7abdd94a0e | ||
|
|
22f0684ab0 | ||
|
|
80b2c63693 | ||
|
|
4b2a553bda | ||
|
|
ad30e73b10 | ||
|
|
15b62e302d | ||
|
|
9d5ec20f20 | ||
|
|
c878425fd0 | ||
|
|
90e80dda64 | ||
|
|
1db5bfeab5 | ||
|
|
b2b3fcd4a3 | ||
|
|
9cf97375c7 | ||
|
|
7839b6affb | ||
|
|
597064a07d | ||
|
|
0ea57d14c9 | ||
|
|
afd736d615 | ||
|
|
ce9b8c376f | ||
|
|
79776e6752 | ||
|
|
a2432022a1 | ||
|
|
ea5ee96bdc | ||
|
|
fe954092a4 | ||
|
|
5e148fec92 | ||
|
|
5daa2a9548 | ||
|
|
f1913f7b18 | ||
|
|
65a453553e | ||
|
|
29da8f24da | ||
|
|
3443ad9968 | ||
|
|
838dc93eff | ||
|
|
07ef68ec1f | ||
|
|
3cb7f86086 | ||
|
|
fc9565c157 |
@@ -1,7 +1 @@
|
||||
src/**/*-test.js
|
||||
src/public
|
||||
src/routes/chart/ECharts/theme
|
||||
src/routes/chart/highCharts/mapdata
|
||||
src/locales/_build/
|
||||
src/locales/**/*.js
|
||||
docs/**/*.js
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"extends": "react-app",
|
||||
"rules": {
|
||||
"jsx-a11y/href-no-hash": "off",
|
||||
"import/no-anonymous-default-export": 0,
|
||||
"jsx-a11y/href-no-hash": 0,
|
||||
"no-console": "warn",
|
||||
"valid-jsdoc": "warn"
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ npm-debug.log
|
||||
yarn-error.log
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
|
||||
# ide
|
||||
.idea
|
||||
@@ -20,4 +21,6 @@ package-lock.json
|
||||
|
||||
# jslingui
|
||||
src/locales/_build
|
||||
src/locales/**/*.js
|
||||
src/locales/**/*.js
|
||||
|
||||
.vscode
|
||||
@@ -4,24 +4,15 @@ node_js:
|
||||
script:
|
||||
- npm run build
|
||||
before_install:
|
||||
- |
|
||||
if [ "$TRAVIS_BRANCH" = "develop" ]; then
|
||||
for prefixed_envvar in ${!DEV_*}; do
|
||||
eval export ${prefixed_envvar#DEV_}="${!prefixed_envvar}"
|
||||
done
|
||||
elif [ "$TRAVIS_BRANCH" = "master" ]; then
|
||||
for prefixed_envvar in ${!PROD_*}; do
|
||||
eval export ${prefixed_envvar#PROD_}="${!prefixed_envvar}"
|
||||
done
|
||||
else
|
||||
for prefixed_envvar in ${!TEST_*}; do
|
||||
eval export ${prefixed_envvar#TEST_}="${!prefixed_envvar}"
|
||||
done
|
||||
fi
|
||||
- openssl aes-256-cbc -K $encrypted_18b2305b78c9_key -iv $encrypted_18b2305b78c9_iv -in config/id_rsa.enc -out ~/.ssh/id_rsa -d
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- echo -e "Host $HOST\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
|
||||
- yarn global add now
|
||||
after_script:
|
||||
- scp -o stricthostkeychecking=no -r ./dist root@$HOST:$BUILD_DIR
|
||||
- cd ./docs && now -A $DOC_NOW_CONFIG -t $NOW_TOKEN && now alias -A $DOC_NOW_CONFIG -t $NOW_TOKEN
|
||||
- |
|
||||
if [[ $TRAVIS_BRANCH == 'master' ]]; then
|
||||
echo $PROD_SITE_NOW_CONFIG >> dist/vercel.json && echo $PROD_DOC_NOW_CONFIG >> docs/vercel.json;
|
||||
else
|
||||
echo $DEV_SITE_NOW_CONFIG >> dist/vercel.json && echo $DEV_DOC_NOW_CONFIG >> docs/vercel.json;
|
||||
fi
|
||||
- cd ./dist
|
||||
- now -A vercel.json -t $NOW_TOKEN --prod -c
|
||||
- cd ../docs
|
||||
- now -A vercel.json -t $NOW_TOKEN --prod -c
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
// https://umijs.org/config/
|
||||
import { resolve } from 'path'
|
||||
import { i18n } from './src/utils/config'
|
||||
|
||||
export default {
|
||||
ignoreMomentLocale: true,
|
||||
targets: { ie: 9 },
|
||||
treeShaking: true,
|
||||
plugins: [
|
||||
[
|
||||
// https://umijs.org/plugin/umi-plugin-react.html
|
||||
'umi-plugin-react',
|
||||
{
|
||||
dva: { immer: true },
|
||||
antd: true,
|
||||
dynamicImport: {
|
||||
webpackChunkName: true,
|
||||
loadingComponent: './components/Loader/Loader',
|
||||
},
|
||||
routes: {
|
||||
exclude: [
|
||||
/model\.(j|t)sx?$/,
|
||||
/service\.(j|t)sx?$/,
|
||||
/models\//,
|
||||
/components\//,
|
||||
/services\//,
|
||||
/chart\/Container\.js$/,
|
||||
/chart\/ECharts\/.+Component\.js$/,
|
||||
/chart\/ECharts\/.+ComPonent\.js$/,
|
||||
/chart\/ECharts\/theme\/.+\.js$/,
|
||||
/chart\/highCharts\/.+Component\.js$/,
|
||||
/chart\/highCharts\/mapdata\/.+\.js$/,
|
||||
/chart\/Recharts\/.+Component\.js$/,
|
||||
/chart\/Recharts\/Container\.js$/,
|
||||
],
|
||||
update: routes => {
|
||||
if (!i18n) return routes
|
||||
|
||||
const newRoutes = []
|
||||
for (const item of routes[0].routes) {
|
||||
newRoutes.push(item)
|
||||
if (item.path) {
|
||||
newRoutes.push(
|
||||
Object.assign({}, item, {
|
||||
path:
|
||||
`/:lang(${i18n.languages
|
||||
.map(item => item.key)
|
||||
.join('|')})` + item.path,
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
routes[0].routes = newRoutes
|
||||
|
||||
return routes
|
||||
},
|
||||
},
|
||||
dll: {
|
||||
include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch', 'antd/es'],
|
||||
},
|
||||
pwa: {
|
||||
manifestOptions: {
|
||||
srcPath: 'manifest.json'
|
||||
},
|
||||
}
|
||||
},
|
||||
],
|
||||
],
|
||||
// Theme for antd
|
||||
// https://ant.design/docs/react/customize-theme
|
||||
theme: './config/theme.config.js',
|
||||
// Webpack Configuration
|
||||
proxy: {
|
||||
'/api/v1/weather': {
|
||||
target: 'https://api.seniverse.com/',
|
||||
changeOrigin: true,
|
||||
pathRewrite: { '^/api/v1/weather': '/v3/weather' },
|
||||
},
|
||||
},
|
||||
alias: {
|
||||
api: resolve(__dirname, './src/services/'),
|
||||
components: resolve(__dirname, './src/components'),
|
||||
config: resolve(__dirname, './src/utils/config'),
|
||||
models: resolve(__dirname, './src/models'),
|
||||
routes: resolve(__dirname, './src/routes'),
|
||||
services: resolve(__dirname, './src/services'),
|
||||
themes: resolve(__dirname, './src/themes'),
|
||||
utils: resolve(__dirname, './src/utils'),
|
||||
},
|
||||
extraBabelPresets: ['@lingui/babel-preset-react'],
|
||||
extraBabelPlugins: [
|
||||
[
|
||||
'import',
|
||||
{
|
||||
libraryName: 'lodash',
|
||||
libraryDirectory: '',
|
||||
camel2DashComponentName: false,
|
||||
},
|
||||
'lodash',
|
||||
],
|
||||
],
|
||||
}
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
## 使用
|
||||
|
||||
1. 下载项目代码。
|
||||
1. 下载项目代码。
|
||||
|
||||
```bash
|
||||
git clone https://github.com/zuiidea/antd-admin.git my-project
|
||||
@@ -84,4 +84,4 @@ npm run start
|
||||
- 通过 [Issue](http://github.com/zuiidea/antd-admin/issues) 报告 bug 或进行咨询。
|
||||
- 提交 [Pull Request](http://github.com/zuiidea/antd-admin/pulls) 改进代码。
|
||||
|
||||
> 强烈推荐阅读 [《提问的智慧》](https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way)、[《如何向开源社区提问题》](https://github.com/seajs/seajs/issues/545) 和 [《如何有效地报告 Bug》](http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html)、[《如何向开源项目提交无法解答的问题》](https://zhuanlan.zhihu.com/p/25795393),更好的问题更容易获得帮助。
|
||||
> 强烈推荐阅读 [《提问的智慧》](https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way)、[《如何向开源社区提问题》](https://github.com/seajs/seajs/issues/545) 和 [《如何有效地报告 Bug》](http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html)、[《如何向开源项目提交无法解答的问题》](https://zhuanlan.zhihu.com/p/25795393),更好的问题更容易获得帮助。
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
An excellent front-end solution for enterprise applications.
|
||||
|
||||
[](https://github.com/ant-design/ant-design)
|
||||
[](https://github.com/ant-design/ant-design)
|
||||
[](https://github.com/umijs/umi)
|
||||
[](https://github.com/zuiidea/antd-admin/issues)
|
||||
[](http://opensource.org/licenses/MIT)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
const config = {
|
||||
publicPath: 'https://cdn.antd-admin.zuiidea.com/',
|
||||
}
|
||||
|
||||
export default config
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* see more, https://umijs.org/config
|
||||
*/
|
||||
import lessToJs from 'less-vars-to-js'
|
||||
import fs from 'fs'
|
||||
import routes from './routes'
|
||||
import path from 'path'
|
||||
import proxy from './proxy'
|
||||
|
||||
const theme = lessToJs(
|
||||
fs.readFileSync(path.join(__dirname, '../src/themes/default.less'), 'utf8')
|
||||
)
|
||||
|
||||
const config = {
|
||||
hash: true,
|
||||
ignoreMomentLocale: true,
|
||||
targets: { ie: 11 },
|
||||
theme,
|
||||
proxy,
|
||||
routes,
|
||||
devtool: 'eval',
|
||||
mock: {
|
||||
exclude: ['utils/index'],
|
||||
},
|
||||
extraBabelPresets: ['@lingui/babel-preset-react'],
|
||||
extraBabelPlugins: [
|
||||
'macros',
|
||||
[
|
||||
'import',
|
||||
{
|
||||
libraryName: 'lodash',
|
||||
libraryDirectory: '',
|
||||
camel2DashComponentName: false,
|
||||
},
|
||||
'lodash',
|
||||
],
|
||||
[
|
||||
'import',
|
||||
{
|
||||
libraryName: 'antd',
|
||||
libraryDirectory: 'es',
|
||||
style: 'css',
|
||||
},
|
||||
'antd',
|
||||
],
|
||||
[
|
||||
'import',
|
||||
{
|
||||
libraryName: '@ant-design',
|
||||
libraryDirectory: 'icons',
|
||||
camel2DashComponentName: false,
|
||||
},
|
||||
'ant-design-icons',
|
||||
],
|
||||
],
|
||||
chainWebpack: (memo) => {
|
||||
memo.module.rule('po').test(/\.po$/).use('po').loader('@lingui/loader')
|
||||
},
|
||||
}
|
||||
|
||||
export default config
|
||||
@@ -0,0 +1,7 @@
|
||||
export default {
|
||||
'/api/v1/weather': {
|
||||
target: 'https://api.seniverse.com/',
|
||||
changeOrigin: true,
|
||||
pathRewrite: { '^/api/v1/weather': '/v3/weather' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
const routes = [
|
||||
{
|
||||
exact: false,
|
||||
path: '/',
|
||||
// component: '@/layouts/index', // comment due to double layout
|
||||
routes: [
|
||||
{ exact: true, path: '/login', component: '@/pages/login' },
|
||||
{ exact: true, path: '/user', component: '@/pages/user' },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export default routes
|
||||
@@ -1,8 +0,0 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const lessToJs = require('less-vars-to-js')
|
||||
|
||||
module.exports = () => {
|
||||
const themePath = path.join(__dirname, '../src/themes/default.less')
|
||||
return lessToJs(fs.readFileSync(themePath, 'utf8'))
|
||||
}
|
||||
@@ -5,11 +5,11 @@
|
||||
In the use of `redux` or `dva` projects, we often write functions like the following `service` layer to make the code structure clearer, but it is easy to see that we will write a lot of similar code in `antd -admin@5.0`, using the more concise configuration method to achieve the same function.
|
||||
|
||||
```javascript
|
||||
Export async function login(data) {
|
||||
Return request({
|
||||
Url: '/api/v1/user/login',
|
||||
Method: 'post',
|
||||
Data,
|
||||
export async function login(data) {
|
||||
return request({
|
||||
url: '/api/v1/user/login',
|
||||
method: 'post',
|
||||
data,
|
||||
})
|
||||
}
|
||||
```
|
||||
@@ -19,7 +19,7 @@ Export async function login(data) {
|
||||
In the `src/services/api.js` file, you will see the following configuration object, the object's key is used to call the function name, the object's value is the requested `url`, the default request method is `GET`, The format of the value of the other request mode object is `'method url'`.
|
||||
|
||||
```javascript
|
||||
Export default {
|
||||
export default {
|
||||
...
|
||||
queryUser: '/user/:id',
|
||||
queryUserList: '/users',
|
||||
@@ -34,7 +34,7 @@ Export default {
|
||||
Used in other files
|
||||
|
||||
```javascript
|
||||
Import { queryUser } from 'api'
|
||||
import { queryUser } from 'api'
|
||||
|
||||
// in the general file
|
||||
...
|
||||
@@ -43,7 +43,7 @@ queryUser(option).then(data => console.log(data))
|
||||
|
||||
/ / Model file
|
||||
...
|
||||
Yield call(queryUser, option)
|
||||
yield call(queryUser, option)
|
||||
...
|
||||
```
|
||||
|
||||
@@ -52,35 +52,35 @@ Yield call(queryUser, option)
|
||||
Refer to the `src/services/index.js` file to traverse the api configuration. Each property returns the corresponding encapsulated request function.
|
||||
|
||||
```javascript
|
||||
Import request from 'utils/request'
|
||||
Import { apiPrefix } from 'utils/config'
|
||||
import request from 'utils/request'
|
||||
import { apiPrefix } from 'utils/config'
|
||||
|
||||
Import api from './api'
|
||||
import api from './api'
|
||||
|
||||
Const gen = params => {
|
||||
Let url = apiPrefix + params
|
||||
Let method = 'GET'
|
||||
const gen = params => {
|
||||
let url = apiPrefix + params
|
||||
let method = 'GET'
|
||||
|
||||
Const paramsArray = params.split(' ')
|
||||
If (paramsArray.length === 2) {
|
||||
Method = paramsArray[0]
|
||||
Url = apiPrefix + paramsArray[1]
|
||||
const paramsArray = params.split(' ')
|
||||
if (paramsArray.length === 2) {
|
||||
method = paramsArray[0]
|
||||
url = apiPrefix + paramsArray[1]
|
||||
}
|
||||
|
||||
Return function(data) {
|
||||
Return request({
|
||||
Url,
|
||||
Data,
|
||||
Method,
|
||||
return function(data) {
|
||||
return request({
|
||||
url,
|
||||
data,
|
||||
method,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Const APIFunction = {}
|
||||
For (const key in api) {
|
||||
const APIFunction = {}
|
||||
for (const key in api) {
|
||||
APIFunction[key] = gen(api[key])
|
||||
}
|
||||
|
||||
Module.exports = APIFunction
|
||||
module.exports = APIFunction
|
||||
|
||||
```
|
||||
@@ -9,3 +9,4 @@
|
||||
- Guide
|
||||
- [Deploy](deploy.md)
|
||||
- [Change Log](change-log.md)
|
||||
- [FAQ](faq.md)
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
- Support internationalization, extract source fields from source code, load language packs on demand, and automatically translate online.
|
||||
|
||||
- Support for the introduction of `ant-design-pro` components, `lodash` functions on demand.
|
||||
- Support for the introduction `lodash` functions on demand.
|
||||
|
||||
- Support multiple layouts, which rules can be used according to the rules.
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# FAQ
|
||||
|
||||
Most asked
|
||||
|
||||
## create new page
|
||||
|
||||
1. just copy a page in /src/pages (route here auto generated by [umi](https://umijs.org/guide/router.html#basic-routing))
|
||||
2. modify namespace/pathToRegexp in model.js
|
||||
3. modify mock route.js to add a route
|
||||
@@ -12,7 +12,7 @@ Take Japanese as an example.
|
||||
npm run add-locale ja
|
||||
```
|
||||
|
||||
2. Extract the fields in the code that need to be translated, ie `<Trans>?message</Trans>`, `` i18n.t`message `` in the `message` field, run the following command after `src/locales/ja /messages.json` will appear after the extracted field configuration.
|
||||
2. Extract the fields in the code that need to be translated, ie `<Trans>?message</Trans>`, `` t`message `` in the `message` field, run the following command after `src/locales/ja /messages.json` will appear after the extracted field configuration.
|
||||
|
||||
```bash
|
||||
npm run extract
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## Add a new layout
|
||||
|
||||
Take a new layout named `secondary` as an example to make the route starting with `seconday` use this layout.
|
||||
Take a new layout named `secondary` as an example to make the route starting with `secondary` use this layout.
|
||||
|
||||
1. Add related configuration in `src/utils/config.js`. For details, please refer to [layouts](/configuration?id=layouts).
|
||||
|
||||
@@ -11,11 +11,11 @@ Take a new layout named `secondary` as an example to make the route starting wit
|
||||
{
|
||||
name: 'primary',
|
||||
include: [/.*/],
|
||||
exclude: [/(\/(en|zh))*\/login/, /(\/(en|zh))*\/seconday\/(.*)/],
|
||||
exclude: [/(\/(en|zh))*\/login/, /(\/(en|zh))*\/secondary\/(.*)/],
|
||||
},
|
||||
{
|
||||
name: 'secondary',
|
||||
include: [/(\/(en|zh))*\/seconday\/(.*)/],
|
||||
include: [/(\/(en|zh))*\/secondary\/(.*)/],
|
||||
},
|
||||
],
|
||||
```
|
||||
@@ -26,9 +26,9 @@ Take a new layout named `secondary` as an example to make the route starting wit
|
||||
import SecondaryLayout from './SecondaryLayout'
|
||||
|
||||
const LayoutMap = {
|
||||
Primary: PrimaryLayout,
|
||||
Public: PublicLayout,
|
||||
Secondary: SecondaryLayout,
|
||||
primary: PrimaryLayout,
|
||||
public: PublicLayout,
|
||||
secondary: SecondaryLayout,
|
||||
}
|
||||
```
|
||||
|
||||
@@ -38,23 +38,23 @@ Take a new layout named `secondary` as an example to make the route starting wit
|
||||
import React from 'react'
|
||||
|
||||
export default ({ children }) => {
|
||||
Return (
|
||||
return (
|
||||
<div>
|
||||
<h1>Seconday</h1>
|
||||
<h1>Secondary</h1>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
4. Add a `seconday/index.js` file to the `src/pages/` directory.
|
||||
4. Add a `secondary/index.js` file to the `src/pages/` directory.
|
||||
|
||||
```javascript
|
||||
import React from 'react'
|
||||
|
||||
export default ({ children }) => {
|
||||
Return <div>Seconday page Content</div>
|
||||
Return <div>Secondary page Content</div>
|
||||
}
|
||||
```
|
||||
|
||||
5. Finally, start the development mode `npm run start`, open [http://localhost:7000/seconday/](http://localhost:7000/seconday/) and you will see the page for the `seconday` layout.
|
||||
5. Finally, start the development mode `npm run start`, open [http://localhost:7000/secondary/](http://localhost:7000/secondary/) and you will see the page for the `secondary` layout.
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "antd-admin-devdoc",
|
||||
"alias": ["devdoc-antd-admin.now.sh", "devdoc.antd-admin.zuiidea.com"],
|
||||
"type": "static",
|
||||
"public": true
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "antd-admin-doc",
|
||||
"alias": ["doc-antd-admin.now.sh", "doc.antd-admin.zuiidea.com"],
|
||||
"type": "static",
|
||||
"public": true
|
||||
}
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
- 支持国际化,源码中抽离翻译字段,按需加载语言包,自动在线翻译。
|
||||
|
||||
- 支持按需引入 `ant-design-pro` 组件、`lodash` 函数。
|
||||
- 支持按需引入 `lodash` 函数。
|
||||
|
||||
- 支持多布局,可根据规则规定哪些路由使用哪种布局。
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# 问题集锦
|
||||
|
||||
## 新建页面
|
||||
|
||||
1. 直接从/src/pages复制一个page (会自动创建路由[umi](https://umijs.org/zh/guide/router.html#%E7%BA%A6%E5%AE%9A%E5%BC%8F%E8%B7%AF%E7%94%B1))
|
||||
2. 修改 namespace/pathToRegexp 在 model.js
|
||||
3. 修改 mock中route.js增加一条route
|
||||
@@ -12,7 +12,7 @@
|
||||
npm run add-locale ja
|
||||
```
|
||||
|
||||
2. 提取代码中需要翻译的字段,即 `<Trans>message</Trans>`、`` i18n.t`message `` 中 `message` 字段,运行下面命令后 `src/locales/ja/messages.json` 将会出现提取后的字段配置。
|
||||
2. 提取代码中需要翻译的字段,即 `<Trans>message</Trans>`、`` intl.formatMessage({ id: 'message `` 中 `message` 字段,运行下面命令后 `src/locales/ja/messages.json' }) 将会出现提取后的字段配置。
|
||||
|
||||
```bash
|
||||
npm run extract
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## 新增布局
|
||||
|
||||
以新增名为 `secondary` 的布局为例,使以 `seconday` 开头的路由都使用该布局。
|
||||
以新增名为 `secondary` 的布局为例,使以 `secondary` 开头的路由都使用该布局。
|
||||
|
||||
1. 在 `src/utils/config.js` 新增相关配置,参数详细请查看 [layouts](/zh-cn/configuration?id=layouts)。
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
{
|
||||
name: 'primary',
|
||||
include: [/.*/],
|
||||
exclude: [/(\/(en|zh))*\/login/, /(\/(en|zh))*\/seconday\/(.*)/],
|
||||
exclude: [/(\/(en|zh))*\/login/, /(\/(en|zh))*\/secondary\/(.*)/],
|
||||
},
|
||||
{
|
||||
name: 'secondary',
|
||||
include: [/(\/(en|zh))*\/seconday\/(.*)/],
|
||||
include: [/(\/(en|zh))*\/secondary\/(.*)/],
|
||||
},
|
||||
],
|
||||
```
|
||||
@@ -40,21 +40,21 @@
|
||||
export default ({ children }) => {
|
||||
return (
|
||||
<div>
|
||||
<h1>Seconday</h1>
|
||||
<h1>Secondary</h1>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
4. 在`src/pages/` 目录中新增 `seconday/index.js` 文件。
|
||||
4. 在`src/pages/` 目录中新增 `secondary/index.js` 文件。
|
||||
|
||||
```javascript
|
||||
import React from 'react'
|
||||
|
||||
export default ({ children }) => {
|
||||
return <div>Seconday page Content</div>
|
||||
return <div>Secondary page Content</div>
|
||||
}
|
||||
```
|
||||
|
||||
5. 最后,启动开发模式 `npm run start`,打开 [http://localhost:7000/seconday/](http://localhost:7000/seconday/),你将看到 `seconday` 布局的页面。
|
||||
5. 最后,启动开发模式 `npm run start`,打开 [http://localhost:7000/secondary/](http://localhost:7000/secondary/),你将看到 `secondary` 布局的页面。
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module.exports = {
|
||||
testURL: 'http://localhost:8000',
|
||||
testURL: 'http://localhost:8000'
|
||||
}
|
||||
|
||||
@@ -4,10 +4,33 @@
|
||||
"display": "standalone",
|
||||
"background_color": "#fff",
|
||||
"description": "A front-end solution for enterprise applications built upon Ant Design and UmiJS",
|
||||
"icons": [
|
||||
"icons": [{
|
||||
"src": "logo/logo@96.png",
|
||||
"sizes": "72x72"
|
||||
},
|
||||
{
|
||||
"src": "logo.svg",
|
||||
"sizes": "72x72 96x96 128x128 144x144 152x152 192x192 384x384 512x512"
|
||||
"src": "logo/logo@128.png",
|
||||
"sizes": "128x128"
|
||||
},
|
||||
{
|
||||
"src": "logo/logo@144.png",
|
||||
"sizes": "144x144"
|
||||
},
|
||||
{
|
||||
"src": "logo/logo@152.png",
|
||||
"sizes": "152x152"
|
||||
},
|
||||
{
|
||||
"src": "logo/logo@192.png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo/logo@384.png",
|
||||
"sizes": "384x384"
|
||||
},
|
||||
{
|
||||
"src": "logo/logo@512.png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/**
|
||||
* Query objects that specify keys and values in an array where all values are objects.
|
||||
* @param {array} array An array where all values are objects, like [{key:1},{key:2}].
|
||||
* @param {string} key The key of the object that needs to be queried.
|
||||
* @param {string} value The value of the object that needs to be queried.
|
||||
* @return {object|undefined} Return frist object when query success.
|
||||
*/
|
||||
export function queryArray(array, key, value) {
|
||||
if (!Array.isArray(array)) {
|
||||
return
|
||||
}
|
||||
return array.filter(_ => _[key] === value)
|
||||
}
|
||||
|
||||
export function randomNumber(min, max) {
|
||||
return Math.floor(Math.random() * (max - min) + min)
|
||||
}
|
||||
|
||||
export function randomAvatar() {
|
||||
// https://uifaces.co
|
||||
const avatarList = [
|
||||
'https://randomuser.me/api/portraits/men/32.jpg',
|
||||
'https://images.pexels.com/photos/415829/pexels-photo-415829.jpeg?h=350&auto=compress&cs=tinysrgb',
|
||||
'https://d3iw72m71ie81c.cloudfront.net/female-17.jpg',
|
||||
'https://randomuser.me/api/portraits/men/35.jpg',
|
||||
'https://pbs.twimg.com/profile_images/835224725815246848/jdMBCxHS.jpg',
|
||||
'https://pbs.twimg.com/profile_images/584098247641300992/N25WgvW_.png',
|
||||
'https://d3iw72m71ie81c.cloudfront.net/male-5.jpg',
|
||||
'https://images.pexels.com/photos/413723/pexels-photo-413723.jpeg?h=350&auto=compress&cs=tinysrgb',
|
||||
'https://randomuser.me/api/portraits/women/44.jpg',
|
||||
'https://randomuser.me/api/portraits/women/68.jpg',
|
||||
'https://randomuser.me/api/portraits/women/65.jpg',
|
||||
'https://randomuser.me/api/portraits/men/43.jpg',
|
||||
'https://tinyfac.es/data/avatars/475605E3-69C5-4D2B-8727-61B7BB8C4699-500w.jpeg',
|
||||
'https://pbs.twimg.com/profile_images/943227488292962306/teiNNAiy.jpg',
|
||||
'https://randomuser.me/api/portraits/men/46.jpg'
|
||||
]
|
||||
return avatarList[randomNumber(0, avatarList.length - 1)]
|
||||
}
|
||||
|
||||
export const Constant = {
|
||||
ApiPrefix: '/api/v1',
|
||||
NotFound: {
|
||||
message: 'Not Found',
|
||||
documentation_url: '',
|
||||
},
|
||||
Color: {
|
||||
green: '#64ea91',
|
||||
blue: '#8fc9fb',
|
||||
purple: '#d897eb',
|
||||
red: '#f69899',
|
||||
yellow: '#f8c82e',
|
||||
peach: '#f797d6',
|
||||
borderBase: '#e5e5e5',
|
||||
borderSplit: '#f4f4f4',
|
||||
grass: '#d6fbb5',
|
||||
sky: '#c1e0fc',
|
||||
},
|
||||
}
|
||||
|
||||
export Mock from 'mockjs'
|
||||
export qs from 'qs'
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Mock, Constant } from './_utils'
|
||||
import Mock from 'mockjs'
|
||||
import { Constant } from './utils'
|
||||
|
||||
const { ApiPrefix, Color } = Constant
|
||||
|
||||
@@ -105,7 +106,7 @@ const Dashboard = Mock.mock({
|
||||
content:
|
||||
"I'm selfish, impatient and a little insecure. I make mistakes, I am out of control and at times hard to handle. But if you can't handle me at my worst, then you sure as hell don't deserve me at my best.",
|
||||
avatar:
|
||||
'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236',
|
||||
'//cdn.antd-admin.zuiidea.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236',
|
||||
},
|
||||
numbers: [
|
||||
{
|
||||
@@ -135,7 +136,7 @@ const Dashboard = Mock.mock({
|
||||
],
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
[`GET ${ApiPrefix}/dashboard`](req, res) {
|
||||
res.json(Dashboard)
|
||||
},
|
||||
@@ -0,0 +1,2 @@
|
||||
declare module 'mockjs'
|
||||
declare module 'qs'
|
||||
@@ -1,67 +0,0 @@
|
||||
import { Mock, Constant } from './_utils'
|
||||
|
||||
const { ApiPrefix } = Constant
|
||||
|
||||
let postId = 0
|
||||
const database = Mock.mock({
|
||||
'data|100': [
|
||||
{
|
||||
id() {
|
||||
postId += 1
|
||||
return postId + 10000
|
||||
},
|
||||
'status|1-2': 1,
|
||||
title: '@title',
|
||||
author: '@last',
|
||||
categories: '@word',
|
||||
tags: '@word',
|
||||
'views|10-200': 1,
|
||||
'comments|10-200': 1,
|
||||
visibility: () => {
|
||||
return Mock.mock(
|
||||
'@pick(["Public",' + '"Password protected", ' + '"Private"])'
|
||||
)
|
||||
},
|
||||
date: '@dateTime',
|
||||
image() {
|
||||
return Mock.Random.image(
|
||||
'100x100',
|
||||
Mock.Random.color(),
|
||||
'#757575',
|
||||
'png',
|
||||
this.author.substr(0, 1)
|
||||
)
|
||||
},
|
||||
},
|
||||
],
|
||||
}).data
|
||||
|
||||
module.exports = {
|
||||
[`GET ${ApiPrefix}/posts`](req, res) {
|
||||
const { query } = req
|
||||
let { pageSize, page, ...other } = query
|
||||
pageSize = pageSize || 10
|
||||
page = page || 1
|
||||
|
||||
let newData = database
|
||||
for (let key in other) {
|
||||
if ({}.hasOwnProperty.call(other, key)) {
|
||||
newData = newData.filter(item => {
|
||||
if ({}.hasOwnProperty.call(item, key)) {
|
||||
return (
|
||||
String(item[key])
|
||||
.trim()
|
||||
.indexOf(decodeURI(other[key]).trim()) > -1
|
||||
)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
data: newData.slice((page - 1) * pageSize, page * pageSize),
|
||||
total: newData.length,
|
||||
})
|
||||
},
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Constant } from './_utils'
|
||||
import { Constant } from './utils'
|
||||
const { ApiPrefix } = Constant
|
||||
|
||||
const database = [
|
||||
@@ -7,10 +7,10 @@ const database = [
|
||||
icon: 'dashboard',
|
||||
name: 'Dashboard',
|
||||
zh: {
|
||||
name: '仪表盘'
|
||||
name: '仪表盘',
|
||||
},
|
||||
'pt-br': {
|
||||
name: 'Dashboard'
|
||||
name: 'Dashboard',
|
||||
},
|
||||
route: '/dashboard',
|
||||
},
|
||||
@@ -19,10 +19,10 @@ const database = [
|
||||
breadcrumbParentId: '1',
|
||||
name: 'Users',
|
||||
zh: {
|
||||
name: '用户管理'
|
||||
name: '用户管理',
|
||||
},
|
||||
'pt-br': {
|
||||
name: 'Usuário'
|
||||
name: 'Usuário',
|
||||
},
|
||||
icon: 'user',
|
||||
route: '/user',
|
||||
@@ -32,10 +32,10 @@ const database = [
|
||||
breadcrumbParentId: '1',
|
||||
name: 'Posts',
|
||||
zh: {
|
||||
name: '用户管理'
|
||||
name: '用户管理',
|
||||
},
|
||||
'pt-br': {
|
||||
name: 'Posts'
|
||||
name: 'Posts',
|
||||
},
|
||||
icon: 'shopping-cart',
|
||||
route: '/post',
|
||||
@@ -46,10 +46,10 @@ const database = [
|
||||
breadcrumbParentId: '2',
|
||||
name: 'User Detail',
|
||||
zh: {
|
||||
name: '用户详情'
|
||||
name: '用户详情',
|
||||
},
|
||||
'pt-br': {
|
||||
name: 'Detalhes do usuário'
|
||||
name: 'Detalhes do usuário',
|
||||
},
|
||||
route: '/user/:id',
|
||||
},
|
||||
@@ -58,10 +58,10 @@ const database = [
|
||||
breadcrumbParentId: '1',
|
||||
name: 'Request',
|
||||
zh: {
|
||||
name: 'Request'
|
||||
name: 'Request',
|
||||
},
|
||||
'pt-br': {
|
||||
name: 'Requisição'
|
||||
name: 'Requisição',
|
||||
},
|
||||
icon: 'api',
|
||||
route: '/request',
|
||||
@@ -71,10 +71,10 @@ const database = [
|
||||
breadcrumbParentId: '1',
|
||||
name: 'UI Element',
|
||||
zh: {
|
||||
name: 'UI组件'
|
||||
name: 'UI组件',
|
||||
},
|
||||
'pt-br': {
|
||||
name: 'Elementos UI'
|
||||
name: 'Elementos UI',
|
||||
},
|
||||
icon: 'camera-o',
|
||||
},
|
||||
@@ -84,23 +84,23 @@ const database = [
|
||||
menuParentId: '4',
|
||||
name: 'Editor',
|
||||
zh: {
|
||||
name: 'Editor'
|
||||
name: 'Editor',
|
||||
},
|
||||
'pt-br': {
|
||||
name: 'Editor'
|
||||
name: 'Editor',
|
||||
},
|
||||
icon: 'edit',
|
||||
route: '/UIElement/editor',
|
||||
route: '/editor',
|
||||
},
|
||||
{
|
||||
id: '5',
|
||||
breadcrumbParentId: '1',
|
||||
name: 'Charts',
|
||||
zh: {
|
||||
name: 'Charts'
|
||||
name: 'Charts',
|
||||
},
|
||||
'pt-br': {
|
||||
name: 'Graficos'
|
||||
name: 'Graficos',
|
||||
},
|
||||
icon: 'code-o',
|
||||
},
|
||||
@@ -110,10 +110,10 @@ const database = [
|
||||
menuParentId: '5',
|
||||
name: 'ECharts',
|
||||
zh: {
|
||||
name: 'ECharts'
|
||||
name: 'ECharts',
|
||||
},
|
||||
'pt-br': {
|
||||
name: 'ECharts'
|
||||
name: 'ECharts',
|
||||
},
|
||||
icon: 'line-chart',
|
||||
route: '/chart/ECharts',
|
||||
@@ -124,10 +124,10 @@ const database = [
|
||||
menuParentId: '5',
|
||||
name: 'HighCharts',
|
||||
zh: {
|
||||
name: 'HighCharts'
|
||||
name: 'HighCharts',
|
||||
},
|
||||
'pt-br': {
|
||||
name: 'HighCharts'
|
||||
name: 'HighCharts',
|
||||
},
|
||||
icon: 'bar-chart',
|
||||
route: '/chart/highCharts',
|
||||
@@ -138,17 +138,17 @@ const database = [
|
||||
menuParentId: '5',
|
||||
name: 'Rechartst',
|
||||
zh: {
|
||||
name: 'Rechartst'
|
||||
name: 'Rechartst',
|
||||
},
|
||||
'pt-br': {
|
||||
name: 'Rechartst'
|
||||
name: 'Rechartst',
|
||||
},
|
||||
icon: 'area-chart',
|
||||
route: '/chart/Recharts',
|
||||
},
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
[`GET ${ApiPrefix}/routes`](req, res) {
|
||||
res.status(200).json(database)
|
||||
},
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Mock, Constant, qs, randomAvatar } from './_utils'
|
||||
import Mock from 'mockjs'
|
||||
import qs from 'qs'
|
||||
import { Constant, randomAvatar, waitTime } from './utils'
|
||||
|
||||
const { ApiPrefix } = Constant
|
||||
|
||||
let usersListData = Mock.mock({
|
||||
const usersListData = Mock.mock({
|
||||
'data|80-100': [
|
||||
{
|
||||
id: '@id',
|
||||
@@ -90,10 +92,28 @@ const NOTFOUND = {
|
||||
documentation_url: 'http://localhost:8000/request',
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
[`POST ${ApiPrefix}/user/login`](req, res) {
|
||||
const authorized = (req, res) => {
|
||||
const cookie = req.headers.cookie || ''
|
||||
const cookies = qs.parse(cookie.replace(/\s/g, ''), { delimiter: ';' })
|
||||
if (!cookies.token) {
|
||||
res.status(401).send({ message: 'Not Login' })
|
||||
return false
|
||||
}
|
||||
|
||||
const token = JSON.parse(cookies.token)
|
||||
if (cookies.token && token && token.deadline > new Date().getTime()) {
|
||||
return token
|
||||
}
|
||||
|
||||
res.status(401).send({ message: 'Not Login' })
|
||||
return false
|
||||
}
|
||||
|
||||
export default {
|
||||
async [`POST ${ApiPrefix}/user/login`](req, res) {
|
||||
await waitTime()
|
||||
const { username, password } = req.body
|
||||
const user = adminUsers.filter(item => item.username === username)
|
||||
const user = adminUsers.filter((item) => item.username === username)
|
||||
|
||||
if (user.length > 0 && user[0].password === password) {
|
||||
const now = new Date()
|
||||
@@ -112,33 +132,27 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
[`GET ${ApiPrefix}/user/logout`](req, res) {
|
||||
async [`GET ${ApiPrefix}/user/logout`](req, res) {
|
||||
await waitTime()
|
||||
res.clearCookie('token')
|
||||
res.status(200).end()
|
||||
},
|
||||
|
||||
[`GET ${ApiPrefix}/user`](req, res) {
|
||||
const cookie = req.headers.cookie || ''
|
||||
const cookies = qs.parse(cookie.replace(/\s/g, ''), { delimiter: ';' })
|
||||
const response = {}
|
||||
let user = {}
|
||||
if (!cookies.token) {
|
||||
res.status(200).send({ message: 'Not Login' })
|
||||
async [`GET ${ApiPrefix}/user`](req, res) {
|
||||
await waitTime()
|
||||
|
||||
const token = authorized(req, res)
|
||||
if (!token) {
|
||||
return
|
||||
}
|
||||
const token = JSON.parse(cookies.token)
|
||||
if (token) {
|
||||
response.success = token.deadline > new Date().getTime()
|
||||
|
||||
const userItem = adminUsers.find((_) => _.id === token.id)
|
||||
if (userItem) {
|
||||
const { password, ...rest } = userItem
|
||||
res.json(rest)
|
||||
} else {
|
||||
res.status(401).send({ message: 'Not Login' })
|
||||
}
|
||||
if (response.success) {
|
||||
const userItem = adminUsers.find(_ => _.id === token.id)
|
||||
if (userItem) {
|
||||
const { password, ...other } = userItem
|
||||
user = other
|
||||
}
|
||||
}
|
||||
response.user = user
|
||||
res.json(response)
|
||||
},
|
||||
|
||||
[`GET ${ApiPrefix}/users`](req, res) {
|
||||
@@ -150,10 +164,10 @@ module.exports = {
|
||||
let newData = database
|
||||
for (let key in other) {
|
||||
if ({}.hasOwnProperty.call(other, key)) {
|
||||
newData = newData.filter(item => {
|
||||
newData = newData.filter((item) => {
|
||||
if ({}.hasOwnProperty.call(item, key)) {
|
||||
if (key === 'address') {
|
||||
return other[key].every(iitem => item[key].indexOf(iitem) > -1)
|
||||
return other[key].every((iitem) => item[key].indexOf(iitem) > -1)
|
||||
} else if (key === 'createTime') {
|
||||
const start = new Date(other[key][0]).getTime()
|
||||
const end = new Date(other[key][1]).getTime()
|
||||
@@ -165,9 +179,8 @@ module.exports = {
|
||||
return true
|
||||
}
|
||||
return (
|
||||
String(item[key])
|
||||
.trim()
|
||||
.indexOf(decodeURI(other[key]).trim()) > -1
|
||||
String(item[key]).trim().indexOf(decodeURI(other[key]).trim()) >
|
||||
-1
|
||||
)
|
||||
}
|
||||
return true
|
||||
@@ -176,14 +189,14 @@ module.exports = {
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
data: newData.slice((page - 1) * pageSize, page * pageSize),
|
||||
list: newData.slice((page - 1) * pageSize, page * pageSize),
|
||||
total: newData.length,
|
||||
})
|
||||
},
|
||||
|
||||
[`POST ${ApiPrefix}/users/delete`](req, res) {
|
||||
const { ids=[] } = req.body
|
||||
database = database.filter(item => !ids.some(_ => _ === item.id))
|
||||
const { ids = [] } = req.body
|
||||
database = database.filter((item) => !ids.some((_) => _ === item.id))
|
||||
res.status(204).end()
|
||||
},
|
||||
|
||||
@@ -220,7 +233,7 @@ module.exports = {
|
||||
const { id } = req.params
|
||||
const data = queryArray(database, id, 'id')
|
||||
if (data) {
|
||||
database = database.filter(item => item.id !== id)
|
||||
database = database.filter((item) => item.id !== id)
|
||||
res.status(204).end()
|
||||
} else {
|
||||
res.status(200).json(NOTFOUND)
|
||||
@@ -232,7 +245,7 @@ module.exports = {
|
||||
const editItem = req.body
|
||||
let isExist = false
|
||||
|
||||
database = database.map(item => {
|
||||
database = database.map((item) => {
|
||||
if (item.id === id) {
|
||||
isExist = true
|
||||
return Object.assign({}, item, editItem)
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Query objects that specify keys and values in an array where all values are objects.
|
||||
* @param {array} array An array where all values are objects, like [{key:1},{key:2}].
|
||||
* @param {string} key The key of the object that needs to be queried.
|
||||
* @param {string} value The value of the object that needs to be queried.
|
||||
* @return {object|undefined} Return frist object when query success.
|
||||
*/
|
||||
export function queryArray(array, key, value) {
|
||||
if (!Array.isArray(array)) {
|
||||
return
|
||||
}
|
||||
return array.filter((_) => _[key] === value)
|
||||
}
|
||||
|
||||
export function randomNumber(min, max) {
|
||||
return Math.floor(Math.random() * (max - min) + min)
|
||||
}
|
||||
|
||||
export function randomAvatar() {
|
||||
const avatarList = [
|
||||
'photo-1549492864-2ec7d66ffb04.jpeg',
|
||||
'photo-1480535339474-e083439a320d.jpeg',
|
||||
'photo-1523419409543-a5e549c1faa8.jpeg',
|
||||
'photo-1519648023493-d82b5f8d7b8a.jpeg',
|
||||
'photo-1523307730650-594bc63f9d67.jpeg',
|
||||
'photo-1522962506050-a2f0267e4895.jpeg',
|
||||
'photo-1489779162738-f81aed9b0a25.jpeg',
|
||||
'photo-1534308143481-c55f00be8bd7.jpeg',
|
||||
'photo-1519336555923-59661f41bb45.jpeg',
|
||||
'photo-1551438632-e8c7d9a5d1b7.jpeg',
|
||||
'photo-1525879000488-bff3b1c387cf.jpeg',
|
||||
'photo-1487412720507-e7ab37603c6f.jpeg',
|
||||
'photo-1510227272981-87123e259b17.jpeg',
|
||||
]
|
||||
return `//image.zuiidea.com/${
|
||||
avatarList[randomNumber(0, avatarList.length - 1)]
|
||||
}?imageView2/1/w/200/h/200/format/webp/q/75|imageslim`
|
||||
}
|
||||
|
||||
export const waitTime = (time: number = 300) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(true)
|
||||
}, time)
|
||||
})
|
||||
}
|
||||
|
||||
export const Constant = {
|
||||
ApiPrefix: '/api/v1',
|
||||
NotFound: {
|
||||
message: 'Not Found',
|
||||
documentation_url: '',
|
||||
},
|
||||
Color: {
|
||||
green: '#64ea91',
|
||||
blue: '#8fc9fb',
|
||||
purple: '#d897eb',
|
||||
red: '#f69899',
|
||||
yellow: '#f8c82e',
|
||||
peach: '#f797d6',
|
||||
borderBase: '#e5e5e5',
|
||||
borderSplit: '#f4f4f4',
|
||||
grass: '#d6fbb5',
|
||||
sky: '#c1e0fc',
|
||||
},
|
||||
}
|
||||
@@ -1,108 +1,122 @@
|
||||
{
|
||||
"name": "antd-admin",
|
||||
"version": "5.1.0",
|
||||
"version": "6.0.0-a.1",
|
||||
"license": "MIT",
|
||||
"description": "An admin dashboard application demo built upon Ant Design and UmiJS",
|
||||
"dependencies": {
|
||||
"@lingui/react": "^2.8.0",
|
||||
"ant-design-pro": "^2.3.0",
|
||||
"antd": "^3.19.0",
|
||||
"axios": "^0.19.0",
|
||||
"classnames": "^2.2.6",
|
||||
"d3-shape": "^1.3.0",
|
||||
"draftjs-to-html": "^0.8.4",
|
||||
"draftjs-to-markdown": "^0.5.1",
|
||||
"@ant-design/icons": "^4.7.0",
|
||||
"@ant-design/pro-layout": "^6.37.0",
|
||||
"@lingui/core": "^3.13.3",
|
||||
"@lingui/detect-locale": "^3.13.3",
|
||||
"@lingui/react": "^3.13.3",
|
||||
"antd": "^4.20.1",
|
||||
"axios": "^0.27.2",
|
||||
"classnames": "^2.3.1",
|
||||
"dva-model-extend": "^0.1.2",
|
||||
"echarts": "^4.2.0",
|
||||
"echarts-for-react": "^2.0.15-beta.0",
|
||||
"echarts-gl": "^1.1.1",
|
||||
"echarts-liquidfill": "^2.0.2",
|
||||
"enquire-js": "^0.2.1",
|
||||
"highcharts-exporting": "^0.1.7",
|
||||
"highcharts-more": "^0.1.7",
|
||||
"echarts": "^5.3.2",
|
||||
"echarts-for-react": "^3.0.2",
|
||||
"echarts-gl": "^2.0.9",
|
||||
"echarts-liquidfill": "^3.1.0",
|
||||
"json-format": "^1.0.1",
|
||||
"lodash": "^4.17.11",
|
||||
"md5": "^2.2.1",
|
||||
"lodash": "^4.17.21",
|
||||
"make-plural": "^7.1.0",
|
||||
"md5": "^2.3.0",
|
||||
"nprogress": "^0.2.0",
|
||||
"path-to-regexp": "^3.0.0",
|
||||
"prop-types": "^15.7.0",
|
||||
"qs": "^6.7.0",
|
||||
"react-adsense": "^0.1.0",
|
||||
"react-countup": "^4.1.0",
|
||||
"react-draft-wysiwyg": "^1.13.0",
|
||||
"react-helmet": "^5.2.0",
|
||||
"react-highcharts": "^16.0.2",
|
||||
"react-perfect-scrollbar": "^1.5.0",
|
||||
"recharts": "^1.6.0",
|
||||
"store": "^2.0.0"
|
||||
"path-to-regexp": "^6.2.0",
|
||||
"prop-types": "^15.8.1",
|
||||
"qs": "^6.10.3",
|
||||
"react": "^18.1.0",
|
||||
"react-countup": "^6.2.0",
|
||||
"react-dom": "^18.1.0",
|
||||
"react-helmet": "^6.1.0",
|
||||
"react-highcharts": "^16.1.0",
|
||||
"react-perfect-scrollbar": "^1.5.8",
|
||||
"react-router-dom": "^6.3.0",
|
||||
"recharts": "^2.1.9",
|
||||
"store": "^2.0.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@lingui/babel-preset-react": "^2.8.2",
|
||||
"@lingui/cli": "^2.8.2",
|
||||
"@lingui/loader": "^2.8.2",
|
||||
"babel-core": "7.0.0-bridge.0",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"babel-plugin-dev-expression": "^0.2.1",
|
||||
"babel-plugin-import": "^1.12.0",
|
||||
"babel-plugin-macros": "^2.5.0",
|
||||
"babel-plugin-module-resolver": "^3.2.0",
|
||||
"cross-env": "^5.2.0",
|
||||
"eslint": "^5.15.0",
|
||||
"eslint-config-react-app": "^4.0.0",
|
||||
"eslint-plugin-flowtype": "^3.4.0",
|
||||
"eslint-plugin-import": "^2.17.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.2.1",
|
||||
"eslint-plugin-react": "^7.13.0",
|
||||
"eslint-plugin-react-hooks": "^1.6.0",
|
||||
"husky": "^2.3.0",
|
||||
"@babel/preset-react": "^7.16.7",
|
||||
"@lingui/babel-preset-react": "^2.9.2",
|
||||
"@lingui/cli": "^3.13.3",
|
||||
"@lingui/loader": "^3.13.3",
|
||||
"@lingui/macro": "^3.13.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.21.0",
|
||||
"@typescript-eslint/parser": "^5.21.0",
|
||||
"babel-plugin-dev-expression": "^0.2.3",
|
||||
"babel-plugin-import": "^1.13.5",
|
||||
"babel-plugin-macros": "^3.1.0",
|
||||
"babel-plugin-module-resolver": "^4.1.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.14.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-config-react-app": "^7.0.1",
|
||||
"eslint-plugin-babel": "^5.3.1",
|
||||
"eslint-plugin-flowtype": "^8.0.3",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.5.1",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"eslint-plugin-react": "^7.29.4",
|
||||
"eslint-plugin-react-hooks": "^4.5.0",
|
||||
"husky": "^7.0.4",
|
||||
"less-vars-to-js": "^1.3.0",
|
||||
"lint-staged": "^8.1.0",
|
||||
"mockjs": "^1.0.1-beta3",
|
||||
"module": "^1.2.5",
|
||||
"prettier": "^1.16.0",
|
||||
"stylelint": "^10.0.0",
|
||||
"stylelint-config-prettier": "^5.2.0",
|
||||
"stylelint-config-standard": "^18.3.0",
|
||||
"umi": "^2.8.1",
|
||||
"umi-plugin-react": "^1.9.1"
|
||||
"lint-staged": "^12.4.1",
|
||||
"mockjs": "^1.1.0",
|
||||
"prettier": "^2.6.2",
|
||||
"stylelint": "^14.8.0",
|
||||
"stylelint-config-prettier": "^9.0.3",
|
||||
"stylelint-config-standard": "^25.0.0",
|
||||
"typescript": "^4.6.4",
|
||||
"umi": "4.0.0-canary.20220429.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
},
|
||||
"lint-staged": {
|
||||
"src/**/*.js": [
|
||||
"eslint --ext .js --fix",
|
||||
"npm run prettier",
|
||||
"git add"
|
||||
"*.{ts,tsx,js,jsx}": [
|
||||
"npm run eslint",
|
||||
"npm run prettier"
|
||||
],
|
||||
"**/*.less": [
|
||||
"stylelint --syntax less",
|
||||
"npm run prettier",
|
||||
"git add"
|
||||
"*.less": [
|
||||
"npm run stylelint",
|
||||
"npm run prettier"
|
||||
]
|
||||
},
|
||||
"lingui": {
|
||||
"fallbackLocale": "en",
|
||||
"fallbackLocales": {
|
||||
"default": "en"
|
||||
},
|
||||
"sourceLocale": "en",
|
||||
"localeDir": "src/locales",
|
||||
"srcPathDirs": [
|
||||
"src/pages",
|
||||
"src/layouts",
|
||||
"src/components",
|
||||
"src/layouts"
|
||||
"locales": [
|
||||
"en",
|
||||
"zh",
|
||||
"pt-br"
|
||||
],
|
||||
"catalogs": [
|
||||
{
|
||||
"path": "src/locales/{locale}/messages",
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**"
|
||||
]
|
||||
}
|
||||
],
|
||||
"format": "minimal",
|
||||
"extractBabelOptions": {
|
||||
"presets": [
|
||||
"umi/babel"
|
||||
]
|
||||
}
|
||||
"runtimeConfigModule": [
|
||||
"@/hooks/useIntlProvider",
|
||||
"i18n"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"analyze": "cross-env ANALYZE=1 umi build",
|
||||
"build": "umi build",
|
||||
"lint:js": "eslint --ext .js src",
|
||||
"lint:style": "stylelint \"src/**/*.less\" --syntax less",
|
||||
"start": "umi dev",
|
||||
"test": "cross-env BABELRC=none umi test",
|
||||
"prettier": "prettier --write 'src/**/*.{js,less}'",
|
||||
"build": "cross-env UMI_ENV=prod umi build",
|
||||
"test": "umi test",
|
||||
"analyze": "cross-env ANALYZE=1 umi dev",
|
||||
"eslint": "eslint --fix 'src/**/*.{ts,tsx,js.jsx}'",
|
||||
"stylelint": "stylelint src/**/*.less --syntax less",
|
||||
"prettier": "prettier --write 'src/**/*.{ts,tsx,js.jsx,less}'",
|
||||
"precommit": "lint-staged",
|
||||
"add-locale": "lingui add-locale",
|
||||
"extract": "lingui extract",
|
||||
|
||||
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 9.7 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
|
||||
<rect style="fill:#D80027;" width="512" height="512"/>
|
||||
<polygon style="fill:#6DA544;" points="196.641,0 196.641,264.348 196.641,512 0,512 0,0 "/>
|
||||
<circle style="fill:#FFDA44;" cx="196.641" cy="256" r="96"/>
|
||||
<path style="fill:#D80027;" d="M142.638,208v60c0,29.823,24.178,54,54,54s54-24.178,54-54v-60H142.638z"/>
|
||||
<path style="fill:#F0F0F0;" d="M196.638,286c-9.925,0-18-8.075-18-18v-24.001h36V268C214.638,277.925,206.563,286,196.638,286z"/>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 973 B |
@@ -1,34 +0,0 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Dropdown, Button, Icon, Menu } from 'antd'
|
||||
|
||||
const DropOption = ({
|
||||
onMenuClick,
|
||||
menuOptions = [],
|
||||
buttonStyle,
|
||||
dropdownProps,
|
||||
}) => {
|
||||
const menu = menuOptions.map(item => (
|
||||
<Menu.Item key={item.key}>{item.name}</Menu.Item>
|
||||
))
|
||||
return (
|
||||
<Dropdown
|
||||
overlay={<Menu onClick={onMenuClick}>{menu}</Menu>}
|
||||
{...dropdownProps}
|
||||
>
|
||||
<Button style={{ border: 'none', ...buttonStyle }}>
|
||||
<Icon style={{ marginRight: 2 }} type="bars" />
|
||||
<Icon type="down" />
|
||||
</Button>
|
||||
</Dropdown>
|
||||
)
|
||||
}
|
||||
|
||||
DropOption.propTypes = {
|
||||
onMenuClick: PropTypes.func,
|
||||
menuOptions: PropTypes.array.isRequired,
|
||||
buttonStyle: PropTypes.object,
|
||||
dropdownProps: PropTypes.object,
|
||||
}
|
||||
|
||||
export default DropOption
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "DropOption",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./DropOption.js"
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import React from 'react'
|
||||
import { Editor } from 'react-draft-wysiwyg'
|
||||
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css'
|
||||
import styles from './Editor.less'
|
||||
|
||||
const DraftEditor = props => {
|
||||
return (
|
||||
<Editor
|
||||
toolbarClassName={styles.toolbar}
|
||||
wrapperClassName={styles.wrapper}
|
||||
editorClassName={styles.editor}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default DraftEditor
|
||||
@@ -1,106 +0,0 @@
|
||||
.wrapper {
|
||||
height: 500px;
|
||||
|
||||
:global {
|
||||
.rdw-dropdownoption-default {
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.rdw-dropdown-optionwrapper {
|
||||
box-sizing: content-box;
|
||||
width: 100%;
|
||||
border-radius: 0 0 2px 2px;
|
||||
&:hover {
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
|
||||
.rdw-inline-wrapper {
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 0;
|
||||
|
||||
.rdw-option-wrapper {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
}
|
||||
|
||||
.rdw-option-active {
|
||||
box-shadow: 1px 1px 0 #e8e8e8 inset;
|
||||
}
|
||||
|
||||
.rdw-colorpicker-option {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.rdw-colorpicker-modal,
|
||||
.rdw-embedded-modal,
|
||||
.rdw-emoji-modal,
|
||||
.rdw-image-modal,
|
||||
.rdw-link-modal {
|
||||
box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.rdw-colorpicker-modal,
|
||||
.rdw-embedded-modal,
|
||||
.rdw-link-modal {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.rdw-emoji-modal {
|
||||
width: 214px;
|
||||
}
|
||||
|
||||
.rdw-colorpicker-modal {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.rdw-embedded-modal-btn,
|
||||
.rdw-image-modal-btn,
|
||||
.rdw-link-modal-btn {
|
||||
height: 32px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.rdw-embedded-modal-input,
|
||||
.rdw-embedded-modal-size-input,
|
||||
.rdw-link-modal-input {
|
||||
padding: 2px 6px;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
.rdw-dropdown-selectedtext {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.rdw-dropdown-wrapper,
|
||||
.rdw-option-wrapper {
|
||||
min-width: 36px;
|
||||
transition: all 0.2s ease;
|
||||
height: 30px;
|
||||
|
||||
&:active {
|
||||
box-shadow: 1px 1px 0 #e8e8e8 inset;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
box-shadow: 1px 1px 0 #e8e8e8;
|
||||
}
|
||||
}
|
||||
|
||||
.rdw-dropdown-wrapper {
|
||||
min-width: 60px;
|
||||
}
|
||||
|
||||
.rdw-editor-main {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
|
||||
.editor {
|
||||
border: 1px solid #f1f1f1;
|
||||
padding: 5px;
|
||||
border-radius: 2px;
|
||||
height: auto;
|
||||
min-height: 200px;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "Editor",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./Editor.js"
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import styles from './FilterItem.less'
|
||||
import styles from './index.less'
|
||||
|
||||
const FilterItem = ({ label = '', children }) => {
|
||||
interface FilterItemProps {
|
||||
label: string
|
||||
}
|
||||
const FilterItem: React.FC<FilterItemProps> = ({ label = '', children }) => {
|
||||
const labelArray = label.split('')
|
||||
return (
|
||||
<div className={styles.filterItem}>
|
||||
{labelArray.length > 0 ? (
|
||||
{labelArray.length > 0 && (
|
||||
<div className={styles.labelWrap}>
|
||||
{labelArray.map((item, index) => (
|
||||
<span className="labelText" key={index}>
|
||||
@@ -14,17 +16,10 @@ const FilterItem = ({ label = '', children }) => {
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
<div className={styles.item}>{children}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
FilterItem.propTypes = {
|
||||
label: PropTypes.string,
|
||||
children: PropTypes.element.isRequired,
|
||||
}
|
||||
|
||||
export default FilterItem
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "FilterItem",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./FilterItem.js"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
@import '~antd/lib/style/themes/default.less';
|
||||
|
||||
.globalFooter {
|
||||
margin: 48px 0 24px 0;
|
||||
padding: 0 16px;
|
||||
text-align: center;
|
||||
|
||||
.links {
|
||||
margin-bottom: 8px;
|
||||
|
||||
a {
|
||||
color: @text-color-secondary;
|
||||
transition: all 0.3s;
|
||||
|
||||
&:not(:last-child) {
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
color: @text-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.copyright {
|
||||
color: @text-color-secondary;
|
||||
font-size: @font-size-base;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import React from 'react'
|
||||
import styles from './index.less'
|
||||
|
||||
interface LinkItem {
|
||||
key: string
|
||||
title: React.ReactNode
|
||||
href?: string
|
||||
blankTarget?: boolean
|
||||
}
|
||||
|
||||
interface GlobalFooterProps {
|
||||
links?: LinkItem[]
|
||||
copyright?: React.ReactNode
|
||||
}
|
||||
|
||||
const GlobalFooter: React.FC<GlobalFooterProps> = ({
|
||||
links = [],
|
||||
copyright,
|
||||
}) => {
|
||||
return (
|
||||
<footer className={styles.globalFooter}>
|
||||
<div className={styles.links}>
|
||||
{links.map((link) => (
|
||||
<a
|
||||
key={link.key}
|
||||
title={link.key}
|
||||
target={link.blankTarget ? '_blank' : '_self'}
|
||||
href={link.href}
|
||||
rel="noreferrer"
|
||||
>
|
||||
{link.title}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
{copyright && <div className={styles.copyright}>{copyright}</div>}
|
||||
</footer>
|
||||
)
|
||||
}
|
||||
|
||||
export default GlobalFooter
|
||||
@@ -1,68 +0,0 @@
|
||||
import React, { PureComponent, Fragment } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Breadcrumb, Icon } from 'antd'
|
||||
import Link from 'umi/navlink'
|
||||
import withRouter from 'umi/withRouter'
|
||||
import { withI18n } from '@lingui/react'
|
||||
import { pathMatchRegexp, queryAncestors, addLangPrefix } from 'utils'
|
||||
import styles from './Bread.less'
|
||||
|
||||
@withI18n()
|
||||
@withRouter
|
||||
class Bread extends PureComponent {
|
||||
generateBreadcrumbs = paths => {
|
||||
return paths.map((item, key) => {
|
||||
const content = item && (
|
||||
<Fragment>
|
||||
{item.icon ? (
|
||||
<Icon type={item.icon} style={{ marginRight: 4 }} />
|
||||
) : null}
|
||||
{item.name}
|
||||
</Fragment>
|
||||
)
|
||||
|
||||
return (
|
||||
item && (
|
||||
<Breadcrumb.Item key={key}>
|
||||
{paths.length - 1 !== key ? (
|
||||
<Link to={addLangPrefix(item.route) || '#'}>{content}</Link>
|
||||
) : (
|
||||
content
|
||||
)}
|
||||
</Breadcrumb.Item>
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
render() {
|
||||
const { routeList, location, i18n } = this.props
|
||||
|
||||
// Find a route that matches the pathname.
|
||||
const currentRoute = routeList.find(
|
||||
_ => _.route && pathMatchRegexp(_.route, location.pathname)
|
||||
)
|
||||
|
||||
// Find the breadcrumb navigation of the current route match and all its ancestors.
|
||||
const paths = currentRoute
|
||||
? queryAncestors(routeList, currentRoute, 'breadcrumbParentId').reverse()
|
||||
: [
|
||||
routeList[0],
|
||||
{
|
||||
id: 404,
|
||||
name: i18n.t`Not Found`,
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<Breadcrumb className={styles.bread}>
|
||||
{this.generateBreadcrumbs(paths)}
|
||||
</Breadcrumb>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Bread.propTypes = {
|
||||
routeList: PropTypes.array,
|
||||
}
|
||||
|
||||
export default Bread
|
||||
@@ -1,16 +0,0 @@
|
||||
.bread {
|
||||
margin-bottom: 24px;
|
||||
|
||||
:global {
|
||||
.ant-breadcrumb {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.bread {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
import React, { PureComponent, Fragment } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Menu, Icon, Layout, Avatar, Popover, Badge, List } from 'antd'
|
||||
import { Ellipsis } from 'ant-design-pro'
|
||||
import { Trans, withI18n } from '@lingui/react'
|
||||
import { setLocale } from 'utils'
|
||||
import moment from 'moment'
|
||||
import classnames from 'classnames'
|
||||
import config from 'config'
|
||||
import styles from './Header.less'
|
||||
|
||||
const { SubMenu } = Menu
|
||||
|
||||
@withI18n()
|
||||
class Header extends PureComponent {
|
||||
handleClickMenu = e => {
|
||||
e.key === 'SignOut' && this.props.onSignOut()
|
||||
}
|
||||
render() {
|
||||
const {
|
||||
i18n,
|
||||
fixed,
|
||||
avatar,
|
||||
username,
|
||||
collapsed,
|
||||
notifications,
|
||||
onCollapseChange,
|
||||
onAllNotificationsRead,
|
||||
} = this.props
|
||||
|
||||
const rightContent = [
|
||||
<Menu key="user" mode="horizontal" onClick={this.handleClickMenu}>
|
||||
<SubMenu
|
||||
title={
|
||||
<Fragment>
|
||||
<span style={{ color: '#999', marginRight: 4 }}>
|
||||
<Trans>Hi,</Trans>
|
||||
</span>
|
||||
<span>{username}</span>
|
||||
<Avatar style={{ marginLeft: 8 }} src={avatar} />
|
||||
</Fragment>
|
||||
}
|
||||
>
|
||||
<Menu.Item key="SignOut">
|
||||
<Trans>Sign out</Trans>
|
||||
</Menu.Item>
|
||||
</SubMenu>
|
||||
</Menu>,
|
||||
]
|
||||
|
||||
if (config.i18n) {
|
||||
const { languages } = config.i18n
|
||||
const currentLanguage = languages.find(
|
||||
item => item.key === i18n._language
|
||||
)
|
||||
|
||||
rightContent.unshift(
|
||||
<Menu
|
||||
key="language"
|
||||
selectedKeys={[currentLanguage.key]}
|
||||
onClick={data => {
|
||||
setLocale(data.key)
|
||||
}}
|
||||
mode="horizontal"
|
||||
>
|
||||
<SubMenu title={<Avatar size="small" src={currentLanguage.flag} />}>
|
||||
{languages.map(item => (
|
||||
<Menu.Item key={item.key}>
|
||||
<Avatar
|
||||
size="small"
|
||||
style={{ marginRight: 8 }}
|
||||
src={item.flag}
|
||||
/>
|
||||
{item.title}
|
||||
</Menu.Item>
|
||||
))}
|
||||
</SubMenu>
|
||||
</Menu>
|
||||
)
|
||||
}
|
||||
|
||||
rightContent.unshift(
|
||||
<Popover
|
||||
placement="bottomRight"
|
||||
trigger="click"
|
||||
key="notifications"
|
||||
overlayClassName={styles.notificationPopover}
|
||||
getPopupContainer={() => document.querySelector('#layoutHeader')}
|
||||
content={
|
||||
<div className={styles.notification}>
|
||||
<List
|
||||
itemLayout="horizontal"
|
||||
dataSource={notifications}
|
||||
locale={{
|
||||
emptyText: <Trans>You have viewed all notifications.</Trans>,
|
||||
}}
|
||||
renderItem={item => (
|
||||
<List.Item className={styles.notificationItem}>
|
||||
<List.Item.Meta
|
||||
title={
|
||||
<Ellipsis tooltip lines={1}>
|
||||
{item.title}
|
||||
</Ellipsis>
|
||||
}
|
||||
description={moment(item.date).fromNow()}
|
||||
/>
|
||||
<Icon
|
||||
style={{ fontSize: 10, color: '#ccc' }}
|
||||
type="right"
|
||||
theme="outlined"
|
||||
/>
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
{notifications.length ? (
|
||||
<div
|
||||
onClick={onAllNotificationsRead}
|
||||
className={styles.clearButton}
|
||||
>
|
||||
<Trans>Clear notifications</Trans>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Badge
|
||||
count={notifications.length}
|
||||
dot
|
||||
offset={[-10, 10]}
|
||||
className={styles.iconButton}
|
||||
>
|
||||
<Icon className={styles.iconFont} type="bell" />
|
||||
</Badge>
|
||||
</Popover>
|
||||
)
|
||||
|
||||
return (
|
||||
<Layout.Header
|
||||
className={classnames(styles.header, {
|
||||
[styles.fixed]: fixed,
|
||||
[styles.collapsed]: collapsed,
|
||||
})}
|
||||
id="layoutHeader"
|
||||
>
|
||||
<div
|
||||
className={styles.button}
|
||||
onClick={onCollapseChange.bind(this, !collapsed)}
|
||||
>
|
||||
<Icon
|
||||
type={classnames({
|
||||
'menu-unfold': collapsed,
|
||||
'menu-fold': !collapsed,
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className={styles.rightContainer}>{rightContent}</div>
|
||||
</Layout.Header>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Header.propTypes = {
|
||||
fixed: PropTypes.bool,
|
||||
user: PropTypes.object,
|
||||
menus: PropTypes.array,
|
||||
collapsed: PropTypes.bool,
|
||||
onSignOut: PropTypes.func,
|
||||
notifications: PropTypes.array,
|
||||
onCollapseChange: PropTypes.func,
|
||||
onAllNotificationsRead: PropTypes.func,
|
||||
}
|
||||
|
||||
export default Header
|
||||
@@ -1,154 +0,0 @@
|
||||
@import '~themes/vars.less';
|
||||
|
||||
.header {
|
||||
padding: 0;
|
||||
box-shadow: @shadow-2;
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
height: 72px;
|
||||
z-index: 9;
|
||||
align-items: center;
|
||||
background-color: #fff;
|
||||
|
||||
&.fixed {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: ~'calc(100% - 256px)';
|
||||
z-index: 29;
|
||||
transition: width 0.2s;
|
||||
|
||||
&.collapsed {
|
||||
width: ~'calc(100% - 80px)';
|
||||
}
|
||||
}
|
||||
|
||||
:global {
|
||||
.ant-menu-submenu-title {
|
||||
height: 72px;
|
||||
}
|
||||
|
||||
.ant-menu-horizontal {
|
||||
line-height: 72px;
|
||||
|
||||
& > .ant-menu-submenu:hover {
|
||||
color: @primary-color;
|
||||
background-color: @hover-color;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-menu {
|
||||
border-bottom: none;
|
||||
height: 72px;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
.rightContainer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.button {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
line-height: 72px;
|
||||
text-align: center;
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
transition: @transition-ease-in;
|
||||
|
||||
&:hover {
|
||||
color: @primary-color;
|
||||
background-color: @hover-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.iconButton {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
border-radius: 24px;
|
||||
cursor: pointer;
|
||||
.background-hover();
|
||||
|
||||
&:hover {
|
||||
.iconFont {
|
||||
color: @primary-color;
|
||||
}
|
||||
}
|
||||
|
||||
& + .iconButton {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.iconFont {
|
||||
color: #b2b0c7;
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
.notification {
|
||||
padding: 24px 0;
|
||||
width: 320px;
|
||||
.notificationItem {
|
||||
transition: all 0.3s;
|
||||
padding: 12px 24px;
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
background-color: @hover-color;
|
||||
}
|
||||
}
|
||||
.clearButton {
|
||||
text-align: center;
|
||||
height: 48px;
|
||||
line-height: 48px;
|
||||
cursor: pointer;
|
||||
.background-hover();
|
||||
}
|
||||
}
|
||||
|
||||
.notificationPopover {
|
||||
:global {
|
||||
.ant-popover-inner-content {
|
||||
padding: 0;
|
||||
}
|
||||
.ant-popover-arrow {
|
||||
display: none;
|
||||
}
|
||||
.ant-list-item-content {
|
||||
flex: 0;
|
||||
margin-left: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.header {
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
import React, { PureComponent, Fragment } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Menu, Icon } from 'antd'
|
||||
import Navlink from 'umi/navlink'
|
||||
import withRouter from 'umi/withRouter'
|
||||
import {
|
||||
arrayToTree,
|
||||
queryAncestors,
|
||||
pathMatchRegexp,
|
||||
addLangPrefix,
|
||||
} from 'utils'
|
||||
import store from 'store'
|
||||
|
||||
const { SubMenu } = Menu
|
||||
|
||||
@withRouter
|
||||
class SiderMenu extends PureComponent {
|
||||
state = {
|
||||
openKeys: store.get('openKeys') || [],
|
||||
}
|
||||
|
||||
onOpenChange = openKeys => {
|
||||
const { menus } = this.props
|
||||
const rootSubmenuKeys = menus.filter(_ => !_.menuParentId).map(_ => _.id)
|
||||
|
||||
const latestOpenKey = openKeys.find(
|
||||
key => this.state.openKeys.indexOf(key) === -1
|
||||
)
|
||||
|
||||
let newOpenKeys = openKeys
|
||||
if (rootSubmenuKeys.indexOf(latestOpenKey) !== -1) {
|
||||
newOpenKeys = latestOpenKey ? [latestOpenKey] : []
|
||||
}
|
||||
|
||||
this.setState({
|
||||
openKeys: newOpenKeys,
|
||||
})
|
||||
store.set('openKeys', newOpenKeys)
|
||||
}
|
||||
|
||||
generateMenus = data => {
|
||||
return data.map(item => {
|
||||
if (item.children) {
|
||||
return (
|
||||
<SubMenu
|
||||
key={item.id}
|
||||
title={
|
||||
<Fragment>
|
||||
{item.icon && <Icon type={item.icon} />}
|
||||
<span>{item.name}</span>
|
||||
</Fragment>
|
||||
}
|
||||
>
|
||||
{this.generateMenus(item.children)}
|
||||
</SubMenu>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Menu.Item key={item.id}>
|
||||
<Navlink to={addLangPrefix(item.route) || '#'}>
|
||||
{item.icon && <Icon type={item.icon} />}
|
||||
<span>{item.name}</span>
|
||||
</Navlink>
|
||||
</Menu.Item>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
collapsed,
|
||||
theme,
|
||||
menus,
|
||||
location,
|
||||
isMobile,
|
||||
onCollapseChange,
|
||||
} = this.props
|
||||
|
||||
// Generating tree-structured data for menu content.
|
||||
const menuTree = arrayToTree(menus, 'id', 'menuParentId')
|
||||
|
||||
// Find a menu that matches the pathname.
|
||||
const currentMenu = menus.find(
|
||||
_ => _.route && pathMatchRegexp(_.route, location.pathname)
|
||||
)
|
||||
|
||||
// Find the key that should be selected according to the current menu.
|
||||
const selectedKeys = currentMenu
|
||||
? queryAncestors(menus, currentMenu, 'menuParentId').map(_ => _.id)
|
||||
: []
|
||||
|
||||
const menuProps = collapsed
|
||||
? {}
|
||||
: {
|
||||
openKeys: this.state.openKeys,
|
||||
}
|
||||
|
||||
return (
|
||||
<Menu
|
||||
mode="inline"
|
||||
theme={theme}
|
||||
onOpenChange={this.onOpenChange}
|
||||
selectedKeys={selectedKeys}
|
||||
onClick={
|
||||
isMobile
|
||||
? () => {
|
||||
onCollapseChange(true)
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
{...menuProps}
|
||||
>
|
||||
{this.generateMenus(menuTree)}
|
||||
</Menu>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
SiderMenu.propTypes = {
|
||||
menus: PropTypes.array,
|
||||
theme: PropTypes.string,
|
||||
isMobile: PropTypes.bool,
|
||||
onCollapseChange: PropTypes.func,
|
||||
}
|
||||
|
||||
export default SiderMenu
|
||||
@@ -1,87 +0,0 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Icon, Switch, Layout } from 'antd'
|
||||
import { withI18n, Trans } from '@lingui/react'
|
||||
import ScrollBar from '../ScrollBar'
|
||||
import { config } from 'utils'
|
||||
import SiderMenu from './Menu'
|
||||
import styles from './Sider.less'
|
||||
|
||||
@withI18n()
|
||||
class Sider extends PureComponent {
|
||||
render() {
|
||||
const {
|
||||
i18n,
|
||||
menus,
|
||||
theme,
|
||||
isMobile,
|
||||
collapsed,
|
||||
onThemeChange,
|
||||
onCollapseChange,
|
||||
} = this.props
|
||||
|
||||
return (
|
||||
<Layout.Sider
|
||||
width={256}
|
||||
theme={theme}
|
||||
breakpoint="lg"
|
||||
trigger={null}
|
||||
collapsible
|
||||
collapsed={collapsed}
|
||||
onBreakpoint={isMobile ? null : onCollapseChange}
|
||||
className={styles.sider}
|
||||
>
|
||||
<div className={styles.brand}>
|
||||
<div className={styles.logo}>
|
||||
<img alt="logo" src={config.logoPath} />
|
||||
{collapsed ? null : <h1>{config.siteName}</h1>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles.menuContainer}>
|
||||
<ScrollBar
|
||||
options={{
|
||||
// Disabled horizontal scrolling, https://github.com/utatti/perfect-scrollbar#options
|
||||
suppressScrollX: true,
|
||||
}}
|
||||
>
|
||||
<SiderMenu
|
||||
menus={menus}
|
||||
theme={theme}
|
||||
isMobile={isMobile}
|
||||
onCollapseChange={onCollapseChange}
|
||||
/>
|
||||
</ScrollBar>
|
||||
</div>
|
||||
{collapsed ? null : (
|
||||
<div className={styles.switchTheme}>
|
||||
<span>
|
||||
<Icon type="bulb" />
|
||||
<Trans>Switch Theme</Trans>
|
||||
</span>
|
||||
<Switch
|
||||
onChange={onThemeChange.bind(
|
||||
this,
|
||||
theme === 'dark' ? 'light' : 'dark'
|
||||
)}
|
||||
defaultChecked={theme === 'dark'}
|
||||
checkedChildren={i18n.t`Dark`}
|
||||
unCheckedChildren={i18n.t`Light`}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Layout.Sider>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Sider.propTypes = {
|
||||
menus: PropTypes.array,
|
||||
theme: PropTypes.string,
|
||||
isMobile: PropTypes.bool,
|
||||
collapsed: PropTypes.bool,
|
||||
onThemeChange: PropTypes.func,
|
||||
onCollapseChange: PropTypes.func,
|
||||
}
|
||||
|
||||
export default Sider
|
||||
@@ -1,110 +0,0 @@
|
||||
@import '~themes/vars.less';
|
||||
|
||||
.sider {
|
||||
box-shadow: fade(@primary-color, 10%) 0 0 28px 0;
|
||||
z-index: 10;
|
||||
:global {
|
||||
.ant-layout-sider-children {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.brand {
|
||||
z-index: 1;
|
||||
height: 72px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 24px;
|
||||
box-shadow: 0 1px 9px -3px rgba(0, 0, 0, 0.2);
|
||||
.logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
img {
|
||||
width: 36px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
vertical-align: text-bottom;
|
||||
font-size: 16px;
|
||||
text-transform: uppercase;
|
||||
display: inline-block;
|
||||
font-weight: 700;
|
||||
color: @primary-color;
|
||||
white-space: nowrap;
|
||||
margin-bottom: 0;
|
||||
.text-gradient();
|
||||
|
||||
:local {
|
||||
animation: fadeRightIn 300ms @ease-in-out;
|
||||
animation-fill-mode: both;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.menuContainer {
|
||||
height: ~'calc(100vh - 120px)';
|
||||
overflow-x: hidden;
|
||||
flex: 1;
|
||||
padding: 24px 0;
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
:global {
|
||||
.ant-menu-inline {
|
||||
border-right: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.switchTheme {
|
||||
width: 100%;
|
||||
height: 48px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0 16px;
|
||||
overflow: hidden;
|
||||
transition: all 0.3s;
|
||||
|
||||
span {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
:global {
|
||||
.anticon {
|
||||
min-width: 14px;
|
||||
margin-right: 4px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeLeftIn {
|
||||
0% {
|
||||
transform: translateX(5px);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translateX(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import Header from './Header'
|
||||
import Menu from './Menu'
|
||||
import Bread from './Bread'
|
||||
import Sider from './Sider'
|
||||
|
||||
export { Header, Menu, Bread, Sider }
|
||||
@@ -1,67 +1,67 @@
|
||||
.loader {
|
||||
background-color: #fff;
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 100000;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
opacity: 1;
|
||||
text-align: center;
|
||||
|
||||
&.fullScreen {
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
.warpper {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.inner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
margin: 0 auto;
|
||||
text-indent: -12345px;
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-right: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-left: 1px solid rgba(0, 0, 0, 0.7);
|
||||
border-radius: 50%;
|
||||
z-index: 100001;
|
||||
|
||||
:local {
|
||||
animation: spinner 600ms infinite linear;
|
||||
}
|
||||
}
|
||||
|
||||
.text {
|
||||
width: 100px;
|
||||
height: 20px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
letter-spacing: 4px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
&.hidden {
|
||||
z-index: -1;
|
||||
opacity: 0;
|
||||
transition: opacity 1s ease 0.5s, z-index 0.1s ease 1.5s;
|
||||
}
|
||||
}
|
||||
@keyframes spinner {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
.loader {
|
||||
background-color: #fff;
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 100000;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
opacity: 1;
|
||||
text-align: center;
|
||||
|
||||
&.fullScreen {
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
.warpper {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.inner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
margin: 0 auto;
|
||||
text-indent: -12345px;
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-right: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-left: 1px solid rgba(0, 0, 0, 0.7);
|
||||
border-radius: 50%;
|
||||
z-index: 100001;
|
||||
|
||||
:local {
|
||||
animation: spinner 600ms infinite linear;
|
||||
}
|
||||
}
|
||||
|
||||
.text {
|
||||
width: 100px;
|
||||
height: 20px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
letter-spacing: 4px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
&.hidden {
|
||||
z-index: -1;
|
||||
opacity: 0;
|
||||
transition: opacity 1s ease 0.5s, z-index 0.1s ease 1.5s;
|
||||
}
|
||||
}
|
||||
@keyframes spinner {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import classNames from 'classnames'
|
||||
import styles from './Loader.less'
|
||||
import styles from './index.less'
|
||||
|
||||
const Loader = ({ spinning = false, fullScreen }) => {
|
||||
interface LoaderProps {
|
||||
spinning?: boolean
|
||||
fullScreen?: boolean
|
||||
}
|
||||
|
||||
const Loader: React.FC<LoaderProps> = ({ spinning = false, fullScreen }) => {
|
||||
return (
|
||||
<div
|
||||
className={classNames(styles.loader, {
|
||||
@@ -19,9 +23,4 @@ const Loader = ({ spinning = false, fullScreen }) => {
|
||||
)
|
||||
}
|
||||
|
||||
Loader.propTypes = {
|
||||
spinning: PropTypes.bool,
|
||||
fullScreen: PropTypes.bool,
|
||||
}
|
||||
|
||||
export default Loader
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "Loader",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./Loader.js"
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import React, { Component } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import classnames from 'classnames'
|
||||
import Loader from '../Loader'
|
||||
import styles from './Page.less'
|
||||
|
||||
export default class Page extends Component {
|
||||
render() {
|
||||
const { className, children, loading = false, inner = false } = this.props
|
||||
const loadingStyle = {
|
||||
height: 'calc(100vh - 184px)',
|
||||
overflow: 'hidden',
|
||||
}
|
||||
return (
|
||||
<div
|
||||
className={classnames(className, {
|
||||
[styles.contentInner]: inner,
|
||||
})}
|
||||
style={loading ? loadingStyle : null}
|
||||
>
|
||||
{loading ? <Loader spinning /> : ''}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Page.propTypes = {
|
||||
className: PropTypes.string,
|
||||
children: PropTypes.node,
|
||||
loading: PropTypes.bool,
|
||||
inner: PropTypes.bool,
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
@import '~themes/vars.less';
|
||||
@import '~@/themes/vars.less';
|
||||
|
||||
.contentInner {
|
||||
background: #fff;
|
||||
@@ -0,0 +1,32 @@
|
||||
import React from 'react'
|
||||
import classnames from 'classnames'
|
||||
import Loader from '../Loader'
|
||||
import styles from './index.less'
|
||||
|
||||
interface IPageProps {
|
||||
inner?: boolean
|
||||
loading?: boolean
|
||||
className?: string
|
||||
}
|
||||
|
||||
const Page: React.FC = (props: IPageProps) => {
|
||||
const { className, children, loading = false, inner = false } = props
|
||||
const loadingStyle = {
|
||||
height: 'calc(100vh - 184px)',
|
||||
overflow: 'hidden',
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classnames(className, {
|
||||
[styles.contentInner]: inner,
|
||||
})}
|
||||
style={loading ? loadingStyle : null}
|
||||
>
|
||||
{loading ? <Loader spinning /> : ''}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Page
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "Page",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./Page.js"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import Editor from './Editor'
|
||||
import FilterItem from './FilterItem'
|
||||
import DropOption from './DropOption'
|
||||
import Loader from './Loader'
|
||||
import ScrollBar from './ScrollBar'
|
||||
import * as MyLayout from './Layout/index.js'
|
||||
import Page from './Page'
|
||||
|
||||
export { MyLayout, Editor, FilterItem, DropOption, Loader, Page, ScrollBar }
|
||||
@@ -0,0 +1,7 @@
|
||||
import FilterItem from './FilterItem'
|
||||
import Loader from './Loader'
|
||||
import ScrollBar from './ScrollBar'
|
||||
import GlobalFooter from './GlobalFooter'
|
||||
import Page from './Page'
|
||||
|
||||
export { GlobalFooter, FilterItem, Loader, ScrollBar, Page }
|
||||
@@ -0,0 +1 @@
|
||||
export const LOCALE_LANGUAGE = 'LOCALE_LANGUAGE'
|
||||
@@ -0,0 +1,33 @@
|
||||
import { IConfig, ISupportedLocales } from '@/typings'
|
||||
import { LOCALE_LANGUAGE } from '@/configs/constants'
|
||||
import checkLanguage from '@/utils/checkLanguage'
|
||||
import {
|
||||
detect,
|
||||
fromUrl,
|
||||
fromStorage,
|
||||
fromNavigator,
|
||||
} from '@lingui/detect-locale'
|
||||
|
||||
const language = detect(
|
||||
checkLanguage(fromUrl('lang')),
|
||||
checkLanguage(fromStorage(LOCALE_LANGUAGE)),
|
||||
checkLanguage(fromNavigator()),
|
||||
'en'
|
||||
)
|
||||
|
||||
export const config: IConfig = {
|
||||
title: 'Antd Admin',
|
||||
logo: 'logo.svg',
|
||||
copyright: 'Ant Design Admin © 2021 zuiidea',
|
||||
language: language as ISupportedLocales,
|
||||
apiPrefix: '/api/v1',
|
||||
|
||||
/* Layout configuration, specify which layout to use for route. */
|
||||
layouts: [
|
||||
{
|
||||
name: 'primary',
|
||||
include: [/.*/],
|
||||
exlude: [/\/login/],
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import menus from './menus'
|
||||
import menuIcon from './menus/icon'
|
||||
|
||||
export * from './default'
|
||||
export * from './languages'
|
||||
export * from './constants'
|
||||
|
||||
export { menus, menuIcon }
|
||||
@@ -0,0 +1,32 @@
|
||||
import { ILanguage, ILanguages, IAntdI18nMap } from '@/typings'
|
||||
|
||||
/**
|
||||
* Countrys flags: https://www.flaticon.com/packs/countrys-flags
|
||||
*/
|
||||
export const language: ILanguage = {
|
||||
en: {
|
||||
flag: '/america.svg',
|
||||
value: 'English',
|
||||
},
|
||||
zh: {
|
||||
flag: '/china.svg',
|
||||
value: '简体中文',
|
||||
},
|
||||
'pt-br': {
|
||||
flag: '/portugal.svg',
|
||||
value: 'Português',
|
||||
},
|
||||
}
|
||||
|
||||
export const languages: ILanguages[] = Object.entries(language).map(
|
||||
([key, value]: any) => ({
|
||||
key,
|
||||
...value,
|
||||
})
|
||||
)
|
||||
|
||||
export const antdI18nMap: IAntdI18nMap = {
|
||||
zh: 'zh_CN',
|
||||
en: 'en_US',
|
||||
'pt-br': 'pt_BR',
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
PayCircleOutlined,
|
||||
ShoppingCartOutlined,
|
||||
MessageOutlined,
|
||||
TeamOutlined,
|
||||
UserOutlined,
|
||||
DashboardOutlined,
|
||||
ApiOutlined,
|
||||
CameraOutlined,
|
||||
EditOutlined,
|
||||
CodeOutlined,
|
||||
LineOutlined,
|
||||
BarChartOutlined,
|
||||
AreaChartOutlined,
|
||||
} from '@ant-design/icons'
|
||||
import { IMenuIcon } from '@/typings'
|
||||
|
||||
const menuIcon: IMenuIcon = {
|
||||
'pay-circle-o': <PayCircleOutlined />,
|
||||
'shopping-cart': <ShoppingCartOutlined />,
|
||||
'camera-o': <CameraOutlined />,
|
||||
'line-chart': <LineOutlined />,
|
||||
'code-o': <CodeOutlined />,
|
||||
'area-chart': <AreaChartOutlined />,
|
||||
'bar-chart': <BarChartOutlined />,
|
||||
message: <MessageOutlined />,
|
||||
team: <TeamOutlined />,
|
||||
dashboard: <DashboardOutlined />,
|
||||
user: <UserOutlined />,
|
||||
api: <ApiOutlined />,
|
||||
edit: <EditOutlined />,
|
||||
}
|
||||
|
||||
export default menuIcon
|
||||
@@ -0,0 +1,22 @@
|
||||
import { t } from '@lingui/macro'
|
||||
|
||||
/*
|
||||
* Note:
|
||||
* Menu items with children need to set a key starting with "/"
|
||||
* @see https://github.com/umijs/route-utils/blob/master/src/transformRoute/transformRoute.ts#L219
|
||||
*/
|
||||
|
||||
const menus = [
|
||||
{
|
||||
path: '/',
|
||||
name: t`Dashboard`,
|
||||
icon: 'dashboard',
|
||||
},
|
||||
{
|
||||
path: '/user',
|
||||
name: t`User`,
|
||||
icon: 'user',
|
||||
},
|
||||
]
|
||||
|
||||
export default menus
|
||||
@@ -0,0 +1,8 @@
|
||||
import { SettingDrawerProps } from '@ant-design/pro-layout'
|
||||
|
||||
const defaultSettings: SettingDrawerProps['settings'] = {
|
||||
navTheme: 'light',
|
||||
primaryColor: '#006EFF',
|
||||
}
|
||||
|
||||
export default defaultSettings
|
||||
@@ -18,7 +18,7 @@ describe('Login', () => {
|
||||
afterEach(() => page.close())
|
||||
|
||||
it('should login with failure', async () => {
|
||||
await page.waitFor(selector => !!document.querySelector('#username'), {
|
||||
await page.waitFor((selector) => !!document.querySelector('#username'), {
|
||||
timeout: 3000,
|
||||
})
|
||||
await page.type('#username', 'wrong_user')
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { useNavigate, useLocation } from 'react-router-dom';
|
||||
import { useLingui } from '@lingui/react';
|
||||
import useConfig from './useConfig'
|
||||
import useIntlProvider from './useIntlProvider'
|
||||
import useLocalStorage from './useLocalStorage';
|
||||
import useRequest from './useRequest';
|
||||
|
||||
export {
|
||||
useConfig,
|
||||
useNavigate,
|
||||
useLocation,
|
||||
useRequest,
|
||||
useLocalStorage,
|
||||
useIntlProvider,
|
||||
useLingui,
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { useContext } from 'react'
|
||||
import { ConfigContext } from '@/utils/context'
|
||||
|
||||
const useConfig = () => {
|
||||
return useContext(ConfigContext)
|
||||
}
|
||||
|
||||
export default useConfig
|
||||
@@ -0,0 +1,47 @@
|
||||
import { useEffect, useContext, useState } from 'react';
|
||||
import { setupI18n } from '@lingui/core';
|
||||
import { LOCALE_LANGUAGE } from '@/configs/constants';
|
||||
import { ConfigContext } from '@/utils/context';
|
||||
import { useLocalStorage } from '@/hooks';
|
||||
import { antdI18nMap } from '@/configs';
|
||||
import { SupportedLocales } from '@/typings';
|
||||
import { ConfigProviderProps } from 'antd/lib/config-provider';
|
||||
import { en, zh } from 'make-plural/plurals';
|
||||
|
||||
export const i18n = setupI18n({
|
||||
localeData: {
|
||||
en: { plurals: en },
|
||||
zh: { plurals: zh },
|
||||
},
|
||||
});
|
||||
|
||||
const useIntlProvider = () => {
|
||||
const { language: defaultLocale } = useContext(ConfigContext);
|
||||
const [language, setLanguage] = useLocalStorage<SupportedLocales>(
|
||||
LOCALE_LANGUAGE,
|
||||
defaultLocale
|
||||
);
|
||||
|
||||
const [locale, setLocale] = useState<ConfigProviderProps['locale']>();
|
||||
|
||||
useEffect(() => {
|
||||
import(`@/locales/${language}/messages.json`).then(data => {
|
||||
i18n.load(language, data.default);
|
||||
i18n.activate(language);
|
||||
});
|
||||
|
||||
const path = antdI18nMap[language];
|
||||
import(`antd/lib/locale/${path}.js`).then(data => {
|
||||
setLocale(data.default);
|
||||
});
|
||||
}, [language]);
|
||||
|
||||
return {
|
||||
language,
|
||||
setLanguage,
|
||||
locale,
|
||||
i18n,
|
||||
};
|
||||
};
|
||||
|
||||
export default useIntlProvider;
|
||||
@@ -0,0 +1,29 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
const useLocalStorage = <T>(
|
||||
key: string,
|
||||
initialValue?: T
|
||||
): [T, (value: T) => void] => {
|
||||
let defaultValue = initialValue;
|
||||
try {
|
||||
const item = window.localStorage.getItem(key);
|
||||
defaultValue = item ? JSON.parse(item) : initialValue;
|
||||
} catch (error) {
|
||||
defaultValue = initialValue;
|
||||
}
|
||||
|
||||
const [state, setState] = useState(defaultValue as T);
|
||||
const setValue = (value: T) => {
|
||||
try {
|
||||
const valueToStore = value instanceof Function ? value(state) : value;
|
||||
setState(valueToStore);
|
||||
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
return [state, setValue];
|
||||
};
|
||||
|
||||
export default useLocalStorage;
|
||||
@@ -0,0 +1,56 @@
|
||||
import { useEffect, useState, useCallback } from 'react'
|
||||
|
||||
interface Options<R, P, RR> {
|
||||
onSuccess?: (data: R, params?: P) => void
|
||||
onError?: (e: Error, params?: P) => void
|
||||
formatResult?: (data: RR) => R
|
||||
manual?: boolean
|
||||
initialData?: R
|
||||
}
|
||||
|
||||
const useFetch = <R = any, P = any, RR = any>(
|
||||
service: any,
|
||||
options: Options<R, P, RR>
|
||||
) => {
|
||||
const { initialData, manual, formatResult, onSuccess, onError } = options
|
||||
const [loading, setLoading] = useState<boolean>(false)
|
||||
const [data, setData] = useState<R>(initialData as R)
|
||||
const [error, setError] = useState<any>(null)
|
||||
|
||||
const run = useCallback(
|
||||
(params?: P) => {
|
||||
setLoading(true)
|
||||
return service(params)
|
||||
.then((result) => {
|
||||
const resultData = formatResult ? formatResult(result) : result
|
||||
setData(resultData)
|
||||
onSuccess && onSuccess(resultData, params)
|
||||
})
|
||||
.catch((result) => {
|
||||
setError(result || new Error())
|
||||
onError && onError(result, params)
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false)
|
||||
})
|
||||
},
|
||||
[formatResult, onError, onSuccess, service]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (manual) {
|
||||
return
|
||||
}
|
||||
run()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
|
||||
return {
|
||||
run,
|
||||
data,
|
||||
error,
|
||||
loading,
|
||||
}
|
||||
}
|
||||
|
||||
export default useFetch
|
||||
@@ -0,0 +1,30 @@
|
||||
import { config } from '@/configs/default'
|
||||
import { setupI18n, I18n } from '@lingui/core'
|
||||
import { en, zh, pt } from 'make-plural/plurals'
|
||||
import { messages as zhMessages } from '@/locales/zh/messages.po'
|
||||
import { messages as enMessages } from '@/locales/en/messages.po'
|
||||
import { messages as ptMessages } from '@/locales/pt-br/messages.po'
|
||||
|
||||
const i18nBase: I18n = setupI18n()
|
||||
|
||||
i18nBase.loadLocaleData({
|
||||
en: {
|
||||
plurals: en,
|
||||
},
|
||||
zh: {
|
||||
plurals: zh,
|
||||
},
|
||||
'pt-br': {
|
||||
plurals: pt,
|
||||
},
|
||||
})
|
||||
|
||||
i18nBase.load({
|
||||
zh: zhMessages,
|
||||
en: enMessages,
|
||||
'pt-br': ptMessages,
|
||||
})
|
||||
|
||||
i18nBase.activate(config.language)
|
||||
|
||||
export const i18n = i18nBase
|
||||
@@ -1,55 +0,0 @@
|
||||
import React, { PureComponent, Fragment } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { connect } from 'dva'
|
||||
import { Helmet } from 'react-helmet'
|
||||
import { Loader } from 'components'
|
||||
import { queryLayout } from 'utils'
|
||||
import NProgress from 'nprogress'
|
||||
import config from 'utils/config'
|
||||
import withRouter from 'umi/withRouter'
|
||||
|
||||
import PublicLayout from './PublicLayout'
|
||||
import PrimaryLayout from './PrimaryLayout'
|
||||
import './BaseLayout.less'
|
||||
|
||||
const LayoutMap = {
|
||||
primary: PrimaryLayout,
|
||||
public: PublicLayout,
|
||||
}
|
||||
|
||||
@withRouter
|
||||
@connect(({ loading }) => ({ loading }))
|
||||
class BaseLayout extends PureComponent {
|
||||
previousPath = ''
|
||||
|
||||
render() {
|
||||
const { loading, children, location } = this.props
|
||||
const Container = LayoutMap[queryLayout(config.layouts, location.pathname)]
|
||||
|
||||
const currentPath = location.pathname + location.search
|
||||
if (currentPath !== this.previousPath) {
|
||||
NProgress.start()
|
||||
}
|
||||
|
||||
if (!loading.global) {
|
||||
NProgress.done()
|
||||
this.previousPath = currentPath
|
||||
}
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<Helmet>
|
||||
<title>{config.siteName}</title>
|
||||
</Helmet>
|
||||
<Loader fullScreen spinning={loading.effects['app/query']} />
|
||||
<Container>{children}</Container>
|
||||
</Fragment>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
BaseLayout.propTypes = {
|
||||
loading: PropTypes.object,
|
||||
}
|
||||
|
||||
export default BaseLayout
|
||||
@@ -1,44 +1,44 @@
|
||||
@import '~themes/vars.less';
|
||||
@import '~themes/index.less';
|
||||
@import '~@/themes/vars.less';
|
||||
@import '~@/themes/index.less';
|
||||
|
||||
:global {
|
||||
#nprogress {
|
||||
pointer-events: none;
|
||||
|
||||
.bar {
|
||||
background: @primary-color;
|
||||
position: fixed;
|
||||
z-index: 2048;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
left: 0;
|
||||
z-index: 2048;
|
||||
width: 100%;
|
||||
height: 2px;
|
||||
background: @primary-color;
|
||||
}
|
||||
|
||||
.peg {
|
||||
display: block;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
display: block;
|
||||
width: 100px;
|
||||
height: 100%;
|
||||
box-shadow: 0 0 10px @primary-color, 0 0 5px @primary-color;
|
||||
opacity: 1;
|
||||
transform: rotate(3deg) translate(0, -4px);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
display: block;
|
||||
position: fixed;
|
||||
z-index: 1031;
|
||||
top: 15px;
|
||||
right: 15px;
|
||||
z-index: 1031;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.spinner-icon {
|
||||
box-sizing: border-box;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
box-sizing: border-box;
|
||||
border: solid 2px transparent;
|
||||
border-top-color: @primary-color;
|
||||
border-left-color: @primary-color;
|
||||
@@ -51,8 +51,8 @@
|
||||
}
|
||||
|
||||
.nprogress-custom-parent {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
#nprogress {
|
||||
.bar,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import React from 'react'
|
||||
import { useLocation } from '@/hooks'
|
||||
import { queryLayout } from '@/utils'
|
||||
import { config } from '@/configs'
|
||||
import { Outlet } from 'umi'
|
||||
import PublicLayout from './PublicLayout'
|
||||
import PrimaryLayout from './PrimaryLayout/index'
|
||||
import './BaseLayout.less'
|
||||
|
||||
const LayoutMap = {
|
||||
primary: PrimaryLayout,
|
||||
public: PublicLayout,
|
||||
}
|
||||
|
||||
const BaseLayout: React.FC = (props) => {
|
||||
const location = useLocation()
|
||||
const Container = LayoutMap[queryLayout(config.layouts, location.pathname)]
|
||||
return <Container><Outlet /></Container>
|
||||
}
|
||||
|
||||
export default BaseLayout
|
||||
@@ -1,168 +0,0 @@
|
||||
/* global window */
|
||||
/* global document */
|
||||
import React, { PureComponent, Fragment } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import withRouter from 'umi/withRouter'
|
||||
import { connect } from 'dva'
|
||||
import { MyLayout } from 'components'
|
||||
import { BackTop, Layout, Drawer } from 'antd'
|
||||
import { GlobalFooter } from 'ant-design-pro'
|
||||
import { enquireScreen, unenquireScreen } from 'enquire-js'
|
||||
import { config, pathMatchRegexp, langFromPath } from 'utils'
|
||||
import Error from '../pages/404'
|
||||
import styles from './PrimaryLayout.less'
|
||||
import store from 'store'
|
||||
|
||||
const { Content } = Layout
|
||||
const { Header, Bread, Sider } = MyLayout
|
||||
|
||||
@withRouter
|
||||
@connect(({ app, loading }) => ({ app, loading }))
|
||||
class PrimaryLayout extends PureComponent {
|
||||
state = {
|
||||
isMobile: false,
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.enquireHandler = enquireScreen(mobile => {
|
||||
const { isMobile } = this.state
|
||||
if (isMobile !== mobile) {
|
||||
this.setState({
|
||||
isMobile: mobile,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
unenquireScreen(this.enquireHandler)
|
||||
}
|
||||
|
||||
onCollapseChange = collapsed => {
|
||||
this.props.dispatch({
|
||||
type: 'app/handleCollapseChange',
|
||||
payload: collapsed,
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
const { app, location, dispatch, children } = this.props
|
||||
const { theme, collapsed, notifications } = app
|
||||
const user = store.get('user') || {}
|
||||
const permissions = store.get('permissions') || {}
|
||||
const routeList = store.get('routeList') || []
|
||||
const { isMobile } = this.state
|
||||
const { onCollapseChange } = this
|
||||
|
||||
// Localized route name.
|
||||
|
||||
const lang = langFromPath(location.pathname)
|
||||
const newRouteList =
|
||||
lang !== 'en'
|
||||
? routeList.map(item => {
|
||||
const { name, ...other } = item
|
||||
return {
|
||||
...other,
|
||||
name: (item[lang] || {}).name || name,
|
||||
}
|
||||
})
|
||||
: routeList
|
||||
|
||||
// Find a route that matches the pathname.
|
||||
const currentRoute = newRouteList.find(
|
||||
_ => _.route && pathMatchRegexp(_.route, location.pathname)
|
||||
)
|
||||
|
||||
// Query whether you have permission to enter this page
|
||||
const hasPermission = currentRoute
|
||||
? permissions.visit.includes(currentRoute.id)
|
||||
: false
|
||||
|
||||
// MenuParentId is equal to -1 is not a available menu.
|
||||
const menus = newRouteList.filter(_ => _.menuParentId !== '-1')
|
||||
|
||||
const headerProps = {
|
||||
menus,
|
||||
collapsed,
|
||||
notifications,
|
||||
onCollapseChange,
|
||||
avatar: user.avatar,
|
||||
username: user.username,
|
||||
fixed: config.fixedHeader,
|
||||
onAllNotificationsRead() {
|
||||
dispatch({ type: 'app/allNotificationsRead' })
|
||||
},
|
||||
onSignOut() {
|
||||
dispatch({ type: 'app/signOut' })
|
||||
},
|
||||
}
|
||||
|
||||
const siderProps = {
|
||||
theme,
|
||||
menus,
|
||||
isMobile,
|
||||
collapsed,
|
||||
onCollapseChange,
|
||||
onThemeChange(theme) {
|
||||
dispatch({
|
||||
type: 'app/handleThemeChange',
|
||||
payload: theme,
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<Layout>
|
||||
{isMobile ? (
|
||||
<Drawer
|
||||
maskClosable
|
||||
closable={false}
|
||||
onClose={onCollapseChange.bind(this, !collapsed)}
|
||||
visible={!collapsed}
|
||||
placement="left"
|
||||
width={200}
|
||||
style={{
|
||||
padding: 0,
|
||||
height: '100vh',
|
||||
}}
|
||||
>
|
||||
<Sider {...siderProps} collapsed={false} />
|
||||
</Drawer>
|
||||
) : (
|
||||
<Sider {...siderProps} />
|
||||
)}
|
||||
<div
|
||||
className={styles.container}
|
||||
style={{ paddingTop: config.fixedHeader ? 72 : 0 }}
|
||||
id="primaryLayout"
|
||||
>
|
||||
<Header {...headerProps} />
|
||||
<Content className={styles.content}>
|
||||
<Bread routeList={newRouteList} />
|
||||
{hasPermission ? children : <Error />}
|
||||
</Content>
|
||||
<BackTop
|
||||
className={styles.backTop}
|
||||
target={() => document.querySelector('#primaryLayout')}
|
||||
/>
|
||||
<GlobalFooter
|
||||
className={styles.footer}
|
||||
copyright={config.copyright}
|
||||
/>
|
||||
</div>
|
||||
</Layout>
|
||||
</Fragment>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
PrimaryLayout.propTypes = {
|
||||
children: PropTypes.element.isRequired,
|
||||
location: PropTypes.object,
|
||||
dispatch: PropTypes.func,
|
||||
app: PropTypes.object,
|
||||
loading: PropTypes.object,
|
||||
}
|
||||
|
||||
export default PrimaryLayout
|
||||
@@ -0,0 +1,69 @@
|
||||
import React from 'react'
|
||||
import { Dropdown, Menu, Avatar } from 'antd'
|
||||
import { language, languages } from '@/configs'
|
||||
import { ISupportedLocales } from '@/typings'
|
||||
import { Trans } from '@lingui/macro'
|
||||
import { history } from 'umi'
|
||||
import { useRequest, useConfig } from '@/hooks'
|
||||
import { logoutUser } from '@/services'
|
||||
import styles from './index.less'
|
||||
|
||||
const { SubMenu } = Menu
|
||||
|
||||
const NotFoundPage: React.FC = () => {
|
||||
const { language: locale, setLanguage, userInfo } = useConfig()
|
||||
const currentLanguage = language[locale]
|
||||
const { run: runLogoutUser } = useRequest(logoutUser, {
|
||||
manual: true,
|
||||
onSuccess: () => history.push('/login'),
|
||||
})
|
||||
|
||||
return (
|
||||
<>
|
||||
<Dropdown
|
||||
overlay={
|
||||
<Menu
|
||||
selectedKeys={[currentLanguage.value]}
|
||||
onClick={(data) => {
|
||||
setLanguage(data.key as ISupportedLocales)
|
||||
}}
|
||||
>
|
||||
{languages.map((item) => (
|
||||
<Menu.Item key={item.key}>
|
||||
<Avatar
|
||||
size="small"
|
||||
style={{ marginRight: 8 }}
|
||||
src={item.flag}
|
||||
/>
|
||||
{item.value}
|
||||
</Menu.Item>
|
||||
))}
|
||||
</Menu>
|
||||
}
|
||||
>
|
||||
<div className={styles.headerButton}>
|
||||
<Avatar size="small" src={currentLanguage.flag} />
|
||||
</div>
|
||||
</Dropdown>
|
||||
<Menu key="user" mode="horizontal">
|
||||
<SubMenu
|
||||
title={
|
||||
<>
|
||||
<span style={{ color: '#999', marginRight: 4 }}>
|
||||
<Trans>Hi,</Trans>
|
||||
</span>
|
||||
<span>{userInfo?.username}</span>
|
||||
<Avatar style={{ marginLeft: 8 }} src={userInfo?.avatar} />
|
||||
</>
|
||||
}
|
||||
>
|
||||
<Menu.Item key="SignOut" onClick={() => runLogoutUser()}>
|
||||
<Trans>Sign out</Trans>
|
||||
</Menu.Item>
|
||||
</SubMenu>
|
||||
</Menu>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default NotFoundPage
|
||||
@@ -1,5 +1,9 @@
|
||||
@import '~themes/vars.less';
|
||||
|
||||
@import '~@/themes/vars.less';
|
||||
:global {
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
.backTop {
|
||||
right: 50px;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import React, { useState, useEffect, useMemo, useCallback } from 'react'
|
||||
import ProBasicLayout, {
|
||||
getMenuData,
|
||||
MenuDataItem,
|
||||
SettingDrawerProps,
|
||||
} from '@ant-design/pro-layout'
|
||||
import { Link, Outlet } from 'umi'
|
||||
import { useLocation } from '@/hooks'
|
||||
import { menus, menuIcon, config } from '@/configs'
|
||||
import defaultSettings from '@/defaultSettings'
|
||||
import type { MenuProps } from 'antd/es/menu'
|
||||
import HeaderRightContent from './HeaderRightContent'
|
||||
|
||||
const renderMenuItem = (menus: MenuDataItem[]): MenuDataItem[] =>
|
||||
menus.map(({ icon, children, ...item }) => ({
|
||||
...item,
|
||||
icon: icon && menuIcon[icon as string],
|
||||
children: children && renderMenuItem(children),
|
||||
}))
|
||||
|
||||
const PrimaryLayout: React.FC = (props) => {
|
||||
const location = useLocation()
|
||||
const [settings] = useState<SettingDrawerProps['settings']>(defaultSettings)
|
||||
const [openKeys, setOpenKeys] = useState<string[]>([])
|
||||
const [selectedKeys, setSelectedKeys] = useState<string[]>(['/'])
|
||||
const { pathname } = location
|
||||
const { breadcrumbMap, menuData } = useMemo(() => getMenuData(menus), [])
|
||||
|
||||
useEffect(() => {
|
||||
const select = breadcrumbMap.get(pathname)
|
||||
if (select) {
|
||||
setOpenKeys((select as MenuDataItem)['pro_layout_parentKeys'])
|
||||
setSelectedKeys([(select as MenuDataItem)['key'] as string])
|
||||
}
|
||||
}, [breadcrumbMap, pathname])
|
||||
|
||||
const menuDataRender = useCallback(() => renderMenuItem(menuData), [menuData])
|
||||
|
||||
const menuItemRender = useCallback((menuItemProps, defaultDom) => {
|
||||
if (menuItemProps.isUrl || !menuItemProps.path) {
|
||||
return defaultDom
|
||||
}
|
||||
return <Link to={menuItemProps.path}>{defaultDom}</Link>
|
||||
}, [])
|
||||
|
||||
const handleOnOpenChange = useCallback(
|
||||
(keys) => setOpenKeys(keys as string[]),
|
||||
[]
|
||||
)
|
||||
|
||||
const menuProps = useMemo<MenuProps>(
|
||||
() => ({
|
||||
selectedKeys,
|
||||
openKeys,
|
||||
onOpenChange: handleOnOpenChange,
|
||||
}),
|
||||
[handleOnOpenChange, openKeys, selectedKeys]
|
||||
)
|
||||
|
||||
return (
|
||||
<>
|
||||
<ProBasicLayout
|
||||
{...settings}
|
||||
title={config.title}
|
||||
logo={config.logo}
|
||||
menuDataRender={menuDataRender}
|
||||
menuItemRender={menuItemRender}
|
||||
menuProps={menuProps}
|
||||
rightContentRender={() => <HeaderRightContent />}
|
||||
>
|
||||
<Outlet />
|
||||
</ProBasicLayout>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default PrimaryLayout
|
||||
@@ -1,3 +0,0 @@
|
||||
export default ({ children }) => {
|
||||
return children
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import React from 'react'
|
||||
import { Outlet } from 'umi'
|
||||
|
||||
const PublicLayout: React.FC = (props) => {
|
||||
return <><Outlet /></>
|
||||
}
|
||||
|
||||
export default PublicLayout
|
||||
@@ -1,75 +0,0 @@
|
||||
import React, { Component } from 'react'
|
||||
import withRouter from 'umi/withRouter'
|
||||
import { LocaleProvider } from 'antd'
|
||||
import { I18nProvider } from '@lingui/react'
|
||||
import { langFromPath, defaultLanguage } from 'utils'
|
||||
import zh_CN from 'antd/lib/locale-provider/zh_CN'
|
||||
import en_US from 'antd/lib/locale-provider/en_US'
|
||||
|
||||
import BaseLayout from './BaseLayout'
|
||||
|
||||
const languages = {
|
||||
zh: zh_CN,
|
||||
en: en_US,
|
||||
}
|
||||
|
||||
@withRouter
|
||||
class Layout extends Component {
|
||||
state = {
|
||||
catalogs: {},
|
||||
}
|
||||
|
||||
language = defaultLanguage
|
||||
|
||||
componentDidMount() {
|
||||
const language = langFromPath(this.props.location.pathname)
|
||||
this.language = language
|
||||
this.loadCatalog(language)
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps, nextState) {
|
||||
const language = langFromPath(nextProps.location.pathname)
|
||||
const preLanguage = this.language
|
||||
const { catalogs } = nextState
|
||||
|
||||
if (preLanguage !== language && !catalogs[language]) {
|
||||
this.loadCatalog(language)
|
||||
this.language = language
|
||||
return false
|
||||
}
|
||||
this.language = language
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
loadCatalog = async language => {
|
||||
const catalog = await import(/* webpackMode: "lazy", webpackChunkName: "i18n-[index]" */
|
||||
`@lingui/loader!../locales/${language}/messages.json`)
|
||||
|
||||
this.setState(state => ({
|
||||
catalogs: {
|
||||
...state.catalogs,
|
||||
[language]: catalog,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
render() {
|
||||
const { location, children } = this.props
|
||||
const { catalogs } = this.state
|
||||
|
||||
let language = langFromPath(location.pathname)
|
||||
// If the language pack is not loaded or is loading, use the default language
|
||||
if (!catalogs[language]) language = defaultLanguage
|
||||
|
||||
return (
|
||||
<LocaleProvider locale={languages[language]}>
|
||||
<I18nProvider language={language} catalogs={catalogs}>
|
||||
<BaseLayout>{children}</BaseLayout>
|
||||
</I18nProvider>
|
||||
</LocaleProvider>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default Layout
|
||||
@@ -0,0 +1,22 @@
|
||||
:global {
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.headerButton {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
padding: 0 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 0.025);
|
||||
}
|
||||
}
|
||||
|
||||
.headerFlag {
|
||||
margin-right: 8px;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import React from 'react'
|
||||
import { history } from 'umi'
|
||||
import { ConfigProvider } from 'antd'
|
||||
import { I18nProvider } from '@lingui/react'
|
||||
import {
|
||||
useIntlProvider,
|
||||
useRequest,
|
||||
} from '@/hooks'
|
||||
// @ts-ignore
|
||||
import { Outlet } from 'umi'
|
||||
import { ConfigContext } from '@/utils/context'
|
||||
import request from '@/utils/request'
|
||||
import { queryUserInfo, IUserInfo } from '@/services'
|
||||
import BaseLayout from './BaseLayout'
|
||||
|
||||
const Layout: React.FC = (props) => {
|
||||
const { language, setLanguage, i18n, locale } = useIntlProvider()
|
||||
|
||||
const {
|
||||
data: userInfo,
|
||||
run: runQueryUserInfo,
|
||||
loading,
|
||||
} = useRequest<IUserInfo>(queryUserInfo, {
|
||||
onError: (data: any) => {
|
||||
if (data.statusCode === 401) {
|
||||
history.push('/login')
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const globalConfig = {
|
||||
language,
|
||||
setLanguage,
|
||||
userInfo: userInfo as IUserInfo,
|
||||
queryUserInfo: runQueryUserInfo,
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <div>loading</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<ConfigContext.Provider value={globalConfig}>
|
||||
<I18nProvider i18n={i18n}>
|
||||
<ConfigProvider locale={locale}>
|
||||
<BaseLayout><Outlet /></BaseLayout>
|
||||
</ConfigProvider>
|
||||
</I18nProvider>
|
||||
</ConfigContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export default Layout
|
||||