Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccaf67076e | ||
|
|
8f7dd82e40 | ||
|
|
9989aa4de5 | ||
|
|
f983533d59 | ||
|
|
2182759d47 | ||
|
|
4d1851ddd2 | ||
|
|
0d82eca735 | ||
|
|
cfb6b271ee | ||
|
|
0b97964457 | ||
|
|
edfbfcf5db | ||
|
|
e5172432df | ||
|
|
741b04f120 | ||
|
|
83f2cc1344 | ||
|
|
152556d582 | ||
|
|
67fc31a008 | ||
|
|
23eace8350 | ||
|
|
93817e4840 | ||
|
|
bb97d982e4 | ||
|
|
700f58015d | ||
|
|
872ce3a825 | ||
|
|
385b31e7bb | ||
|
|
3d66a616ff | ||
|
|
b7e18a1214 | ||
|
|
3b0bae9c70 | ||
|
|
8b9343a320 | ||
|
|
8618c75459 | ||
|
|
711d2077e2 | ||
|
|
b25646b033 | ||
|
|
02bf7784b1 | ||
|
|
c164d60643 | ||
|
|
1bd4cfe73c | ||
|
|
f4e1eeb21c | ||
|
|
4b5fe62014 | ||
|
|
36c2be61ae | ||
|
|
e9206a9448 | ||
|
|
0bf28879c4 | ||
|
|
7c936712b9 | ||
|
|
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 | ||
|
|
557f6022f3 | ||
|
|
d0a56169e3 | ||
|
|
f7d6e2b4ed | ||
|
|
df82ee42fd | ||
|
|
a29d761483 | ||
|
|
713a86b9d6 | ||
|
|
d6250f16b0 | ||
|
|
1c5d5c3788 | ||
|
|
699e9d9ff1 | ||
|
|
fad0cb931a | ||
|
|
5d7ff55869 | ||
|
|
642ccb5b82 | ||
|
|
51a7ce0827 | ||
|
|
157a54b11d | ||
|
|
be083d81fc | ||
|
|
f6c869ad47 | ||
|
|
bef5b26509 | ||
|
|
59cfe24178 | ||
|
|
87d0d58ae8 | ||
|
|
de8b6c972d | ||
|
|
0ac4839e94 | ||
|
|
565bce6d8b | ||
|
|
b278b028cf | ||
|
|
33abd9369e | ||
|
|
e6b2f7f271 | ||
|
|
0bd1e9cf59 | ||
|
|
693625bf2c | ||
|
|
3a6c587569 | ||
|
|
bd85eaf0a0 | ||
|
|
29aa0f416e | ||
|
|
5b32607911 | ||
|
|
76e5359752 | ||
|
|
5ec4efbb6e | ||
|
|
f8bb7b421a | ||
|
|
887c169aa8 | ||
|
|
8c10dcc6c2 | ||
|
|
671da6b5fa | ||
|
|
7fdb2f4ea8 | ||
|
|
67388b31f5 | ||
|
|
2379cca765 | ||
|
|
34be6651e5 | ||
|
|
10f8e3e8ef | ||
|
|
0c6ea8eb5c | ||
|
|
6e69b06e61 | ||
|
|
98ba383a68 | ||
|
|
4e6d81a9bf | ||
|
|
0e2c206023 | ||
|
|
285f06d1e7 | ||
|
|
d03787a871 | ||
|
|
6aead03f3e | ||
|
|
0949a298c9 | ||
|
|
94c8e2168f | ||
|
|
358134f417 | ||
|
|
7eb9e06452 | ||
|
|
fab06d5005 | ||
|
|
7483572b1d | ||
|
|
d1ce8e0739 | ||
|
|
16860f93ad | ||
|
|
6ba45d5bc3 | ||
|
|
f230429ddd | ||
|
|
78c3b6d597 | ||
|
|
cdbc2782ff | ||
|
|
108aca99b9 | ||
|
|
7dd5dfb1bf | ||
|
|
ee7a0fffc2 | ||
|
|
6999871860 | ||
|
|
6742207c77 | ||
|
|
d71c29ee2e | ||
|
|
6917d6b89a | ||
|
|
c3f369f0b3 | ||
|
|
01abc5ca38 | ||
|
|
08a348090c | ||
|
|
63b1ecf79f | ||
|
|
efe7e74375 | ||
|
|
6d552d22d9 | ||
|
|
017af0ddfc | ||
|
|
c2161ceca9 | ||
|
|
140af31bec | ||
|
|
1199e7e618 | ||
|
|
3fa24d00fa | ||
|
|
5d23c77100 | ||
|
|
286178fc5e | ||
|
|
f6621572df | ||
|
|
d32b09d802 | ||
|
|
dbe86ec0a8 | ||
|
|
5f8141148a | ||
|
|
c7c24983cc | ||
|
|
f80b6d366f | ||
|
|
0b360eeebb | ||
|
|
c92a1e1342 | ||
|
|
c0963cbcd9 | ||
|
|
4979d5cbc4 | ||
|
|
ff85c1447b | ||
|
|
df608b2dc1 | ||
|
|
f38e0ce7e2 | ||
|
|
0499b70218 | ||
|
|
f654b277fa | ||
|
|
95eeebb09e | ||
|
|
bb61d7f7dc | ||
|
|
d821a7cf59 | ||
|
|
9db8827d4a | ||
|
|
0b17931c62 | ||
|
|
c1df88c25f | ||
|
|
f6454e71f0 | ||
|
|
66a6e55191 | ||
|
|
0a3fac2e72 | ||
|
|
2f928329d1 | ||
|
|
9a5ff4aa98 | ||
|
|
dd3c191139 | ||
|
|
9a702fb774 | ||
|
|
d0c2713f20 | ||
|
|
a6bf4286dc | ||
|
|
08f40efd2b | ||
|
|
4e7795ec7c | ||
|
|
5aa187334a | ||
|
|
abfcf2460e | ||
|
|
bcd6248833 | ||
|
|
baa5869fe5 | ||
|
|
58f62d8145 | ||
|
|
2044beb7f1 | ||
|
|
5f8a298ece | ||
|
|
487b39f97c | ||
|
|
c5724f208a | ||
|
|
03a23bab9a | ||
|
|
d58b6ce948 | ||
|
|
7c83c80d5d | ||
|
|
0801d83856 | ||
|
|
8aa55330b4 | ||
|
|
ee10965f43 | ||
|
|
755e19ed12 | ||
|
|
40d3914b3c | ||
|
|
47fd515944 | ||
|
|
ba426defdd | ||
|
|
a8bd1a587a | ||
|
|
237efb4e72 | ||
|
|
0de24b8251 | ||
|
|
7077ef15f3 | ||
|
|
b3d5d11539 | ||
|
|
2522b971f1 | ||
|
|
c6be37ca09 | ||
|
|
ae8ac62938 | ||
|
|
349eb3216d | ||
|
|
d1d559b1d6 | ||
|
|
7d5ad95cff | ||
|
|
e09c22fc18 | ||
|
|
a7e84edad3 | ||
|
|
0f466b2abe | ||
|
|
0ccdcdbc92 | ||
|
|
3d3f8e70dd | ||
|
|
417215cfcc | ||
|
|
ae8aba68f2 | ||
|
|
cd53b36e76 | ||
|
|
a44f5795fd | ||
|
|
556169871a | ||
|
|
261fbb8428 | ||
|
|
f02d39ace0 | ||
|
|
4d32829445 | ||
|
|
5438e04fc5 | ||
|
|
54bbe4d70a | ||
|
|
78ece0c9fb | ||
|
|
3407f9a0c1 | ||
|
|
f1b78e8d1f | ||
|
|
df2fc9c32e | ||
|
|
cc5c319332 | ||
|
|
43ef09dfed | ||
|
|
0c95751b8d | ||
|
|
843bd1a088 | ||
|
|
a0db71e571 | ||
|
|
7fc14eddd9 | ||
|
|
7f2fdc383b | ||
|
|
ff2caecb3a | ||
|
|
d01df1ef13 | ||
|
|
cd55df3a15 | ||
|
|
ce59f3e7b2 | ||
|
|
4d722f103a | ||
|
|
c1bc6f27b1 | ||
|
|
ed88c087bf | ||
|
|
4e337caa07 | ||
|
|
ea3929b4c2 | ||
|
|
9eff4ca129 | ||
|
|
d6d94e2121 | ||
|
|
737c0236d6 | ||
|
|
69571f2916 | ||
|
|
6dffa7378c | ||
|
|
c2a7bc7106 | ||
|
|
e752750c9e | ||
|
|
32bde8f69e | ||
|
|
b5f9ef51f1 | ||
|
|
8c10be6ee6 | ||
|
|
c1e3872792 | ||
|
|
c3eef53e4d | ||
|
|
a1b9c0c33d | ||
|
|
c49b0edbe9 | ||
|
|
0fd8824ad7 | ||
|
|
973199135f | ||
|
|
43b7b21ad3 | ||
|
|
ba96ebb874 | ||
|
|
c66f086f42 | ||
|
|
07b2175e92 | ||
|
|
d245a1eabc | ||
|
|
f1e2fd3b18 | ||
|
|
a6b3dba92e | ||
|
|
9fd0abe6ea | ||
|
|
d06ee20c47 | ||
|
|
2ef1fa0367 | ||
|
|
9d459106c1 | ||
|
|
cd5a52a8fc | ||
|
|
d89320f578 | ||
|
|
df5ce2991e | ||
|
|
668c9c7dfe | ||
|
|
9bd13055c0 | ||
|
|
9f3adda59d | ||
|
|
bfa7aaecb8 | ||
|
|
9d4310d8e0 | ||
|
|
b3555b01f3 | ||
|
|
74895fbb0d | ||
|
|
5f04d19d2d | ||
|
|
0fef06e0c6 | ||
|
|
89d22451c5 | ||
|
|
fb49056c73 | ||
|
|
a3071819c4 | ||
|
|
d4e10ad5c2 | ||
|
|
59e9a1053e | ||
|
|
308fc09b33 | ||
|
|
99ec9facd3 | ||
|
|
2a96d7a5f6 | ||
|
|
195e1d17f8 | ||
|
|
580ff59b3d | ||
|
|
cfa5aae5da | ||
|
|
761125735a | ||
|
|
d1b12ff0e1 | ||
|
|
a47176a4e5 | ||
|
|
bc3d7fb39a | ||
|
|
458548150c | ||
|
|
f6e11bb464 | ||
|
|
479fc647c3 | ||
|
|
9a4c63390d | ||
|
|
42cd1221fa | ||
|
|
98b773fdc3 | ||
|
|
cd54fcbf52 | ||
|
|
bd68f8c631 | ||
|
|
3fde5aaa3c | ||
|
|
2f34de5602 | ||
|
|
2de1e81661 | ||
|
|
cea60c5683 | ||
|
|
f16e104f73 | ||
|
|
c397f552c3 | ||
|
|
11c4ac803e | ||
|
|
09b9a100de | ||
|
|
0e59df39ee | ||
|
|
30254a2ec7 | ||
|
|
cd796a6db9 | ||
|
|
6ba75de576 | ||
|
|
a3637b3a99 | ||
|
|
85ec09ec9a | ||
|
|
eb683b98e7 | ||
|
|
9221173309 | ||
|
|
55a96f41c6 | ||
|
|
ce510e79c7 | ||
|
|
3d4f2a8814 | ||
|
|
38e24edd7b | ||
|
|
841c987a1a | ||
|
|
dc26f7d25e | ||
|
|
bc754e683e | ||
|
|
c7acc8db4b | ||
|
|
057acc514f | ||
|
|
53ce7d08fb | ||
|
|
8ffd68a4e2 | ||
|
|
766653ee7a | ||
|
|
9dedcc68c3 | ||
|
|
5ea2b3c9b8 | ||
|
|
d2ac91839a | ||
|
|
bfca2746d8 | ||
|
|
b417065ac3 | ||
|
|
abdc97f087 | ||
|
|
07016c6c26 | ||
|
|
b8162060cd | ||
|
|
36fb5d293c | ||
|
|
429280a97a | ||
|
|
7ac36c779e | ||
|
|
d2e7b464e3 | ||
|
|
25839ea99f | ||
|
|
9c99581aa6 | ||
|
|
e42c21f0eb | ||
|
|
782bf214e5 | ||
|
|
a8a4496c7a | ||
|
|
f5f013ff23 | ||
|
|
8cff3af897 | ||
|
|
322d5a6d0e | ||
|
|
2ee26f51a7 | ||
|
|
e670ed2f96 | ||
|
|
601a03b5b4 | ||
|
|
00582e70ff | ||
|
|
fa4385055b | ||
|
|
01f4de55df | ||
|
|
dedd34e8e8 | ||
|
|
d1b373201e | ||
|
|
dbcc90e7ad | ||
|
|
87fce74d5b | ||
|
|
5c51679ad7 | ||
|
|
6d17b5b876 | ||
|
|
1288853112 | ||
|
|
d3e7e17789 | ||
|
|
6077d74f10 | ||
|
|
7bf031699a | ||
|
|
a6eb693636 | ||
|
|
39c377e0e2 | ||
|
|
67b90c4df0 | ||
|
|
0e2727f9c8 | ||
|
|
0cf02e7324 | ||
|
|
68c9f2b65f | ||
|
|
587b1f6b9d | ||
|
|
d94580a253 | ||
|
|
531e3c0fcc | ||
|
|
d68de7a30c | ||
|
|
45cb70f006 | ||
|
|
af85384f11 | ||
|
|
208539134f | ||
|
|
a3f41e3d64 | ||
|
|
3855c402c9 | ||
|
|
6a58d8434b | ||
|
|
d26a92ce79 | ||
|
|
0d20717c3c | ||
|
|
a0d81dcda9 | ||
|
|
4490af8553 | ||
|
|
6ae39bfd55 | ||
|
|
d86f0ebd78 | ||
|
|
a320c77ecb | ||
|
|
7f091d7642 | ||
|
|
d8f222f312 | ||
|
|
38637ef167 | ||
|
|
fe8527e72e | ||
|
|
da64cac414 | ||
|
|
f6021cbaa4 |
@@ -1,16 +0,0 @@
|
||||
# http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
@@ -1 +1,10 @@
|
||||
src/**/*-test.js
|
||||
node_modules
|
||||
dist
|
||||
.umi
|
||||
build
|
||||
public
|
||||
coverage
|
||||
*.config.js
|
||||
|
||||
# ignore umi generated files under src
|
||||
src/.umi
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
{
|
||||
"extends": "airbnb",
|
||||
"rules": {
|
||||
"semi": [2, "never"],
|
||||
"no-console": 0,
|
||||
"comma-dangle": [2, "always-multiline"],
|
||||
"max-len": 0,
|
||||
"react/jsx-first-prop-new-line": 0,
|
||||
"react/jsx-filename-extension": 0,
|
||||
"space-before-function-paren": [2, "always"],
|
||||
"no-unused-expressions": [0, {
|
||||
"allowShortCircuit": true,
|
||||
"allowTernary": true
|
||||
}],
|
||||
"arrow-body-style": [0, "never"],
|
||||
"func-names": 0,
|
||||
"prefer-const": 0,
|
||||
"no-extend-native": 0,
|
||||
"no-param-reassign": 0,
|
||||
"no-restricted-syntax": 0,
|
||||
"no-eval": 0,
|
||||
"no-continue": 0,
|
||||
"react/jsx-no-bind": 0,
|
||||
"no-unused-vars": [2, { "ignoreRestSiblings": true }],
|
||||
"no-underscore-dangle": 0,
|
||||
"global-require": 0,
|
||||
"import/no-unresolved": 0,
|
||||
"import/extensions": 0,
|
||||
"jsx-a11y/href-no-hash": 0,
|
||||
"react/no-array-index-key": 0,
|
||||
"react/require-default-props": 0,
|
||||
"react/forbid-prop-types": 0,
|
||||
"react/no-string-refs": 0,
|
||||
"react/no-find-dom-node": 0,
|
||||
"import/no-extraneous-dependencies": 0,
|
||||
"import/prefer-default-export": 0,
|
||||
"react/no-danger": 0,
|
||||
"jsx-a11y/no-static-element-interactions": 0,
|
||||
},
|
||||
"parser": "babel-eslint",
|
||||
"parserOptions": {
|
||||
"sourceType": "module",
|
||||
"ecmaVersion": 8,
|
||||
"ecmaFeatures": {
|
||||
"jsx": true,
|
||||
"experimentalObjectRestSpread": true
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"import/resolver": "node"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
ecmaVersion: 2020,
|
||||
sourceType: 'module',
|
||||
ecmaFeatures: { jsx: true },
|
||||
},
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
'react',
|
||||
'react-hooks',
|
||||
'unused-imports',
|
||||
'prettier',
|
||||
'import',
|
||||
'jsx-a11y',
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:react/recommended',
|
||||
'plugin:react-hooks/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
settings: {
|
||||
react: { version: 'detect' },
|
||||
'import/resolver': {
|
||||
typescript: {},
|
||||
},
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
node: true,
|
||||
es6: true,
|
||||
},
|
||||
rules: {
|
||||
'prettier/prettier': 'error',
|
||||
'react/react-in-jsx-scope': 'off',
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'warn',
|
||||
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
|
||||
],
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'unused-imports/no-unused-imports': 'warn',
|
||||
'no-console': [
|
||||
'warn',
|
||||
{
|
||||
allow: ['warn', 'error', 'info'],
|
||||
},
|
||||
],
|
||||
'import/order': 'off',
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
rules: {
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,76 @@
|
||||
++ name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18, 20]
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: 'pnpm'
|
||||
|
||||
- name: Enable corepack (pnpm)
|
||||
run: |
|
||||
corepack enable
|
||||
corepack prepare pnpm@latest --activate
|
||||
|
||||
- name: Cache pnpm store
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.pnpm-store
|
||||
~/.cache/pnpm
|
||||
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: Test (if present)
|
||||
run: pnpm test --if-present
|
||||
|
||||
- name: Lint
|
||||
run: pnpm run lint
|
||||
|
||||
- name: Build
|
||||
run: pnpm run build
|
||||
|
||||
- name: Upload build (artifact)
|
||||
if: success()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: dist
|
||||
path: ./dist
|
||||
|
||||
publish:
|
||||
name: Publish to GitHub Pages
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
steps:
|
||||
- name: Download artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: dist
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
publish_dir: ./dist
|
||||
publish_branch: gh-pages
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -1,4 +1,14 @@
|
||||
dist
|
||||
node_modules
|
||||
yarn.lock
|
||||
npm-debug.log
|
||||
/node_modules
|
||||
/.env.local
|
||||
/.umirc.local.ts
|
||||
/config/config.local.ts
|
||||
/src/.umi
|
||||
/src/.umi-production
|
||||
/src/.umi-test
|
||||
/dist
|
||||
.swc
|
||||
.turbopack
|
||||
|
||||
pnpm-lock.yaml
|
||||
yarn.lock
|
||||
npm-lock.json
|
||||
@@ -0,0 +1,9 @@
|
||||
node_modules
|
||||
dist
|
||||
.umi
|
||||
build
|
||||
coverage
|
||||
public
|
||||
node_modules
|
||||
.umi
|
||||
.umi-production
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all",
|
||||
"proseWrap": "never",
|
||||
"overrides": [{ "files": ".prettierrc", "options": { "parser": "json" } }],
|
||||
"plugins": ["prettier-plugin-organize-imports", "prettier-plugin-packagejson"]
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
const path = require('path')
|
||||
const { version } = require('./package.json')
|
||||
|
||||
const svgSpriteDirs = [
|
||||
path.resolve(__dirname, 'src/svg/'),
|
||||
require.resolve('antd').replace(/index\.js$/, '')
|
||||
]
|
||||
|
||||
export default {
|
||||
entry : 'src/index.js',
|
||||
svgSpriteLoaderDirs : svgSpriteDirs,
|
||||
theme : "./theme.config.js",
|
||||
publicPath : `/${version}/`,
|
||||
outputPath : `./dist/${version}`,
|
||||
// 接口代理示例
|
||||
// "proxy": {
|
||||
// "/api/v1": {
|
||||
// "target": "http://api.zuiidea.com",
|
||||
// "changeOrigin": true,
|
||||
// "pathRewrite": { "^/api/v1" : "/v1" }
|
||||
// },
|
||||
// "/api/v2": {
|
||||
// "target": "http://192.168.0.110",
|
||||
// "changeOrigin": true,
|
||||
// "pathRewrite": { "^/api/v2" : "/api/v2" }
|
||||
// }
|
||||
// },
|
||||
env : {
|
||||
development: {
|
||||
extraBabelPlugins: [
|
||||
"dva-hmr",
|
||||
"transform-runtime",
|
||||
[
|
||||
"import", {
|
||||
"libraryName": "antd",
|
||||
"style": true
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
production: {
|
||||
extraBabelPlugins: [
|
||||
"transform-runtime",
|
||||
[
|
||||
"import", {
|
||||
"libraryName": "antd",
|
||||
"style": true
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
dllPlugin : {
|
||||
exclude: ["babel-runtime"],
|
||||
include: ["dva/router", "dva/saga", "dva/fetch"]
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
const mock = {}
|
||||
require('fs').readdirSync(require('path').join(__dirname + '/src/mock')).forEach(function(file) {
|
||||
Object.assign(mock, require('./src/mock/' + file))
|
||||
})
|
||||
module.exports = mock
|
||||
@@ -0,0 +1,15 @@
|
||||
import { defineConfig } from 'umi';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: ['@umijs/plugins/dist/antd', '@umijs/plugins/dist/locale'],
|
||||
esbuildMinifyIIFE: true,
|
||||
locale: {
|
||||
antd: true,
|
||||
default: 'zh-CN',
|
||||
baseNavigator: true,
|
||||
useLocalStorage: true,
|
||||
baseSeparator: '-',
|
||||
title: true,
|
||||
},
|
||||
npmClient: 'pnpm',
|
||||
});
|
||||
@@ -0,0 +1,109 @@
|
||||
<p align="center">
|
||||
<a href="http://github.com/zuiidea/antd-admin" target="_blank">
|
||||
<img alt="antd-admin-logo" height="80" src="./public/logo.svg">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<h1 align="center">AntD Admin</h1>
|
||||
|
||||
<div align="center">
|
||||
|
||||
基于 Ant Design 6、Umi 4 与 TypeScript 构建的企业级前端解决方案。
|
||||
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
## 📖 项目简介
|
||||
|
||||
**AntD Admin** 是一个轻量、高性能的管理后台模板,旨在为构建企业级应用提供干净、可扩展的起点。项目使用 **Ant Design 6**、**Umi 4** 与 **TypeScript** 的最新特性,减轻样板代码,提升开发体验。
|
||||
|
||||
无论您要构建仪表盘、管理系统,还是集成 AI 功能的工具,本项目都能提供必要的基础。
|
||||
|
||||
## ✨ 主要特性
|
||||
|
||||
- 🚀 **现代栈**:基于 **Ant Design 6** + **Umi 4** + **TypeScript**。
|
||||
- 🎨 **清晰架构**:使用 `zustand` 进行轻量状态管理。
|
||||
- 🛠 **良好的开发体验**:内置本地 mock 服务器(`mock/index.js`),无需后端即可开发前端功能。
|
||||
- 📦 **丰富示例页面**:包含可直接使用的页面示例:
|
||||
- 📊 **仪表盘**:数据可视化概览。
|
||||
- 👥 **用户管理**:CRUD 操作示例。
|
||||
- 🧩 **菜单管理**:动态路由配置示例。
|
||||
- 🤖 **AI 聊天示例**:大模型(LLM)接口集成示例。
|
||||
- ✅ **CI/CD 支持**:预配置的 GitHub Actions 工作流,用于 lint 和构建。
|
||||
|
||||
## 🚀 快速开始
|
||||
|
||||
建议使用 **pnpm** 进行包管理。
|
||||
|
||||
```bash
|
||||
# 1. 克隆仓库
|
||||
git clone https://github.com/zuiidea/antd-admin.git -b master --depth=1
|
||||
cd antd-admin
|
||||
|
||||
# 2. 安装依赖
|
||||
pnpm install
|
||||
|
||||
# 3. 启动本地开发(含 mock 数据)
|
||||
npm run dev
|
||||
|
||||
# 4. 构建生产包
|
||||
npm run build
|
||||
|
||||
# 5. 代码质量检查
|
||||
npm run lint
|
||||
npm run format
|
||||
```
|
||||
|
||||
🔌 开发说明
|
||||
|
||||
#### Mock 服务
|
||||
|
||||
项目包含位于 `mock/index.js` 的内置 mock 服务,方便在没有后端的情况下独立开发前端功能。
|
||||
|
||||
如需关闭 mock 或切换到真实 API,请修改项目的代理配置(例如 Umi 项目可能的配置文件 `config/proxy.ts`、`.umirc.ts` 或 `config/config.ts`),以匹配您的实际项目结构。
|
||||
|
||||
#### 常用路由
|
||||
|
||||
| 路由 | 说明 |
|
||||
| --- | --- |
|
||||
| `/` 或 `/dashboard` | 主仪表盘 |
|
||||
| `/users` | 用户列表与管理 |
|
||||
| `/sys/menu` | 系统菜单配置 |
|
||||
| `/ai/chat` | AI 聊天示例界面 |
|
||||
|
||||
#### 定制化
|
||||
|
||||
- **API 集成:** 在 `src/services` 中更新 API 接口以对接真实后端。
|
||||
- **组件扩展:** 在 `src/components` 中复用或扩展现有组件(例如 `DropOption`、`StandardTable`)。
|
||||
- **主题:** 在主题配置中自定义 Ant Design 变量以匹配品牌视觉。
|
||||
|
||||
#### GitHub Actions(CI)
|
||||
|
||||
仓库包含预配置的 GitHub Actions 工作流(见 `.github/workflows/ci.yml`),用于保证代码质量:
|
||||
|
||||
- 使用 `pnpm` 安装依赖。
|
||||
- 运行 lint 检查。
|
||||
- 构建生产包。
|
||||
|
||||
- **工作流位置:** `.github/workflows/ci.yml`
|
||||
- **提示:** 若要在 CI 中加入自动化测试,请在 `package.json` 中添加测试脚本并更新 workflow YAML。
|
||||
|
||||
## 🤝 贡献
|
||||
|
||||
欢迎各类贡献:修复 bug、添加新示例页面或组件、完善类型定义与 lint 规则、改进国际化等。
|
||||
|
||||
常见贡献流程:
|
||||
|
||||
1. Fork 仓库。
|
||||
2. 新建分支:`git checkout -b feature/AmazingFeature`。
|
||||
3. 提交变更:`git commit -m 'Add some AmazingFeature'`。
|
||||
4. 推送分支:`git push origin feature/AmazingFeature`。
|
||||
5. 提交 Pull Request。
|
||||
|
||||
## 📄 许可证
|
||||
|
||||
本项目采用 MIT 许可证。
|
||||
|
||||
由 zuiidea 与贡献者共同维护,Made with ❤️。
|
||||
|
||||
@@ -1,160 +1,114 @@
|
||||
# Antd Admin
|
||||
<p align="center">
|
||||
<a href="http://github.com/zuiidea/antd-admin" target="_blank">
|
||||
<img alt="antd-admin-logo" height="80" src="./public/logo.svg">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
[](https://github.com/facebook/react)
|
||||
[](https://github.com/ant-design/ant-design)
|
||||
[](https://github.com/dvajs/dva)
|
||||
<h1 align="center">AntD Admin</h1>
|
||||
|
||||
[](https://github.com/zuiidea/antd-admin)
|
||||
[](https://github.com/zuiidea/antd-admin/pulls)
|
||||
[](http://opensource.org/licenses/MIT)
|
||||
[](http://standardjs.com)
|
||||
<div align="center">
|
||||
|
||||
演示地址 <http://zuiidea.github.io/antd-admin> \| [备用地址](http://47.92.30.98:8000)
|
||||
An excellent enterprise-grade front-end solution built with Ant Design 6, Umi 4, and TypeScript.
|
||||
|
||||
## 特性
|
||||
[](https://github.com/ant-design/ant-design)
|
||||
[](https://github.com/umijs/umi)
|
||||
[](https://www.typescriptlang.org/)
|
||||
[](https://github.com/zuiidea/antd-admin/issues)
|
||||
[](https://github.com/zuiidea/antd-admin/stargazers)
|
||||
[](http://opensource.org/licenses/MIT)
|
||||
[](https://github.com/zuiidea/antd-admin/pulls)
|
||||
|
||||
- 基于[react](https://github.com/facebook/react),[ant-design](https://github.com/ant-design/ant-design),[dva](https://github.com/dvajs/dva),[Mock](https://github.com/nuysoft/Mock) 企业级后台管理系统最佳实践。
|
||||
- 基于Antd UI 设计语言,提供后台管理系统常见使用场景。
|
||||
- 基于[dva](https://github.com/dvajs/dva)动态加载 Model 和路由,按需加载。
|
||||
- 使用[roadhog](https://github.com/sorrycc/roadhog)本地调试和构建,其中Mock功能实现脱离后端独立开发。
|
||||
- 浅度响应式设计。
|
||||
</div>
|
||||
|
||||
## 更新日志
|
||||
---
|
||||
|
||||
### 4.3.0
|
||||
## 📖 Introduction
|
||||
|
||||
`2017-07-30`
|
||||
**AntD Admin** is a lightweight, high-performance admin template designed to provide a clean and extensible starting point for building enterprise applications. It leverages the latest features of **Ant Design 6**, **Umi 4**, and **TypeScript**, offering a modern development experience with minimal boilerplate.
|
||||
|
||||
- 更新[roadhog](https://github.com/sorrycc/roadhog)至`1.0.0-beta.7`,得益于`webpack@3.4`,编译速度不减。
|
||||
- 基于使用roadhog的dll插件,开发时编译耗时减半。
|
||||
- 新增打包时按项目版本号生成文件目录。[#449](https://github.com/zuiidea/antd-admin/issues/449)
|
||||
- 更新`eslint`,并适当修改了`.eslintrc`。
|
||||
Whether you are building a dashboard, a management system, or an AI-powered tool, this project provides the essential foundation you need.
|
||||
|
||||
### 4.2.3
|
||||
## ✨ Key Features
|
||||
|
||||
`2017-07-07`
|
||||
- 🚀 **Modern Stack**: Built on **Ant Design 6** + **Umi 4** + **TypeScript**.
|
||||
- 🎨 **Clean Architecture**: Lightweight state management using `zustand`.
|
||||
- 🛠 **Dev Experience**: Integrated local mock server (`mock/index.js`) for seamless frontend development without backend dependency.
|
||||
- 📦 **Rich Examples**: Includes ready-to-use pages:
|
||||
- 📊 **Dashboard**: Data visualization overview.
|
||||
- 👥 **User Management**: CRUD operations example.
|
||||
- 🧩 **Menu Management**: Dynamic routing configuration.
|
||||
- 🤖 **AI Chat Demo**: Integration example for LLM interfaces.
|
||||
- ✅ **CI/CD Ready**: Pre-configured GitHub Actions for linting and building.
|
||||
|
||||
- 新增用户按权限访问。[#384](https://github.com/zuiidea/antd-admin/issues/384)
|
||||
## 🚀 Quick Start
|
||||
|
||||
### 4.2.2
|
||||
|
||||
`2017-06-01`
|
||||
|
||||
- 新增用户管理批量删除。[#320](https://github.com/zuiidea/antd-admin/issues/320)
|
||||
|
||||
### 4.2.1
|
||||
|
||||
`2017-05-12`
|
||||
|
||||
- 新增IconFont扩展方案,本地使用方案。[#270](https://github.com/zuiidea/antd-admin/issues/270) [Live](http://47.92.30.98:666/UIElement/iconfont)
|
||||
- 新增常见场景使用loading。 [dva-loading](https://github.com/dvajs/dva-loading)
|
||||
|
||||
### 4.2
|
||||
|
||||
`2017-04-28`
|
||||
|
||||
- 修改user相关API使用`Restful`风格。
|
||||
- 增加user页面多条件查询。[#266](https://github.com/zuiidea/antd-admin/issues/226)
|
||||
- 修复菜单默认高亮。[#201](https://github.com/zuiidea/antd-admin/issues/201)
|
||||
|
||||
[More Change Log](https://github.com/zuiidea/antd-admin/wiki/Change-Log)
|
||||
|
||||
## 开发构建
|
||||
|
||||
### 目录结构
|
||||
We recommend using **pnpm** for package management.
|
||||
|
||||
```bash
|
||||
├── /dist/ # 项目输出目录
|
||||
├── /src/ # 项目源码目录
|
||||
│ ├── /public/ # 公共文件,编译时copy至dist目录
|
||||
│ ├── /components/ # UI组件及UI相关方法
|
||||
│ │ ├── skin.less # 全局样式
|
||||
│ │ └── vars.less # 全局样式变量
|
||||
│ ├── /routes/ # 路由组件
|
||||
│ │ └── app.js # 路由入口
|
||||
│ ├── /models/ # 数据模型
|
||||
│ ├── /services/ # 数据接口
|
||||
│ ├── /themes/ # 项目样式
|
||||
│ ├── /mock/ # 数据mock
|
||||
│ ├── /utils/ # 工具函数
|
||||
│ │ ├── config.js # 项目常规配置
|
||||
│ │ ├── menu.js # 菜单及面包屑配置
|
||||
│ │ ├── config.js # 项目常规配置
|
||||
│ │ ├── request.js # 异步请求函数
|
||||
│ │ └── theme.js # 项目需要在js中使用到样式变量
|
||||
│ ├── route.js # 路由配置
|
||||
│ ├── index.js # 入口文件
|
||||
│ └── index.html
|
||||
├── package.json # 项目信息
|
||||
├── .eslintrc # Eslint配置
|
||||
└── .roadhogrc.js # roadhog配置
|
||||
```
|
||||
# 1. Clone the repository
|
||||
git clone https://github.com/zuiidea/antd-admin.git -b master --depth=1
|
||||
cd antd-admin
|
||||
|
||||
文件夹命名说明:
|
||||
# 2. Install dependencies
|
||||
pnpm install
|
||||
|
||||
- components:组件(方法)为单位以文件夹保存,文件夹名组件首字母大写(如`DataTable`),方法首字母小写(如`layer`),文件夹内主文件与文件夹同名,多文件以`index.js`导出对象(如`./src/components/Layout`)。
|
||||
- routes:页面为单位以文件夹保存,文件夹名首字母小写(特殊除外,如`UIElement`),文件夹内主文件以`index.js`导出,多文件时可建立`components`文件夹(如`./src/routes/dashboard`),如果有子路由,依次按照路由层次建立文件夹(如`./src/routes/UIElement`)。
|
||||
|
||||
### 快速开始
|
||||
|
||||
克隆项目文件:
|
||||
|
||||
git clone https://github.com/zuiidea/antd-admin.git
|
||||
|
||||
进入目录安装依赖:
|
||||
|
||||
npm i 或者 yarn install
|
||||
|
||||
开发:
|
||||
|
||||
```bash
|
||||
npm run build:dll #第一次npm run dev时需运行此命令,使开发时编译更快
|
||||
# 3. Start local development server (with mock data)
|
||||
npm run dev
|
||||
打开 http://localhost:8000
|
||||
```
|
||||
|
||||
构建:
|
||||
[详情](https://github.com/zuiidea/antd-admin/issues/269)
|
||||
|
||||
```bash
|
||||
# 4. Build for production
|
||||
npm run build
|
||||
|
||||
将会打包至dist/{version}目录 #package.json里version字段
|
||||
|
||||
npm run build:new
|
||||
|
||||
将会打包至dist/{version增加1}目录 #package.json里version字段
|
||||
```
|
||||
|
||||
代码检测:
|
||||
|
||||
```bash
|
||||
# 5. Code quality checks
|
||||
npm run lint
|
||||
npm run format
|
||||
```
|
||||
|
||||
## FAQ
|
||||
🔌 **Development Notes**
|
||||
|
||||
- 项目打包后如何部署? [#269](https://github.com/zuiidea/antd-admin/issues/269)
|
||||
- 如何做权限管理? [#384](https://github.com/zuiidea/antd-admin/issues/384)
|
||||
- 如何使用mock.js模拟接口,怎么使用线上接口? [#348](https://github.com/zuiidea/antd-admin/issues/348)
|
||||
- 如何使用Iconfont,如何使用本地的svg图标? [#270](https://github.com/zuiidea/antd-admin/issues/270)
|
||||
- 怎么按版本打包,上线时不影响正在访问的用户? [#449](https://github.com/zuiidea/antd-admin/issues/449)
|
||||
- windows处理CRLF?[参考](http://blog.csdn.net/lysc_forever/article/details/42835203)
|
||||
#### Mock Server
|
||||
|
||||
git config --global core.autocrlf false
|
||||
The project includes a built-in mock server defined in `mock/index.js`. This allows you to develop frontend features independently of the backend.
|
||||
|
||||
## 参考
|
||||
To disable mocks or switch to a real API, modify the proxy settings in your configuration file (for example, `config/proxy.ts` or `.umirc.ts`).
|
||||
|
||||
用户列表:<https://github.com/dvajs/dva/tree/master/examples/user-dashboard>
|
||||
#### Common Routes
|
||||
|
||||
dashboard设计稿:<https://dribbble.com/shots/3108122-Dashboard-Admin> (已征得作者同意)
|
||||
| Route | Description |
|
||||
| --- | --- |
|
||||
| `/` or `/dashboard` | Main Dashboard |
|
||||
| `/users` | User List & Management |
|
||||
| `/sys/menu` | System Menu Configuration |
|
||||
| `/ai/chat` | AI Chat Interface Demo |
|
||||
|
||||
## 截屏
|
||||
#### Customization
|
||||
|
||||
web
|
||||
- **API Integration:** Update API endpoints in `src/services` to connect to your real backend.
|
||||
- **Component Extension:** Reuse or extend existing components in `src/components` (for example, `DropOption`, `StandardTable`).
|
||||
- **Theme:** Customize Ant Design tokens in the theme configuration to match your brand identity.
|
||||
|
||||

|
||||
#### GitHub Actions CI
|
||||
|
||||
移动
|
||||
This repository includes a pre-configured GitHub Actions workflow to ensure code quality:
|
||||
|
||||

|
||||
- Installs dependencies using `pnpm`.
|
||||
- Runs linting checks.
|
||||
- Builds the project for production.
|
||||
|
||||
- **Workflow location:** `.github/workflows/ci.yml`
|
||||
- **Tip:** To add automated tests to the CI pipeline, add a test script to `package.json` and update the workflow YAML accordingly.
|
||||
🤝 Contributing
|
||||
Contributions are always welcome! Whether it's fixing a bug, adding a new feature, or improving documentation, please feel free to submit an Issue or a Pull Request.
|
||||
Typical contributions include:
|
||||
🐛 Bug fixes
|
||||
🧩 New example pages or components
|
||||
📝 Type definitions and linting improvements
|
||||
🌍 Internationalization (i18n) updates
|
||||
How to contribute:
|
||||
Fork the repository.
|
||||
Create your feature branch (git checkout -b feature/AmazingFeature).
|
||||
Commit your changes (git commit -m 'Add some AmazingFeature').
|
||||
Push to the branch (git push origin feature/AmazingFeature).
|
||||
Open a Pull Request.
|
||||
📄 License
|
||||
This project is licensed under the MIT License.
|
||||
Made with ❤️ by zuiidea and contributors.
|
||||
|
||||
|
Before Width: | Height: | Size: 3.7 MiB |
|
Before Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 645 KiB |
@@ -1,35 +0,0 @@
|
||||
### 开发环境
|
||||
|
||||
- OS:Windows
|
||||
- 编辑器:Atom
|
||||
- cmd:Cmder
|
||||
|
||||
### Atom 插件
|
||||
|
||||
- [atom-beautify](https://atom.io/packages/atom-beautify)
|
||||
|
||||
#### Less
|
||||
|
||||
- [x] Beautify On Save
|
||||
|
||||
#### Javascript
|
||||
|
||||
- [ ] Disable Beautifying Language
|
||||
|
||||
#### Markdown
|
||||
|
||||
- [x] Beautify On Save
|
||||
- [x] Default Beautifier:Remark
|
||||
|
||||
#### HTML
|
||||
|
||||
- [x] Beautify On Save
|
||||
|
||||
- [linter](https://atom.io/packages/linter)
|
||||
- [ ] Lint on Change
|
||||
- [linter-eslint](https://atom.io/packages/linter-eslint)
|
||||
- [x] Fix errors on save
|
||||
|
||||
### Cmder 主题
|
||||
|
||||
- [Panda-Theme-Cmder](https://github.com/HamidFaraji/Panda-Theme-Cmder)
|
||||
@@ -0,0 +1,36 @@
|
||||
# API configuration
|
||||
|
||||
This project uses explicit per-feature service modules (TypeScript) under `src/services/` that call a shared HTTP helper `src/utils/request.ts` (exported as the default `api` function).
|
||||
|
||||
Why this pattern?
|
||||
- Clear function boundaries per domain (users, admin, menu, dashboard).
|
||||
- Type-safe signatures in TypeScript for inputs/outputs (`src/types`).
|
||||
- Centralized request handling (query params, JSON body, auth header, unified response format) in `src/utils/request.ts`.
|
||||
|
||||
Example service (from `src/services/user.ts`):
|
||||
|
||||
```ts
|
||||
import type { PagedResponse, User } from '@/types/user';
|
||||
import api from '../utils/request';
|
||||
|
||||
export async function listUsers(
|
||||
params?: Record<string, string | number | boolean>,
|
||||
): Promise<PagedResponse<User>> {
|
||||
return api<PagedResponse<User>>('/users', { method: 'GET', params });
|
||||
}
|
||||
|
||||
export async function createUser(values: Record<string, unknown>): Promise<User> {
|
||||
return api('/user', { method: 'POST', body: values });
|
||||
}
|
||||
```
|
||||
|
||||
Usage:
|
||||
- Import named functions from the service module: `import { listUsers } from '@/services/user'`.
|
||||
- The helper `api(path, options)` returns the parsed `data` payload from responses that follow the `{ success, message, data }` convention.
|
||||
|
||||
Notes about `src/utils/request.ts`:
|
||||
- Combines `config.apiPrefix` with the provided `path`.
|
||||
- Supports `params` (query), `body` (JSON or FormData), and sets `Authorization` header from local storage when available.
|
||||
- Throws errors and shows UI messages for non-success responses.
|
||||
|
||||
If you are migrating older code that used an API mapping, prefer creating small service modules with clear function names and types as shown above.
|
||||
@@ -0,0 +1,57 @@
|
||||
<p align="center">
|
||||
<a href="http://github.com/zuiidea/antd-admin">
|
||||
<img alt="antd-admin" height="64" src="./_media/logo.svg">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<h1 align="center">AntD Admin</h1>
|
||||
|
||||
<div align="center">
|
||||
|
||||
An enterprise-grade front-end starter built with Ant Design 6, Umi 4 and TypeScript.
|
||||
|
||||
[](https://github.com/ant-design/ant-design)
|
||||
[](https://github.com/umijs/umi)
|
||||
[](https://www.typescriptlang.org/)
|
||||
[](http://opensource.org/licenses/MIT)
|
||||
[](https://github.com/zuiidea/antd-admin/pulls)
|
||||
|
||||
</div>
|
||||
|
||||
- Documentation source for this project is under `docs/`.
|
||||
|
||||
## Quick start
|
||||
|
||||
This repository uses `pnpm` in examples and CI; `npm` or `yarn` also work but `pnpm` is recommended.
|
||||
|
||||
```bash
|
||||
# clone
|
||||
git clone https://github.com/zuiidea/antd-admin.git
|
||||
cd antd-admin
|
||||
|
||||
# install
|
||||
pnpm install
|
||||
|
||||
# start dev server (includes local mock server)
|
||||
npm run dev
|
||||
|
||||
# build
|
||||
npm run build
|
||||
|
||||
# lint & format
|
||||
npm run lint
|
||||
npm run format
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- Mock data live in `mock/index.js` and the project can run without a backend during development.
|
||||
- CI workflow is available at `.github/workflows/ci.yml` (uses pnpm, lint, build).
|
||||
- Update API endpoints under `src/services` to integrate a real backend.
|
||||
|
||||
For detailed documentation see the other pages in this `docs/` folder.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions welcome — file issues or open a PR as usual on GitHub.
|
||||
|
||||
|
After Width: | Height: | Size: 66 KiB |
@@ -0,0 +1,24 @@
|
||||
|
||||
<svg width="169px" height="141px" viewBox="0 0 169 141" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: Sketch 51.3 (57544) - http://www.bohemiancoding.com/sketch -->
|
||||
<desc>Created with Sketch.</desc>
|
||||
<defs>
|
||||
<linearGradient x1="54.0428975%" y1="4.39752391%" x2="54.0428975%" y2="108.456714%" id="linearGradient-1">
|
||||
<stop stop-color="#29CDFF" offset="0%"></stop>
|
||||
<stop stop-color="#148EFF" offset="62.3089445%"></stop>
|
||||
<stop stop-color="#0A60FF" offset="100%"></stop>
|
||||
</linearGradient>
|
||||
<linearGradient x1="50%" y1="14.2201464%" x2="50%" y2="113.263844%" id="linearGradient-2">
|
||||
<stop stop-color="#FA816E" offset="0%"></stop>
|
||||
<stop stop-color="#F74A5C" offset="65.9092442%"></stop>
|
||||
<stop stop-color="#F51D2C" offset="100%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="Group" transform="translate(0.000000, -5.000000)">
|
||||
<rect id="Rectangle" fill="url(#linearGradient-1)" transform="translate(83.718923, 75.312358) rotate(-24.000000) translate(-83.718923, -75.312358) " x="68.7189234" y="0.312357954" width="30" height="150" rx="15"></rect>
|
||||
<rect id="Rectangle" fill="url(#linearGradient-1)" transform="translate(129.009910, 75.580213) rotate(-24.000000) translate(-129.009910, -75.580213) " x="114.00991" y="0.580212739" width="30" height="150" rx="15"></rect>
|
||||
<circle id="Oval" fill="url(#linearGradient-2)" cx="25" cy="120" r="25"></circle>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 194 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 199 KiB |
|
After Width: | Height: | Size: 124 KiB |
@@ -0,0 +1,12 @@
|
||||
- Getting started
|
||||
- [Quick Start](getting-started.md)
|
||||
- Customization
|
||||
- [Configuration](configuration.md)
|
||||
- [API Configuration](API-configuration.md)
|
||||
- [I18n](i18n.md)
|
||||
- [Layout](layout.md)
|
||||
- [Request](request.md)
|
||||
- Guide
|
||||
- [Deploy](deploy.md)
|
||||
- [Change Log](change-log.md)
|
||||
- [FAQ](faq.md)
|
||||
@@ -0,0 +1,26 @@
|
||||
## 6.0.0
|
||||
|
||||
This project was modernized and migrated to a modern front-end stack. Key highlights of the current version:
|
||||
|
||||
### Modern stack
|
||||
- Upgraded to Ant Design 6, Umi 4 and TypeScript 5.
|
||||
- React has been updated to the current major line used in the repo (see `package.json`).
|
||||
|
||||
### Architecture & DX
|
||||
- Services are implemented as TypeScript modules under `src/services/` and use a centralized HTTP helper `src/utils/request.ts`.
|
||||
- Lightweight local state management using `zustand` replacing older `dva` patterns.
|
||||
- Local mock server using `mock/index.js` with `mockjs` for frontend development without backend dependency.
|
||||
|
||||
### Tooling & CI
|
||||
- Dev workflows use `pnpm` by default; scripts are defined in `package.json` (e.g. `pnpm run dev`, `pnpm run build`).
|
||||
- Tests use `jest` and related tooling; CI is implemented with GitHub Actions (`.github/workflows/ci.yml`) which installs via `pnpm`, lints and builds the project.
|
||||
|
||||
### Quality and types
|
||||
- TypeScript types are added/expanded under `src/types/` for safer APIs and components.
|
||||
- Prettier / ESLint configuration added to enforce code style.
|
||||
|
||||
### Other
|
||||
- Documentation is maintained under `docs/` (this site) and updated to reflect the new stack and commands.
|
||||
- Removed old custom components that duplicate Ant Design functionality and simplified the codebase accordingly.
|
||||
|
||||
If you want a more detailed, commit-level changelog for each migration step, I can generate one from git history or help draft a migration guide.
|
||||
@@ -0,0 +1,33 @@
|
||||
# Configuration
|
||||
|
||||
You can do some custom configuration in `/src/utils/config.js`:
|
||||
|
||||
## siteName
|
||||
|
||||
- Type `String`
|
||||
|
||||
Configure the site name, apply it to the login box, and display the title text at the top of the sidebar.
|
||||
|
||||
## copyright
|
||||
|
||||
- Type: `String`
|
||||
|
||||
Configure the copyright notice to apply to the login page, at the bottom of the `Primary` layout.
|
||||
|
||||
## logoPath
|
||||
|
||||
- Type: `String`
|
||||
|
||||
Configure the site logo to apply to the login box and the Logo display at the top of the sidebar.
|
||||
|
||||
## apiPrefix
|
||||
|
||||
- Type: `String`
|
||||
|
||||
Configure the prefix of the interface in the project. The interface related documents can be viewed [API configuration](API-configuration.md)
|
||||
|
||||
## fixedHeader
|
||||
|
||||
- Type: `String`
|
||||
|
||||
Under the `Primary` layout, whether the top of the page is fixed when scrolling。
|
||||
@@ -0,0 +1,113 @@
|
||||
# Deploy
|
||||
|
||||
After the development is completed and verified in the development environment, it needs to be deployed to our users.
|
||||
|
||||

|
||||
|
||||
## Build
|
||||
|
||||
First execute the following command,
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
After a few seconds, the output should look like this:
|
||||
|
||||
```bash
|
||||
> antd-admin@5.0.0-beta build /Users/zuiidea/web/antd-admin
|
||||
> umi build
|
||||
|
||||
[21:13:17] webpack compiled in 43s 868ms
|
||||
DONE Compiled successfully in 43877ms 21:13:17
|
||||
|
||||
File sizes after gzip:
|
||||
|
||||
1.3 MB dist/vendors.async.js
|
||||
308.21 KB dist/umi.js
|
||||
45.49 KB dist/vendors.chunk.css
|
||||
36.08 KB dist/p__chart__highCharts__index.async.js
|
||||
33.53 KB dist/p__user__index.async.js
|
||||
22.36 KB dist/p__chart__ECharts__index.async.js
|
||||
4.21 KB dist/p__dashboard__index.async.js
|
||||
4.06 KB dist/umi.css
|
||||
...
|
||||
```
|
||||
|
||||
The `build` command will package all resources, including JavaScript, CSS, web fonts, images, html, and more. You can find these files in the `dist/` directory.
|
||||
|
||||
> If you have requirements for using HashHistory , deploying html to non-root directories, statics, etc., check out [Umi Deployment] (https://umijs.org/en/guide/deploy.html).
|
||||
|
||||
## Local verification
|
||||
|
||||
|
||||
Local verification can be done via `serve` before publishing.
|
||||
|
||||
```
|
||||
$ yarn global add serve
|
||||
$ serve ./dist
|
||||
|
||||
Serving!
|
||||
|
||||
- Local: http://localhost:5000
|
||||
- On Your Network: http://{Your IP}:5000
|
||||
|
||||
Copied local address to clipboard!
|
||||
|
||||
```
|
||||
|
||||
Access [http://localhost:5000](http://localhost:5000), under normal circumstances, it should be consistent with `npm start` (The API may not get the correct data).
|
||||
|
||||
|
||||
## Deploy
|
||||
|
||||
Next, we can upload the static file to the server. If you use Nginx as the Web server, you can configure it in `ngnix.conf`:
|
||||
```
|
||||
server
|
||||
{
|
||||
listen 80;
|
||||
# Specify an accessible domain name
|
||||
server_name antd-admin.zuiidea.com;
|
||||
# The directory where the compiled files are stored
|
||||
root /home/www/antd-admin/dist;
|
||||
|
||||
# Proxy server interface to avoid cross-domain
|
||||
location /api {
|
||||
proxy_pass http://localhost:7000/api;
|
||||
}
|
||||
|
||||
Because the front end uses BrowserHistory, it will route backback to index.html
|
||||
location / {
|
||||
index index.html;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Restart the web server and access [http://antd-admin.zuiidea.com](http://antd-admin.zuiidea.com) , You will see the correct page.
|
||||
|
||||
```bash
|
||||
nginx -s reload
|
||||
```
|
||||
|
||||
Similarly, if you use Caddy as a web server, you can do this in `Caddyfile`:
|
||||
|
||||
```
|
||||
antd-admin.zuiidea.com {
|
||||
gzip
|
||||
root /home/www/antd-admin/dist
|
||||
proxy /api http://localhost:7000
|
||||
|
||||
rewrite {
|
||||
if {path} not_match ^/api
|
||||
to {path} {path}/ /
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
antd-admin.zuiidea.com/public {
|
||||
gzip
|
||||
root /home/www/antd-admin/dist/static/public
|
||||
}
|
||||
|
||||
```
|
||||
@@ -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
|
||||
@@ -0,0 +1,75 @@
|
||||
# Quick Start
|
||||
|
||||
> Before delving into Ant Design React, a good knowledge base of [React](http://facebook.github.io/react/) 、 [ES2015+](http://es6.ruanyifeng.com/) 、 [Antd Design](https://ant.design/docs/react/introduce-cn). Learn about [UmiJS](https://umijs.org/). Ensure you have [Node.js](https://nodejs.org/) (v18+ recommended) and [Git](https://git-scm.com/) installed.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
git clone https://github.com/zuiidea/antd-admin.git my-project
|
||||
cd my-project
|
||||
```
|
||||
|
||||
## Scaffolding
|
||||
|
||||
The project layout is as follows:
|
||||
|
||||
```bash
|
||||
├── dist/ # Default build output directory
|
||||
├── mock/ # Mock files
|
||||
├── public/ # Static resource
|
||||
├── src/ # Source code
|
||||
│ ├── components/ # Components
|
||||
│ ├── e2e/ # Integrated Test Case
|
||||
│ ├── layouts/ # Common Layouts
|
||||
│ ├── locales/ # i18n resources
|
||||
│ ├── models/ # Global dva Model
|
||||
│ ├── pages/ # Sub-pages and templates
|
||||
│ ├── services/ # Backend Services
|
||||
│ │ ├── api.js # API configuration
|
||||
│ │ └── index.js # API export
|
||||
│ ├── themes/ # Themes
|
||||
│ │ ├── default.less # Less variable
|
||||
│ │ ├── index.less # Global style
|
||||
│ │ ├── mixin.less # Less mixin
|
||||
│ │ └── vars.less # Less variable and mixin
|
||||
│ ├── utils/ # Utility
|
||||
│ │ ├── config.js # Application configuration
|
||||
│ │ ├── constant.js # Static constant
|
||||
│ │ ├── index.js # Utility methods
|
||||
│ │ ├── request.js # Request function(axios)
|
||||
│ │ └── theme.js # Style variables used in js
|
||||
├── .editorconfig
|
||||
├── .env
|
||||
├── .eslintrc
|
||||
├── .gitignore
|
||||
├── .prettierignore
|
||||
├── .prettierrc
|
||||
├── .stylelintrc.json
|
||||
├── .travis.yml
|
||||
└── .umirc.js
|
||||
└── package.json
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
1. Install dependencies (recommended: `pnpm`).
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
Or with other package managers:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
# or
|
||||
yarn install
|
||||
```
|
||||
|
||||
2. Start local development server.
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
3. After startup, open the app in a browser (see dev server output for the actual URL/port).
|
||||
@@ -0,0 +1,121 @@
|
||||
# Internationalization (i18n) Guide
|
||||
|
||||
This project uses Umi's `plugin-locale` (based on `react-intl`) to manage localization. Translation resources live in `src/locales` (for example `en-US.json`, `zh-CN.json`). Below are instructions for: adding a language, adding a translation entry, switching languages, and disabling i18n. Examples use Japanese `ja-JP`.
|
||||
|
||||
## 1. Add a new language (persistent)
|
||||
|
||||
1. Create a new translation file under `src/locales/` with the language id as the file name, for example: `src/locales/ja-JP.json`.
|
||||
|
||||
2. The file should contain a JSON object of translation keys and values (nesting allowed):
|
||||
|
||||
```json
|
||||
{
|
||||
"welcome": "ようこそ",
|
||||
"login": {
|
||||
"username": "ユーザー名",
|
||||
"password": "パスワード",
|
||||
"submit": "ログイン"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. If you want Ant Design components to use the same locale (dates, component text), add the AntD locale import and mapping in `src/app.tsx`'s `pick` function, e.g.:
|
||||
|
||||
```ts
|
||||
import jaJP from 'antd/locale/ja_JP';
|
||||
// ...
|
||||
if (l === 'ja-JP') return jaJP;
|
||||
```
|
||||
|
||||
4. Add the language to the language selector (for example in `src/components/TopbarControls.tsx`):
|
||||
|
||||
```ts
|
||||
{ key: 'ja-JP', label: '日本語' }
|
||||
```
|
||||
|
||||
5. Restart the dev server:
|
||||
|
||||
```bash
|
||||
pnpm run dev
|
||||
```
|
||||
|
||||
Umi collects files in `src/locales` into `localeInfo` at build/dev time so the new language becomes available. If you prefer not to restart, see the runtime registration option below.
|
||||
|
||||
## 2. Add a translation entry
|
||||
|
||||
1. Add the same key to each language JSON (keep `en-US.json` and `zh-CN.json` up to date alongside the new language):
|
||||
|
||||
`src/locales/en-US.json`
|
||||
|
||||
```json
|
||||
"my.feature.greeting": "Hello from feature"
|
||||
```
|
||||
|
||||
`src/locales/zh-CN.json`
|
||||
|
||||
```json
|
||||
"my.feature.greeting": "来自功能的问候"
|
||||
```
|
||||
|
||||
2. In a component use `useIntl()` and `formatMessage`:
|
||||
|
||||
```ts
|
||||
import { useIntl } from 'umi';
|
||||
const intl = useIntl();
|
||||
const text = intl.formatMessage({ id: 'my.feature.greeting', defaultMessage: 'Hello' });
|
||||
```
|
||||
|
||||
Use `useIntl()` (or `injectIntl`) so the component updates automatically when the locale changes.
|
||||
|
||||
## 3. Runtime switching and registering
|
||||
|
||||
- Switch locale (writes `umi_locale` to localStorage and either reloads or triggers an update):
|
||||
|
||||
```ts
|
||||
import { setLocale } from 'umi';
|
||||
// switch and reload
|
||||
setLocale('ja-JP', true);
|
||||
// switch without reload (emit update event)
|
||||
setLocale('zh-CN', false);
|
||||
```
|
||||
|
||||
- Register a locale at runtime (no server restart required):
|
||||
|
||||
```ts
|
||||
import { addLocale, setLocale } from 'umi';
|
||||
import jaMessages from '@/locales/ja-JP.json';
|
||||
import jaAntd from 'antd/locale/ja_JP';
|
||||
|
||||
addLocale('ja-JP', jaMessages, { antd: jaAntd, momentLocale: 'ja' });
|
||||
setLocale('ja-JP', false);
|
||||
```
|
||||
|
||||
`addLocale` merges messages into the internal `localeInfo`. You can pass extra data (like AntD locale and moment locale) so components using AntD/moment behave correctly.
|
||||
|
||||
## 4. Disable i18n (turn off multi-language)
|
||||
|
||||
To permanently disable multi-language support:
|
||||
|
||||
1. In `src/app.tsx`'s `LocaleWrapper`, return a fixed AntD locale (ignore `localStorage` `umi_locale`):
|
||||
|
||||
```ts
|
||||
const pick = (l: string | null) => {
|
||||
return zhCN; // force Chinese
|
||||
};
|
||||
```
|
||||
|
||||
2. Remove or hide the language switcher (for example, remove language menu items in `src/components/TopbarControls.tsx`).
|
||||
|
||||
3. Optionally remove other JSON files in `src/locales` except the single target language to reduce build size.
|
||||
|
||||
If you only want to temporarily prevent user switching, hide the switcher (step 2) and keep files intact for easy re-enable.
|
||||
|
||||
## 5. Debugging & common issues
|
||||
|
||||
- New language not appearing: restart dev server or use `addLocale`; ensure AntD locale mapping exists in `app.tsx`.
|
||||
- Missing translations: check all `src/locales/*.json` contain the key, and the `formatMessage` id is correct.
|
||||
- Want automated extraction of message ids: this repo does not include extraction scripts; consider integrating `lingui`, `babel-plugin-react-intl`, or other tooling and adding scripts to `package.json`.
|
||||
|
||||
If you want, I can:
|
||||
- create an initial `src/locales/ja-JP.json` and update `TopbarControls`/`app.tsx` mappings; or
|
||||
- add a small example component that demonstrates runtime registration using `addLocale`. Tell me which one you prefer.
|
||||
@@ -0,0 +1,55 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>antd-admin - An admin dashboard application demo built upon Ant Design and UmiJS</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<meta name="description" content="An admin dashboard application demo built upon Ant Design and UmiJS">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
|
||||
<link rel="icon" href="/_media/favicon.ico" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav data-cloak class="app-nav">
|
||||
<a href="/">En</a>
|
||||
<a href="#/zh-cn/">中文</a>
|
||||
</nav>
|
||||
<div id="app">Loading...</div>
|
||||
<script>
|
||||
window.$docsify = {
|
||||
name: 'AntD Admin',
|
||||
loadSidebar: true,
|
||||
maxLevel: 3,
|
||||
subMaxLevel: 3,
|
||||
auto2top: true,
|
||||
autoHeader: true,
|
||||
repo: 'zuiidea/antd-admin',
|
||||
themeColor: '#1890ff',
|
||||
search: {
|
||||
paths: 'auto',
|
||||
placeholder: {
|
||||
'/zh-cn/': '搜索',
|
||||
'/': 'Type to search'
|
||||
},
|
||||
|
||||
noData: {
|
||||
'/zh-cn/': '找不到结果',
|
||||
'/': 'No Results'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (typeof navigator.serviceWorker !== 'undefined') {
|
||||
// navigator.serviceWorker.register('sw.js')
|
||||
// }
|
||||
</script>
|
||||
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
|
||||
<script src="//unpkg.com/docsify/lib/plugins/emoji.min.js"></script>
|
||||
<script src="//unpkg.com/docsify/lib/plugins/zoom-image.min.js"></script>
|
||||
<script src="//unpkg.com/docsify-copy-code"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,60 @@
|
||||
# Layout
|
||||
|
||||
## Add a new 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).
|
||||
|
||||
```javascript
|
||||
layouts: [
|
||||
{
|
||||
name: 'primary',
|
||||
include: [/.*/],
|
||||
exclude: [/(\/(en|zh))*\/login/, /(\/(en|zh))*\/secondary\/(.*)/],
|
||||
},
|
||||
{
|
||||
name: 'secondary',
|
||||
include: [/(\/(en|zh))*\/secondary\/(.*)/],
|
||||
},
|
||||
],
|
||||
```
|
||||
|
||||
2. Add the `secondary` layout component to the `src/layouts/BaseLayout.js` file.
|
||||
|
||||
```javascript
|
||||
import SecondaryLayout from './SecondaryLayout'
|
||||
|
||||
const LayoutMap = {
|
||||
primary: PrimaryLayout,
|
||||
public: PublicLayout,
|
||||
secondary: SecondaryLayout,
|
||||
}
|
||||
```
|
||||
|
||||
3. Add the `SecondaryLayout.js` file to the `src/layouts/` directory.
|
||||
|
||||
```javascript
|
||||
import React from 'react'
|
||||
|
||||
export default ({ children }) => {
|
||||
return (
|
||||
<div>
|
||||
<h1>Secondary</h1>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
4. Add a `secondary/index.js` file to the `src/pages/` directory.
|
||||
|
||||
```javascript
|
||||
import React from 'react'
|
||||
|
||||
export default ({ children }) => {
|
||||
Return <div>Secondary page Content</div>
|
||||
}
|
||||
```
|
||||
|
||||
5. Finally, start the development mode with `npm run dev`, then open the layout page in your browser (see dev server output for the actual URL), e.g. `/secondary/`.
|
||||
@@ -0,0 +1,33 @@
|
||||
# HTTP requests
|
||||
|
||||
This project uses a small fetch-based HTTP helper implemented at `src/utils/request.ts` (export default `api`). The helper centralizes:
|
||||
|
||||
- Prefixing paths with `config.apiPrefix`.
|
||||
- Handling `params` (query string) and `body` (JSON or FormData).
|
||||
- Injecting an `Authorization` header from local storage when available.
|
||||
- Unified response parsing and error handling (expects backend responses in the form `{ success, message, data }`).
|
||||
|
||||
Key behaviors
|
||||
|
||||
- `api(path, options)` merges `config.apiPrefix` + `path` to build the URL.
|
||||
- If `options.params` is provided it's serialized and appended as query string.
|
||||
- `options.body` handling:
|
||||
- FormData is sent as-is (do not set Content-Type manually).
|
||||
- Strings and Blobs are sent directly.
|
||||
- Plain objects are JSON.stringified and Content-Type defaults to `application/json`.
|
||||
- If a token exists in local storage (key `app-auth-token`), the helper injects an `Authorization: Bearer <token>` header unless one is already provided.
|
||||
- Responses are expected to be JSON with `{ success: boolean, message?: string, data: T }`. Non-success responses throw an Error and show a UI message (uses `antd`'s `message`).
|
||||
|
||||
Usage (TypeScript-friendly):
|
||||
|
||||
```ts
|
||||
import api from '@/utils/request';
|
||||
|
||||
// GET with query params
|
||||
const page = await api('/users', { method: 'GET', params: { page: 1, pageSize: 10 } });
|
||||
|
||||
// POST with JSON body
|
||||
const created = await api('/user', { method: 'POST', body: { name: 'Alice' } });
|
||||
```
|
||||
|
||||
The helper returns the `data` field from successful responses. Check `src/utils/request.ts` for exact typings and behavior.
|
||||
@@ -0,0 +1,83 @@
|
||||
/* ===========================================================
|
||||
* docsify sw.js
|
||||
* ===========================================================
|
||||
* Copyright 2016 @huxpro
|
||||
* Licensed under Apache 2.0
|
||||
* Register service worker.
|
||||
* ========================================================== */
|
||||
|
||||
const RUNTIME = 'docsify'
|
||||
const HOSTNAME_WHITELIST = [
|
||||
self.location.hostname,
|
||||
'fonts.gstatic.com',
|
||||
'fonts.googleapis.com',
|
||||
'unpkg.com'
|
||||
]
|
||||
|
||||
// The Util Function to hack URLs of intercepted requests
|
||||
const getFixedUrl = (req) => {
|
||||
var now = Date.now()
|
||||
var url = new URL(req.url)
|
||||
|
||||
// 1. fixed http URL
|
||||
// Just keep syncing with location.protocol
|
||||
// fetch(httpURL) belongs to active mixed content.
|
||||
// And fetch(httpRequest) is not supported yet.
|
||||
url.protocol = self.location.protocol
|
||||
|
||||
// 2. add query for caching-busting.
|
||||
// Github Pages served with Cache-Control: max-age=600
|
||||
// max-age on mutable content is error-prone, with SW life of bugs can even extend.
|
||||
// Until cache mode of Fetch API landed, we have to workaround cache-busting with query string.
|
||||
// Cache-Control-Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=453190
|
||||
if (url.hostname === self.location.hostname) {
|
||||
url.search += (url.search ? '&' : '?') + 'cache-bust=' + now
|
||||
}
|
||||
return url.href
|
||||
}
|
||||
|
||||
/**
|
||||
* @Lifecycle Activate
|
||||
* New one activated when old isnt being used.
|
||||
*
|
||||
* waitUntil(): activating ====> activated
|
||||
*/
|
||||
self.addEventListener('activate', event => {
|
||||
event.waitUntil(self.clients.claim())
|
||||
})
|
||||
|
||||
/**
|
||||
* @Functional Fetch
|
||||
* All network requests are being intercepted here.
|
||||
*
|
||||
* void respondWith(Promise<Response> r)
|
||||
*/
|
||||
self.addEventListener('fetch', event => {
|
||||
// Skip some of cross-origin requests, like those for Google Analytics.
|
||||
if (HOSTNAME_WHITELIST.indexOf(new URL(event.request.url).hostname) > -1) {
|
||||
// Stale-while-revalidate
|
||||
// similar to HTTP's stale-while-revalidate: https://www.mnot.net/blog/2007/12/12/stale
|
||||
// Upgrade from Jake's to Surma's: https://gist.github.com/surma/eb441223daaedf880801ad80006389f1
|
||||
const cached = caches.match(event.request)
|
||||
const fixedUrl = getFixedUrl(event.request)
|
||||
const fetched = fetch(fixedUrl, { cache: 'no-store' })
|
||||
const fetchedCopy = fetched.then(resp => resp.clone())
|
||||
|
||||
// Call respondWith() with whatever we get first.
|
||||
// If the fetch fails (e.g disconnected), wait for the cache.
|
||||
// If there’s nothing in cache, wait for the fetch.
|
||||
// If neither yields a response, return offline pages.
|
||||
event.respondWith(
|
||||
Promise.race([fetched.catch(_ => cached), cached])
|
||||
.then(resp => resp || fetched)
|
||||
.catch(_ => { /* eat any errors */ })
|
||||
)
|
||||
|
||||
// Update the cache with the version we fetched (only for ok status)
|
||||
event.waitUntil(
|
||||
Promise.all([fetchedCopy, caches.open(RUNTIME)])
|
||||
.then(([response, cache]) => response.ok && cache.put(event.request, response))
|
||||
.catch(_ => { /* eat any errors */ })
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
# 接口配置
|
||||
|
||||
本项目使用基于 TypeScript 的按功能分割服务模块,位于 `src/services/`,所有服务通过共享的 HTTP 封装 `src/utils/request.ts`(默认导出为 `api` 函数)发起请求。
|
||||
|
||||
为什么采用此模式?
|
||||
- 每个领域(user/admin/menu/dashboard)有独立函数,职责清晰。
|
||||
- 使用 TypeScript 提供输入/输出类型定义,便于维护(参见 `src/types`)。
|
||||
- 请求处理集中化(查询参数、JSON body、鉴权 header、统一响应格式等)在 `src/utils/request.ts`。
|
||||
|
||||
示例(来自 `src/services/user.ts`):
|
||||
|
||||
```ts
|
||||
import type { PagedResponse, User } from '@/types/user';
|
||||
import api from '../utils/request';
|
||||
|
||||
export async function listUsers(
|
||||
params?: Record<string, string | number | boolean>,
|
||||
): Promise<PagedResponse<User>> {
|
||||
return api<PagedResponse<User>>('/users', { method: 'GET', params });
|
||||
}
|
||||
|
||||
export async function createUser(values: Record<string, unknown>): Promise<User> {
|
||||
return api('/user', { method: 'POST', body: values });
|
||||
}
|
||||
```
|
||||
|
||||
使用方式:
|
||||
- 通过 `import { listUsers } from '@/services/user'` 导入命名函数。
|
||||
- `api(path, options)` 返回后端约定格式 `{ success, message, data }` 中的 `data` 字段。
|
||||
|
||||
关于 `src/utils/request.ts`:
|
||||
- 会将 `config.apiPrefix` 与 `path` 拼接;支持 `params`(查询)、`body`(JSON 或 FormData);若存在本地 token 则自动注入 `Authorization`。
|
||||
- 对非成功响应会抛出异常并在界面上显示消息(使用 `antd` 的 `message`)。
|
||||
|
||||
如果你在迁移旧的 API 映射实现,建议按当前结构将功能拆分为小型服务模块并补充类型定义。
|
||||
@@ -0,0 +1,53 @@
|
||||
<p align="center">
|
||||
<a href="http://github.com/zuiidea/antd-admin">
|
||||
<img alt="antd-admin" height="64" src="../_media/logo.svg">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<h1 align="center">AntD Admin</h1>
|
||||
|
||||
<div align="center">
|
||||
|
||||
基于 Ant Design 6、Umi 4 与 TypeScript 的企业级前端起手模版。
|
||||
|
||||
[](https://github.com/ant-design/ant-design)
|
||||
[](https://github.com/umijs/umi)
|
||||
|
||||
</div>
|
||||
|
||||
- 文档源文件位于 `docs/` 目录。
|
||||
|
||||
## 快速开始
|
||||
|
||||
本仓库示例与 CI 使用 `pnpm`,你也可以使用 `npm` 或 `yarn`,但推荐 `pnpm`。
|
||||
|
||||
```bash
|
||||
# 克隆
|
||||
git clone https://github.com/zuiidea/antd-admin.git
|
||||
cd antd-admin
|
||||
|
||||
# 安装依赖
|
||||
pnpm install
|
||||
|
||||
# 启动开发(含本地 mock)
|
||||
npm run dev
|
||||
|
||||
# 构建
|
||||
npm run build
|
||||
|
||||
# lint 与格式化
|
||||
npm run lint
|
||||
npm run format
|
||||
```
|
||||
|
||||
说明:
|
||||
|
||||
- 本地 mock 实现在 `mock/index.js`,便于在无后端时开发。
|
||||
- CI 工作流位于 `.github/workflows/ci.yml`(使用 pnpm、lint、build)。
|
||||
- 若需对接真实后端,请修改 `src/services` 下的 API。
|
||||
|
||||
更多详细文档请查看 `docs/` 目录下的其他页面。
|
||||
|
||||
## 参与贡献
|
||||
|
||||
欢迎提交 Issue 或 PR 改进项目文档或代码。
|
||||
@@ -0,0 +1,11 @@
|
||||
- 入门
|
||||
- [快速上手](zh-cn/getting-started.md)
|
||||
- 定制化
|
||||
- [配置项](zh-cn/configuration.md)
|
||||
- [接口配置](zh-cn/API-configuration.md)
|
||||
- [国际化](zh-cn/i18n.md)
|
||||
- [布局](zh-cn/layout.md)
|
||||
- [http 请求](zh-cn/request.md)
|
||||
- 指南
|
||||
- [部署](zh-cn/deploy.md)
|
||||
- [更新日志](zh-cn/change-log.md)
|
||||
@@ -0,0 +1,52 @@
|
||||
## 5.0.0
|
||||
|
||||
#### 优化
|
||||
|
||||
- 尽量使用修饰器,简化代码编写,提高代码可读性。
|
||||
|
||||
- API 配置化,简化获取数据方式。
|
||||
|
||||
- `utils` 内文件拆分,各司其职。
|
||||
|
||||
- 简化`utils/request`文件,不做特殊处理。
|
||||
|
||||
#### 规范
|
||||
|
||||
- 函数添加描述、参数、返回值等注释,含糊不清的代码增加注释,规范参考 [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html#appendices-jsdoc-tag-reference)。
|
||||
|
||||
- 语义化版本号,规范参加 [语义化版本 2.0.0](https://semver.org/lang/zh-CN/)。
|
||||
|
||||
- 静态代码检查,统一代码风格,代码提交前将会使用 `prettier`、`stylelint`、`eslint` 规范代码。
|
||||
|
||||
- Git 提交信息规范化,[git-commit-emoji-cn](https://github.com/liuchengxu/git-commit-emoji-cn)。
|
||||
|
||||
- 基于 `Umi` 的约定式路由,无需再写路由配置文件。
|
||||
|
||||
- 使用 `React 16` 新特性,如 `Fragment`、`Context`、 `PureComponent`等。
|
||||
|
||||
#### 功能
|
||||
|
||||
- 支持国际化,源码中抽离翻译字段,按需加载语言包,自动在线翻译。
|
||||
|
||||
- 支持按需引入 `lodash` 函数。
|
||||
|
||||
- 支持多布局,可根据规则规定哪些路由使用哪种布局。
|
||||
|
||||
- 支持 Antd Admin 在 Travis 上自动编译和部署。
|
||||
|
||||
- 使用 `Docsify` 生成文档网站。
|
||||
|
||||
|
||||
#### 样式
|
||||
|
||||
- 新增 Antd Admin 独立 Logo。
|
||||
|
||||
- 重写整体布局组件,优化菜单、面包屑导航自动高亮,菜单自动展开等逻辑。
|
||||
|
||||
- 移动端菜单更改为抽屉式。
|
||||
|
||||
#### 其他
|
||||
|
||||
- 废弃 `IconFont`、 `Search`、`DataTable`等组件,因为在 `Antd` 中有很好的支持和可替代的。
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# 配置项
|
||||
|
||||
你可以在 `/src/utils/config.js` 里做一些自定义配置:
|
||||
|
||||
## siteName
|
||||
|
||||
- 类型: `String`
|
||||
|
||||
配置站点名称,应用到登录框,侧边栏顶部的标题文字显示。
|
||||
|
||||
## copyright
|
||||
|
||||
- 类型: `String`
|
||||
|
||||
配置版权声明,应用到登录页、`Primay`布局底部。
|
||||
|
||||
## logoPath
|
||||
|
||||
- 类型: `String`
|
||||
|
||||
配置站点 Logo,应用到登录框,侧边栏顶部的 Logo 显示。
|
||||
|
||||
## apiPrefix
|
||||
|
||||
- 类型: `String`
|
||||
|
||||
配置项目中接口的前缀,接口相关文档可查看 [接口配置](API-configuration.md)
|
||||
|
||||
## fixedHeader
|
||||
|
||||
- 类型: `String`
|
||||
|
||||
在`Primary`布局下,页面滚动时是否固定顶部。
|
||||
@@ -0,0 +1,114 @@
|
||||
# 部署
|
||||
|
||||
完成开发并且在开发环境验证之后,就需要部署给我们的用户了。
|
||||
|
||||

|
||||
|
||||
## 构建
|
||||
|
||||
先执行下面的命令,
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
几秒后,输出应该如下:
|
||||
|
||||
```bash
|
||||
> antd-admin@5.0.0-beta build /Users/zuiidea/web/antd-admin
|
||||
> umi build
|
||||
|
||||
[21:13:17] webpack compiled in 43s 868ms
|
||||
DONE Compiled successfully in 43877ms 21:13:17
|
||||
|
||||
File sizes after gzip:
|
||||
|
||||
1.3 MB dist/vendors.async.js
|
||||
308.21 KB dist/umi.js
|
||||
45.49 KB dist/vendors.chunk.css
|
||||
36.08 KB dist/p__chart__highCharts__index.async.js
|
||||
33.53 KB dist/p__user__index.async.js
|
||||
22.36 KB dist/p__chart__ECharts__index.async.js
|
||||
4.21 KB dist/p__dashboard__index.async.js
|
||||
4.06 KB dist/umi.css
|
||||
...
|
||||
```
|
||||
|
||||
`build` 命令会打包所有的资源,包含 JavaScript, CSS, web fonts, images, html 等。你可以在 `dist/` 目录下找到这些文件。
|
||||
|
||||
> 如果有使用 HashHistory 、 部署 html 到非根目录、静态化等需求,请查看[Umi 部署](https://umijs.org/zh/guide/deploy.html)。
|
||||
|
||||
## 本地验证
|
||||
|
||||
|
||||
发布之前,可以通过 `serve` 做本地验证,
|
||||
|
||||
```
|
||||
$ yarn global add serve
|
||||
$ serve ./dist
|
||||
|
||||
Serving!
|
||||
|
||||
- Local: http://localhost:5000
|
||||
- On Your Network: http://{Your IP}:5000
|
||||
|
||||
Copied local address to clipboard!
|
||||
|
||||
```
|
||||
|
||||
访问 [http://localhost:5000](http://localhost:5000),正常情况下法应该是和 `npm start` 一致的(接口可能无法获取到正确数据)。
|
||||
|
||||
|
||||
## 部署
|
||||
|
||||
接下来,我们可以把静态文件上传到服务器,如果使用 Nginx 作为 Web server,你可以在 `ngnix.conf` 中这样配置:
|
||||
|
||||
```
|
||||
server
|
||||
{
|
||||
listen 80;
|
||||
# 指定可访问的域名
|
||||
server_name antd-admin.zuiidea.com;
|
||||
# 编译后的文件存放的目录
|
||||
root /home/www/antd-admin/dist;
|
||||
|
||||
# 代理服务端接口,避免跨域
|
||||
location /api {
|
||||
proxy_pass http://localhost:7000/api;
|
||||
}
|
||||
|
||||
# 因为前端使用了BrowserHistory,所以将路由 fallback 到 index.html
|
||||
location / {
|
||||
index index.html;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
重启 Web server,访问 [http://antd-admin.zuiidea.com](http://antd-admin.zuiidea.com) ,你将看到正确的页面。
|
||||
|
||||
```bash
|
||||
nginx -s reload
|
||||
```
|
||||
|
||||
类似的,如果你使用 Caddy 作为 Web server,你可以在 `Caddyfile` 中这样配置:
|
||||
|
||||
```
|
||||
antd-admin.zuiidea.com {
|
||||
gzip
|
||||
root /home/www/antd-admin/dist
|
||||
proxy /api http://localhost:7000
|
||||
|
||||
rewrite {
|
||||
if {path} not_match ^/api
|
||||
to {path} {path}/ /
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
antd-admin.zuiidea.com/public {
|
||||
gzip
|
||||
root /home/www/antd-admin/dist/static/public
|
||||
}
|
||||
|
||||
```
|
||||
@@ -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
|
||||
@@ -0,0 +1,69 @@
|
||||
# 快速上手
|
||||
|
||||
> 在开始之前,推荐先学习 [React](http://facebook.github.io/react/) 、 [ES2015+](http://es6.ruanyifeng.com/) 、 [Antd Design](https://ant.design/docs/react/introduce-cn) , 了解 [UmiJS](https://umijs.org/) 、[Dva](http://github.com/dvajs/dva) ,并正确安装和配置了 [Node.js](https://nodejs.org/) v8 或以上 、[Git](https://git-scm.com/)。提前了解和学习这些知识会非常有帮助。
|
||||
|
||||
## 安装
|
||||
|
||||
```bash
|
||||
git clone https://github.com/zuiidea/antd-admin.git my-project
|
||||
cd my-project
|
||||
```
|
||||
|
||||
1. 克隆项目并安装依赖(推荐使用 `pnpm`)。
|
||||
|
||||
```bash
|
||||
git clone https://github.com/zuiidea/antd-admin.git my-project
|
||||
cd my-project
|
||||
pnpm install
|
||||
```
|
||||
|
||||
或使用其它包管理器:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
# 或
|
||||
yarn install
|
||||
```
|
||||
|
||||
2. 启动开发模式:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
3. 启动完成后在浏览器打开项目(查看开发服务器输出以获取实际 URL/端口)。
|
||||
│ │ ├── index.js # 工具函数
|
||||
│ │ ├── request.js # 异步请求函数(axios)
|
||||
│ │ └── theme.js # 项目需要在js中使用到样式变量
|
||||
├── .editorconfig # 编辑器配置
|
||||
├── .env # 环境变量
|
||||
├── .eslintrc # ESlint配置
|
||||
├── .gitignore # Git忽略文件配置
|
||||
├── .prettierignore # Prettier忽略文件配置
|
||||
├── .prettierrc # Prettier配置
|
||||
├── .stylelintrc.json # Stylelint配置
|
||||
├── .travis.yml # Travis配置
|
||||
└── .umirc.js # Umi配置
|
||||
└── package.json # 项目信息
|
||||
```
|
||||
|
||||
## 本地开发
|
||||
|
||||
项目推荐使用 `pnpm` 进行依赖管理:
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
也可以使用 `npm` 或 `yarn`:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
# 或
|
||||
yarn install
|
||||
# 然后使用对应的启动命令,例如 `npm run dev` 或 `yarn dev`(若 package.json 中配置了),
|
||||
# 本仓库默认开发脚本为 `npm run dev`。
|
||||
```
|
||||
|
||||
启动后在浏览器打开项目(查看开发服务器输出以获取实际 URL/端口)。
|
||||
@@ -0,0 +1,123 @@
|
||||
# 国际化(i18n)使用说明
|
||||
|
||||
本项目通过 Umi 的 `plugin-locale`(基于 `react-intl`)管理多语言,翻译资源位于 `src/locales`(例如 `en-US.json`、`zh-CN.json`)。下面说明如何:新增语言、增加翻译条目、切换语言与关闭多语言。示例以新增日语 `ja-JP` 为例。
|
||||
|
||||
## 1. 新增一种语言(长期支持)
|
||||
|
||||
1. 在 `src/locales/` 下创建新的翻译文件,文件名为语言标识,例如:`src/locales/ja-JP.json`。
|
||||
|
||||
2. 文件内容为 JSON 格式的翻译对象(可嵌套):
|
||||
|
||||
```json
|
||||
{
|
||||
"welcome": "ようこそ",
|
||||
"login": {
|
||||
"username": "ユーザー名",
|
||||
"password": "パスワード",
|
||||
"submit": "ログイン"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. 若希望 Ant Design 组件也使用对应的本地化(日期/组件文案),在 `src/app.tsx` 的 `pick` 函数中添加对应的 AntD locale 引入与映射,例如:
|
||||
|
||||
```ts
|
||||
import jaJP from 'antd/locale/ja_JP';
|
||||
// ...
|
||||
if (l === 'ja-JP') return jaJP;
|
||||
```
|
||||
|
||||
4. 在语言选择列表(例如 `src/components/TopbarControls.tsx` 的 `localeMenuItems`)中加入新语言项:
|
||||
|
||||
```ts
|
||||
{ key: 'ja-JP', label: '日本語' }
|
||||
```
|
||||
|
||||
5. 重启开发服务器:
|
||||
|
||||
```bash
|
||||
pnpm run dev
|
||||
```
|
||||
|
||||
Umi 会在构建时将 `src/locales` 下的文件编入 `localeInfo`,页面即可使用新语言。
|
||||
|
||||
提示:如不想重启或想动态注册翻译,可使用运行时 API `addLocale(name, messages, extraLocales)`(见下一节)。
|
||||
|
||||
## 2. 增加一条多语言文本(翻译条目)
|
||||
|
||||
1. 在所有语言的 JSON 文件中添加相同的 id(推荐同时维护 `en-US.json` 与 `zh-CN.json`,新语言也应添加):
|
||||
|
||||
`src/locales/en-US.json`
|
||||
|
||||
```json
|
||||
"my.feature.greeting": "Hello from feature"
|
||||
```
|
||||
|
||||
`src/locales/zh-CN.json`
|
||||
|
||||
```json
|
||||
"my.feature.greeting": "来自功能的问候"
|
||||
```
|
||||
|
||||
2. 在组件中使用 `useIntl()` 获取 `intl`,并调用 `formatMessage`:
|
||||
|
||||
```ts
|
||||
import { useIntl } from 'umi';
|
||||
const intl = useIntl();
|
||||
const text = intl.formatMessage({ id: 'my.feature.greeting', defaultMessage: 'Hello' });
|
||||
```
|
||||
|
||||
建议使用 `useIntl()`(或 `injectIntl`)以保证语言切换时组件可自动刷新并显示新文本。
|
||||
|
||||
## 3. 运行时切换或注册语言
|
||||
|
||||
- 切换语言(会写入 `localStorage` 并触发刷新或事件):
|
||||
|
||||
```ts
|
||||
import { setLocale } from 'umi';
|
||||
// 切换并刷新页面
|
||||
setLocale('ja-JP', true);
|
||||
// 切换但不刷新(触发事件更新)
|
||||
setLocale('zh-CN', false);
|
||||
```
|
||||
|
||||
- 运行时注册(无需重启):
|
||||
|
||||
```ts
|
||||
import { addLocale, setLocale } from 'umi';
|
||||
import jaMessages from '@/locales/ja-JP.json';
|
||||
import jaAntd from 'antd/locale/ja_JP';
|
||||
|
||||
addLocale('ja-JP', jaMessages, { antd: jaAntd, momentLocale: 'ja' });
|
||||
setLocale('ja-JP', false);
|
||||
```
|
||||
|
||||
`addLocale` 会把翻译合并到内部 `localeInfo`,并可同时提供 AntD 与(可选的)moment 本地化配置。
|
||||
|
||||
## 4. 关闭多语言(禁用 i18n)
|
||||
|
||||
若想永久关闭多语言功能:
|
||||
|
||||
1. 在 `src/app.tsx` 的 `LocaleWrapper` 中,直接返回固定的 AntD locale(忽略 `localStorage` 中的 `umi_locale`):
|
||||
|
||||
```ts
|
||||
const pick = (l: string | null) => {
|
||||
return zhCN; // 强制使用中文
|
||||
};
|
||||
```
|
||||
|
||||
2. 移除或隐藏语言切换控件(例如删除 `src/components/TopbarControls.tsx` 中的语言菜单项或 Dropdown)。
|
||||
|
||||
3. 可选:删除 `src/locales` 中其它语言文件,仅保留目标语言文件以减少构建体积。
|
||||
|
||||
如果只是临时禁止用户切换,建议仅执行第 2 步(隐藏切换),以便未来快速恢复多语言支持。
|
||||
|
||||
## 5. 调试与常见问题
|
||||
|
||||
- 新增语言后无显示:确认已重启 dev server(或使用 `addLocale` 动态注册),并在 `app.tsx` 中为该语言提供 AntD locale。
|
||||
- 翻译未生效或缺失:检查 `src/locales/*.json` 是否包含对应 id,且 `formatMessage` 中的 id 拼写正确。
|
||||
- 想自动抽取翻译 id:仓库未内置抽取脚本,建议按需集成 `lingui`、`babel-plugin-react-intl` 或其他工具并在 `package.json` 中添加相应脚本。
|
||||
|
||||
如果你需要,我可以:
|
||||
- 为你创建一个 `src/locales/ja-JP.json` 的初始翻译并更新 `TopbarControls` 与 `app.tsx` 映射;或
|
||||
- 添加一个示例组件,演示如何在运行时通过 `addLocale` 注册新语言。请告诉我你更希望我执行哪项。
|
||||
@@ -0,0 +1,60 @@
|
||||
# 布局
|
||||
|
||||
## 新增布局
|
||||
|
||||
以新增名为 `secondary` 的布局为例,使以 `secondary` 开头的路由都使用该布局。
|
||||
|
||||
1. 在 `src/utils/config.js` 新增相关配置,参数详细请查看 [layouts](/zh-cn/configuration?id=layouts)。
|
||||
|
||||
```javascript
|
||||
layouts: [
|
||||
{
|
||||
name: 'primary',
|
||||
include: [/.*/],
|
||||
exclude: [/(\/(en|zh))*\/login/, /(\/(en|zh))*\/secondary\/(.*)/],
|
||||
},
|
||||
{
|
||||
name: 'secondary',
|
||||
include: [/(\/(en|zh))*\/secondary\/(.*)/],
|
||||
},
|
||||
],
|
||||
```
|
||||
|
||||
2. 在`src/layouts/BaseLayout.js` 文件中新增 `secondary` 布局组件。
|
||||
|
||||
```javascript
|
||||
import SecondaryLayout from './SecondaryLayout'
|
||||
|
||||
const LayoutMap = {
|
||||
primary: PrimaryLayout,
|
||||
public: PublicLayout,
|
||||
secondary: SecondaryLayout,
|
||||
}
|
||||
```
|
||||
|
||||
3. 在`src/layouts/` 目录中新增 `SecondaryLayout.js` 文件。
|
||||
|
||||
```javascript
|
||||
import React from 'react'
|
||||
|
||||
export default ({ children }) => {
|
||||
return (
|
||||
<div>
|
||||
<h1>Secondary</h1>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
4. 在`src/pages/` 目录中新增 `secondary/index.js` 文件。
|
||||
|
||||
```javascript
|
||||
import React from 'react'
|
||||
|
||||
export default ({ children }) => {
|
||||
return <div>Secondary page Content</div>
|
||||
}
|
||||
```
|
||||
|
||||
5. 最后,使用 `npm run dev` 启动开发模式,然后在浏览器中打开该布局页面(查看开发服务器输出以获取实际 URL),例如 `/secondary/`。
|
||||
@@ -0,0 +1,33 @@
|
||||
# HTTP 请求
|
||||
|
||||
本项目使用位于 `src/utils/request.ts` 的轻量封装(基于 `fetch`),默认导出为 `api`。该封装负责:
|
||||
|
||||
- 将 `config.apiPrefix` 与请求 `path` 拼接为最终 URL。
|
||||
- 处理 `params`(查询字符串)与 `body`(JSON 或 FormData)。
|
||||
- 在本地有 token 时自动注入 `Authorization` 头(本项目使用 localStorage 键 `app-auth-token`)。
|
||||
- 统一解析后端返回(后端需遵循 `{ success, message, data }` 约定)并在非成功时抛出错误并显示 UI 提示(使用 `antd` 的 `message`)。
|
||||
|
||||
主要行为说明
|
||||
|
||||
- `api(path, options)` 会把 `config.apiPrefix` 与 `path` 拼接。
|
||||
- 当传入 `options.params` 时,会序列化为查询字符串并追加到 URL。
|
||||
- `options.body` 的处理策略:
|
||||
- 若为 FormData,直接发送(不要手动设置 Content-Type)。
|
||||
- 若为字符串或 Blob,直接发送。
|
||||
- 其余对象会被 `JSON.stringify`,默认设置 `Content-Type: application/json`(除非已在 headers 中指定)。
|
||||
- 若 localStorage 中有 token 且未在 headers 中显式提供 Authorization,将自动设置 `Authorization: Bearer <token>`。
|
||||
- 成功响应返回后端 `data` 字段;响应格式不符合约定或后端返回失败时会抛出异常。
|
||||
|
||||
使用示例(TypeScript):
|
||||
|
||||
```ts
|
||||
import api from '@/utils/request';
|
||||
|
||||
// 带查询参数的 GET
|
||||
const page = await api('/users', { method: 'GET', params: { page: 1, pageSize: 10 } });
|
||||
|
||||
// 发送 JSON 请求体的 POST
|
||||
const created = await api('/user', { method: 'POST', body: { name: 'Alice' } });
|
||||
```
|
||||
|
||||
详细实现请参阅 `src/utils/request.ts`,文档中仅列出使用建议与约定。
|
||||
@@ -0,0 +1,5 @@
|
||||
# 路由
|
||||
|
||||
本项目中采用约定式路由
|
||||
|
||||
参考[umi 路由](https://umijs.org/zh/guide/router.html)
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Config, configUmiAlias, createConfig } from 'umi/test';
|
||||
|
||||
export default async () => {
|
||||
return (
|
||||
(await configUmiAlias({
|
||||
...createConfig({
|
||||
target: 'browser',
|
||||
jsTransformer: 'esbuild',
|
||||
jsTransformerOpts: { jsx: 'automatic' },
|
||||
}),
|
||||
// you can override umi default jest config here
|
||||
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
|
||||
})) as Config.InitialOptions
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
import * as adminSvc from '../../src/services/admin';
|
||||
|
||||
/**
|
||||
* Skill 元数据与封装 — Admin
|
||||
* 目的:为自动化代理或 LLM 提供明确的能力描述与可直接调用的包装函数。
|
||||
*/
|
||||
export const meta = {
|
||||
id: 'admin:manage',
|
||||
name: 'Admin Management',
|
||||
description: '登录/登出、获取当前管理员、管理管理员列表(增删改查)',
|
||||
inputs: {
|
||||
login: { adminname: 'string', password: 'string' },
|
||||
getAdmin: { id: 'string' },
|
||||
createAdmin: { values: 'object' },
|
||||
updateAdmin: { id: 'string', values: 'object' },
|
||||
deleteAdmin: { id: 'string' },
|
||||
deleteAdmins: { ids: 'string[]' },
|
||||
listAdmins: { params: 'object | undefined' },
|
||||
},
|
||||
outputs: 'JSON (see src/types/admin.ts for schema)',
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
async login(payload: { adminname: string; password: string }) {
|
||||
return adminSvc.login(payload);
|
||||
},
|
||||
async logout() {
|
||||
return adminSvc.logout();
|
||||
},
|
||||
async currentAdmin() {
|
||||
return adminSvc.currentAdmin();
|
||||
},
|
||||
async listAdmins(params?: Record<string, string | number | boolean>) {
|
||||
return adminSvc.listAdmins(params as any);
|
||||
},
|
||||
async createAdmin(values: Record<string, unknown>) {
|
||||
return adminSvc.createAdmin(values);
|
||||
},
|
||||
async getAdmin(id: string) {
|
||||
return adminSvc.getAdmin(id);
|
||||
},
|
||||
async updateAdmin(id: string, values: Record<string, unknown>) {
|
||||
return adminSvc.updateAdmin(id, values);
|
||||
},
|
||||
async deleteAdmin(id: string) {
|
||||
return adminSvc.deleteAdmin(id);
|
||||
},
|
||||
async deleteAdmins(ids: string[]) {
|
||||
return adminSvc.deleteAdmins(ids);
|
||||
},
|
||||
};
|
||||
|
||||
export default { meta, actions };
|
||||
@@ -0,0 +1,17 @@
|
||||
import * as dashSvc from '../../src/services/dashboard';
|
||||
|
||||
export const meta = {
|
||||
id: 'dashboard:view',
|
||||
name: 'Dashboard View',
|
||||
description: '获取仪表盘汇总数据',
|
||||
inputs: {},
|
||||
outputs: 'JSON summary data from /dashboard',
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
async getDashboard() {
|
||||
return dashSvc.getDashboard();
|
||||
},
|
||||
};
|
||||
|
||||
export default { meta, actions };
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Skills registry
|
||||
*
|
||||
* 目的:集中导出 llm/skills 下的 skill 模块,便于运行时自动发现或静态引入。
|
||||
* 导出:
|
||||
* - `skills`:按短名映射的 skill 模块集合。
|
||||
* - `listSkills()`:返回所有 skill 的 meta 数组,便于展示或自动选择。
|
||||
* - `getSkillById(id)`:基于 meta.id 查找对应 skill 模块。
|
||||
*/
|
||||
import admin from './admin.skill';
|
||||
import dashboard from './dashboard.skill';
|
||||
import menu from './menu.skill';
|
||||
import user from './user.skill';
|
||||
|
||||
const skills: Record<string, any> = {
|
||||
admin,
|
||||
menu,
|
||||
user,
|
||||
dashboard,
|
||||
};
|
||||
|
||||
export function listSkills() {
|
||||
return Object.values(skills).map((s) => s.meta);
|
||||
}
|
||||
|
||||
export function getSkillById(id: string) {
|
||||
return Object.values(skills).find((s) => s.meta && s.meta.id === id);
|
||||
}
|
||||
|
||||
export { skills };
|
||||
|
||||
export default skills;
|
||||
@@ -0,0 +1,35 @@
|
||||
import * as menuSvc from '../../src/services/menu';
|
||||
|
||||
export const meta = {
|
||||
id: 'menu:manage',
|
||||
name: 'Menu Management',
|
||||
description: '列出、创建、更新、删除与排序菜单项',
|
||||
inputs: {
|
||||
listMenus: {},
|
||||
createMenu: { values: 'MenuFormValues' },
|
||||
updateMenu: { id: 'number | string', values: 'Partial<MenuFormValues>' },
|
||||
deleteMenu: { id: 'number | string' },
|
||||
sortMenus: { order: 'Array<number | string>' },
|
||||
},
|
||||
outputs: 'JSON (see src/types/menu.ts for schema)',
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
async listMenus() {
|
||||
return menuSvc.listMenus();
|
||||
},
|
||||
async createMenu(values: any) {
|
||||
return menuSvc.createMenu(values);
|
||||
},
|
||||
async updateMenu(id: number | string, values: any) {
|
||||
return menuSvc.updateMenu(id, values);
|
||||
},
|
||||
async deleteMenu(id: number | string) {
|
||||
return menuSvc.deleteMenu(id);
|
||||
},
|
||||
async sortMenus(order: Array<number | string>) {
|
||||
return menuSvc.sortMenus(order);
|
||||
},
|
||||
};
|
||||
|
||||
export default { meta, actions };
|
||||
@@ -0,0 +1,39 @@
|
||||
import * as userSvc from '../../src/services/user';
|
||||
|
||||
export const meta = {
|
||||
id: 'user:manage',
|
||||
name: 'User Management',
|
||||
description: '用户列表/分页、创建、获取、更新、删除与批量删除',
|
||||
inputs: {
|
||||
listUsers: { params: 'object | undefined' },
|
||||
createUser: { values: 'object' },
|
||||
getUser: { id: 'string' },
|
||||
updateUser: { id: 'string', values: 'object' },
|
||||
deleteUser: { id: 'string' },
|
||||
deleteUsers: { ids: 'string[]' },
|
||||
},
|
||||
outputs: 'JSON (see src/types/user.ts for schema)',
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
async listUsers(params?: Record<string, string | number | boolean>) {
|
||||
return userSvc.listUsers(params as any);
|
||||
},
|
||||
async createUser(values: Record<string, unknown>) {
|
||||
return userSvc.createUser(values);
|
||||
},
|
||||
async getUser(id: string) {
|
||||
return userSvc.getUser(id);
|
||||
},
|
||||
async updateUser(id: string, values: Record<string, unknown>) {
|
||||
return userSvc.updateUser(id, values);
|
||||
},
|
||||
async deleteUser(id: string) {
|
||||
return userSvc.deleteUser(id);
|
||||
},
|
||||
async deleteUsers(ids: string[]) {
|
||||
return userSvc.deleteUsers(ids);
|
||||
},
|
||||
};
|
||||
|
||||
export default { meta, actions };
|
||||
@@ -0,0 +1,36 @@
|
||||
项目:antd-admin_next
|
||||
|
||||
目标:将仓库中的关键信息写成对大模型(LLM)友好的简短说明,便于自动化理解、代码导航和提示生成。
|
||||
|
||||
概览:
|
||||
- 技术栈:React + Ant Design + TypeScript(前端单页/多页面结构),源码位于 `src/`。
|
||||
- 路由/页面:页面文件放在 `src/pages/` 目录;布局在 `src/layouts/`;组件在 `src/components/`。
|
||||
- 重要工具:`src/utils/request.ts` 为 HTTP 请求封装,使用 `fetch`,默认 API 前缀由 `src/utils/config.ts` 提供。
|
||||
|
||||
API 与约定:
|
||||
- 全局 API 前缀:`/api/v1`(见 `src/utils/config.ts`)。
|
||||
- 请求函数 `api(path, options)`:
|
||||
- 自动把 `options.params` 转为查询字符串。
|
||||
- 对对象 body 自动 JSON 序列化并设置 `Content-Type: application/json`(FormData 会被保留)。
|
||||
- 当响应状态为 `204` 返回空对象;当 `res.ok` 为 false 时抛出 Error,错误信息优先使用响应体中的 `message` 字段。
|
||||
|
||||
如何使用(对模型说明):
|
||||
- 若要调用后端资源,请调用 `api('/resource', { method: 'GET' | 'POST', params, body })`。
|
||||
- 成功响应应为 JSON,失败会抛出 Error。处理调用时应捕获异常并展示 `error.message`。
|
||||
|
||||
本文件用途:
|
||||
- 作为 LLM 的快速上下文:当模型在代码中自动生成、补全或审阅代码时,可引用此文件以获得仓库结构、关键约定和请求行为的摘要。
|
||||
|
||||
快速运行(可能依赖 package manager):
|
||||
- 常用:`npm run dev` 或 `pnpm dev` 启动开发服务器。
|
||||
|
||||
如需更详细的接口契约或后端响应示例,请查看对应的 `src/services/` 目录下的 API 封装文件。
|
||||
|
||||
Agent Skills:
|
||||
- 为方便自动化代理(Agent/LLM)调用,项目在 `llm/skills/` 下提供了若干能力描述与包装:
|
||||
- `llm/skills/admin.skill.ts`:管理员管理相关操作(login、logout、list/create/update/delete)
|
||||
- `llm/skills/menu.skill.ts`:菜单管理操作(list/create/update/delete/sort)
|
||||
- `llm/skills/user.skill.ts`:用户管理操作(list/create/get/update/delete/batch)
|
||||
- `llm/skills/dashboard.skill.ts`:获取仪表盘数据的读取操作
|
||||
|
||||
这些 skill 文件导出 `meta`(能力描述)和 `actions`(可直接调用的异步函数),便于代理在运行时发现并调用对应后端逻辑。
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "Antd-Admin",
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"background_color": "#fff",
|
||||
"description": "A front-end solution for enterprise applications built upon Ant Design and UmiJS",
|
||||
"icons": [{
|
||||
"src": "logo/logo@96.png",
|
||||
"sizes": "72x72"
|
||||
},
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
// Consolidated mock server for development (simplified)
|
||||
const Mock = require('mockjs');
|
||||
const qs = require('qs');
|
||||
|
||||
const ApiPrefix = '/api/v1';
|
||||
|
||||
// simple in-memory admin users with richer mock fields
|
||||
const adminList = [
|
||||
{
|
||||
id: 1,
|
||||
username: 'admin',
|
||||
password: 'admin',
|
||||
real_name: '李四',
|
||||
nick_name: '超级管理员',
|
||||
mobile: '13800000000',
|
||||
avatar: Mock.Random.image('100x100', '#4096ff', '#fff', 'png', 'A'),
|
||||
role: '管理员',
|
||||
department: '运维部',
|
||||
permissions: '*',
|
||||
status: 1,
|
||||
remark: '拥有所有权限',
|
||||
lastLogin: Mock.Random.datetime(),
|
||||
createdBy: 'system',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
username: 'guest',
|
||||
password: 'guest',
|
||||
real_name: '访客',
|
||||
nick_name: '访客',
|
||||
mobile: '15100000000',
|
||||
avatar: Mock.Random.image('100x100', '#ff7f50', '#fff', 'png', 'G'),
|
||||
role: '访客',
|
||||
department: '外部',
|
||||
permissions: '/dashboard,/users,/users/list',
|
||||
status: 1,
|
||||
remark: '',
|
||||
lastLogin: Mock.Random.datetime(),
|
||||
createdBy: 'system',
|
||||
},
|
||||
];
|
||||
|
||||
// users list
|
||||
let users = Mock.mock({
|
||||
'data|20-30': [
|
||||
{
|
||||
id: '@id',
|
||||
name: '@name',
|
||||
nickName: '@last',
|
||||
phone: /^1[34578]\d{9}$/,
|
||||
'age|18-60': 1,
|
||||
address: '@county(true)',
|
||||
isMale: '@boolean',
|
||||
email: '@email',
|
||||
createTime: '@datetime',
|
||||
avatar() {
|
||||
return Mock.Random.image(
|
||||
'100x100',
|
||||
'#4096ff',
|
||||
'#757575',
|
||||
'png',
|
||||
this.nickName ? this.nickName.substr(0, 1) : '',
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
}).data;
|
||||
|
||||
// routes database (source of truth)
|
||||
const ROUTES_DB = [
|
||||
{ id: '1', name: '仪表盘', icon: 'home', route: '/dashboard' },
|
||||
{ id: '2', name: 'Ai会话', icon: 'robot', route: '/ai/chat' },
|
||||
{ id: '3', name: '用户管理', icon: 'user', route: '/users' },
|
||||
{
|
||||
id: '4',
|
||||
breadcrumbParentId: '3',
|
||||
name: '用户列表',
|
||||
icon: 'team',
|
||||
route: '/users/list',
|
||||
},
|
||||
{
|
||||
id: '5',
|
||||
menuParentId: '-1',
|
||||
breadcrumbParentId: '4',
|
||||
name: '用户详情',
|
||||
route: '/users/:id',
|
||||
},
|
||||
{ id: '6', name: '系统设置', icon: 'settings', route: '/sys' },
|
||||
{
|
||||
id: '7',
|
||||
breadcrumbParentId: '6',
|
||||
name: '成员列表',
|
||||
icon: 'team',
|
||||
route: '/admin/list',
|
||||
},
|
||||
{
|
||||
id: '8',
|
||||
menuParentId: '-1',
|
||||
breadcrumbParentId: '6',
|
||||
name: '成员详情',
|
||||
icon: 'user',
|
||||
route: '/admin/:id',
|
||||
},
|
||||
{
|
||||
id: '9',
|
||||
breadcrumbParentId: '6',
|
||||
name: '菜单设置',
|
||||
icon: 'tool',
|
||||
route: '/sys/menu',
|
||||
},
|
||||
{ id: '10', name: '项目介绍', icon: 'info-c', route: '/guide' },
|
||||
];
|
||||
|
||||
// convert routes DB into menus tree used by UI
|
||||
function buildMenusFromRoutes(db) {
|
||||
const items = db
|
||||
// exclude routes that should not appear in menu (explicit menuParentId === '-1')
|
||||
.filter((r) => !(r.menuParentId === '-1' || r.menuParentId === -1))
|
||||
.map((r, idx) => {
|
||||
const id = Number(r.id) || r.id;
|
||||
// prefer explicit menuParentId, fall back to breadcrumbParentId
|
||||
const parentIdRaw = r.breadcrumbParentId ?? null;
|
||||
const parentId =
|
||||
parentIdRaw === undefined || parentIdRaw === null
|
||||
? null
|
||||
: parentIdRaw === '-1'
|
||||
? null
|
||||
: Number(parentIdRaw);
|
||||
return {
|
||||
id,
|
||||
title: r.name,
|
||||
icon: r.icon,
|
||||
route: r.route,
|
||||
parentId,
|
||||
status: 1,
|
||||
sort: idx + 1,
|
||||
children: [],
|
||||
};
|
||||
});
|
||||
|
||||
const map = new Map();
|
||||
items.forEach((it) => map.set(it.id, it));
|
||||
const roots = [];
|
||||
items.forEach((it) => {
|
||||
if (it.parentId == null || !map.has(it.parentId)) {
|
||||
roots.push(it);
|
||||
} else {
|
||||
map.get(it.parentId).children.push(it);
|
||||
}
|
||||
});
|
||||
|
||||
// sort recursively by sort
|
||||
const sortRec = (arr) => {
|
||||
arr.sort((a, b) => (a.sort || 0) - (b.sort || 0));
|
||||
arr.forEach((c) => {
|
||||
if (c.children && c.children.length) sortRec(c.children);
|
||||
});
|
||||
};
|
||||
sortRec(roots);
|
||||
return roots;
|
||||
}
|
||||
|
||||
const menus = buildMenusFromRoutes(ROUTES_DB);
|
||||
|
||||
// dashboard
|
||||
const Dashboard = Mock.mock({
|
||||
'sales|6': [
|
||||
{
|
||||
'name|+1': 2008,
|
||||
'Clothes|200-500': 1,
|
||||
'Food|180-400': 1,
|
||||
'Electronics|300-550': 1,
|
||||
},
|
||||
],
|
||||
cpu: { 'usage|50-600': 1, space: 825, 'cpu|40-90': 1 },
|
||||
browser: [
|
||||
{ name: 'Google Chrome', percent: 43.3, status: 1 },
|
||||
{ name: 'Mozilla Firefox', percent: 33.4, status: 2 },
|
||||
],
|
||||
});
|
||||
|
||||
// simple helper to read cookie token
|
||||
function parseTokenFromCookie(headers) {
|
||||
const cookie = headers.cookie || '';
|
||||
const cookies = qs.parse(cookie.replace(/\s/g, ''), { delimiter: ';' });
|
||||
if (!cookies.token) return null;
|
||||
try {
|
||||
return JSON.parse(cookies.token);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
[`GET ${ApiPrefix}/dashboard`](req, res) {
|
||||
res.json({ success: true, data: Dashboard });
|
||||
},
|
||||
|
||||
[`GET ${ApiPrefix}/menus`](req, res) {
|
||||
res.json({ success: true, data: menus });
|
||||
},
|
||||
|
||||
[`POST ${ApiPrefix}/admin/login`](req, res) {
|
||||
const { username, password } = req.body || {};
|
||||
const admin = adminList.find(
|
||||
(u) => u.username === username && u.password === password,
|
||||
);
|
||||
|
||||
if (admin) {
|
||||
const now = new Date();
|
||||
now.setDate(now.getDate() + 1);
|
||||
res.cookie(
|
||||
'token',
|
||||
JSON.stringify({ id: admin.id, deadline: now.getTime() }),
|
||||
{ maxAge: 24 * 3600 * 1000, httpOnly: true },
|
||||
);
|
||||
res.json({ success: true, message: 'Ok', data: null });
|
||||
} else {
|
||||
res
|
||||
.status(400)
|
||||
.json({ success: false, message: 'Invalid credentials', data: null });
|
||||
}
|
||||
},
|
||||
|
||||
[`GET ${ApiPrefix}/admin/logout`](req, res) {
|
||||
res.clearCookie('token');
|
||||
res.json({ success: true, data: null });
|
||||
},
|
||||
|
||||
[`GET ${ApiPrefix}/admin`](req, res) {
|
||||
const token = parseTokenFromCookie(req.headers);
|
||||
const response = {};
|
||||
let admin = {};
|
||||
if (!token) {
|
||||
res
|
||||
.status(200)
|
||||
.json({ success: false, message: 'Not Login', data: null });
|
||||
return;
|
||||
}
|
||||
response.success = token.deadline > new Date().getTime();
|
||||
if (response.success) {
|
||||
const adminItem = adminList.find((u) => u.id === token.id);
|
||||
if (adminItem) {
|
||||
const { password, ...other } = adminItem;
|
||||
admin = other;
|
||||
}
|
||||
}
|
||||
res.json({ success: response.success, data: admin || null });
|
||||
},
|
||||
|
||||
[`GET ${ApiPrefix}/users`](req, res) {
|
||||
const { query } = req;
|
||||
let { pageSize, page, ...other } = query || {};
|
||||
pageSize = Number(pageSize) || 10;
|
||||
page = Number(page) || 1;
|
||||
let newData = users.slice();
|
||||
for (const key in other) {
|
||||
if (Object.prototype.hasOwnProperty.call(other, key)) {
|
||||
newData = newData.filter(
|
||||
(item) => String(item[key]).indexOf(String(other[key])) > -1,
|
||||
);
|
||||
}
|
||||
}
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: {
|
||||
data: newData.slice((page - 1) * pageSize, page * pageSize),
|
||||
total: newData.length,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
[`GET ${ApiPrefix}/user/:id`](req, res) {
|
||||
const { id } = req.params || {};
|
||||
let item = users.find((u) => String(u.id) === String(id));
|
||||
// 如果找不到用户,则生成一个带有相同 id 的 mock 用户,避免 404
|
||||
if (!item) {
|
||||
item = Mock.mock({
|
||||
id: String(id),
|
||||
name: '@name',
|
||||
nickName: '@last',
|
||||
phone: /^1[34578]\d{9}$/,
|
||||
'age|18-60': 1,
|
||||
address: '@county(true)',
|
||||
isMale: '@boolean',
|
||||
email: '@email',
|
||||
createTime: '@datetime',
|
||||
avatar() {
|
||||
return Mock.Random.image(
|
||||
'100x100',
|
||||
'#4096ff',
|
||||
'#757575',
|
||||
'png',
|
||||
this.nickName ? this.nickName.substr(0, 1) : '',
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
// enrich with some additional mock fields: phone model and browsing history
|
||||
const enriched = {
|
||||
...item,
|
||||
// ensure lastLogin exists for user detail view (used by UI)
|
||||
lastLogin: item.lastLogin || Mock.Random.datetime(),
|
||||
phoneModel: Mock.Random.pick([
|
||||
'iPhone 13',
|
||||
'iPhone 14 Pro',
|
||||
'Samsung S22',
|
||||
'Huawei P50',
|
||||
'Xiaomi 12',
|
||||
]),
|
||||
browsingHistory: Mock.mock({
|
||||
'data|3-6': [
|
||||
{
|
||||
url: '@url',
|
||||
title: '@title',
|
||||
time: '@datetime',
|
||||
},
|
||||
],
|
||||
}).data,
|
||||
};
|
||||
const { ...other } = enriched;
|
||||
res.status(200).json({ success: true, data: other });
|
||||
},
|
||||
|
||||
[`GET ${ApiPrefix}/routes`](req, res) {
|
||||
res.status(200).json({ success: true, data: ROUTES_DB });
|
||||
},
|
||||
|
||||
// admin accounts CRUD
|
||||
[`GET ${ApiPrefix}/admins`](req, res) {
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: { data: adminList, total: adminList.length },
|
||||
});
|
||||
},
|
||||
|
||||
[`GET ${ApiPrefix}/admin/:id`](req, res) {
|
||||
const { id } = req.params || {};
|
||||
const item = adminList.find((u) => String(u.id) === String(id));
|
||||
if (!item)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ success: false, message: 'Not found', data: null });
|
||||
const { password, ...other } = item;
|
||||
res.status(200).json({ success: true, data: other });
|
||||
},
|
||||
|
||||
[`POST ${ApiPrefix}/admin`](req, res) {
|
||||
const body = req.body || {};
|
||||
const id = adminList.length
|
||||
? Math.max(...adminList.map((u) => u.id)) + 1
|
||||
: 1;
|
||||
|
||||
const next = { id, ...body };
|
||||
adminList.push(next);
|
||||
const { password, ...other } = next;
|
||||
res.status(200).json({ success: true, data: other });
|
||||
},
|
||||
|
||||
[`PATCH ${ApiPrefix}/admin/:id`](req, res) {
|
||||
const { id } = req.params || {};
|
||||
const body = req.body || {};
|
||||
const idx = adminList.findIndex((u) => String(u.id) === String(id));
|
||||
if (idx === -1)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ success: false, message: 'Not found', data: null });
|
||||
|
||||
adminList[idx] = { ...adminList[idx], ...body };
|
||||
const { password, ...other } = adminList[idx];
|
||||
res.status(200).json({ success: true, data: other });
|
||||
},
|
||||
};
|
||||
@@ -1,62 +1,56 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "antd-admin",
|
||||
"version": "4.3.2",
|
||||
"version": "6.0.0",
|
||||
"description": "An admin dashboard application demo built upon Ant Design and UmiJS",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "umi build",
|
||||
"dev": "umi dev",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint --ext .ts,.tsx src",
|
||||
"lint:fix": "eslint --ext .ts,.tsx src --fix",
|
||||
"start": "npm run dev"
|
||||
},
|
||||
"dependencies": {
|
||||
"antd": "^2.11.2",
|
||||
"axios": "^0.16.2",
|
||||
"babel-polyfill": "^6.23.0",
|
||||
"classnames": "^2.2.5",
|
||||
"d3-shape": "^1.2.0",
|
||||
"draftjs-to-markdown": "^0.4.0",
|
||||
"dva": "^1.2.0",
|
||||
"dva-loading": "^0.2.0",
|
||||
"ejs-loader": "^0.3.0",
|
||||
"js-beautify": "^1.6.14",
|
||||
"jsonp": "^0.2.1",
|
||||
"less-vars-to-js": "^1.1.2",
|
||||
"lodash": "^4.17.4",
|
||||
"mockjs": "^1.0.1-beta3",
|
||||
"nprogress": "^0.2.0",
|
||||
"path-to-regexp": "^1.7.0",
|
||||
"prop-types": "^15.5.10",
|
||||
"qs": "^6.5.0",
|
||||
"rc-tween-one": "^1.3.1",
|
||||
"react": "^15.6.1",
|
||||
"react-countup": "^2.1.1",
|
||||
"react-dom": "^15.6.1",
|
||||
"react-draft-wysiwyg": "^1.10.0",
|
||||
"react-helmet": "^5.1.3",
|
||||
"recharts": "^0.22.4"
|
||||
"@ant-design/icons": "^6.1.0",
|
||||
"@ant-design/x": "^2.3.0",
|
||||
"@ant-design/x-sdk": "^2.3.0",
|
||||
"@umijs/plugins": "^4.6.32",
|
||||
"antd": "^6.3.2",
|
||||
"react": "^19.2.4",
|
||||
"react-dom": "^19.2.4",
|
||||
"umi": "^4.6.32",
|
||||
"zustand": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-eslint": "^7.2.3",
|
||||
"babel-plugin-dev-expression": "^0.2.1",
|
||||
"babel-plugin-dva-hmr": "^0.3.2",
|
||||
"babel-plugin-import": "^1.1.1",
|
||||
"babel-plugin-transform-runtime": "^6.9.0",
|
||||
"babel-runtime": "^6.9.2",
|
||||
"copy-webpack-plugin": "^4.0.1",
|
||||
"draftjs-to-html": "^0.7.0",
|
||||
"dva-model-extend": "^0.1.1",
|
||||
"eslint": "^4.1.1",
|
||||
"eslint-config-airbnb": "^15.0.2",
|
||||
"eslint-import-resolver-node": "^0.3.1",
|
||||
"eslint-loader": "^1.9.0",
|
||||
"eslint-plugin-import": "^2.6.1",
|
||||
"eslint-plugin-jsx-a11y": "^6.0.2",
|
||||
"eslint-plugin-react": "^7.1.0",
|
||||
"html-webpack-plugin": "^2.29.0",
|
||||
"html-webpack-template": "^5.6.0",
|
||||
"redbox-react": "^1.2.10",
|
||||
"roadhog": "1.0.0-beta.7"
|
||||
},
|
||||
"pre-commit": ["lint"],
|
||||
"scripts": {
|
||||
"dev": "set BROWSER=none&&set HOST=0.0.0.0&&roadhog server",
|
||||
"lint": "eslint --fix --ext .js src",
|
||||
"build": "roadhog build",
|
||||
"build:dll": "roadhog buildDll",
|
||||
"build:new": "node version && roadhog build"
|
||||
"@testing-library/jest-dom": "^6.1.1",
|
||||
"@testing-library/react": "^14.0.0",
|
||||
"@types/jest": "^29.5.3",
|
||||
"@types/react": "19.2.14",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@typescript-eslint/eslint-plugin": "^6.9.0",
|
||||
"@typescript-eslint/parser": "^6.9.0",
|
||||
"@umijs/test": "^4.6.32",
|
||||
"eslint": "^8.47.0",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-import-resolver-typescript": "^4.4.4",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||
"eslint-plugin-prettier": "^5.1.0",
|
||||
"eslint-plugin-react": "^7.33.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-unused-imports": "^2.0.0",
|
||||
"jest": "^29.6.1",
|
||||
"mockjs": "^1.1.0",
|
||||
"prettier": "^2.8.8",
|
||||
"prettier-plugin-organize-imports": "^3.2.2",
|
||||
"prettier-plugin-packagejson": "^2.4.3",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.9.3",
|
||||
"jest-environment-jsdom": "^29.6.1",
|
||||
"jsdom": "^21.1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 66 KiB |
@@ -0,0 +1,24 @@
|
||||
|
||||
<svg width="169px" height="141px" viewBox="0 0 169 141" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: Sketch 51.3 (57544) - http://www.bohemiancoding.com/sketch -->
|
||||
<desc>Created with Sketch.</desc>
|
||||
<defs>
|
||||
<linearGradient x1="54.0428975%" y1="4.39752391%" x2="54.0428975%" y2="108.456714%" id="linearGradient-1">
|
||||
<stop stop-color="#29CDFF" offset="0%"></stop>
|
||||
<stop stop-color="#148EFF" offset="62.3089445%"></stop>
|
||||
<stop stop-color="#0A60FF" offset="100%"></stop>
|
||||
</linearGradient>
|
||||
<linearGradient x1="50%" y1="14.2201464%" x2="50%" y2="113.263844%" id="linearGradient-2">
|
||||
<stop stop-color="#FA816E" offset="0%"></stop>
|
||||
<stop stop-color="#F74A5C" offset="65.9092442%"></stop>
|
||||
<stop stop-color="#F51D2C" offset="100%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="Group" transform="translate(0.000000, -5.000000)">
|
||||
<rect id="Rectangle" fill="url(#linearGradient-1)" transform="translate(83.718923, 75.312358) rotate(-24.000000) translate(-83.718923, -75.312358) " x="68.7189234" y="0.312357954" width="30" height="150" rx="15"></rect>
|
||||
<rect id="Rectangle" fill="url(#linearGradient-1)" transform="translate(129.009910, 75.580213) rotate(-24.000000) translate(-129.009910, -75.580213) " x="114.00991" y="0.580212739" width="30" height="150" rx="15"></rect>
|
||||
<circle id="Oval" fill="url(#linearGradient-2)" cx="25" cy="120" r="25"></circle>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
|
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,82 @@
|
||||
import { ConfigProvider } from 'antd';
|
||||
import 'antd/dist/reset.css';
|
||||
import enUS from 'antd/locale/en_US';
|
||||
import zhCN from 'antd/locale/zh_CN';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
import AuthGate from './components/AuthGate';
|
||||
|
||||
function LocaleWrapper({ children }: { children: React.ReactElement }) {
|
||||
// read initial locale synchronously so Antd has correct locale on first render
|
||||
const pick = (l: string | null) => {
|
||||
if (l === 'zh-CN') return zhCN;
|
||||
return enUS;
|
||||
};
|
||||
let initial: typeof zhCN | typeof enUS | undefined = undefined;
|
||||
const stored = window.localStorage.getItem('umi_locale') || null;
|
||||
initial = pick(stored);
|
||||
|
||||
const [locale, setLocale] = useState<typeof zhCN | typeof enUS | undefined>(
|
||||
initial,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const read = () => {
|
||||
let l: string | null = null;
|
||||
try {
|
||||
l = window.localStorage.getItem('umi_locale') || null;
|
||||
} catch (e) {
|
||||
l = null;
|
||||
}
|
||||
setLocale(pick(l));
|
||||
};
|
||||
|
||||
const onStorage = (ev: StorageEvent) => {
|
||||
if (ev.key === 'umi_locale') read();
|
||||
};
|
||||
|
||||
const onLocaleChange = (ev: Event) => {
|
||||
// CustomEvent used by TopbarControls with detail = locale string
|
||||
const possible = ev as CustomEvent | Event;
|
||||
if (possible && typeof (possible as CustomEvent).detail !== 'undefined') {
|
||||
const d = (possible as CustomEvent).detail;
|
||||
if (d) setLocale(pick(String(d)));
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('storage', onStorage);
|
||||
window.addEventListener('localechange', onLocaleChange as EventListener);
|
||||
return () => {
|
||||
window.removeEventListener('storage', onStorage);
|
||||
window.removeEventListener(
|
||||
'localechange',
|
||||
onLocaleChange as EventListener,
|
||||
);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return <ConfigProvider locale={locale}>{children}</ConfigProvider>;
|
||||
}
|
||||
|
||||
export function rootContainer(container: React.ReactElement) {
|
||||
return (
|
||||
<LocaleWrapper>
|
||||
<AuthGate>{container}</AuthGate>
|
||||
</LocaleWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
// ensure mobile viewport meta exists (adds meta tag if not present)
|
||||
try {
|
||||
if (typeof window !== 'undefined') {
|
||||
const hasVp = document.querySelector('meta[name="viewport"]');
|
||||
if (!hasVp) {
|
||||
const m = document.createElement('meta');
|
||||
m.name = 'viewport';
|
||||
m.content = 'width=device-width,initial-scale=1,maximum-scale=1';
|
||||
document.head.appendChild(m);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore in non-DOM environments
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { Spin } from 'antd';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { history } from 'umi';
|
||||
|
||||
import useGlobalSync from '@/hooks/useGlobalSync';
|
||||
import useIsMounted from '@/hooks/useIsMounted';
|
||||
import adminService from '../services/admin';
|
||||
|
||||
import useGlobalStore from '../store/useGlobalStore';
|
||||
|
||||
export default function AuthGate({ children }: { children: React.ReactNode }) {
|
||||
const isLoggedIn = useGlobalSync((s) => s.isLoggedIn);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const isMounted = useIsMounted();
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
const admin = (await adminService.currentAdmin()) as
|
||||
| import('@/types/admin').Admin
|
||||
| undefined;
|
||||
if (!isMounted()) return;
|
||||
if (admin) {
|
||||
useGlobalStore.getState().login();
|
||||
useGlobalStore.getState().setCurrentUser(admin);
|
||||
} else {
|
||||
useGlobalStore.getState().logout();
|
||||
}
|
||||
} catch (e) {
|
||||
useGlobalStore.getState().logout();
|
||||
} finally {
|
||||
if (isMounted()) setLoading(false);
|
||||
}
|
||||
})();
|
||||
}, [isMounted]);
|
||||
|
||||
useEffect(() => {
|
||||
const path = history.location.pathname;
|
||||
if (!isLoggedIn && path !== '/login') {
|
||||
history.replace('/login');
|
||||
}
|
||||
if (isLoggedIn && path === '/login') {
|
||||
history.replace('/');
|
||||
}
|
||||
}, [isLoggedIn]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
minHeight: '100vh',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<Spin size="large" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { TweenOneGroup } from 'rc-tween-one'
|
||||
|
||||
const enterAnim = [
|
||||
{
|
||||
opacity: 0,
|
||||
x: 30,
|
||||
backgroundColor: '#fffeee',
|
||||
duration: 0,
|
||||
}, {
|
||||
height: 0,
|
||||
duration: 200,
|
||||
type: 'from',
|
||||
delay: 250,
|
||||
ease: 'easeOutQuad',
|
||||
onComplete: (e) => {
|
||||
e.target.style.height = 'auto'
|
||||
},
|
||||
}, {
|
||||
opacity: 1,
|
||||
x: 0,
|
||||
duration: 250,
|
||||
ease: 'easeOutQuad',
|
||||
}, {
|
||||
delay: 1000,
|
||||
backgroundColor: '#fff',
|
||||
},
|
||||
]
|
||||
|
||||
const leaveAnim = [
|
||||
{
|
||||
duration: 250,
|
||||
x: -30,
|
||||
opacity: 0,
|
||||
}, {
|
||||
height: 0,
|
||||
duration: 200,
|
||||
ease: 'easeOutQuad',
|
||||
},
|
||||
]
|
||||
|
||||
const AnimTableBody = ({ body, page = 1, current }) => {
|
||||
if (current !== +page) {
|
||||
return body
|
||||
}
|
||||
|
||||
return (
|
||||
<TweenOneGroup
|
||||
component="tbody"
|
||||
className={body.props.className}
|
||||
enter={enterAnim}
|
||||
leave={leaveAnim}
|
||||
appear={false}
|
||||
>
|
||||
{body.props.children}
|
||||
</TweenOneGroup>
|
||||
)
|
||||
}
|
||||
|
||||
AnimTableBody.propTypes = {
|
||||
body: PropTypes.element,
|
||||
page: PropTypes.any,
|
||||
current: PropTypes.number.isRequired,
|
||||
}
|
||||
|
||||
export default AnimTableBody
|
||||
@@ -1,112 +0,0 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Table } from 'antd'
|
||||
import { request } from 'utils'
|
||||
import lodash from 'lodash'
|
||||
import './DataTable.less'
|
||||
|
||||
class DataTable extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
const { dataSource, pagination = {
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: total => `共 ${total} 条`,
|
||||
current: 1,
|
||||
total: 100 },
|
||||
} = props
|
||||
this.state = {
|
||||
loading: false,
|
||||
dataSource,
|
||||
fetchData: {},
|
||||
pagination,
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
if (this.props.fetch) {
|
||||
this.fetch()
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps (nextProps) {
|
||||
const staticNextProps = lodash.cloneDeep(nextProps)
|
||||
delete staticNextProps.columns
|
||||
const { columns, ...otherProps } = this.props
|
||||
|
||||
if (!lodash.isEqual(staticNextProps, otherProps)) {
|
||||
this.props = nextProps
|
||||
this.fetch()
|
||||
}
|
||||
}
|
||||
|
||||
handleTableChange = (pagination, filters, sorter) => {
|
||||
const pager = this.state.pagination
|
||||
pager.current = pagination.current
|
||||
this.setState({
|
||||
pagination: pager,
|
||||
fetchData: {
|
||||
results: pagination.pageSize,
|
||||
page: pagination.current,
|
||||
sortField: sorter.field,
|
||||
sortOrder: sorter.order,
|
||||
...filters,
|
||||
},
|
||||
}, () => {
|
||||
this.fetch()
|
||||
})
|
||||
}
|
||||
|
||||
fetch = () => {
|
||||
const { fetch: { url, data, dataKey } } = this.props
|
||||
const { fetchData } = this.state
|
||||
this.setState({ loading: true })
|
||||
this.promise = request({
|
||||
url,
|
||||
data: {
|
||||
...data,
|
||||
...fetchData,
|
||||
},
|
||||
}).then((result) => {
|
||||
if (!this.refs.DataTable) {
|
||||
return
|
||||
}
|
||||
const { pagination } = this.state
|
||||
pagination.total = result.total || pagination.total
|
||||
this.setState({
|
||||
loading: false,
|
||||
dataSource: dataKey ? result[dataKey] : result.data,
|
||||
pagination,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
render () {
|
||||
const { fetch, ...tableProps } = this.props
|
||||
const { loading, dataSource, pagination } = this.state
|
||||
|
||||
return (<Table
|
||||
ref="DataTable"
|
||||
bordered
|
||||
loading={loading}
|
||||
onChange={this.handleTableChange}
|
||||
{...tableProps}
|
||||
pagination={pagination}
|
||||
dataSource={dataSource}
|
||||
/>)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DataTable.propTypes = {
|
||||
fetch: PropTypes.object,
|
||||
rowKey: PropTypes.string,
|
||||
pagination: React.PropTypes.oneOfType([
|
||||
React.PropTypes.bool,
|
||||
React.PropTypes.object,
|
||||
]),
|
||||
columns: PropTypes.array,
|
||||
dataSource: PropTypes.array,
|
||||
}
|
||||
|
||||
export default DataTable
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "DataTable",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./DataTable.js"
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import DropOption from './DropOption';
|
||||
|
||||
// Mock antd Dropdown to expose menu items for testing
|
||||
jest.mock('antd', () => {
|
||||
return {
|
||||
Dropdown: ({ menu, children }: any) =>
|
||||
React.createElement(
|
||||
'div',
|
||||
null,
|
||||
React.createElement('div', { 'data-testid': 'trigger' }, children),
|
||||
React.createElement(
|
||||
'div',
|
||||
{ 'data-testid': 'menu' },
|
||||
menu?.items?.map((it: any) =>
|
||||
React.createElement(
|
||||
'button',
|
||||
{
|
||||
key: it.key,
|
||||
'data-key': it.key,
|
||||
onClick: () => menu.onClick?.({ key: it.key }),
|
||||
},
|
||||
typeof it.label === 'string'
|
||||
? it.label
|
||||
: React.createElement('span', null, it.label),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('@ant-design/icons', () => ({
|
||||
BarsOutlined: () => React.createElement('span', null, 'Bars'),
|
||||
DownOutlined: () => React.createElement('span', null, 'Down'),
|
||||
}));
|
||||
|
||||
test('renders default trigger when no children provided', () => {
|
||||
render(<DropOption menuOptions={[]} />);
|
||||
const trigger = screen.getByTestId('trigger');
|
||||
// default trigger in component is an <a>
|
||||
expect(trigger.querySelector('a')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('wraps plain text children in a span', () => {
|
||||
render(<DropOption menuOptions={[]}>PlainChild</DropOption>);
|
||||
const trigger = screen.getByTestId('trigger');
|
||||
expect(screen.getByText('PlainChild')).toBeTruthy();
|
||||
expect(trigger.firstElementChild?.tagName.toLowerCase()).toBe('span');
|
||||
});
|
||||
|
||||
test('clicking menu item calls onMenuClick with key', () => {
|
||||
const onMenuClick = jest.fn();
|
||||
render(
|
||||
<DropOption
|
||||
menuOptions={[{ key: 'one', label: 'One' }]}
|
||||
onMenuClick={onMenuClick}
|
||||
/>,
|
||||
);
|
||||
const item = screen.getByText('One');
|
||||
fireEvent.click(item);
|
||||
expect(onMenuClick).toHaveBeenCalledWith('one');
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
import { BarsOutlined, DownOutlined } from '@ant-design/icons';
|
||||
import { Dropdown } from 'antd';
|
||||
import React from 'react';
|
||||
|
||||
type Option = { key: string; label: React.ReactNode };
|
||||
|
||||
interface DropOptionProps {
|
||||
menuOptions: Option[];
|
||||
onMenuClick?: (key: string) => void;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
const DropOption: React.FC<DropOptionProps> = ({
|
||||
menuOptions,
|
||||
onMenuClick,
|
||||
children,
|
||||
}) => {
|
||||
const items = menuOptions.map((o) => ({ key: o.key, label: o.label }));
|
||||
|
||||
const menu = {
|
||||
items,
|
||||
onClick: ({ key }: { key: string }) => onMenuClick?.(key),
|
||||
};
|
||||
|
||||
// ensure Dropdown receives a single React element as child
|
||||
let triggerNode: React.ReactElement;
|
||||
if (React.Children.count(children) === 1 && React.isValidElement(children)) {
|
||||
triggerNode = children as React.ReactElement;
|
||||
} else if (children) {
|
||||
// wrap non-element children (like plain text) in a span
|
||||
triggerNode = <span>{children}</span>;
|
||||
} else {
|
||||
triggerNode = (
|
||||
<a onClick={(e) => e.preventDefault()}>
|
||||
<BarsOutlined style={{ marginRight: 2 }} />
|
||||
<DownOutlined />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Dropdown menu={menu} trigger={['click']}>
|
||||
{triggerNode}
|
||||
</Dropdown>
|
||||
);
|
||||
};
|
||||
|
||||
export default DropOption;
|
||||
@@ -1,25 +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,11 +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,111 +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;
|
||||
}
|
||||
|
||||
.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-dropdown-optionwrapper {
|
||||
&:hover {
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.toolbar {}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "Editor",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./Editor.js"
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import styles from './FilterItem.less'
|
||||
|
||||
const FilterItem = ({
|
||||
label = '',
|
||||
children,
|
||||
}) => {
|
||||
const labelArray = label.split('')
|
||||
return (
|
||||
<div className={styles.filterItem}>
|
||||
{labelArray.length > 0
|
||||
? <div className={styles.labelWrap}>
|
||||
{labelArray.map((item, index) => <span className="labelText" key={index}>{item}</span>)}
|
||||
</div>
|
||||
: ''}
|
||||
<div className={styles.item}>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
FilterItem.propTypes = {
|
||||
label: PropTypes.string,
|
||||
children: PropTypes.element.isRequired,
|
||||
}
|
||||
|
||||
export default FilterItem
|
||||
@@ -1,17 +0,0 @@
|
||||
.filterItem {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
.labelWrap {
|
||||
width: 64px;
|
||||
line-height: 28px;
|
||||
margin-right: 12px;
|
||||
justify-content: space-between;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.item {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "FilterItem",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./FilterItem.js"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import React from 'react';
|
||||
|
||||
interface LinkItem {
|
||||
title: string;
|
||||
href: string;
|
||||
}
|
||||
|
||||
interface GlobalFooterProps {
|
||||
links?: LinkItem[];
|
||||
copyright?: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const GlobalFooter: React.FC<GlobalFooterProps> = ({
|
||||
links = [],
|
||||
copyright,
|
||||
}) => {
|
||||
return (
|
||||
<footer style={{ textAlign: 'center', padding: '24px 0', color: '#666' }}>
|
||||
{links.length > 0 && (
|
||||
<div style={{ marginBottom: 8 }}>
|
||||
{links.map((l, i) => (
|
||||
<a key={i} href={l.href} style={{ margin: '0 8px' }}>
|
||||
{l.title}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div>{copyright ?? `© ${new Date().getFullYear()}`}</div>
|
||||
</footer>
|
||||
);
|
||||
};
|
||||
|
||||
export default GlobalFooter;
|
||||
@@ -0,0 +1,33 @@
|
||||
import {
|
||||
AppstoreOutlined,
|
||||
HomeOutlined,
|
||||
InfoCircleOutlined,
|
||||
ProfileOutlined,
|
||||
RobotOutlined,
|
||||
SettingOutlined,
|
||||
TeamOutlined,
|
||||
ToolOutlined,
|
||||
UserAddOutlined,
|
||||
UserOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import React from 'react';
|
||||
|
||||
export const ICON_MAP: Record<string, React.ReactNode> = {
|
||||
home: <HomeOutlined />,
|
||||
'info-c': <InfoCircleOutlined />,
|
||||
user: <UserOutlined />,
|
||||
team: <TeamOutlined />,
|
||||
profile: <ProfileOutlined />,
|
||||
'user-add': <UserAddOutlined />,
|
||||
settings: <SettingOutlined />,
|
||||
tool: <ToolOutlined />,
|
||||
robot: <RobotOutlined />,
|
||||
'app-store': <AppstoreOutlined />,
|
||||
};
|
||||
|
||||
export function Icon({ name }: { name?: string }) {
|
||||
if (!name) return null;
|
||||
return ICON_MAP[name] || null;
|
||||
}
|
||||
|
||||
export default Icon;
|
||||
@@ -1,21 +0,0 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import './iconfont.less'
|
||||
|
||||
const Iconfont = ({ type, colorful }) => {
|
||||
if (colorful) {
|
||||
return (<span
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `<svg class="colorful-icon" aria-hidden="true"><use xlink:href="#${type.startsWith('#') ? type.replace(/#/, '') : type}"></use></svg>`,
|
||||
}}
|
||||
/>)
|
||||
}
|
||||
return <i className={`antdadmin icon-${type}`} />
|
||||
}
|
||||
|
||||
Iconfont.propTypes = {
|
||||
type: PropTypes.string,
|
||||
colorful: PropTypes.bool,
|
||||
}
|
||||
|
||||
export default Iconfont
|
||||
@@ -1,8 +0,0 @@
|
||||
:global .colorful-icon {
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
vertical-align: -0.15em;
|
||||
fill: currentColor;
|
||||
overflow: hidden;
|
||||
font-size: 16px;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "Iconfont",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./Iconfont.js"
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/* global location */
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Breadcrumb, Icon } from 'antd'
|
||||
import { Link } from 'dva/router'
|
||||
import pathToRegexp from 'path-to-regexp'
|
||||
import { queryArray } from 'utils'
|
||||
import styles from './Bread.less'
|
||||
|
||||
const Bread = ({ menu }) => {
|
||||
// 匹配当前路由
|
||||
let pathArray = []
|
||||
let current
|
||||
for (let index in menu) {
|
||||
if (menu[index].route && pathToRegexp(menu[index].route).exec(location.pathname)) {
|
||||
current = menu[index]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const getPathArray = (item) => {
|
||||
pathArray.unshift(item)
|
||||
if (item.bpid) {
|
||||
getPathArray(queryArray(menu, item.bpid, 'id'))
|
||||
}
|
||||
}
|
||||
|
||||
if (!current) {
|
||||
pathArray.push(menu[0] || {
|
||||
id: 1,
|
||||
icon: 'laptop',
|
||||
name: 'Dashboard',
|
||||
})
|
||||
pathArray.push({
|
||||
id: 404,
|
||||
name: 'Not Found',
|
||||
})
|
||||
} else {
|
||||
getPathArray(current)
|
||||
}
|
||||
|
||||
// 递归查找父级
|
||||
const breads = pathArray.map((item, key) => {
|
||||
const content = (
|
||||
<span>{item.icon
|
||||
? <Icon type={item.icon} style={{ marginRight: 4 }} />
|
||||
: ''}{item.name}</span>
|
||||
)
|
||||
return (
|
||||
<Breadcrumb.Item key={key}>
|
||||
{((pathArray.length - 1) !== key)
|
||||
? <Link to={item.route}>
|
||||
{content}
|
||||
</Link>
|
||||
: content}
|
||||
</Breadcrumb.Item>
|
||||
)
|
||||
})
|
||||
|
||||
return (
|
||||
<div className={styles.bread}>
|
||||
<Breadcrumb>
|
||||
{breads}
|
||||
</Breadcrumb>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Bread.propTypes = {
|
||||
menu: PropTypes.array,
|
||||
}
|
||||
|
||||
export default Bread
|
||||
@@ -1,8 +0,0 @@
|
||||
@import "~themes/vars";
|
||||
|
||||
.bread {
|
||||
height: 64px;
|
||||
line-height: 64px;
|
||||
padding: 0 24px;
|
||||
margin-bottom: -24px;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import React from 'react'
|
||||
import { config } from 'utils'
|
||||
import styles from './Footer.less'
|
||||
|
||||
const Footer = () => (<div className={styles.footer}>
|
||||
{config.footerText}
|
||||
</div>)
|
||||
|
||||
export default Footer
|
||||
@@ -1,12 +0,0 @@
|
||||
@import "~themes/vars";
|
||||
|
||||
.footer {
|
||||
height: 48px;
|
||||
line-height: 48px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
background: #fff;
|
||||
box-shadow: @shadow-2;
|
||||
width: 100%;
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Menu, Icon, Popover } from 'antd'
|
||||
import classnames from 'classnames'
|
||||
import styles from './Header.less'
|
||||
import Menus from './Menu'
|
||||
|
||||
const SubMenu = Menu.SubMenu
|
||||
|
||||
const Header = ({ user, logout, switchSider, siderFold, isNavbar, menuPopoverVisible, location, switchMenuPopover, navOpenKeys, changeOpenKeys, menu }) => {
|
||||
let handleClickMenu = e => e.key === 'logout' && logout()
|
||||
const menusProps = {
|
||||
menu,
|
||||
siderFold: false,
|
||||
darkTheme: false,
|
||||
isNavbar,
|
||||
handleClickNavMenu: switchMenuPopover,
|
||||
location,
|
||||
navOpenKeys,
|
||||
changeOpenKeys,
|
||||
}
|
||||
return (
|
||||
<div className={styles.header}>
|
||||
{isNavbar
|
||||
? <Popover placement="bottomLeft" onVisibleChange={switchMenuPopover} visible={menuPopoverVisible} overlayClassName={styles.popovermenu} trigger="click" content={<Menus {...menusProps} />}>
|
||||
<div className={styles.button}>
|
||||
<Icon type="bars" />
|
||||
</div>
|
||||
</Popover>
|
||||
: <div
|
||||
className={styles.button}
|
||||
onClick={switchSider}
|
||||
>
|
||||
<Icon type={classnames({ 'menu-unfold': siderFold, 'menu-fold': !siderFold })} />
|
||||
</div>}
|
||||
<div className={styles.rightWarpper}>
|
||||
<div className={styles.button}>
|
||||
<Icon type="mail" />
|
||||
</div>
|
||||
<Menu mode="horizontal" onClick={handleClickMenu}>
|
||||
<SubMenu
|
||||
style={{
|
||||
float: 'right',
|
||||
}}
|
||||
title={<span>
|
||||
<Icon type="user" />
|
||||
{user.username}
|
||||
</span>}
|
||||
>
|
||||
<Menu.Item key="logout">
|
||||
Sign out
|
||||
</Menu.Item>
|
||||
</SubMenu>
|
||||
</Menu>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Header.propTypes = {
|
||||
menu: PropTypes.array,
|
||||
user: PropTypes.object,
|
||||
logout: PropTypes.func,
|
||||
switchSider: PropTypes.func,
|
||||
siderFold: PropTypes.bool,
|
||||
isNavbar: PropTypes.bool,
|
||||
menuPopoverVisible: PropTypes.bool,
|
||||
location: PropTypes.object,
|
||||
switchMenuPopover: PropTypes.func,
|
||||
navOpenKeys: PropTypes.array,
|
||||
changeOpenKeys: PropTypes.func,
|
||||
}
|
||||
|
||||
export default Header
|
||||
@@ -1,59 +0,0 @@
|
||||
@import "~themes/vars";
|
||||
|
||||
.header {
|
||||
:global .ant-menu-horizontal {
|
||||
& > .ant-menu-submenu {
|
||||
float: right;
|
||||
}
|
||||
border: none;
|
||||
display: inline-block;
|
||||
}
|
||||
box-shadow: @shadow-2;
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
height: 47px;
|
||||
background-color: #fff;
|
||||
z-index: 999;
|
||||
|
||||
.rightWarpper {
|
||||
display: flex;
|
||||
padding-right: 16px;
|
||||
}
|
||||
|
||||
.button {
|
||||
width: 47px;
|
||||
height: 47px;
|
||||
line-height: 47px;
|
||||
text-align: center;
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
transition: @transition-ease-in;
|
||||
|
||||
&:hover {
|
||||
color: @primary-color;
|
||||
background-color: fade(@primary-color, 15%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.popovermenu {
|
||||
width: 280px;
|
||||
margin-left: 6px;
|
||||
|
||||
:global .ant-popover-inner-content {
|
||||
padding: 0;
|
||||
|
||||
.ant-menu-inline .ant-menu-item,
|
||||
.ant-menu-vertical .ant-menu-item {
|
||||
border-right: 0;
|
||||
height: 48px;
|
||||
line-height: 48px;
|
||||
}
|
||||
|
||||
.ant-menu-inline .ant-menu-item-selected,
|
||||
.ant-menu-inline .ant-menu-selected {
|
||||
border-right: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
@import "~themes/vars";
|
||||
|
||||
.layout {
|
||||
position: relative;
|
||||
height: 100vh;
|
||||
|
||||
&.withnavbar {
|
||||
.main {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.fold {
|
||||
.sider {
|
||||
width: 42px;
|
||||
|
||||
.logo {
|
||||
img {
|
||||
width: 28px;
|
||||
margin: 6px 7px;
|
||||
}
|
||||
}
|
||||
|
||||
:global {
|
||||
.ant-menu-root {
|
||||
width: 100%;
|
||||
overflow: visible;
|
||||
|
||||
& > .ant-menu-item {
|
||||
padding: 0;
|
||||
text-align: center;
|
||||
|
||||
.anticon {
|
||||
font-size: 14px;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
& > .ant-menu-submenu {
|
||||
& > .ant-menu-submenu-title {
|
||||
padding: 0;
|
||||
text-align: center;
|
||||
|
||||
.anticon {
|
||||
font-size: 14px;
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
&::after {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.main {
|
||||
margin-left: 42px;
|
||||
}
|
||||
}
|
||||
|
||||
.sider {
|
||||
width: 224px;
|
||||
background: #3e3e3e;
|
||||
position: absolute;
|
||||
overflow: visible;
|
||||
padding-bottom: 24px;
|
||||
height: 100vh;
|
||||
transition: @transition-ease-out;
|
||||
box-shadow: @shadow-1;
|
||||
color: #999;
|
||||
|
||||
&.light {
|
||||
background: #fff;
|
||||
|
||||
.switchtheme {
|
||||
background: #fff;
|
||||
border-top: solid 1px #f8f8f8;
|
||||
}
|
||||
}
|
||||
|
||||
.logo {
|
||||
text-align: center;
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
cursor: pointer;
|
||||
margin: 28px 0;
|
||||
transition: @transition-ease-out;
|
||||
overflow: hidden;
|
||||
|
||||
img {
|
||||
width: 40px;
|
||||
margin-right: 8px;
|
||||
transition: @transition-ease-out;
|
||||
}
|
||||
|
||||
span {
|
||||
vertical-align: text-bottom;
|
||||
font-size: 16px;
|
||||
text-transform: uppercase;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.anticon {
|
||||
transition: @transition-ease-out;
|
||||
}
|
||||
}
|
||||
|
||||
.switchtheme {
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
height: 48px;
|
||||
background-color: @dark-half;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0 16px 0 24px;
|
||||
overflow: hidden;
|
||||
z-index: 1000;
|
||||
|
||||
span {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
:global {
|
||||
.anticon {
|
||||
min-width: 14px;
|
||||
margin-right: 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:global {
|
||||
.ant-menu-dark,
|
||||
.ant-menu-dark .ant-menu-sub {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.ant-menu-root {
|
||||
height: ~"calc(100vh - 144px)";
|
||||
overflow-x: hidden;
|
||||
border-right: none;
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
&.ant-menu-vertical {
|
||||
.ant-menu-sub {
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.ant-menu-submenu-active {
|
||||
.ant-menu-sub {
|
||||
height: auto;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-menu {
|
||||
transition: @transition-ease-out;
|
||||
|
||||
.ant-menu-item,
|
||||
.ant-menu-submenu-title {
|
||||
overflow: hidden;
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.main {
|
||||
margin-left: 224px;
|
||||
overflow: auto;
|
||||
height: 100vh;
|
||||
transition: @transition-ease-out;
|
||||
|
||||
:global {
|
||||
.content-inner {
|
||||
background: #fff;
|
||||
padding: 24px;
|
||||
box-shadow: @shadow-1;
|
||||
min-height: e("calc(100vh - 184px)");
|
||||
}
|
||||
}
|
||||
|
||||
.container {
|
||||
margin: 24px;
|
||||
}
|
||||
|
||||
.content {
|
||||
min-height: e("calc(100vh - 184px)");
|
||||
position: relative;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:global .ant-menu-dark {
|
||||
color: #999;
|
||||
background-color: #3e3e3e;
|
||||
|
||||
.ant-menu-submenu-title:hover,
|
||||
.ant-menu-submenu:hover {
|
||||
color: @primary-color;
|
||||
}
|
||||
|
||||
.ant-menu-sub {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.ant-menu-submenu-selected {
|
||||
color: @primary-color;
|
||||
|
||||
&:not(.ant-menu-submenu-open) {
|
||||
background-color: @dark-half;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-menu-item,
|
||||
.ant-menu-submenu-title {
|
||||
& > a {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
&:hover > a {
|
||||
color: @primary-color;
|
||||
}
|
||||
}
|
||||
|
||||
&.ant-menu-inline {
|
||||
.ant-menu-item-selected {
|
||||
background-color: @dark-half;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-menu-item-selected {
|
||||
color: @primary-color;
|
||||
background-color: @dark-half;
|
||||
|
||||
& > a {
|
||||
color: @primary-color;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: @dark-half;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.spin {
|
||||
:global .ant-spin-container {
|
||||
height: 100vh;
|
||||
}
|
||||
}
|
||||
@media (max-width: 767px) {
|
||||
.layout {
|
||||
.main {
|
||||
.container {
|
||||
margin: 12px;
|
||||
}
|
||||
|
||||
.bread {
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
.content {
|
||||
min-height: e("calc(100vh - 160px)");
|
||||
}
|
||||
|
||||
:global {
|
||||
.content-inner {
|
||||
padding: 12px;
|
||||
min-height: e("calc(100vh - 160px)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/* global location */
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Menu, Icon } from 'antd'
|
||||
import { Link } from 'dva/router'
|
||||
import { arrayToTree, queryArray } from 'utils'
|
||||
import pathToRegexp from 'path-to-regexp'
|
||||
|
||||
const Menus = ({ siderFold, darkTheme, handleClickNavMenu, navOpenKeys, changeOpenKeys, menu }) => {
|
||||
// 生成树状
|
||||
const menuTree = arrayToTree(menu.filter(_ => _.mpid !== '-1'), 'id', 'mpid')
|
||||
const levelMap = {}
|
||||
|
||||
// 递归生成菜单
|
||||
const getMenus = (menuTreeN, siderFoldN) => {
|
||||
return menuTreeN.map((item) => {
|
||||
if (item.children) {
|
||||
if (item.mpid) {
|
||||
levelMap[item.id] = item.mpid
|
||||
}
|
||||
return (
|
||||
<Menu.SubMenu
|
||||
key={item.id}
|
||||
title={<span>
|
||||
{item.icon && <Icon type={item.icon} />}
|
||||
{(!siderFoldN || !menuTree.includes(item)) && item.name}
|
||||
</span>}
|
||||
>
|
||||
{getMenus(item.children, siderFoldN)}
|
||||
</Menu.SubMenu>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Menu.Item key={item.id}>
|
||||
<Link to={item.route}>
|
||||
{item.icon && <Icon type={item.icon} />}
|
||||
{(!siderFoldN || !menuTree.includes(item)) && item.name}
|
||||
</Link>
|
||||
</Menu.Item>
|
||||
)
|
||||
})
|
||||
}
|
||||
const menuItems = getMenus(menuTree, siderFold)
|
||||
|
||||
// 保持选中
|
||||
const getAncestorKeys = (key) => {
|
||||
let map = {}
|
||||
const getParent = (index) => {
|
||||
const result = [String(levelMap[index])]
|
||||
if (levelMap[result[0]]) {
|
||||
result.unshift(getParent(result[0])[0])
|
||||
}
|
||||
return result
|
||||
}
|
||||
for (let index in levelMap) {
|
||||
if ({}.hasOwnProperty.call(levelMap, index)) {
|
||||
map[index] = getParent(index)
|
||||
}
|
||||
}
|
||||
return map[key] || []
|
||||
}
|
||||
|
||||
const onOpenChange = (openKeys) => {
|
||||
const latestOpenKey = openKeys.find(key => !navOpenKeys.includes(key))
|
||||
const latestCloseKey = navOpenKeys.find(key => !openKeys.includes(key))
|
||||
let nextOpenKeys = []
|
||||
if (latestOpenKey) {
|
||||
nextOpenKeys = getAncestorKeys(latestOpenKey).concat(latestOpenKey)
|
||||
}
|
||||
if (latestCloseKey) {
|
||||
nextOpenKeys = getAncestorKeys(latestCloseKey)
|
||||
}
|
||||
changeOpenKeys(nextOpenKeys)
|
||||
}
|
||||
|
||||
let menuProps = !siderFold ? {
|
||||
onOpenChange,
|
||||
openKeys: navOpenKeys,
|
||||
} : {}
|
||||
|
||||
|
||||
// 寻找选中路由
|
||||
let currentMenu
|
||||
let defaultSelectedKeys
|
||||
for (let item of menu) {
|
||||
if (item.route && pathToRegexp(item.route).exec(location.pathname)) {
|
||||
currentMenu = item
|
||||
break
|
||||
}
|
||||
}
|
||||
const getPathArray = (array, current, pid, id) => {
|
||||
let result = [String(current[id])]
|
||||
const getPath = (item) => {
|
||||
if (item && item[pid]) {
|
||||
result.unshift(String(item[pid]))
|
||||
getPath(queryArray(array, item[pid], id))
|
||||
}
|
||||
}
|
||||
getPath(current)
|
||||
return result
|
||||
}
|
||||
if (currentMenu) {
|
||||
defaultSelectedKeys = getPathArray(menu, currentMenu, 'mpid', 'id')
|
||||
}
|
||||
|
||||
return (
|
||||
<Menu
|
||||
{...menuProps}
|
||||
mode={siderFold ? 'vertical' : 'inline'}
|
||||
theme={darkTheme ? 'dark' : 'light'}
|
||||
onClick={handleClickNavMenu}
|
||||
defaultSelectedKeys={defaultSelectedKeys}
|
||||
>
|
||||
{menuItems}
|
||||
</Menu>
|
||||
)
|
||||
}
|
||||
|
||||
Menus.propTypes = {
|
||||
menu: PropTypes.array,
|
||||
siderFold: PropTypes.bool,
|
||||
darkTheme: PropTypes.bool,
|
||||
handleClickNavMenu: PropTypes.func,
|
||||
navOpenKeys: PropTypes.array,
|
||||
changeOpenKeys: PropTypes.func,
|
||||
}
|
||||
|
||||
export default Menus
|
||||
@@ -1,42 +0,0 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Icon, Switch } from 'antd'
|
||||
import { config } from 'utils'
|
||||
import styles from './Layout.less'
|
||||
import Menus from './Menu'
|
||||
|
||||
const Sider = ({ siderFold, darkTheme, location, changeTheme, navOpenKeys, changeOpenKeys, menu }) => {
|
||||
const menusProps = {
|
||||
menu,
|
||||
siderFold,
|
||||
darkTheme,
|
||||
location,
|
||||
navOpenKeys,
|
||||
changeOpenKeys,
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<div className={styles.logo}>
|
||||
<img alt={'logo'} src={config.logo} />
|
||||
{siderFold ? '' : <span>{config.name}</span>}
|
||||
</div>
|
||||
<Menus {...menusProps} />
|
||||
{!siderFold ? <div className={styles.switchtheme}>
|
||||
<span><Icon type="bulb" />Switch Theme</span>
|
||||
<Switch onChange={changeTheme} defaultChecked={darkTheme} checkedChildren="Dark" unCheckedChildren="Light" />
|
||||
</div> : ''}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Sider.propTypes = {
|
||||
menu: PropTypes.array,
|
||||
siderFold: PropTypes.bool,
|
||||
darkTheme: PropTypes.bool,
|
||||
location: PropTypes.object,
|
||||
changeTheme: PropTypes.func,
|
||||
navOpenKeys: PropTypes.array,
|
||||
changeOpenKeys: PropTypes.func,
|
||||
}
|
||||
|
||||
export default Sider
|
||||
@@ -1 +0,0 @@
|
||||
@import "~themes/vars";
|
||||