fangmingyue 1年前
当前提交
652ca3ab54
共有 88 个文件被更改,包括 5929 次插入0 次删除
  1. 24
    0
      .gitignore
  2. 18
    0
      index.html
  3. 8
    0
      jsconfig.json
  4. 36
    0
      package.json
  5. 7
    0
      public/config.js
  6. 二进制
      public/logo.png
  7. 110
    0
      public/particles/particles.json
  8. 9
    0
      public/particles/particles.min.js
  9. 1
    0
      public/qrcode.min.js
  10. 1
    0
      public/vite.svg
  11. 42
    0
      src/App.css
  12. 10
    0
      src/App.jsx
  13. 1
    0
      src/assets/react.svg
  14. 15
    0
      src/components/EditableTag/Tag.jsx
  15. 21
    0
      src/components/EditableTag/index.jsx
  16. 27
    0
      src/components/EditableTag/style.less
  17. 4
    0
      src/components/Money/float.js
  18. 30
    0
      src/components/Money/index.jsx
  19. 83
    0
      src/components/Page/Curd.jsx
  20. 93
    0
      src/components/Page/Edit.jsx
  21. 89
    0
      src/components/Page/List.jsx
  22. 24
    0
      src/components/Page/index.jsx
  23. 10
    0
      src/components/Upload/Upload.jsx
  24. 61
    0
      src/components/Upload/UploadFile.jsx
  25. 69
    0
      src/components/Upload/UploadImage.jsx
  26. 115
    0
      src/components/Upload/UploadImageList.jsx
  27. 49
    0
      src/components/Upload/UploadImages.jsx
  28. 94
    0
      src/components/Upload/UploadVideo.jsx
  29. 11
    0
      src/components/Upload/index.jsx
  30. 42
    0
      src/components/Upload/request.js
  31. 21
    0
      src/components/Upload/style.less
  32. 87
    0
      src/components/Wangeditor/index.jsx
  33. 81
    0
      src/components/chart/index.jsx
  34. 90
    0
      src/index.less
  35. 27
    0
      src/layouts/AuthLayout/Main.jsx
  36. 3
    0
      src/layouts/AuthLayout/RedirectLogin.jsx
  37. 31
    0
      src/layouts/AuthLayout/RequireLogin.jsx
  38. 72
    0
      src/layouts/AuthLayout/components/Background.jsx
  39. 31
    0
      src/layouts/AuthLayout/components/Container.jsx
  40. 15
    0
      src/layouts/AuthLayout/components/Footer.jsx
  41. 35
    0
      src/layouts/AuthLayout/components/Header/Exit.jsx
  42. 24
    0
      src/layouts/AuthLayout/components/Header/Title.jsx
  43. 122
    0
      src/layouts/AuthLayout/components/Header/User.jsx
  44. 28
    0
      src/layouts/AuthLayout/components/Header/index.jsx
  45. 19
    0
      src/layouts/AuthLayout/components/HtmlTitle.jsx
  46. 17
    0
      src/layouts/AuthLayout/components/Logo.jsx
  47. 36
    0
      src/layouts/AuthLayout/components/Menus.jsx
  48. 21
    0
      src/layouts/AuthLayout/components/PageTransition/index.jsx
  49. 21
    0
      src/layouts/AuthLayout/components/PageTransition/style.less
  50. 19
    0
      src/layouts/AuthLayout/components/SiderBar.jsx
  51. 51
    0
      src/layouts/AuthLayout/index.jsx
  52. 80
    0
      src/layouts/AuthLayout/style.less
  53. 28
    0
      src/layouts/AuthLayout/withLogin.jsx
  54. 16
    0
      src/main.jsx
  55. 29
    0
      src/pages/404/index.jsx
  56. 56
    0
      src/pages/article/Detail.jsx
  57. 49
    0
      src/pages/article/Edit.jsx
  58. 119
    0
      src/pages/article/index.jsx
  59. 11
    0
      src/pages/login/Effect.jsx
  60. 67
    0
      src/pages/login/LoginForm.jsx
  61. 24
    0
      src/pages/login/Particles.jsx
  62. 60
    0
      src/pages/login/index.jsx
  63. 99
    0
      src/pages/login/style.less
  64. 18
    0
      src/routes/Router.jsx
  65. 37
    0
      src/routes/hooks/usePrompt.jsx
  66. 17
    0
      src/routes/hooks/useRoute.jsx
  67. 44
    0
      src/routes/menus.jsx
  68. 14
    0
      src/routes/permissions.js
  69. 110
    0
      src/routes/routes.jsx
  70. 22
    0
      src/routes/utils.js
  71. 36
    0
      src/services/login.js
  72. 3
    0
      src/services/ossPolicy.js
  73. 16
    0
      src/store/index.js
  74. 20
    0
      src/store/models/system.js
  75. 31
    0
      src/store/models/useOssPolicy.js
  76. 49
    0
      src/store/models/user.js
  77. 11
    0
      src/theme.less
  78. 64
    0
      src/utils/array.js
  79. 8
    0
      src/utils/css.js
  80. 5
    0
      src/utils/float.js
  81. 23
    0
      src/utils/form.js
  82. 13
    0
      src/utils/hooks/useBool.js
  83. 19
    0
      src/utils/observe.js
  84. 201
    0
      src/utils/request.js
  85. 70
    0
      src/utils/sso.js
  86. 8
    0
      src/utils/token.js
  87. 41
    0
      vite.config.js
  88. 2456
    0
      yarn.lock

+ 24
- 0
.gitignore 查看文件

@@ -0,0 +1,24 @@
1
+# Logs
2
+logs
3
+*.log
4
+npm-debug.log*
5
+yarn-debug.log*
6
+yarn-error.log*
7
+pnpm-debug.log*
8
+lerna-debug.log*
9
+
10
+node_modules
11
+dist
12
+dist-ssr
13
+*.local
14
+
15
+# Editor directories and files
16
+.vscode/*
17
+!.vscode/extensions.json
18
+.idea
19
+.DS_Store
20
+*.suo
21
+*.ntvs*
22
+*.njsproj
23
+*.sln
24
+*.sw?

+ 18
- 0
index.html 查看文件

@@ -0,0 +1,18 @@
1
+<!DOCTYPE html>
2
+<html lang="en">
3
+
4
+<head>
5
+  <meta charset="UTF-8" />
6
+  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
7
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
+  <script src="./config.js"></script>
9
+  <script src="./qrcode.min.js"></script>
10
+  <title>云致开发模板</title>
11
+</head>
12
+
13
+<body>
14
+  <div id="root"></div>
15
+  <script type="module" src="/src/main.jsx"></script>
16
+</body>
17
+
18
+</html>

+ 8
- 0
jsconfig.json 查看文件

@@ -0,0 +1,8 @@
1
+{
2
+  "compilerOptions": {
3
+    "baseUrl": ".",
4
+    "paths": {
5
+      "@/*": ["./src/*"]
6
+    }
7
+  }
8
+}

+ 36
- 0
package.json 查看文件

@@ -0,0 +1,36 @@
1
+{
2
+  "name": "vite-project",
3
+  "private": true,
4
+  "version": "0.0.0",
5
+  "type": "module",
6
+  "scripts": {
7
+    "dev": "vite",
8
+    "build": "vite build",
9
+    "preview": "vite preview"
10
+  },
11
+  "dependencies": {
12
+    "@ant-design/icons": "^4.7.0",
13
+    "@ant-design/pro-components": "^2.6.41",
14
+    "@wangeditor/editor": "^5.1.23",
15
+    "@wangeditor/editor-for-react": "^1.0.6",
16
+    "@zjxpcyc/react-tiny-store": "^2.0.1",
17
+    "antd": "^5.11.2",
18
+    "axios": "^1.2.0",
19
+    "classnames": "^2.3.2",
20
+    "echarts": "^5.4.0",
21
+    "md5": "^2.3.0",
22
+    "react": "18.2.0",
23
+    "react-dom": "18.2.0",
24
+    "react-helmet": "^6.1.0",
25
+    "react-router-dom": "^6.4.2",
26
+    "react-transition-group": "^4.4.5"
27
+  },
28
+  "devDependencies": {
29
+    "@types/react": "18.0.27",
30
+    "@types/react-dom": "18.0.10",
31
+    "@vitejs/plugin-react": "^2.0.0",
32
+    "less": "^4.1.3",
33
+    "vite": "^3.0.0",
34
+    "vite-plugin-imp": "^2.2.0"
35
+  }
36
+}

+ 7
- 0
public/config.js 查看文件

@@ -0,0 +1,7 @@
1
+
2
+var SERVER_BASE = '';
3
+
4
+// 获取真实的上传文件地址
5
+function getRealPath(path) {
6
+  return path;
7
+}

二进制
public/logo.png 查看文件


+ 110
- 0
public/particles/particles.json 查看文件

@@ -0,0 +1,110 @@
1
+{
2
+  "particles": {
3
+    "number": {
4
+      "value": 80,
5
+      "density": {
6
+        "enable": true,
7
+        "value_area": 800
8
+      }
9
+    },
10
+    "color": {
11
+      "value": "#1890ff"
12
+    },
13
+    "shape": {
14
+      "type": "circle",
15
+      "stroke": {
16
+        "width": 0,
17
+        "color": "#000000"
18
+      },
19
+      "polygon": {
20
+        "nb_sides": 5
21
+      },
22
+      "image": {
23
+        "src": "img/github.svg",
24
+        "width": 100,
25
+        "height": 100
26
+      }
27
+    },
28
+    "opacity": {
29
+      "value": 0.5,
30
+      "random": false,
31
+      "anim": {
32
+        "enable": false,
33
+        "speed": 1,
34
+        "opacity_min": 0.1,
35
+        "sync": false
36
+      }
37
+    },
38
+    "size": {
39
+      "value": 3,
40
+      "random": true,
41
+      "anim": {
42
+        "enable": false,
43
+        "speed": 40,
44
+        "size_min": 0.1,
45
+        "sync": false
46
+      }
47
+    },
48
+    "line_linked": {
49
+      "enable": true,
50
+      "distance": 150,
51
+      "color": "#1890ff",
52
+      "opacity": 0.4,
53
+      "width": 1
54
+    },
55
+    "move": {
56
+      "enable": true,
57
+      "speed": 2,
58
+      "direction": "none",
59
+      "random": false,
60
+      "straight": false,
61
+      "out_mode": "out",
62
+      "bounce": false,
63
+      "attract": {
64
+        "enable": false,
65
+        "rotateX": 600,
66
+        "rotateY": 1200
67
+      }
68
+    }
69
+  },
70
+  "interactivity": {
71
+    "detect_on": "canvas",
72
+    "events": {
73
+      "onhover": {
74
+        "enable": false,
75
+        "mode": "repulse"
76
+      },
77
+      "onclick": {
78
+        "enable": false,
79
+        "mode": "push"
80
+      },
81
+      "resize": true
82
+    },
83
+    "modes": {
84
+      "grab": {
85
+        "distance": 400,
86
+        "line_linked": {
87
+          "opacity": 1
88
+        }
89
+      },
90
+      "bubble": {
91
+        "distance": 400,
92
+        "size": 40,
93
+        "duration": 2,
94
+        "opacity": 8,
95
+        "speed": 3
96
+      },
97
+      "repulse": {
98
+        "distance": 200,
99
+        "duration": 0.4
100
+      },
101
+      "push": {
102
+        "particles_nb": 4
103
+      },
104
+      "remove": {
105
+        "particles_nb": 2
106
+      }
107
+    }
108
+  },
109
+  "retina_detect": true
110
+}

+ 9
- 0
public/particles/particles.min.js
文件差异内容过多而无法显示
查看文件


+ 1
- 0
public/qrcode.min.js
文件差异内容过多而无法显示
查看文件


+ 1
- 0
public/vite.svg 查看文件

@@ -0,0 +1 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

+ 42
- 0
src/App.css 查看文件

@@ -0,0 +1,42 @@
1
+#root {
2
+  max-width: 1280px;
3
+  margin: 0 auto;
4
+  padding: 2rem;
5
+  text-align: center;
6
+}
7
+
8
+.logo {
9
+  height: 6em;
10
+  padding: 1.5em;
11
+  will-change: filter;
12
+}
13
+.logo:hover {
14
+  filter: drop-shadow(0 0 2em #646cffaa);
15
+}
16
+.logo.react:hover {
17
+  filter: drop-shadow(0 0 2em #61dafbaa);
18
+}
19
+
20
+
21
+@keyframes logo-spin {
22
+  from {
23
+    transform: rotate(0deg);
24
+  }
25
+  to {
26
+    transform: rotate(360deg);
27
+  }
28
+}
29
+
30
+@media (prefers-reduced-motion: no-preference) {
31
+  a:nth-of-type(2) .logo {
32
+    animation: logo-spin infinite 20s linear;
33
+  }
34
+}
35
+
36
+.card {
37
+  padding: 2em;
38
+}
39
+
40
+.read-the-docs {
41
+  color: #888;
42
+}

+ 10
- 0
src/App.jsx 查看文件

@@ -0,0 +1,10 @@
1
+import { useState } from 'react'
2
+
3
+
4
+function App() {
5
+  const [count, setCount] = useState(0)
6
+
7
+  return null;
8
+}
9
+
10
+export default App

+ 1
- 0
src/assets/react.svg 查看文件

@@ -0,0 +1 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>

+ 15
- 0
src/components/EditableTag/Tag.jsx 查看文件

@@ -0,0 +1,15 @@
1
+import React from 'react';
2
+import { Button } from 'antd';
3
+import { CloseOutlined } from '@ant-design/icons';
4
+import './style.less'
5
+
6
+export default (props) => {
7
+  const { size, type, onDelete, children } = props;
8
+
9
+  return (
10
+    <div className='tag-btn-group'>
11
+      <Button size={size} type={type}>{children}</Button>
12
+      <Button size={size} type="primary" icon={<CloseOutlined />} onClick={onDelete} />
13
+    </div>
14
+  )
15
+}

+ 21
- 0
src/components/EditableTag/index.jsx 查看文件

@@ -0,0 +1,21 @@
1
+import React from 'react';
2
+import { Button } from 'antd';
3
+import Tag from './Tag';
4
+import './style.less'
5
+
6
+export default (props) => {
7
+  const { size, type, list = [], onDelete, keyFuc, labelFunc } = props;
8
+
9
+  return (
10
+    <div className='editable-tag-box'>
11
+      {
12
+        list.map((item, index) => {
13
+          const key = keyFuc(item, index);
14
+          const label = labelFunc(item, index);
15
+
16
+          return <Tag key={key} size={size} type={type} onDelete={() => onDelete(item)}>{label}</Tag>
17
+        })
18
+      }
19
+    </div>
20
+  )
21
+}

+ 27
- 0
src/components/EditableTag/style.less 查看文件

@@ -0,0 +1,27 @@
1
+.tag-btn-group {
2
+  .ant-btn {
3
+    vertical-align: middle;
4
+  }
5
+
6
+  .ant-btn:first-child {
7
+    border-right: none;
8
+  }
9
+
10
+  .ant-btn:last-child {
11
+    // border-left: none;
12
+    border-top-left-radius: 0;
13
+    border-bottom-left-radius: 0;
14
+    margin-left: -1px;
15
+  }
16
+}
17
+
18
+.editable-tag-box {
19
+  display: flex;
20
+  flex-wrap: wrap;
21
+
22
+  .tag-btn-group {
23
+    flex: none;
24
+    box-sizing: border-box;
25
+    padding: 1em;
26
+  }
27
+}

+ 4
- 0
src/components/Money/float.js 查看文件

@@ -0,0 +1,4 @@
1
+const epsilonN = N => num => Math.round( num * N + Number.EPSILON ) / N;
2
+const epsilon2 = epsilonN(1e2);
3
+
4
+export default epsilon2;

+ 30
- 0
src/components/Money/index.jsx 查看文件

@@ -0,0 +1,30 @@
1
+import { InputNumber } from "antd"
2
+import { useEffect, useState } from "react"
3
+import epsilon2 from './float'
4
+
5
+export default (props) => {
6
+
7
+  const { value, onChange, ...leftProps } = props
8
+
9
+  const [money, setMoney] = useState(0)
10
+
11
+  useEffect(() => {
12
+    setMoney(epsilon2(value / 100))
13
+  }, [value])
14
+
15
+  const handleChange = (val) => {
16
+    onChange(epsilon2(val * 100))
17
+  }
18
+
19
+  return (
20
+    <InputNumber
21
+      min='0'
22
+      {...leftProps}
23
+      value={money}
24
+      onChange={handleChange}
25
+      precision={2}
26
+      formatter={value => `¥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}
27
+      parser={value => value.replace(/\¥\s?|(,*)/g, '')}
28
+    />
29
+  )
30
+}

+ 83
- 0
src/components/Page/Curd.jsx 查看文件

@@ -0,0 +1,83 @@
1
+import React from 'react';
2
+import { DrawerForm } from '@ant-design/pro-components';
3
+import { Form } from 'antd';
4
+import List from './List';
5
+
6
+const drawerProps = {
7
+  destroyOnClose: true
8
+}
9
+export default (props) => {
10
+  const { rowKey, columns, request, formProps, renderFormItems, ...leftProps } = props;
11
+
12
+  const [form] = Form.useForm();
13
+  const listRef = React.useRef();
14
+  const rowRef = React.useRef();
15
+  const [open, setOpen] = React.useState(false);
16
+  
17
+  const onAdd = () => {
18
+    rowRef.current = undefined;
19
+    form.resetFields();
20
+    setOpen(true);
21
+  }
22
+
23
+  const onEdit = (row) => {
24
+    rowRef.current = row;
25
+    form.setFieldsValue(row);
26
+    setOpen(true);
27
+  }
28
+
29
+  const onDelete = (row) => {
30
+    rowRef.current = row;
31
+
32
+    listRef.current.showLoading('正在操作, 请稍候...');
33
+    request.del(row[rowKey]).then(() => {
34
+      listRef.current.hideLoading();
35
+      listRef.current.reload();
36
+    }).catch(() => {
37
+      listRef.current.hideLoading();
38
+    });
39
+  }
40
+
41
+  const onFinish = async (values) => {
42
+    if (rowRef.current) {
43
+      await request.update(rowRef.current[rowKey], {
44
+        ...rowRef.current,
45
+        ...values,
46
+      });
47
+    } else {
48
+      await request.save(values);
49
+    }
50
+    listRef.current.reload();
51
+
52
+    return true;
53
+  }
54
+
55
+  return (
56
+    <>
57
+      <List
58
+        ref={listRef}
59
+        rowKey={rowKey}
60
+        columns={columns}
61
+        request={request.list}
62
+        onAdd={onAdd}
63
+        onDelete={onDelete}
64
+        onEdit={onEdit}
65
+        {...leftProps}
66
+      />
67
+
68
+      <DrawerForm
69
+        submitTimeout={3000}
70
+        open={open}
71
+        form={form}
72
+        drawerProps={drawerProps}
73
+        onOpenChange={setOpen}
74
+        onFinish={onFinish}
75
+        {...formProps}
76
+      >
77
+        {
78
+          renderFormItems && renderFormItems()
79
+        }
80
+      </DrawerForm>
81
+    </>
82
+  )
83
+}

+ 93
- 0
src/components/Page/Edit.jsx 查看文件

@@ -0,0 +1,93 @@
1
+import React from 'react';
2
+import { Button, Card, Form } from 'antd';
3
+import { useSearchParams, useNavigate } from "react-router-dom";
4
+import useBool from '@/utils/hooks/useBool';
5
+import Page from './index';
6
+
7
+const FormItem = Form.Item;
8
+const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
9
+
10
+export default (props) => {
11
+  /**
12
+   * request 编辑或者新增接口
13
+   * dataFunc 将 form 表单数据转换为接口需要格式, 一般情况下不需要这个操作
14
+   * formDataFunc 将接口返回的值转换为 form 表单数据格式, 一般情况下不需要这个操作
15
+   * width form 表单宽度, 默认 800px
16
+   */
17
+  const { request, dataFunc, formDataFunc, width = '800px', onFinish, ...leftProps } = props;
18
+  const [loading, startLoading, stopLoading] = useBool();
19
+  const [form] = Form.useForm();
20
+  const navigate = useNavigate();
21
+
22
+  // 获取 id query 参数, 如果存在说明是编辑,而不是新增
23
+  const [params] = useSearchParams();
24
+  const id = params.get("id");
25
+  
26
+  const navBack = React.useCallback(() => {
27
+    const t = setTimeout(() => {
28
+      navigate(-1);
29
+      clearTimeout(t);
30
+    }, 600);
31
+  }, [navigate]);
32
+
33
+  // 表单提交
34
+  const onSubmit = (values) => {    
35
+    startLoading();
36
+    // 可能需要转换下格式
37
+    const data = dataFunc ? dataFunc(id, values) : values;
38
+    if (id) {
39
+      request.update(id, data).then((res) => {
40
+        stopLoading();
41
+        if (onFinish) {
42
+          onFinish(res);
43
+        } else {
44
+          navBack();
45
+        }
46
+      }).catch(stopLoading);
47
+    } else {
48
+      request.save(data)
49
+        .then((res) => {
50
+          stopLoading();
51
+          if (onFinish) {
52
+            onFinish(res);
53
+          } else {
54
+            navBack();
55
+          }
56
+        }).catch(stopLoading);
57
+    }
58
+  }
59
+
60
+  // 查询详情
61
+  React.useEffect(() => {
62
+    if (id && request) {
63
+      request.get(id).then(res => {
64
+        // 此处可能需要转换下数据格式
65
+        const formData = formDataFunc ? formDataFunc(res) : res;
66
+        form.setFieldsValue(formData);
67
+      })
68
+    }
69
+  }, [request, id]);
70
+
71
+  return (
72
+    <Page>
73
+      <Card bodyStyle={{padding: '48px 24px'}}>
74
+        <Form {...formItemLayout} form={form} onFinish={onSubmit} style={{width}} {...leftProps} >
75
+          {props.children}
76
+          <FormItem label=" " colon={false} style={{marginBottom: 0}}>
77
+            <Button type="default" onClick={() => navigate(-1)}>
78
+              取消
79
+            </Button>
80
+            <Button
81
+              type="primary"
82
+              htmlType="submit"
83
+              style={{ marginLeft: '4em' }}
84
+              loading={loading}
85
+            >
86
+              确认
87
+            </Button>
88
+          </FormItem>
89
+        </Form>
90
+      </Card>
91
+    </Page>
92
+  )
93
+}

+ 89
- 0
src/components/Page/List.jsx 查看文件

@@ -0,0 +1,89 @@
1
+import React from 'react';
2
+import { Button, Popconfirm, message } from 'antd';
3
+import { ProTable } from '@ant-design/pro-components';
4
+import { queryTable } from '@/utils/request';
5
+import Page from './index';
6
+
7
+export default React.forwardRef((props, ref) => {
8
+  /**
9
+   * request 与 ProTable 定义不同,这个只是普通的接口即可
10
+   */
11
+  const { request, rowKey, columns, onAdd, onDelete, onEdit, toolBarRender, columnOptionRender, ...leftProps } = props;
12
+  const actionRef = React.useRef();
13
+  const hideRef = React.useRef();
14
+
15
+  const api = React.useMemo(() => queryTable(request), [request]);
16
+
17
+  // 统一实现操作列
18
+  const cols = React.useMemo(() => [
19
+    ...columns,
20
+    {
21
+      title: '操作',
22
+      valueType: 'option',
23
+      key: 'option',
24
+      ellipsis: true,
25
+      render: (_, record) => [
26
+        (
27
+          onEdit && 
28
+          <Button style={{ padding: 0 }} type="link" key={1} onClick={() => onEdit(record) }>
29
+            编辑
30
+          </Button>
31
+        ),
32
+        (
33
+          onDelete &&
34
+          <Popconfirm
35
+            key={3}
36
+            title="您是否确认删除 ?"
37
+            onConfirm={() => onDelete(record)}
38
+            okText="确定"
39
+            cancelText="取消"
40
+          >
41
+            <Button style={{ padding: 0 }} type="link">
42
+              删除
43
+            </Button>
44
+          </Popconfirm>
45
+        ),
46
+        ...(columnOptionRender ? columnOptionRender(_, record) : []),
47
+      ].filter(Boolean),
48
+    },
49
+  ], [columns, onEdit, onDelete]);
50
+
51
+  React.useImperativeHandle(ref, () => {
52
+    const showLoading = msg => (hideRef.current = message.loading(msg || '操作中, 请稍候...'));
53
+    const hideLoading = () => hideRef.current && hideRef.current();
54
+    const reload = () => actionRef.current?.reload && actionRef.current.reload();
55
+
56
+    return {
57
+      showLoading,
58
+      hideLoading,
59
+      reload,
60
+      actionRef: actionRef,
61
+    }
62
+  }, []);
63
+
64
+  return (
65
+    <Page>
66
+      <ProTable
67
+        rowKey={rowKey}
68
+        columns={cols}
69
+        request={api}
70
+        cardBordered
71
+        actionRef={actionRef}
72
+        toolBarRender={() => [
73
+          (
74
+            onAdd && 
75
+            <Button
76
+              key="1"
77
+              type="primary"
78
+              onClick={onAdd}
79
+            >
80
+              新增
81
+            </Button>
82
+          ),
83
+          ...(toolBarRender ? toolBarRender() : []),
84
+        ].filter(Boolean)}
85
+        {...leftProps}
86
+      />
87
+    </Page>
88
+  )
89
+});

+ 24
- 0
src/components/Page/index.jsx 查看文件

@@ -0,0 +1,24 @@
1
+import React from 'react';
2
+import { Typography } from 'antd';
3
+import useRoute from '@/routes/hooks/useRoute';
4
+
5
+const pageStyle = {
6
+  margin: '0 24px 24px 24px',
7
+  // margin: '24px',
8
+  minHeight: 'calc(100% - 24px)',
9
+}
10
+const { Title } = Typography;
11
+
12
+export default (props) => {
13
+  console.log(props);
14
+  const { meta = {} } = useRoute() || {};
15
+  const style = meta.noLayout ? { height: '100%' } : pageStyle;
16
+  const title = props.title || meta.title;
17
+
18
+  return (
19
+    <div style={style}>
20
+      { title && !meta.noLayout && <Title level={3} style={{ paddingBottom: '12px', fontWeight: 400 }}>{ title }</Title> }
21
+      {props.children}
22
+    </div>
23
+  )
24
+}

+ 10
- 0
src/components/Upload/Upload.jsx 查看文件

@@ -0,0 +1,10 @@
1
+import { Upload } from 'antd';
2
+import { uploadFile } from './request'
3
+
4
+export default (props) => {
5
+  return (
6
+    <Upload {...props} customRequest={uploadFile} >
7
+      {props.children}
8
+    </Upload>
9
+  )
10
+}

+ 61
- 0
src/components/Upload/UploadFile.jsx 查看文件

@@ -0,0 +1,61 @@
1
+import React from "react";
2
+import { UploadOutlined } from "@ant-design/icons";
3
+import { Button } from "antd";
4
+import Upload from "@/components/Upload/Upload";
5
+
6
+const getFileInfo = (x) => ({
7
+  uid: x,
8
+  name: x?.split("/")?.at(-1)?.replace(/^\d+-/, ""),
9
+  status: "done",
10
+  thumbUrl: x,
11
+  url: x,
12
+});
13
+
14
+export default (props) => {
15
+  const { value, onChange, accept = ".ppt,.pptx,.pdf" } = props;
16
+
17
+  const [loading, setLoading] = React.useState(false);
18
+
19
+  const [fileList, setFileList] = React.useState([]);
20
+
21
+
22
+  const handleChange = (info) => {
23
+    const newFileList = [...info.fileList];
24
+
25
+    if (info.file.status === "uploading") {
26
+      setLoading(true);
27
+    } else if (info.file.status === "error") {
28
+      setLoading(false);
29
+    } else if (info.file.status === "done") {
30
+      setLoading(false);
31
+      const { url, fileType } = info.file.response;
32
+      if (onChange) {
33
+        onChange(url, fileType);
34
+      }
35
+    }
36
+
37
+    setFileList(newFileList);
38
+  };
39
+
40
+  React.useEffect(() => {
41
+    if (!value) {
42
+      setFileList([]);
43
+    } else {
44
+      setFileList([getFileInfo(value)]);
45
+    }
46
+  }, [value]);
47
+
48
+  return (
49
+    <>
50
+      <Upload
51
+        accept={accept}
52
+        fileList={fileList}
53
+        onChange={handleChange}
54
+      >
55
+        <Button loading={loading} icon={<UploadOutlined />}>
56
+          点击上传文件
57
+        </Button>
58
+      </Upload>
59
+    </>
60
+  );
61
+};

+ 69
- 0
src/components/Upload/UploadImage.jsx 查看文件

@@ -0,0 +1,69 @@
1
+import React, { useState } from 'react';
2
+import { setProperty } from '@/utils/css';
3
+import { LoadingOutlined, PlusOutlined } from '@ant-design/icons';
4
+import Upload from './Upload';
5
+
6
+function beforeUpload (file) {
7
+  const isImage = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif';
8
+  if (!isImage) {
9
+    message.error('请上传 JPG , PNG或GIF 图片!');
10
+  }
11
+  const isLt10M = file.size / 1024 / 1024 < 10;
12
+  if (!isLt10M) {
13
+    message.error('图片大小必须小于 10MB!');
14
+  }
15
+
16
+  return isImage && isLt10M;
17
+}
18
+
19
+const UploadButton = (props) => (
20
+  <div>
21
+    {props.loading ? <LoadingOutlined /> : <PlusOutlined />}
22
+    <div style={{ marginTop: 8 }}>上传</div>
23
+  </div>
24
+);
25
+
26
+export default (props) => {
27
+  const { value, onChange, width = 200, ratio = 1 } = props;
28
+
29
+  const [loading, setLoading] = useState(false);
30
+
31
+  const handleChange = info => {
32
+    if (info.file.status === 'uploading') {
33
+      setLoading(true);
34
+      return;
35
+    }
36
+    if (info.file.status === 'error') {
37
+      setLoading(false);
38
+      return;
39
+    }
40
+
41
+    if (info.file.status === 'done') {
42
+      setLoading(false);
43
+      const { url, fileType } = info.file.response;
44
+      onChange(url);
45
+    }
46
+  };
47
+
48
+  const previewUrl = getRealPath ? getRealPath(value) : value;
49
+
50
+  React.useEffect(() => {
51
+    setProperty('--cust-upload-ratio', ratio);
52
+  }, [ratio]);
53
+
54
+  React.useEffect(() => {
55
+    setProperty('--cust-upload-width', `${width}px`);
56
+  }, [width]);
57
+
58
+  return (
59
+    <Upload
60
+      listType="picture-card"
61
+      className="cust-img-upload"
62
+      showUploadList={false}
63
+      beforeUpload={beforeUpload}
64
+      onChange={handleChange}
65
+    >
66
+      {value ? <img src={previewUrl} className="cust-img-thumb" alt="avatar" style={{ width: '100%', height: '100%' }} /> : <UploadButton loading={loading} />}
67
+    </Upload>
68
+  );
69
+}

+ 115
- 0
src/components/Upload/UploadImageList.jsx 查看文件

@@ -0,0 +1,115 @@
1
+
2
+import React, { useEffect, useState } from 'react';
3
+import { Modal } from 'antd'
4
+import { LoadingOutlined, PlusOutlined } from '@ant-design/icons';
5
+import Upload from './Upload';
6
+
7
+function beforeUpload(file) {
8
+  const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'|| file.type === 'image/gif';
9
+  if (!isJpgOrPng) {
10
+    message.error('请上传 JPG,PNG 或 GIF 图片!');
11
+  }
12
+  const isLt10M = file.size / 1024 / 1024 < 10;
13
+  if (!isLt10M) {
14
+    message.error('图片大小必须小于 10MB!');
15
+  }
16
+
17
+  return isJpgOrPng && isLt10M;
18
+}
19
+
20
+const UploadButton = (props) => (
21
+  <div>
22
+    {props.loading ? <LoadingOutlined /> : <PlusOutlined />}
23
+    <div style={{ marginTop: 8 }}>上传</div>
24
+  </div>
25
+);
26
+
27
+export default (props) => {
28
+  const { value, onChange, input, output } = props;
29
+
30
+  const [loading, setLoading] = useState(false);
31
+  const [previewVisible, setPreviewVisible] = useState(false);
32
+  const [previewImage, setPreviewImage] = useState();
33
+  const [fileList, setFileList] = useState([]);
34
+
35
+  const handleChange = info => {
36
+    if (info.file.status === 'uploading') {
37
+      setLoading(true);
38
+      return;
39
+    }
40
+    if (info.file.status === 'error') {
41
+      setLoading(false);
42
+      return;
43
+    }
44
+
45
+    if (info.file.status === 'removed') {
46
+      toggleChange(info.fileList)
47
+    }
48
+  };
49
+
50
+  const handleSuccess = ({url}) => {
51
+    setLoading(false)
52
+    const inx = fileList?.length ? fileList.length + 1 : 1
53
+    const list = fileList.concat({
54
+      url,
55
+      uid: `new-${inx}`,
56
+      status: 'done'
57
+    })
58
+    toggleChange(list)
59
+  }
60
+
61
+  const toggleChange = (list) => {
62
+    if (output) {
63
+      onChange(list.map(x => output(x)))
64
+    } else {
65
+      onChange(list)
66
+    }
67
+  }
68
+
69
+  const handlePreview = (file) => {
70
+    setPreviewImage(file.url)
71
+    setPreviewVisible(true)
72
+  }
73
+
74
+  useEffect(() => {
75
+    if (input) {
76
+      const lst = (value || []).map((it) => {
77
+        const { uid, url } = input(it)
78
+        return {
79
+          uid,
80
+          url,
81
+          status: 'done',
82
+          raw: it,
83
+        }
84
+      })
85
+      setFileList(lst)
86
+    } else {
87
+      setFileList(value || [])
88
+    }
89
+  }, [value])
90
+
91
+  return (
92
+    <>
93
+      <Upload
94
+        listType="picture-card"
95
+        className="image-uploader"
96
+        fileList={fileList}
97
+        beforeUpload={beforeUpload}
98
+        onChange={handleChange}
99
+        onPreview={handlePreview}
100
+        onSuccess={handleSuccess}
101
+      >
102
+        <UploadButton loading={loading} />
103
+      </Upload>
104
+      <Modal
105
+        visible={previewVisible}
106
+        title="图片预览"
107
+        footer={null}
108
+        onCancel={() => setPreviewVisible(false)}
109
+      >
110
+        <img alt="example" style={{ width: '100%' }} src={previewImage} />
111
+      </Modal>
112
+    </>
113
+  );
114
+}
115
+

+ 49
- 0
src/components/Upload/UploadImages.jsx 查看文件

@@ -0,0 +1,49 @@
1
+import React from 'react';
2
+import { Space } from 'antd';
3
+import UploadImage from "@/components/Upload/UploadImage";
4
+
5
+export default (props) => {
6
+  const { value = [], onChange, limit = 1, ratio, tips } = props;
7
+
8
+  const handleChange = (inx = 0) => e => {
9
+    value[inx] = e;
10
+    onChange(value.slice());
11
+  }
12
+
13
+  return (
14
+    <div className="flex">
15
+      <div className="flex-0">
16
+        <UploadImage
17
+          onChange={handleChange(0)}
18
+          value={value[0]}
19
+          ratio={ratio}
20
+          tips={tips}
21
+        />
22
+      </div>
23
+      {/* {
24
+        limit > 1 ? (
25
+          <div className="flex-0" style={{ marginLeft: '24px' }}>
26
+            <UploadImage
27
+              onChange={handleChange(1)}
28
+              value={value[1]}
29
+              ratio={ratio}
30
+              tips={tips}
31
+            />
32
+          </div>
33
+        ) : null
34
+      }
35
+      {
36
+        limit > 2 ? (
37
+          <div className="flex-0" style={{ marginLeft: '24px' }}>
38
+            <UploadImage
39
+              onChange={handleChange(2)}
40
+              value={value[2]}
41
+              ratio={ratio}
42
+              tips={tips}
43
+            />
44
+          </div>
45
+        ) : null
46
+      } */}
47
+    </div>
48
+  )
49
+}

+ 94
- 0
src/components/Upload/UploadVideo.jsx 查看文件

@@ -0,0 +1,94 @@
1
+import React, { useState, useRef, useEffect } from 'react';
2
+import { Button } from 'antd'
3
+import Upload from './Upload';
4
+// import { uplodeNoteImage } from '@/services/note';
5
+import styles from './style.less';
6
+
7
+function beforeUpload(file) {
8
+  const isMp4 = file.type === 'video/mp4';
9
+  if (!isMp4) {
10
+    message.error('请上传 MP4 视频!');
11
+  }
12
+
13
+  return isMp4;
14
+}
15
+
16
+export default (props) => {
17
+  //onPoster 改变主图事件   isScreenshot判断父组件是否需要截屏按钮
18
+  const { value, onChange, onPoster, isScreenshot } = props;
19
+  const [loading, setLoading] = useState(false);//上传按钮loading框
20
+  const [capturing, setCapturing] = useState(false);//截屏按钮loading框
21
+  const [video, setVideo] = useState()//当前上传的视频
22
+  const [isVideoReady, setIsVideoReady] = useState(false)//判断视频是否加载成功
23
+  
24
+  const canvasRef = useRef()
25
+  const videoRef = useRef()
26
+
27
+  useEffect(() => {
28
+    setVideo(value)//父组件的视频获取成功时改变当前页面的视频
29
+  }, [value])
30
+
31
+  const handleChange = info => {
32
+    if (info.file.status === 'uploading') {
33
+      setLoading(true);
34
+      return;
35
+    }
36
+    if (info.file.status === 'error') {
37
+      setLoading(false);
38
+      return;
39
+    }
40
+    if (info.file.status === 'done') {
41
+      onChange(info.file.response);
42
+      setLoading(false);
43
+    }
44
+  };
45
+
46
+  //开始截图
47
+  const handelScreenshot = () => {
48
+    const ctx = canvasRef.current.getContext("2d");  
49
+    ctx.drawImage(videoRef.current, 0, 0);    
50
+    const image = canvasRef.current.toDataURL("image/png", 0.9)
51
+    setCapturing(true)
52
+    // uplodeNoteImage({ base64: image }).then((res) => {
53
+    //   onPoster(res)
54
+    //   setCapturing(false)
55
+    // })
56
+  }
57
+
58
+  //视频加载成功事件
59
+  const handleVideoReady = (e) => {
60
+    setIsVideoReady(true)
61
+    canvasRef.current.width = e.target.videoWidth;
62
+    canvasRef.current.height = e.target.videoHeight;
63
+  }
64
+
65
+  return (
66
+    <div className={styles['video-uploader']}>
67
+      <Upload
68
+        className="image-uploader"
69
+        showUploadList={false}
70
+        beforeUpload={beforeUpload}
71
+        onChange={handleChange}
72
+      >
73
+        <div style={{ maxWidth: '1px', maxHeight: '1px', overflow: 'hidden' }}>
74
+          <canvas ref={canvasRef}></canvas>
75
+        </div>
76
+        <Button loading={loading}>
77
+          点击上传视频 (MP4)
78
+        </Button>
79
+
80
+      </Upload>
81
+      {
82
+        isScreenshot && (
83
+          // disabled={!isVideoReady} 当视频准备成功时截屏按钮可以点击  否则不能点击
84
+          <Button loading={capturing} style={{ marginLeft: '1em' }} onClick={handelScreenshot} disabled={!isVideoReady}>截屏</Button>
85
+        )
86
+      }
87
+      {
88
+        !!video && (
89
+          <video ref={videoRef} width="320" height='500' crossOrigin='anonymous' controls src={video} onCanPlay={handleVideoReady}></video>
90
+        )
91
+      }
92
+    </div>
93
+  );
94
+}

+ 11
- 0
src/components/Upload/index.jsx 查看文件

@@ -0,0 +1,11 @@
1
+import Upload from './Upload';
2
+import UploadImage from './UploadImage';
3
+import UploadImageList from './UploadImageList';
4
+import UploadVideo from './UploadVideo';
5
+
6
+export {
7
+  Upload,
8
+  UploadImage,
9
+  UploadImageList,
10
+  UploadVideo,
11
+}

+ 42
- 0
src/components/Upload/request.js 查看文件

@@ -0,0 +1,42 @@
1
+import request from "@/utils/request";
2
+
3
+import { useModel } from "@/store";
4
+
5
+const upload = (file, fileType = "image") => {
6
+  const { policyList } = useModel("policy");
7
+  const formData = new FormData();
8
+  formData.append("OSSAccessKeyId", policyList.OSSAccessKeyId);
9
+  formData.append("signature", policyList.signature);
10
+  formData.append("policy", policyList.policy);
11
+  formData.append("key", policyList.dir);
12
+  formData.append("success_action_status", 200);
13
+  formData.append("file", file);
14
+
15
+  // return request(policyList.host, {
16
+  //   method: "post",
17
+  //   data: formData,
18
+  //   headers: {
19
+  //     "Content-Type": "multipart/form-data",
20
+  //     "Access-Control-Allow-Origin": "*",
21
+  //   },
22
+  // });
23
+};
24
+
25
+/**
26
+ * 上传文件
27
+ * @returns
28
+ */
29
+export function uploadFile(params) {
30
+  const { file, onSuccess, onError } = params;
31
+  upload(file)
32
+    .then((res) => {
33
+      onSuccess(res, file);
34
+    })
35
+    .catch((e) => {
36
+      onError(e);
37
+    });
38
+
39
+  return {
40
+    abort: () => {},
41
+  };
42
+}

+ 21
- 0
src/components/Upload/style.less 查看文件

@@ -0,0 +1,21 @@
1
+.video-uploader {
2
+  video {
3
+    margin-top: 2em;
4
+    width: 100%;
5
+    max-height: 360px;
6
+  }
7
+}
8
+
9
+.cust-img-upload {
10
+  :global(.ant-upload-select) {
11
+    width: var(--cust-upload-width) !important;
12
+    height: auto !important;
13
+    aspect-ratio: var(--cust-upload-ratio);
14
+  }
15
+
16
+  .cust-img-thumb {
17
+    width: var(--cust-upload-width) !important;
18
+    height: auto !important;
19
+    aspect-ratio: var(--cust-upload-ratio);
20
+  }
21
+}

+ 87
- 0
src/components/Wangeditor/index.jsx 查看文件

@@ -0,0 +1,87 @@
1
+import React, { useState, useEffect } from "react";
2
+import "@wangeditor/editor/dist/css/style.css";
3
+import { Editor, Toolbar } from "@wangeditor/editor-for-react";
4
+
5
+// 工具栏配置参考
6
+// https://www.cnblogs.com/-roc/p/16400965.html
7
+
8
+const defaultStyle = {
9
+  border: "1px solid #ccc",
10
+  zIndex: 100,
11
+  marginTop: "15px"
12
+}
13
+
14
+function MyEditor(props) {
15
+
16
+  const style = React.useMemo(() => ({ ...defaultStyle, ...(props.style || {}) }), [props.style])
17
+
18
+  const {
19
+    value = "",
20
+    onChange = (e) => {
21
+      setHtml(e);
22
+    },
23
+    toolbarConfig = {
24
+      excludeKeys: ["group-image", "group-video"],
25
+    },
26
+    editorConfig = {
27
+      placeholder: "请输入内容...",
28
+    },
29
+    readonly = false,
30
+  } = props;
31
+  const [editor, setEditor] = useState(null); // 存储 editor 实例
32
+  const [html, setHtml] = useState("");
33
+ 
34
+  // 模拟 ajax 请求,异步设置 html
35
+  useEffect(() => {
36
+    setHtml(value || "");
37
+  }, [value]);
38
+
39
+  // 及时销毁 editor
40
+  useEffect(() => {
41
+    return () => {
42
+      if (editor == null) return;
43
+      editor.destroy();
44
+      setEditor(null);
45
+    };
46
+  }, [editor]);
47
+
48
+  function insertText() {
49
+    if (editor == null) return;
50
+    editor.insertText(" hello ");
51
+  }
52
+
53
+  function printHtml() {
54
+    if (editor == null) return;
55
+    console.log(editor.getHtml());
56
+  }
57
+
58
+  const handleChange = (editor) => {
59
+    const raw = editor.getHtml();
60
+    if (raw !== '<p><br></p>') {
61
+      onChange(raw)
62
+    }
63
+  }
64
+
65
+  return !readonly ? (
66
+    <div className={props.className} style={style}>
67
+      <Toolbar
68
+        editor={editor}
69
+        defaultConfig={toolbarConfig}
70
+        mode="default"
71
+        style={{ borderBottom: "1px solid #ccc" }}
72
+      />
73
+      <Editor
74
+        defaultConfig={editorConfig}
75
+        value={html}
76
+        onCreated={setEditor}
77
+        onChange={handleChange}
78
+        mode="default"
79
+        style={{ height: "500px" }}
80
+      />
81
+    </div>
82
+  ) : (
83
+    <div dangerouslySetInnerHTML={{ __html: value }}></div>
84
+  );
85
+}
86
+
87
+export default MyEditor;

+ 81
- 0
src/components/chart/index.jsx 查看文件

@@ -0,0 +1,81 @@
1
+import React, { useRef, useEffect } from 'react';
2
+
3
+// 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。
4
+import * as echarts from 'echarts/core';
5
+// 引入图表,图表后缀都为 Chart
6
+import {
7
+  BarChart,
8
+  PieChart,
9
+  LineChart,
10
+  GaugeChart,
11
+  RadarChart,
12
+  PictorialBarChart,
13
+} from 'echarts/charts';
14
+// 引入提示框,标题,直角坐标系,数据集,内置数据转换器组件,组件后缀都为 Component
15
+import {
16
+  TitleComponent,
17
+  TooltipComponent,
18
+  ToolboxComponent,
19
+  GridComponent,
20
+  DatasetComponent,
21
+  LegendComponent,
22
+  DataZoomComponent,
23
+  TransformComponent,
24
+  VisualMapComponent,
25
+} from 'echarts/components';
26
+// 标签自动布局,全局过渡动画等特性
27
+import { LabelLayout, UniversalTransition } from 'echarts/features';
28
+// 引入 Canvas 渲染器,注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
29
+import { CanvasRenderer } from 'echarts/renderers';
30
+
31
+// 注册必须的组件
32
+echarts.use([
33
+  TitleComponent,
34
+  TooltipComponent,
35
+  ToolboxComponent,
36
+  GridComponent,
37
+  DatasetComponent,
38
+  LegendComponent,
39
+  DataZoomComponent,
40
+  TransformComponent,
41
+  VisualMapComponent,
42
+  BarChart,
43
+  PieChart,
44
+  LineChart,
45
+  GaugeChart,
46
+  RadarChart,
47
+  PictorialBarChart,
48
+  LabelLayout,
49
+  UniversalTransition,
50
+  CanvasRenderer
51
+]);
52
+
53
+export default (props) => {
54
+  const { className, style, option } = props;
55
+
56
+  const domRef = useRef();
57
+  const chartRef = useRef();
58
+
59
+  useEffect(() => {
60
+    if (!chartRef.current) {
61
+      chartRef.current = echarts.init(domRef.current);
62
+    }
63
+
64
+    const resize = () => {
65
+      const t = setTimeout(() => {
66
+        clearTimeout(t);
67
+        chartRef.current.resize();
68
+      }, 100);
69
+    };
70
+
71
+    chartRef.current.setOption(option);
72
+    resize();
73
+
74
+    window.addEventListener('resize', resize);    
75
+    return () => window.removeEventListener('resize', resize);
76
+  }, [option]);
77
+
78
+  return (
79
+    <div className={className} style={style} ref={domRef}></div>
80
+  )
81
+}

+ 90
- 0
src/index.less 查看文件

@@ -0,0 +1,90 @@
1
+@import './theme.less';
2
+
3
+html,
4
+body,
5
+#root {
6
+  width: 100%;
7
+  height: 100%;
8
+  margin: 0;
9
+}
10
+
11
+:root {
12
+  --theme-color: #fff;
13
+  --theme-front: #000;
14
+  --theme-main-bg: #f1f7fe; // #f0f2f5;
15
+  --header-height: 60px;
16
+  --siderbar-width: 240px;
17
+
18
+  // 图片上传比例
19
+  --cust-upload-width: 200px;
20
+  --cust-upload-ratio: 1;
21
+}
22
+
23
+.main-layout {
24
+  height: 100vh;
25
+  display: flex;
26
+  flex-direction: column;
27
+}
28
+
29
+.fixd-header {
30
+  width: 100%;
31
+  position: fixed;
32
+  top: 0;
33
+  height: var(--header-height);
34
+  line-height: var(--header-height);
35
+  z-index: 100;
36
+}
37
+
38
+.ant-layout-header {
39
+  line-height: var(--header-height);
40
+  z-index: 10;
41
+}
42
+
43
+.layout-sidebar {
44
+  width: var(--siderbar-width);
45
+  color: var(--theme-front);
46
+}
47
+
48
+.ant-card,
49
+.ant-pro-card {
50
+  border-radius: 8px !important;
51
+}
52
+.flex {
53
+  display: flex;
54
+}
55
+.flex-0 {
56
+  flex: none;
57
+}
58
+
59
+.flex-1 {
60
+  flex: 1;
61
+}
62
+
63
+// 兼容 360
64
+.ant-pro-sider-collapsed-button {
65
+  top: 18px;
66
+  right: -13px;
67
+}
68
+
69
+.ant-pro .ant-pro-layout .ant-pro-sider-logo {
70
+  padding: 16px;
71
+}
72
+
73
+.ant-pro .ant-pro-query-filter .ant-form-item {
74
+  margin: 0;
75
+}
76
+
77
+.ant-pro-page-container
78
+  .ant-pro-page-container-warp-page-header
79
+  ~ .ant-pro-grid-content
80
+  .ant-pro-page-container-children-content {
81
+  margin: 8px 40px 40px 40px;
82
+}
83
+
84
+.ant-pro-table-list-toolbar-container {
85
+  padding: 16px 0;
86
+}
87
+
88
+.ant-pro-card .ant-pro-card-body {
89
+  padding: 16px 24px;
90
+}

+ 27
- 0
src/layouts/AuthLayout/Main.jsx 查看文件

@@ -0,0 +1,27 @@
1
+import React from 'react'
2
+import { Layout } from 'antd'
3
+import { useLocation, Outlet, useNavigate } from 'react-router-dom'
4
+import { useModel } from '@/store'
5
+import useRoute from '@/routes/hooks/useRoute'
6
+import SiderBar from './components/SiderBar'
7
+import Header from './components/Header'
8
+import Container from './components/Container'
9
+
10
+import './style.less'
11
+
12
+export default (props) => {
13
+  const { theme } = useModel('system')
14
+  const { user, menus } = useModel('user')
15
+  const navigate = useNavigate()
16
+  const location = useLocation()
17
+  console.log('menus', menus)
18
+  return (
19
+    <Layout className={theme} style={{ height: '100vh' }}>
20
+      <Header theme={theme} user={user} />
21
+      <Layout style={{ height: 'calc(100vh - var(--header-height))' }}>
22
+        <SiderBar theme={theme} menus={menus} location={location} />
23
+        <Container location={location} />
24
+      </Layout>
25
+    </Layout>
26
+  )
27
+}

+ 3
- 0
src/layouts/AuthLayout/RedirectLogin.jsx 查看文件

@@ -0,0 +1,3 @@
1
+import { Navigate } from "react-router-dom";
2
+
3
+export default () => <Navigate to="/login?back=true" />;

+ 31
- 0
src/layouts/AuthLayout/RequireLogin.jsx 查看文件

@@ -0,0 +1,31 @@
1
+import React, { useState, useEffect } from "react";
2
+import { useNavigate } from "react-router-dom";
3
+import { useModel } from "@/store";
4
+
5
+export default (props) => {
6
+  const { user, getCurrentUser } = useModel("user");
7
+  const navigate = useNavigate();
8
+  const [userStatus, setUserStatus] = useState(user && user.userId ? 1 : 0);
9
+
10
+  useEffect(() => {
11
+    if (!user || !user.userId) {
12
+      getCurrentUser()
13
+        .then((res) => {
14
+          setUserStatus(1);
15
+        })
16
+        .catch((err) => {
17
+          console.error(err);
18
+          setUserStatus(-1);
19
+        });
20
+    }
21
+  }, []);
22
+
23
+  useEffect(() => {
24
+    if (userStatus === -1) {
25
+      navigate("/login");
26
+      return;
27
+    }
28
+  }, [userStatus]);
29
+
30
+  return userStatus < 1 ? null : props.children;
31
+};

+ 72
- 0
src/layouts/AuthLayout/components/Background.jsx 查看文件

@@ -0,0 +1,72 @@
1
+import React from 'react'
2
+
3
+const wrapperStyle = {
4
+  width: '100%',
5
+  height: '100%',
6
+  position: 'absolute',
7
+  zIndex: 0,
8
+  top: 0,
9
+  left: 0,
10
+  overflow: 'hidden',
11
+}
12
+
13
+const colors = [
14
+  '#fff1f0',
15
+  '#fff2e8',
16
+  '#fff7e6',
17
+  '#fffbe6',
18
+  '#feffe6',
19
+  '#fcffe6',
20
+  '#f6ffed',
21
+  '#e6fffb',
22
+  '#e6f4ff',
23
+  '#f0f5ff',
24
+  '#f9f0ff',
25
+  '#fff0f6',
26
+]
27
+
28
+export default (props) => {
29
+  const ref = React.useRef();
30
+
31
+  const [color1, color2] = React.useMemo(() => {
32
+    const inx1 = Math.floor(Math.random() * colors.length);
33
+    const inx2 = Math.floor(Math.random() * colors.length);
34
+
35
+    return [colors[inx1], colors[inx2]];
36
+  }, []);
37
+
38
+  React.useEffect(() => {
39
+    const dom = ref.current;
40
+    const canvas = dom.firstElementChild;
41
+    canvas.width = dom.offsetWidth;
42
+    canvas.height = dom.offsetHeight;
43
+
44
+    const centerX = canvas.width / 2;
45
+    const centerY = canvas.height / 2;
46
+    const size = centerX / 3
47
+
48
+    const ctx = canvas.getContext("2d");
49
+    
50
+    ctx.filter = `blur(200px)`;
51
+
52
+    ctx.beginPath()
53
+    ctx.fillStyle = color1; // "#ffd8bf";
54
+    ctx.ellipse(centerX + 100, centerY + 80, size, size + Math.random() * 100, Math.PI / 4, 0, 2 * Math.PI);
55
+    ctx.fill();
56
+    ctx.closePath();
57
+
58
+    ctx.beginPath()
59
+    ctx.fillStyle = color2; // "#e6fffb";
60
+    ctx.ellipse(centerX + 400, centerY + 120, size, size + Math.random() * 100, Math.PI / 2, 0, 2 * Math.PI);
61
+    ctx.fill();
62
+    ctx.closePath();
63
+
64
+  }, []);
65
+
66
+  return (
67
+    <div ref={ref} style={wrapperStyle}>
68
+      <canvas>
69
+      </canvas>
70
+    </div>
71
+  )
72
+}

+ 31
- 0
src/layouts/AuthLayout/components/Container.jsx 查看文件

@@ -0,0 +1,31 @@
1
+import React from 'react';
2
+import { Layout } from 'antd';
3
+import { Outlet } from "react-router-dom";
4
+import PageTransition from './PageTransition';
5
+import Footer from './Footer';
6
+
7
+const { Content } = Layout;
8
+const marginSpace = 24;
9
+
10
+export default (props) => {
11
+  const { noFooter } = props;
12
+  const footerRef = React.useRef();
13
+  const [height, setHeight] = React.useState(`calc(100% - ${marginSpace * 2}px`);
14
+
15
+  React.useEffect(() => {
16
+    if (footerRef.current) {
17
+      setHeight(`calc(100% - ${footerRef.current.offsetHeight + marginSpace * 2}px)`);
18
+    }
19
+  }, [noFooter])
20
+
21
+  return (
22
+    <div className='layout-container'>
23
+      <Content style={{ minHeight: height, margin: `0 ${marginSpace}px`}}>
24
+        <PageTransition location={props.location}>
25
+          <Outlet />
26
+        </PageTransition>
27
+      </Content>
28
+      {!noFooter && <Footer ref={footerRef} />}
29
+    </div>
30
+  )
31
+}

+ 15
- 0
src/layouts/AuthLayout/components/Footer.jsx 查看文件

@@ -0,0 +1,15 @@
1
+import React from 'react';
2
+import { Layout } from 'antd';
3
+import { useModel } from '@/store';
4
+
5
+const { Footer } = Layout;
6
+
7
+const year = new Date().getFullYear();
8
+export default React.forwardRef((props, ref) => {
9
+  const { app } = useModel('system');
10
+  const copyRight = `${app.company || '南京云致'} @ ${year}`;
11
+
12
+  return (
13
+    <Footer ref={ref} style={{ textAlign: 'center', color: 'rgba(0,0,0, 0.3)' }}>{copyRight}</Footer>
14
+  )
15
+})

+ 35
- 0
src/layouts/AuthLayout/components/Header/Exit.jsx 查看文件

@@ -0,0 +1,35 @@
1
+import React from "react";
2
+import { useNavigate } from "react-router-dom";
3
+import { LogoutOutlined } from "@ant-design/icons";
4
+import { Button, Modal } from "antd";
5
+import { useModel } from "@/store";
6
+
7
+const { confirm } = Modal;
8
+
9
+export default (props) => {
10
+  const navigate = useNavigate();
11
+  const { setUser } = useModel("user");
12
+
13
+  const onExit = () => {
14
+    confirm({
15
+      title: "确认退出系统?",
16
+      onOk: () => {
17
+        // logout(); // 调用接口
18
+        localStorage.removeItem("token");
19
+        setUser();
20
+        navigate("/login?back=true");
21
+      },
22
+    });
23
+  };
24
+
25
+  return (
26
+    <Button
27
+      className="font"
28
+      type="text"
29
+      icon={<LogoutOutlined />}
30
+      onClick={onExit}
31
+    >
32
+      退出
33
+    </Button>
34
+  );
35
+};

+ 24
- 0
src/layouts/AuthLayout/components/Header/Title.jsx 查看文件

@@ -0,0 +1,24 @@
1
+
2
+import useRoute from '@/routes/hooks/useRoute';
3
+
4
+const titleStyle = {
5
+  margin: 0,
6
+}
7
+
8
+const spanStyle = {
9
+  display: 'inline-block',
10
+  width: '24px',
11
+  textAlign: 'center'
12
+}
13
+
14
+export default (props) => {
15
+  const route = useRoute();
16
+  const { title } = route && route.meta || {}
17
+
18
+  return (
19
+    <h5 style={titleStyle}>
20
+      { title && <span style={spanStyle}>&raquo;</span> }
21
+      { title && <span>{title}</span> }
22
+    </h5>
23
+  );
24
+}

+ 122
- 0
src/layouts/AuthLayout/components/Header/User.jsx 查看文件

@@ -0,0 +1,122 @@
1
+import React, {
2
+  useState,
3
+  forwardRef,
4
+  useRef,
5
+  useImperativeHandle,
6
+} from "react";
7
+import { Avatar, Dropdown } from "antd";
8
+import {
9
+  ModalForm,
10
+  ProFormText,
11
+  ProFormDependency,
12
+} from "@ant-design/pro-components";
13
+import md5 from "md5";
14
+import { changePassword } from "@/services/login";
15
+
16
+const DefaultAvatar = ({ color = "#1296db" }) => (
17
+  <svg
18
+    viewBox="0 0 1024 1024"
19
+    version="1.1"
20
+    xmlns="http://www.w3.org/2000/svg"
21
+    width="24"
22
+    height="24"
23
+  >
24
+    <path
25
+      d="M938.666667 883.2c0-8.533333 0-42.666667-21.333334-81.066667-12.8-25.6-34.133333-42.666667-59.733333-59.733333-29.866667-17.066667-68.266667-34.133333-115.2-42.666667-4.266667 0-34.133333-4.266667-59.733333-12.8-29.866667-8.533333-42.666667-12.8-46.933334-17.066666v-25.6c4.266667-55.466667 34.133333-85.333333 59.733334-110.933334 8.533333-8.533333 17.066667-17.066667 25.6-29.866666 29.866667-42.666667 34.133333-85.333333 34.133333-93.866667 0-8.533333 0-12.8-4.266667-21.333333s-8.533333-17.066667-12.8-21.333334c0-12.8 4.266667-25.6 4.266667-34.133333 0-21.333333 4.266667-55.466667-4.266667-89.6 0-4.266667 0-12.8-4.266666-21.333333-8.533333-25.6-17.066667-46.933333-34.133334-64-8.533333 0-68.266667-59.733333-230.4-72.533334H405.333333c-8.533333 0-17.066667 0-25.6 4.266667-29.866667 8.533333-34.133333 29.866667-38.4 38.4v25.6l-4.266666 4.266667c-4.266667 4.266667-46.933333 42.666667-51.2 93.866666-4.266667 34.133333-4.266667 85.333333 0 123.733334-4.266667 8.533333-12.8 17.066667-12.8 38.4 0 8.533333 4.266667 51.2 34.133333 89.6 8.533333 8.533333 12.8 17.066667 25.6 29.866666 25.6 29.866667 55.466667 59.733333 59.733333 110.933334v25.6c-8.533333 4.266667-21.333333 12.8-51.2 21.333333s-59.733333 12.8-64 12.8c-42.666667 8.533333-81.066667 21.333333-110.933333 38.4-25.6 17.066667-46.933333 38.4-59.733333 59.733333-21.333333 38.4-21.333333 72.533333-21.333334 81.066667v21.333333c0 17.066667 17.066667 34.133333 38.4 34.133334h776.533334c21.333333 0 38.4-17.066667 38.4-38.4v-17.066667z"
26
+      fill={color}
27
+    ></path>
28
+  </svg>
29
+);
30
+
31
+const ChangePassword = forwardRef((props, ref) => {
32
+  const { user } = props;
33
+
34
+  const [visible, setVisible] = useState(false);
35
+
36
+  const onFinish = async (values) => {
37
+    const data = {
38
+      originPassword: md5(values.password),
39
+      newPassword: md5(values.newPassword),
40
+    };
41
+
42
+    await changePassword(user.userId, data);
43
+
44
+    return true;
45
+  };
46
+
47
+  useImperativeHandle(ref, () => {
48
+    return {
49
+      show: () => setVisible(true),
50
+    };
51
+  });
52
+
53
+  return (
54
+    <ModalForm
55
+      title="修改密码"
56
+      width="480px"
57
+      open={visible}
58
+      onOpenChange={setVisible}
59
+      onFinish={onFinish}
60
+    >
61
+      <ProFormText.Password
62
+        label="原始密码"
63
+        name="password"
64
+        rules={[{ required: true, message: "请输入原始密码!" }]}
65
+      />
66
+      <ProFormText.Password
67
+        label="新密码"
68
+        name="newPassword"
69
+        rules={[{ required: true, message: "请输入新密码!" }]}
70
+      />
71
+
72
+      <ProFormDependency name={["newPassword"]}>
73
+        {({ newPassword }) => (
74
+          <ProFormText.Password
75
+            label="确认新密码"
76
+            name="newPassword2"
77
+            rules={[
78
+              { required: true, message: "请输入新密码!" },
79
+              () => ({
80
+                validator (_, value) {
81
+                  if (!value || value == newPassword) {
82
+                    return Promise.resolve();
83
+                  }
84
+
85
+                  return Promise.reject("两次输入密码不一致");
86
+                },
87
+              }),
88
+            ]}
89
+          />
90
+        )}
91
+      </ProFormDependency>
92
+    </ModalForm>
93
+  );
94
+});
95
+
96
+export default (props) => {
97
+  const items = [
98
+    {
99
+      key: "changePassword",
100
+      label: "修改密码",
101
+    },
102
+  ];
103
+
104
+  const passRef = useRef();
105
+  const { user = {} } = props;
106
+
107
+  const onClick = ({ key }) => {
108
+    if (key === "changePassword") {
109
+      passRef.current.show();
110
+    }
111
+  };
112
+
113
+  return (
114
+    <Dropdown menu={{ items, onClick }}>
115
+      <div className="user-info">
116
+        <Avatar size={24} src={user.avatar || <DefaultAvatar />} />
117
+        <span className="font">{user.name || 'admin'}</span>
118
+        <ChangePassword user={user} ref={passRef} />
119
+      </div>
120
+    </Dropdown>
121
+  );
122
+};

+ 28
- 0
src/layouts/AuthLayout/components/Header/index.jsx 查看文件

@@ -0,0 +1,28 @@
1
+import React, { useMemo } from 'react';
2
+import { Layout, Space } from 'antd';
3
+import classNames from 'classnames';
4
+import Title from './Title';
5
+import User from './User';
6
+import Exit from './Exit';
7
+import Logo from '../Logo';
8
+
9
+const { Header } = Layout;
10
+
11
+export default (props) => {
12
+  const { user } = props;
13
+
14
+  const className = useMemo(() => classNames({
15
+    'layout-header': true,
16
+    'light': props.theme === 'light',
17
+  }), [props.theme]);
18
+
19
+  return (
20
+    <Header className={className}>
21
+      <Logo />
22
+      <Space>
23
+        <User user={user} />
24
+        <Exit />
25
+      </Space>
26
+    </Header>
27
+  )
28
+}

+ 19
- 0
src/layouts/AuthLayout/components/HtmlTitle.jsx 查看文件

@@ -0,0 +1,19 @@
1
+
2
+import { Helmet } from "react-helmet";
3
+import { useModel } from '@/store';
4
+import useRoute from '@/routes/hooks/useRoute';
5
+
6
+export default (props) => {
7
+  const { app } = useModel('system');
8
+  const route = useRoute();
9
+  const { title } = route && route.meta || {}
10
+  
11
+  const titleTemplate = `%s - ${app.fullName}`;
12
+  const defaultTitle = app.fullName;
13
+
14
+  return (
15
+    <Helmet titleTemplate={titleTemplate} defaultTitle={defaultTitle}>
16
+      <title>{title}</title>
17
+    </Helmet>
18
+  );
19
+}

+ 17
- 0
src/layouts/AuthLayout/components/Logo.jsx 查看文件

@@ -0,0 +1,17 @@
1
+import React from 'react';
2
+import { Typography } from 'antd';
3
+import { NavLink } from "react-router-dom";
4
+import { useModel } from '@/store';
5
+
6
+export default (props) => {
7
+  const { app } = useModel('system');
8
+
9
+  return (
10
+    // <NavLink className='logo'  to="/">
11
+    <div className="logo">
12
+      <img src="./logo.png" alt="" />
13
+      <h3>{app.shorName}</h3>
14
+    </div>
15
+    // </NavLink>
16
+  )
17
+}

+ 36
- 0
src/layouts/AuthLayout/components/Menus.jsx 查看文件

@@ -0,0 +1,36 @@
1
+import React from 'react'
2
+import { Menu } from 'antd'
3
+
4
+const menuStyle = { height: '100%' }
5
+
6
+export default (props) => {
7
+  const { theme, items, location } = props
8
+
9
+  // const selectedKeys = React.useMemo(() => {
10
+  //   const parts = location.pathname.split('/').filter(Boolean);
11
+  //   const keys = parts.reduce((acc, it) => {
12
+  //     const parent = acc.pop();
13
+  //     const path = !parent ? `/${it}` : `${parent}/${it}`
14
+
15
+  //     return acc.concat([parent, path].filter(Boolean));
16
+  //   }, []);
17
+
18
+  //   return keys;
19
+  // }, [location.pathname]);
20
+
21
+  // const handClick = (e) => {
22
+  //   console.log('e', e)
23
+  //   navigate(`${e.key}`)
24
+  // }
25
+  const selectedKeys = [location.pathname]
26
+  return (
27
+    <Menu
28
+      // onClick={handClick}
29
+      mode="inline"
30
+      style={menuStyle}
31
+      theme={theme}
32
+      items={items}
33
+      selectedKeys={selectedKeys}
34
+    />
35
+  )
36
+}

+ 21
- 0
src/layouts/AuthLayout/components/PageTransition/index.jsx 查看文件

@@ -0,0 +1,21 @@
1
+import { TransitionGroup, CSSTransition } from 'react-transition-group';
2
+import './style.less';
3
+
4
+export default (props) => {
5
+  const { location } = props;
6
+  const currentURL = location.pathname + location.search;
7
+
8
+  return (
9
+    <TransitionGroup component={null}>
10
+      <CSSTransition
11
+        key={currentURL}
12
+        addEndListener={(node, done) => node.addEventListener("transitionend", done, false)}
13
+        classNames="page-fade"
14
+      >
15
+        <div style={{ height: '100%' }}>
16
+          {props.children}
17
+        </div>
18
+      </CSSTransition>
19
+    </TransitionGroup>
20
+  );
21
+}

+ 21
- 0
src/layouts/AuthLayout/components/PageTransition/style.less 查看文件

@@ -0,0 +1,21 @@
1
+
2
+.page-fade-enter {
3
+  opacity: 0;
4
+  transform: translateY(10%);
5
+}
6
+.page-fade-enter-active {
7
+  opacity: 1;
8
+  transform: translateY(0%);
9
+}
10
+.page-fade-exit {
11
+  opacity: 0; // 1;
12
+  transform: translateY(0%);
13
+}
14
+.page-fade-exit-active {
15
+  opacity: 0;
16
+  transform: translateY(10%);
17
+}
18
+.page-fade-enter-active,
19
+.page-fade-exit-active {
20
+  transition: opacity 220ms, transform 220ms;
21
+}

+ 19
- 0
src/layouts/AuthLayout/components/SiderBar.jsx 查看文件

@@ -0,0 +1,19 @@
1
+import React, { useMemo } from 'react'
2
+import { Layout, Spin } from 'antd'
3
+import { getPropertyValue } from '@/utils/css'
4
+import Menus from './Menus'
5
+
6
+const { Sider } = Layout
7
+
8
+export default (props) => {
9
+  const { theme, location, menus } = props
10
+
11
+  const width = useMemo(() => {
12
+    return /\d+/.exec(getPropertyValue('--siderbar-width'))[0] - 0
13
+  }, [])
14
+  return (
15
+    <Sider className="layout-sidebar" theme={theme} collapsible width={width}>
16
+      <Menus theme={theme} items={menus} location={location} />
17
+    </Sider>
18
+  )
19
+}

+ 51
- 0
src/layouts/AuthLayout/index.jsx 查看文件

@@ -0,0 +1,51 @@
1
+import React from 'react'
2
+import { Spin, Layout } from 'antd'
3
+import HtmlTitle from './components/HtmlTitle'
4
+// import Main from './Main';
5
+import { useLocation, useNavigate } from 'react-router-dom'
6
+import { useModel } from '@/store'
7
+
8
+import SiderBar from './components/SiderBar'
9
+import Header from './components/Header'
10
+import Container from './components/Container'
11
+import { authRoutes } from '@/routes/routes'
12
+import { getMenuItems } from '@/routes/menus'
13
+import RequireLogin from './RequireLogin'
14
+import './style.less'
15
+
16
+const Spinner = () => (
17
+  <div
18
+    style={{
19
+      width: '100%',
20
+      height: '100%',
21
+      display: 'grid',
22
+      placeItems: 'center',
23
+    }}
24
+  >
25
+    <Spin />
26
+  </div>
27
+)
28
+
29
+export default (props) => {
30
+  const { theme } = useModel('system')
31
+  const { user, menus } = useModel('user')
32
+  const navigate = useNavigate()
33
+  const location = useLocation()
34
+  // console.log('menus', menus)
35
+  return (
36
+    <Spin spinning={!user} size="large">
37
+      <HtmlTitle />
38
+      {/* <React.Suspense fallback={<Spinner />}> */}
39
+      <RequireLogin>
40
+        <Layout className={theme} style={{ height: '100vh' }}>
41
+          <Header theme={theme} user={user} />
42
+          <Layout style={{ height: 'calc(100vh - var(--header-height))' }}>
43
+            <SiderBar theme="light" menus={menus} location={location} />
44
+            <Container location={location} />
45
+          </Layout>
46
+        </Layout>
47
+      </RequireLogin>
48
+      {/* </React.Suspense> */}
49
+    </Spin>
50
+  )
51
+}

+ 80
- 0
src/layouts/AuthLayout/style.less 查看文件

@@ -0,0 +1,80 @@
1
+.layout-header {
2
+  height: var(--header-height);
3
+  box-sizing: border-box;
4
+  padding: 0;
5
+  display: flex;
6
+  align-items: center;
7
+  justify-content: space-between;
8
+  color: #fff;
9
+
10
+  &.light {
11
+    color: #000;
12
+  }
13
+
14
+  .header-content {
15
+    flex: 1;
16
+  }
17
+
18
+  .font {
19
+    color: inherit;
20
+    display: inline-block;
21
+  }
22
+
23
+  .user-info {
24
+    cursor: pointer;
25
+
26
+    .ant-avatar {
27
+      border: 1px solid rgba(255, 255, 255, 0.4);
28
+    }
29
+
30
+    span {
31
+      margin-left: 1em;
32
+    }
33
+  }
34
+
35
+  .sys-exit {
36
+    margin-right: 1em;
37
+  }
38
+}
39
+
40
+.logo {
41
+  height: var(--header-height);
42
+  display: flex;
43
+  align-items: center;
44
+  box-sizing: border-box;
45
+  padding-left: 1em;
46
+  color: inherit;
47
+
48
+  & > * {
49
+    color: inherit;
50
+    margin: 0;
51
+  }
52
+
53
+  h5 {
54
+    margin: 0;
55
+  }
56
+
57
+  img {
58
+    width: 28px;
59
+    vertical-align: middle;
60
+    margin-right: 1em;
61
+  }
62
+}
63
+
64
+.layout-container {
65
+  flex: 1;
66
+
67
+  overflow-y: auto;
68
+  scrollbar-width: none;
69
+  -ms-overflow-style: none;
70
+
71
+  &::--webkit-scrollbar {
72
+    display: none;
73
+  }
74
+
75
+  padding-top: 0; // 避免子元素的 margin 影响
76
+}
77
+
78
+.ant-menu-vertical {
79
+  border: none;
80
+}

+ 28
- 0
src/layouts/AuthLayout/withLogin.jsx 查看文件

@@ -0,0 +1,28 @@
1
+import React from "react";
2
+import store from "@/store";
3
+
4
+export default function withLogin (factory) {
5
+  return new Promise((resolve) => {
6
+    const { user, getCurrentUser } = store.getState("user");
7
+    const loged = user && (user.userId || user.id);
8
+
9
+    if (loged) {
10
+      resolve(factory);
11
+    } else {
12
+      let ticket = undefined;
13
+      const match = window.location?.href?.match(/ticket=([^?&/]*)/);
14
+      if (match?.length > 0) {
15
+        ticket = match[1];
16
+      }
17
+
18
+      getCurrentUser({ ticket: ticket })
19
+        .then(() => {
20
+          resolve(factory);
21
+        })
22
+        .catch((e) => {
23
+          console.error(e);
24
+          resolve(import("./RedirectLogin"));
25
+        });
26
+    }
27
+  });
28
+}

+ 16
- 0
src/main.jsx 查看文件

@@ -0,0 +1,16 @@
1
+import React from 'react';
2
+import ReactDOM from 'react-dom/client';
3
+import Background from './layouts/AuthLayout/components/Background';
4
+import Router from './routes/Router';
5
+import './index.less';
6
+import { Provider } from './store';
7
+import { initTokenIfExists } from './utils/sso';
8
+
9
+initTokenIfExists();
10
+
11
+ReactDOM.createRoot(document.getElementById('root')).render(
12
+  <Provider>
13
+    <Background />
14
+    <Router />
15
+  </Provider>
16
+);

+ 29
- 0
src/pages/404/index.jsx 查看文件

@@ -0,0 +1,29 @@
1
+import React from 'react';
2
+import { Button, Result } from 'antd';
3
+import { Helmet } from "react-helmet";
4
+import { NavLink } from "react-router-dom";
5
+import { useModel } from '@/store';
6
+
7
+const style = {
8
+  display: 'grid',
9
+  placeItems: 'center',
10
+  height: '100%'
11
+}
12
+
13
+export default (props) => {
14
+  const { app } = useModel('system');
15
+
16
+  return (
17
+    <div style={style}>
18
+      <Helmet>
19
+        <title>{app.fullName}</title>
20
+      </Helmet>
21
+      <Result
22
+        status="404"
23
+        title="404"
24
+        subTitle="页面不存在"
25
+        extra={<NavLink to="/" replace><Button type="primary">返回首页</Button></NavLink>}
26
+      />
27
+    </div>
28
+  )
29
+}

+ 56
- 0
src/pages/article/Detail.jsx 查看文件

@@ -0,0 +1,56 @@
1
+import React, { useRef, useState } from 'react'
2
+import Page from '@/components/Page'
3
+import { Button, Input, Descriptions, Form, Image, Card, Row, Col, Space, Tag } from 'antd'
4
+
5
+export default (props) => {
6
+
7
+  const { list } = props;
8
+
9
+  return (
10
+    <Page>
11
+      <Card bordered={false}>
12
+        <Descriptions layout="vertical" bordered>
13
+          <Descriptions.Item label="标题">AIgc</Descriptions.Item>
14
+          <Descriptions.Item label="描述" span={2}>我喜欢的智能</Descriptions.Item>
15
+          <Descriptions.Item label="正文" span={3}>
16
+            AIGC,全称为AI-Generated Content,是指基于人工智能技术自动生成各种类型的内容,如文本、图像、声音、视频等。它利用已有数据寻找规律,并自
17
+            动生成内容,既是一种内容分类方式,也是一种内容生产方式,还是一种用于内容自动生成的一类技术集合。
18
+            AIGC涵盖了人工智能、计算机图形学和深度学习等领域技术的综合平台,其目的在于将这些技术结合起来,实现更加高效、智能化的图像识别和处理,提升
19
+            人机交互的用户体验。与百度AI文心一言和ChatGPT相比,AIGC主要侧重于图像识别与处理等技术,而百度AI文心一言则更侧重于自然语言处理。
20
+            AIGC在多个领域具有广泛的应用。在智能安防领域,它可以通过图像识别技术实现人脸识别、车辆识别等功能,提升安全监控的效率和准确性。在游戏和
21
+            虚拟现实领域,AIGC可以实现高度逼真的图像渲染和物理模拟,提升游戏体验。此外,AIGC还可以参与内容共创,推动媒体融合转型,参与制作全流程,推
22
+            进虚实交融,提供发展动能,助力产业加快升级等。
23
+            具体来说,AIGC可以生成高质量、独特的图像作品,包括绘画、插图、设计、艺术品等;可以创作音乐、歌曲、声音效果或其他音频内容,提供新颖和多样
24
+            化的音乐体验;可以生成影片、动画、短视频等,具备专业级的画面效果和剧情呈现;还可以生成3D模型、场景、动画等,为游戏开发、虚拟现实和影视制
25
+            作提供多样化的创意和设计。
26
+            然而,尽管AIGC具有强大的创造力,但仍然需要人类的指导和监督,以确保创作的质量和道德性。在创作过程中,AIGC会遵循人类设定的规则和算法,但其
27
+            结果仍然需要人类进行审查和评估,以确保内容符合社会价值观和法律法规。
28
+            总的来说,AIGC是一种强大的内容生成工具,其应用前景广阔,将在未来为人们的生活带来更多便利和乐趣。
29
+          </Descriptions.Item>
30
+          <Descriptions.Item label="标签">
31
+            <Tag color="red">ai</Tag>
32
+            <Tag color="red">智能</Tag>
33
+          </Descriptions.Item>
34
+          <Descriptions.Item label="横向封面图">
35
+            <Image src="https://gw.alipayobjects.com/zos/antfincdn/cV16ZqzMjW/photo-1473091540282-9b846e7965e3.webp" width={80} />
36
+          </Descriptions.Item>
37
+          <Descriptions.Item label="纵向封面图">
38
+            <Image src="https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp" width={80} />
39
+          </Descriptions.Item>
40
+          <Descriptions.Item label="图片">
41
+            <Image src="https://gw.alipayobjects.com/zos/antfincdn/aPkFc8Sj7n/method-draw-image.svg" width={80} />
42
+          </Descriptions.Item>
43
+          <Descriptions.Item label="分类">
44
+            人工智能
45
+          </Descriptions.Item>
46
+          <Descriptions.Item label="链接地址">
47
+            https://www.baidu.com/
48
+          </Descriptions.Item>
49
+          <Descriptions.Item label="附件" span={3}>
50
+
51
+          </Descriptions.Item>
52
+        </Descriptions>
53
+      </Card>
54
+    </Page>
55
+  )
56
+}

+ 49
- 0
src/pages/article/Edit.jsx 查看文件

@@ -0,0 +1,49 @@
1
+import React, { useRef, useState } from 'react'
2
+import { Button, Input, Form } from 'antd'
3
+import Edit from '@/components/Page/Edit'
4
+import Wangeditor from '@/components/Wangeditor'
5
+import UploadFile from '@/components/Upload/UploadFile'
6
+import UploadImages from '@/components/Upload/UploadImages'
7
+import UploadImageList from '@/components/Upload/UploadImageList'
8
+
9
+export default (props) => {
10
+
11
+  const onFinish = () => { }
12
+
13
+  return (
14
+    <Edit
15
+      onFinish={onFinish}
16
+    >
17
+      <Form.Item label="文章标题" required>
18
+        <Input placeholder="请输入" />
19
+      </Form.Item>
20
+      <Form.Item label="文章描述">
21
+        <Input placeholder="请输入" />
22
+      </Form.Item>
23
+      <Form.Item label="文章正文">
24
+        <Wangeditor />
25
+      </Form.Item>
26
+      <Form.Item label="文章标签">
27
+        <Input placeholder="请输入" />
28
+      </Form.Item>
29
+      <Form.Item label="横向封面图">
30
+        <UploadImages ratio={0.5} />
31
+      </Form.Item>
32
+      <Form.Item label="纵向封面图">
33
+        <UploadImages ratio={'100:200'} />
34
+      </Form.Item>
35
+      <Form.Item label="文章图片">
36
+        <UploadImageList />
37
+      </Form.Item>
38
+      <Form.Item label="文章分类">
39
+        <Input placeholder="请输入" />
40
+      </Form.Item>
41
+      <Form.Item label="链接地址">
42
+        <Input placeholder="请输入" />
43
+      </Form.Item>
44
+      <Form.Item label="文章附件">
45
+        <UploadFile />
46
+      </Form.Item>
47
+    </Edit>
48
+  )
49
+}

+ 119
- 0
src/pages/article/index.jsx 查看文件

@@ -0,0 +1,119 @@
1
+import React, { useRef, useState } from 'react'
2
+import List from '@/components/Page/List'
3
+import { Button, Tag, Image } from 'antd'
4
+import { useNavigate } from 'react-router-dom'
5
+
6
+export default (props) => {
7
+  const navigate = useNavigate();
8
+
9
+  const columns = [
10
+    {
11
+      title: '标题',
12
+      dataIndex: 'title',
13
+      ellipsis: true,
14
+    },
15
+    {
16
+      title: '描述',
17
+      dataIndex: 'describe',
18
+      ellipsis: true,
19
+      search: false,
20
+    },
21
+    {
22
+      title: '正文',
23
+      dataIndex: 'content',
24
+      ellipsis: { showTitle: false },
25
+      search: false,
26
+    },
27
+    {
28
+      title: '标签',
29
+      dataIndex: 'tag',
30
+      search: false,
31
+      render: (_, it) => <Tag color="red">{it?.tag}</Tag>
32
+    },
33
+    {
34
+      title: '横向封面图',
35
+      dataIndex: 'HImg',
36
+      render: (_, it) => <Image src={it?.HImg} width={80} />,
37
+      search: false,
38
+    },
39
+    {
40
+      title: '纵向封面图',
41
+      dataIndex: 'VImg',
42
+      render: (_, it) => <Image src={it?.VImg} width={80} />,
43
+      search: false,
44
+    },
45
+    {
46
+      title: '图片',
47
+      dataIndex: 'img',
48
+      render: (_, it) => <Image src={it?.img} width={80} />,
49
+      search: false,
50
+    },
51
+    {
52
+      title: '分类',
53
+      dataIndex: 'classify'
54
+    },
55
+    {
56
+      title: '链接地址',
57
+      dataIndex: 'link',
58
+      ellipsis: true,
59
+      render: (_, it) => <a href="#">{it?.link}</a>,
60
+      search: false,
61
+    },
62
+    {
63
+      title: '附件',
64
+      dataIndex: 'attachment',
65
+      search: false,
66
+    }
67
+  ]
68
+
69
+  const dataSource = [
70
+    {
71
+      id: 1,
72
+      title: 'AIgc',
73
+      describe: '我喜欢的智能',
74
+      content: 'AIGC,全称为AI-Generated Content,是指基于人工智能技术自动生成各种类型的内容,如文本、图像、声音、视频等。它利用已有数据寻找规律,并自动生成内容,既是一种内容分类方式,也是一种内容生产方式,还是一种用于内容自动生成的一类技术集合。AIGC涵盖了人工智能、计算机图形学和深度学习等领域技术的综合平台,其目的在于将这些技术结合起来,实现更加高效、智能化的图像识别和处理,提升人机交互的用户体验。与百度AI文心一言和ChatGPT相比,AIGC主要侧重于图像识别与处理等技术,而百度AI文心一言则更侧重于自然语言处理。AIGC在多个领域具有广泛的应用。在智能安防领域,它可以通过图像识别技术实现人脸识别、车辆识别等功能,提升安全监控的效率和准确性。在游戏和虚拟现实领域,AIGC可以实现高度逼真的图像渲染和物理模拟,提升游戏体验。此外,AIGC还可以参与内容共创,推动媒体融合转型,参与制作全流程,推进虚实交融,提供发展动能,助力产业加快升级等。具体来说,AIGC可以生成高质量、独特的图像作品,包括绘画、插图、设计、艺术品等;可以创作音乐、歌曲、声音效果或其他音频内容,提供新颖和多样化的音乐体验;可以生成影片、动画、短视频等,具备专业级的画面效果和剧情呈现;还可以生成3D模型、场景、动画等,为游戏开发、虚拟现实和影视制作提供多样化的创意和设计。然而,尽管AIGC具有强大的创造力,但仍然需要人类的指导和监督,以确保创作的质量和道德性。在创作过程中,AIGC会遵循人类设定的规则和算法,但其结果仍然需要人类进行审查和评估,以确保内容符合社会价值观和法律法规。总的来说,AIGC是一种强大的内容生成工具,其应用前景广阔,将在未来为人们的生活带来更多便利和乐趣。',
75
+      tag: 'ai',
76
+      HImg: 'https://gw.alipayobjects.com/zos/antfincdn/cV16ZqzMjW/photo-1473091540282-9b846e7965e3.webp',
77
+      VImg: 'https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp',
78
+      img: 'https://gw.alipayobjects.com/zos/antfincdn/aPkFc8Sj7n/method-draw-image.svg',
79
+      classify: '人工智能',
80
+      link: 'https://www.baidu.com/',
81
+    }
82
+  ]
83
+
84
+  const onEdit = (_, it) => {
85
+    navigate(`/article/edit?id=${'it.id'}`)
86
+  }
87
+
88
+  return (
89
+    <List
90
+      rowKey="id"
91
+      columns={columns}
92
+      dataSource={dataSource}
93
+      onEdit={onEdit}
94
+      request={{}}
95
+      toolBarRender={() => [
96
+        <Button
97
+          key="2"
98
+          type="primary"
99
+          onClick={() => {
100
+            navigate('/article/edit')
101
+          }}
102
+        >
103
+          新增
104
+        </Button>
105
+      ]}
106
+      columnOptionRender={() => [
107
+        <Button
108
+          key="3"
109
+          type="link"
110
+          onClick={() => {
111
+            navigate('/article/detail')
112
+          }}
113
+        >
114
+          详情
115
+        </Button>,
116
+      ]}
117
+    />
118
+  )
119
+}

+ 11
- 0
src/pages/login/Effect.jsx 查看文件

@@ -0,0 +1,11 @@
1
+import React from "react";
2
+
3
+export default (props) => {
4
+  return (
5
+    <div className="login-effect-box">
6
+      <div className="login-effect">
7
+        <div className="login-effect-arc"></div>
8
+      </div>
9
+    </div>
10
+  );
11
+};

+ 67
- 0
src/pages/login/LoginForm.jsx 查看文件

@@ -0,0 +1,67 @@
1
+import React from "react";
2
+import md5 from "md5";
3
+import { Button, Form, Input, Radio } from "antd";
4
+import { login } from "@/services/login";
5
+
6
+export default (props) => {
7
+  const { onSuccess, mode, appid } = props;
8
+  const [form] = Form.useForm();
9
+  const [loading, setLoading] = React.useState(false);
10
+  console.log(process.env.NODE_ENV);
11
+  const onFinish = (values) => {
12
+    setLoading(true);
13
+    login({
14
+      loginName: values.loginName,
15
+      loginType: "platform.pc",
16
+      password: md5(values.password),
17
+    })
18
+      .then((res) => {
19
+        setLoading(true);
20
+        onSuccess(res.user);
21
+        setLoading(false);
22
+      })
23
+      .catch((err) => {
24
+        // console.log('----err--', err);
25
+        setLoading(false);
26
+      });
27
+
28
+    setLoading(false);
29
+  };
30
+  return (
31
+    <Form
32
+      form={form}
33
+      layout="vertical"
34
+      onFinish={onFinish}
35
+    // style={{ width: "260px", marginTop: "24px", paddingBottom: "24px" }}
36
+    >
37
+      <Form.Item
38
+        label="账户"
39
+        name="loginName"
40
+        rules={[{ required: true, message: "请输入账户" }]}
41
+      >
42
+        <Input placeholder="请输入账户" style={{ borderRadius: "4px" }} />
43
+      </Form.Item>
44
+      <Form.Item
45
+        label="密 码"
46
+        name="password"
47
+        rules={[{ required: true, message: "请输入密码" }]}
48
+      >
49
+        <Input.Password
50
+          placeholder="请输入密码"
51
+          style={{ borderRadius: "4px" }}
52
+        />
53
+      </Form.Item>
54
+      <Form.Item>
55
+        <Button
56
+          type="primary"
57
+          size="large"
58
+          style={{ width: "100%", marginTop: "24px", borderRadius: "4px" }}
59
+          loading={loading}
60
+          htmlType="submit"
61
+        >
62
+          登录
63
+        </Button>
64
+      </Form.Item>
65
+    </Form>
66
+  );
67
+};

+ 24
- 0
src/pages/login/Particles.jsx 查看文件

@@ -0,0 +1,24 @@
1
+import React from 'react'
2
+
3
+export default (props) => {
4
+  React.useEffect(() => {
5
+    const baseUrl = import.meta.env.BASE_URL;
6
+    const oScript = document.createElement("script");
7
+    oScript.type = "text\/javascript";
8
+    oScript.onload = () => {
9
+      particlesJS.load('particles-js', `${baseUrl}particles/particles.json`, function() {
10
+        console.log('callback - particles.js config loaded');
11
+      });
12
+    }
13
+    document.querySelector('head').appendChild(oScript);
14
+    oScript.src = `${baseUrl}particles/particles.min.js`;
15
+
16
+    return () => {
17
+      document.querySelector('head').removeChild(oScript);
18
+    }
19
+  }, [])
20
+
21
+  return (
22
+    <div id="particles-js"></div>
23
+  )
24
+}

+ 60
- 0
src/pages/login/index.jsx 查看文件

@@ -0,0 +1,60 @@
1
+import React, { useEffect } from "react";
2
+import { Button, message } from "antd";
3
+import { Helmet } from "react-helmet";
4
+import { useNavigate, useSearchParams } from "react-router-dom";
5
+import { useModel } from "@/store";
6
+import LoginForm from "./LoginForm";
7
+import LoginEffect from "./Effect";
8
+import Particles from './Particles';
9
+import "./style.less";
10
+
11
+const year = new Date().getFullYear();
12
+
13
+export default (props) => {
14
+  const { app } = useModel("system");
15
+  const navigate = useNavigate();
16
+  const [searchParams] = useSearchParams();
17
+
18
+  const title = `欢迎使用${app.fullName}`;
19
+  const copyright = `${app.company} @ ${year}`;
20
+
21
+  const onChangeType = () => {
22
+    setLoginType(loginType == 0 ? 1 : 0);
23
+  };
24
+
25
+  const onSuccess = (row) => {
26
+    try {
27
+      navigate("/article");
28
+    } catch (e) {
29
+      message.error(e);
30
+    }
31
+  };
32
+
33
+  return (
34
+    <div className="login-page">
35
+      <Helmet>
36
+        <title>{app.fullName}</title>
37
+      </Helmet>
38
+      <Particles />
39
+      <div className="login-page-container">
40
+        <div className="login-card">
41
+          <div className="login-card-left">
42
+            <div className="login-form-box">
43
+              <div className="login-form">
44
+                <h2 className="login-text">登录系统</h2>
45
+                <div className="login-subtitle">{title}</div>
46
+                <LoginForm onSuccess={onSuccess} />
47
+              </div>
48
+            </div>
49
+            <div className="login-copyright">
50
+              {copyright}
51
+            </div>
52
+          </div>
53
+          <div className="login-card-right">
54
+            <LoginEffect />
55
+          </div>
56
+        </div>
57
+      </div>
58
+    </div>
59
+  );
60
+};

+ 99
- 0
src/pages/login/style.less 查看文件

@@ -0,0 +1,99 @@
1
+.login-page {
2
+  height: 100%;
3
+  background: linear-gradient(#fff, #e6f7ff);
4
+
5
+  #particles-js {
6
+    position: absolute;
7
+    top: 0;
8
+    left: 0;
9
+    width: 100%;
10
+    height: 100%;
11
+  }
12
+
13
+  .login-page-container {
14
+    height: 100%;
15
+    display: grid;
16
+    place-items: center;
17
+    position: relative;
18
+    z-index: 10;
19
+  }
20
+
21
+  .login-card {
22
+    width: 900px;
23
+    height: 600px;
24
+    border-radius: 8px;
25
+    overflow: hidden;
26
+    backdrop-filter: blur(6px);
27
+    box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.2);
28
+
29
+    display: grid;
30
+    grid-template-columns: 1fr 1fr;
31
+  }
32
+
33
+  .login-card-left {
34
+    background: rgba(255, 255, 255, 0.45);
35
+  }
36
+  .login-card-right {
37
+    // background: #EFF6FA;
38
+  }
39
+
40
+  .login-form-box {
41
+    height: 560px;
42
+    display: grid;
43
+    place-items: center;
44
+
45
+    .login-form {
46
+      min-width: 280px;
47
+      .login-text {
48
+        font-weight: 700;
49
+      }
50
+    }
51
+
52
+    .login-subtitle {
53
+      font-size: 0.9em;
54
+      color: #666;
55
+      margin-bottom: 24px;
56
+      letter-spacing: 2px;
57
+    }
58
+  }
59
+
60
+  .login-effect-box {
61
+    height: 100%;
62
+    display: grid;
63
+    place-items: center;
64
+
65
+    .login-effect {
66
+      width: 180px;
67
+      height: 180px;
68
+      position: relative;
69
+    }
70
+
71
+    .login-effect-arc {
72
+      width: 100%;
73
+      height: 100%;
74
+      border-radius: 50%;
75
+      background-color: #fa8c16;
76
+
77
+      &::after {
78
+        content: '';
79
+        width: 200%;
80
+        height: 100%;
81
+        top: 50%;
82
+        left: -50%;
83
+        position: absolute;
84
+        z-index: 10;
85
+        background-color: rgba(255, 255, 255, 0.001);
86
+        backdrop-filter: blur(16px);
87
+        border-top: 1px solid rgba(255, 255, 255, 0.2);
88
+      }
89
+    }
90
+  }
91
+
92
+  .login-copyright {
93
+    font-size: 12px;
94
+    color: #666;
95
+    line-height: 40px;
96
+    padding-left: 20px;
97
+    box-sizing: border-box;
98
+  }
99
+}

+ 18
- 0
src/routes/Router.jsx 查看文件

@@ -0,0 +1,18 @@
1
+import React from "react";
2
+import { createHashRouter, RouterProvider } from "react-router-dom";
3
+import { useModel } from "@/store";
4
+import { defaultRoutes } from './routes';
5
+
6
+export default (props) => {
7
+  const { routes } = useModel('user');
8
+
9
+  const router = React.useMemo(() => {
10
+    if (!routes || routes.length < 1) {
11
+      return createHashRouter(defaultRoutes);
12
+    } else {
13
+      return createHashRouter(routes);
14
+    }
15
+  }, [routes]);
16
+
17
+  return <RouterProvider router={router} />
18
+}

+ 37
- 0
src/routes/hooks/usePrompt.jsx 查看文件

@@ -0,0 +1,37 @@
1
+import React from "react";
2
+import { UNSAFE_NavigationContext } from "react-router-dom";
3
+
4
+// 估计在 react-router v6 的后续某个版本 usePrompt 会回归
5
+// v6.7 已经添加 UNSAFE_usePrompt
6
+export function usePrompt(message, when = true) {
7
+  let blocker = React.useCallback(
8
+    tx => {
9
+      if (window.confirm(message)) tx.retry();
10
+    },
11
+    [message]
12
+  );
13
+
14
+  useBlocker(blocker, when);
15
+}
16
+
17
+function useBlocker(blocker, when = true) {
18
+  let { navigator } = React.useContext(UNSAFE_NavigationContext);
19
+
20
+  React.useEffect(() => {
21
+    if (!when) return;
22
+
23
+    let unblock = navigator.block((tx) => {
24
+      let autoUnblockingTx = {
25
+        ...tx,
26
+        retry() {
27
+          unblock();
28
+          tx.retry();
29
+        }
30
+      };
31
+
32
+      blocker(autoUnblockingTx);
33
+    });
34
+
35
+    return unblock;
36
+  }, [navigator, blocker, when]);
37
+}

+ 17
- 0
src/routes/hooks/useRoute.jsx 查看文件

@@ -0,0 +1,17 @@
1
+import { useLocation } from "react-router-dom";
2
+import { routes } from '../routes';
3
+import { flatten } from "../utils";
4
+
5
+let routeMap = null;
6
+
7
+// 获取当前的 route 信息
8
+export default function useRoute() {
9
+  if (!routeMap) {
10
+    routeMap = flatten(routes);
11
+  }
12
+
13
+  const location = useLocation();
14
+  return routeMap[location.pathname];
15
+  // const currentRoute = routeArr.filter(x => x.path === location.pathname)[0];
16
+  // return currentRoute;
17
+}

+ 44
- 0
src/routes/menus.jsx 查看文件

@@ -0,0 +1,44 @@
1
+import { Link } from 'react-router-dom';
2
+import { getPath } from './utils';
3
+
4
+// 菜单是否显示
5
+// 没有 meta 或者 meta.title 为空, 或者 meta.hideInMenu = true 的 都不显示
6
+const isShow = item => item.meta && item.meta.title && !item.meta.hideInMenu;
7
+
8
+const hasChildren = (list) => {
9
+  if (!list || list.length < 1) return false;
10
+
11
+  // 如果子元素全部都是不显示的, 说明子菜单不需要显示
12
+  return list.filter(it => !isShow(it)).length !== list.length;
13
+}
14
+
15
+export const getMenuItems = (routes = [], fullPath = '/') => {
16
+  return routes.map(route => {
17
+    const path = getPath(fullPath, route.path);
18
+
19
+    //
20
+    if (!isShow(route)) return false;
21
+    
22
+    const children = hasChildren(route.children) ? getMenuItems(route.children, path) : false;
23
+
24
+    const { target, title, icon } = route.meta || {}
25
+
26
+    // 坑爹 react-router v6 不支持 hash 路由的 target 跳转
27
+    const label = target === '_blank' ?
28
+      <a href={`${window.location.pathname}${path}`} target={target}>{title}</a>
29
+      : (
30
+        path.indexOf('http') === 0  ? <a href={path} target="_blank">{title}</a>
31
+        : <Link to={path} target={target}>{title}</Link>
32
+      );
33
+
34
+    return Object.assign(
35
+      {
36
+        key: path,
37
+        label,
38
+        title,
39
+        icon,
40
+      },
41
+      children && { children },
42
+    )
43
+  }).filter(Boolean);
44
+}

+ 14
- 0
src/routes/permissions.js 查看文件

@@ -0,0 +1,14 @@
1
+
2
+export const getAuthedRoutes = (routes, permissions) => {
3
+  if (!routes || routes.length < 1) return [];
4
+
5
+  return routes.map(route => {
6
+    if (route.meta && route.meta.permission && permissions.indexOf(route.meta.permission) < 0) return false;
7
+
8
+    if (route.children) {
9
+      route.children = getAuthedRoutes(route.children, permissions);
10
+    }
11
+
12
+    return route;
13
+  }).filter(Boolean);
14
+}

+ 110
- 0
src/routes/routes.jsx 查看文件

@@ -0,0 +1,110 @@
1
+import {
2
+  UserOutlined,
3
+  SolutionOutlined,
4
+  FileTextOutlined,
5
+  HeartOutlined,
6
+  HourglassTwoTone,
7
+  StopFilled,
8
+} from '@ant-design/icons'
9
+import { Outlet, Navigate } from 'react-router-dom'
10
+import AuthLayout from '@/layouts/AuthLayout'
11
+import Login from '@/pages/login'
12
+import Page404 from '@/pages/404'
13
+import Article from '@/pages/article'
14
+import ArticleEdit from '@/pages/article/Edit'
15
+import ArticleDetail from '@/pages/article/detail'
16
+
17
+// import RoleEdit from "@/pages/role/Edit";
18
+/**
19
+ * meta 用来扩展自定义数据数据
20
+ * {
21
+ *    title: 用于页面或者菜单的标题, 没有此字段, 菜单不会显示
22
+ *    hideInMenu: 布尔值, 如果为 false, 菜单不会显示
23
+ *    noLayout: 布尔值, 如果为 true, 将不会使用默认布局
24
+ *    noSiderBar: 布尔值, 如果为 true, 将没有左侧菜单栏
25
+ *    noFooter: 布尔值, 如果为 true, 将没有底部 footer
26
+ *    target: 字符串, 如果为 _blank, 将在新窗口打开
27
+ *    permission: 对应服务器端权限名称
28
+ * }
29
+ */
30
+
31
+export const authRoutes = [
32
+  {
33
+    index: true,
34
+    element: <Navigate to="/article" replace={true} />,
35
+  },
36
+  {
37
+    path: 'article',
38
+    element: <Article />,
39
+    meta: {
40
+      title: '文章管理',
41
+      icon: <UserOutlined />,
42
+    },
43
+  },
44
+  {
45
+    path: 'article/edit',
46
+    element: <ArticleEdit />,
47
+    meta: {
48
+      title: '文章维护',
49
+      hideInMenu: true
50
+    },
51
+  },
52
+  {
53
+    path: 'article/detail',
54
+    element: <ArticleDetail />,
55
+    meta: {
56
+      title: '文章详情',
57
+      hideInMenu: true
58
+    },
59
+  }
60
+]
61
+
62
+export const defaultRoutes = [
63
+  {
64
+    path: '/',
65
+    element: <AuthLayout />,
66
+    children: [
67
+      {
68
+        path: '*',
69
+        element: <Page404 />,
70
+      },
71
+    ],
72
+  },
73
+  {
74
+    path: '/login',
75
+    element: <Login />,
76
+  },
77
+  {
78
+    path: '*',
79
+    element: <Page404 />,
80
+  },
81
+]
82
+
83
+export function mergeAuthRoutes (r1, r2) {
84
+  const r = r1.slice()
85
+  const children = r1[0].children.slice()
86
+  r[0].children = children.concat(r2)
87
+  return r
88
+}
89
+
90
+// 全部路由
91
+export const routes = mergeAuthRoutes(defaultRoutes, authRoutes)
92
+function getPath (parent = '/', current = '') {
93
+  if (current.indexOf('/') === 0 || current.indexOf('http') === 0)
94
+    return current
95
+  return `${parent}/${current}`.replace(/\/\//g, '/')
96
+}
97
+
98
+// 路由数组, 一维数组
99
+export const routeArr = (() => {
100
+  const flatten = (routes, parentPath = '/') => {
101
+    return routes.reduce((acc, route) => {
102
+      const path = getPath(parentPath, route.path)
103
+      const children = route.children ? flatten(route.children, path) : []
104
+
105
+      return acc.concat([{ ...route, path }].concat(children))
106
+    }, [])
107
+  }
108
+
109
+  return flatten(routes)
110
+})()

+ 22
- 0
src/routes/utils.js 查看文件

@@ -0,0 +1,22 @@
1
+
2
+// 获取组件路径
3
+export function getPath (parent = "/", current = "") {
4
+  if (current.indexOf("/") === 0 || current.indexOf("http") === 0)
5
+    return current;
6
+  return `${parent}/${current}`.replace(/\/\//g, "/");
7
+}
8
+
9
+// 展平 routes, 为一个简单对象
10
+// 如果出现 父组件与子组件相同路由, 那么子组件会覆盖父组件
11
+export function flatten (routes, parentPath = "/") {
12
+  return routes.reduce((acc, route) => {
13
+    const path = route.index ? parentPath : getPath(parentPath, route.path);
14
+    const children = route.children ? flatten(route.children, path) : {};
15
+
16
+    return {
17
+      ...acc,
18
+      [path]: route,
19
+      ...children,
20
+    }
21
+  }, {});
22
+};

+ 36
- 0
src/services/login.js 查看文件

@@ -0,0 +1,36 @@
1
+import request from "@/utils/request";
2
+
3
+/*
4
+ * 修改密码
5
+ */
6
+export const changePassword = (id, data) =>
7
+  request(`/api/sysUser/${id}/change-pwd`, { data, method: "put" });
8
+
9
+/*
10
+ * 后台登录
11
+ */
12
+export const login = (data) =>
13
+  request("/api/admin/login", { data, method: "post" });
14
+
15
+/*
16
+ * 登出
17
+ */
18
+export const logout = (data) =>
19
+  request("/api/admin/logout", { data, method: "post" });
20
+
21
+/**
22
+ * 获取二维码
23
+ */
24
+export const qrCode = (params) => request("/api/login/qrCode", { params });
25
+
26
+/**
27
+ * 扫码登录
28
+ */
29
+
30
+export const postQrCode = (id, params) =>
31
+  request(`/api/login/qrCode/${id}`, { params, method: "post", silent: true });
32
+
33
+/**
34
+* 获取当前用户信息
35
+*/
36
+export const currentUser = (params) => request("/api/admin/current", { params })

+ 3
- 0
src/services/ossPolicy.js 查看文件

@@ -0,0 +1,3 @@
1
+import request from "@/utils/request";
2
+
3
+export const getPolicy = () => request("/api/admin/getPolicy");

+ 16
- 0
src/store/index.js 查看文件

@@ -0,0 +1,16 @@
1
+import { createStore } from "@zjxpcyc/react-tiny-store";
2
+import useSystem from "./models/system";
3
+import useUser from "./models/user";
4
+import usePolicy from "./models/useOssPolicy";
5
+
6
+const store = createStore({
7
+  system: useSystem,
8
+  user: useUser,
9
+  policy: usePolicy,
10
+});
11
+
12
+export default store
13
+export const useModel = store.useModel
14
+export const addModel = store.addModel
15
+export const removeModel = store.removeModel
16
+export const Provider = store.Provider

+ 20
- 0
src/store/models/system.js 查看文件

@@ -0,0 +1,20 @@
1
+import { useState, useCallback } from "react";
2
+
3
+export default function useSystem () {
4
+  // 主题
5
+  const [theme, updateTheme] = useState('dark');
6
+
7
+  // 其他配置
8
+  const [app, setApp] = useState({
9
+    fullName: '云致开发模板',
10
+    shorName: '云致开发模板',
11
+    company: ''
12
+  });
13
+
14
+  return {
15
+    theme,
16
+    updateTheme,
17
+    app,
18
+    hashRoute: true,
19
+  }
20
+}

+ 31
- 0
src/store/models/useOssPolicy.js 查看文件

@@ -0,0 +1,31 @@
1
+import React, { useEffect, useState } from "react";
2
+import { getPolicy } from "@/services/ossPolicy";
3
+import {useModel} from '@/store'
4
+export default function useOssPolicy() {
5
+  const [policyList, setPolicyList] = useState();
6
+
7
+  const { login } = useModel("user") || {};
8
+  // console.log(login);
9
+
10
+  const getOssPolicy = () => {
11
+    new Promise((resolve, reject) => {
12
+      getPolicy()
13
+        .then((res) => {
14
+          console.log(res);
15
+          //   setPolicyList(res);
16
+          resolve(res);
17
+        })
18
+        .catch((err) => {});
19
+    });
20
+  };
21
+
22
+  useEffect(() => {
23
+    console.log(login)
24
+    if (login) {
25
+      getOssPolicy();
26
+    }
27
+  }, [login]);
28
+  return {
29
+    policyList,
30
+  };
31
+}

+ 49
- 0
src/store/models/user.js 查看文件

@@ -0,0 +1,49 @@
1
+import { useState, useRef, useEffect } from "react";
2
+import { defaultRoutes, authRoutes, mergeAuthRoutes } from "@/routes/routes";
3
+import { getMenuItems } from "@/routes/menus";
4
+import { currentUser } from "@/services/login";
5
+import { getAuthedRoutes } from "@/routes/permissions";
6
+
7
+export default function useUser () {
8
+  const [user, setUser] = useState({ userId: 1, userName: "admin" });
9
+  const [login, setLogin] = useState(false);
10
+  const menusRef = useRef();
11
+  const routesRef = useRef();
12
+  const dbMenusRef = useRef([]);
13
+
14
+  const getCurrentUser = (params) =>
15
+    new Promise((resolve, reject) => {
16
+      // currentUser(params)
17
+      //   .then((res) => {
18
+      // dbMenusRef.current = res?.menuList || [];
19
+      // const permissions = dbMenusRef.current.map((x) => x.menuCode);
20
+
21
+      // // authRoutes 是所有待验证授权的路由
22
+      // // authedRoutes 是已经被授权的路由
23
+      // const authedRoutes = getAuthedRoutes(authRoutes, permissions || []);
24
+
25
+      // menusRef.current = getMenuItems(authedRoutes);
26
+      // routesRef.current = mergeAuthRoutes(defaultRoutes, authedRoutes);
27
+
28
+      //   setUser(res);
29
+      //   resolve();
30
+      // })
31
+      // .catch(reject);
32
+    });
33
+
34
+  // authRoutes 是所有待验证授权的路由
35
+  // authedRoutes 是已经被授权的路由
36
+  const authedRoutes = getAuthedRoutes(authRoutes);
37
+  menusRef.current = getMenuItems(authedRoutes);
38
+  routesRef.current = mergeAuthRoutes(defaultRoutes, authedRoutes);
39
+
40
+  return {
41
+    user,
42
+    setUser,
43
+    getCurrentUser,
44
+    menus: menusRef.current || [],
45
+    routes: routesRef.current || [],
46
+    dbMenus: dbMenusRef.current,
47
+    login,
48
+  };
49
+}

+ 11
- 0
src/theme.less 查看文件

@@ -0,0 +1,11 @@
1
+
2
+.light {
3
+  .ant-layout,
4
+  .ant-layout-header,
5
+  .ant-layout-sider,
6
+  .ant-layout-sider-trigger,
7
+  .ant-menu
8
+   {
9
+    background: transparent !important;
10
+  }
11
+}

+ 64
- 0
src/utils/array.js 查看文件

@@ -0,0 +1,64 @@
1
+/**
2
+ * 数组 转 Tree
3
+ * @param {*} arr
4
+ * @param {*} parent
5
+ * @param {*} key
6
+ * @returns
7
+ */
8
+export function arr2Tree(arr = [], parent = "parentId", key = "key") {
9
+  // 转换为字典
10
+  const dict = arr.reduce((acc, item) => {
11
+    return {
12
+      ...acc,
13
+      [item[key]]: {
14
+        ...item,
15
+        children: [],
16
+      },
17
+    };
18
+  }, {});
19
+
20
+  // // 查找顶级结点
21
+  // const getRootNode = (node) => {
22
+  //   const found = arr.filter((x) => node[parentId] === x[key])[0];
23
+
24
+  //   return !found ? dict[node[key]] : getRootNode(found);
25
+  // };
26
+
27
+  // 挂载父子节点
28
+  const tree = [];
29
+  for (let item of arr) {
30
+    const it = dict[item[key]];
31
+    const parentNodeId = it[parent];
32
+    const parentNode = dict[parentNodeId];
33
+
34
+    if (!parentNode) {
35
+      tree.push(it);
36
+    } else {
37
+      dict[parentNodeId].children.push(it);
38
+    }
39
+  }
40
+  return [tree, dict];
41
+}
42
+
43
+/**
44
+ * 深度展平数组
45
+ * @param {*} arr
46
+ * @returns
47
+ */
48
+export function flatten(arr = []) {
49
+  return arr.reduce((acc, it) => {
50
+    const list = Array.isArray(it) ? flatten(it) : it;
51
+    return acc.concat(list);
52
+  }, []);
53
+}
54
+
55
+/**
56
+ * 深度数组去重
57
+ * @param {*} arr
58
+ */
59
+export function uniq(arr = []) {
60
+  const list = flatten(arr);
61
+  return list.reduce((acc, it) => {
62
+    return acc.indexOf(it) > -1 ? acc : acc.concat(it);
63
+  }, []);
64
+}

+ 8
- 0
src/utils/css.js 查看文件

@@ -0,0 +1,8 @@
1
+
2
+export function setProperty(...args) {
3
+  document.documentElement.style.setProperty(...args);
4
+}
5
+
6
+export function getPropertyValue(...args) {
7
+  return getComputedStyle(document.documentElement).getPropertyValue(...args);
8
+}

+ 5
- 0
src/utils/float.js 查看文件

@@ -0,0 +1,5 @@
1
+const epsilonN = N => num => Math.round( num * N + Number.EPSILON ) / N;
2
+
3
+// 可以处理丢失精度的问题
4
+// 比如 epsilon2(0.29 * 100)
5
+export const epsilon2 = epsilonN(1e2);

+ 23
- 0
src/utils/form.js 查看文件

@@ -0,0 +1,23 @@
1
+
2
+export const formItemLayout = {
3
+  labelCol: {
4
+    xs: { span: 24 },
5
+    sm: { span: 8 },
6
+  },
7
+  wrapperCol: {
8
+    xs: { span: 24 },
9
+    sm: { span: 16 },
10
+  },
11
+};
12
+export const tailFormItemLayout = {
13
+  wrapperCol: {
14
+    xs: {
15
+      span: 24,
16
+      offset: 0,
17
+    },
18
+    sm: {
19
+      span: 16,
20
+      offset: 8,
21
+    },
22
+  },
23
+};

+ 13
- 0
src/utils/hooks/useBool.js 查看文件

@@ -0,0 +1,13 @@
1
+import React from "react";
2
+
3
+export default function useLoading(initial = false) {
4
+  const [loading, setLoading] = React.useState(initial);
5
+  const loadingRef = React.useRef();
6
+  loadingRef.current = loading;
7
+
8
+  const setTrue = React.useCallback(() => setLoading(true), []);
9
+  const setFalse = React.useCallback(() => setLoading(false), []);
10
+  const toggle = React.useCallback(() => setLoading(!loadingRef.current), []);
11
+
12
+  return [loading, setTrue, setFalse, setLoading, toggle];
13
+}

+ 19
- 0
src/utils/observe.js 查看文件

@@ -0,0 +1,19 @@
1
+
2
+export default function observe() {
3
+  const listeners = [];
4
+
5
+  const subscribe = (fn) => {
6
+    listeners.push(fn);
7
+
8
+    return () => listeners.splice(listeners.indexOf(fn), 1)
9
+  }
10
+
11
+  const notify = (...args) => {
12
+    listeners.forEach(fn => fn(...args))
13
+  }
14
+
15
+  return {
16
+    subscribe,
17
+    notify,
18
+  }
19
+}

+ 201
- 0
src/utils/request.js 查看文件

@@ -0,0 +1,201 @@
1
+import axios from "axios";
2
+import React from "react";
3
+import { message } from "antd";
4
+import { getToken, setToken } from "./token";
5
+
6
+const instance = axios.create({
7
+  baseURL: SERVER_BASE,
8
+  timeout: 10000,
9
+  withCredentials: true, // 跨域
10
+});
11
+
12
+// 添加请求拦截器
13
+instance.interceptors.request.use(
14
+  function (config) {
15
+    const {
16
+      headers = {},
17
+      method = "get",
18
+      responseType = "json",
19
+      download = false,
20
+      silent,
21
+      params = {},
22
+    } = config;
23
+    let token = localStorage.getItem("token") || "";
24
+
25
+    let noTip = silent;
26
+    if (noTip === undefined) {
27
+      noTip = method.toLocaleLowerCase() === "get" ? true : false;
28
+    }
29
+
30
+    const ticketOrigin = localStorage.getItem('ticket');
31
+    if (params.ticket && params.ticket != ticketOrigin) {
32
+      token = '';
33
+      localStorage.setItem('ticket', params.ticket);
34
+    } else {
35
+      params.ticket = undefined,
36
+        params.appid = undefined;
37
+    }
38
+    // 在发送请求之前做些什么
39
+    return {
40
+      ...config,
41
+      params,
42
+      silent: noTip,
43
+      headers: {
44
+        ...headers,
45
+        Authorization: token,
46
+      },
47
+      responseType: download ? "blob" : responseType,
48
+    };
49
+  },
50
+  function (error) {
51
+    // 对请求错误做些什么
52
+    return Promise.reject(error);
53
+  }
54
+);
55
+
56
+// 添加响应拦截器
57
+instance.interceptors.response.use(
58
+  function (response) {
59
+    // 2xx 范围内的状态码都会触发该函数。
60
+    // 对响应数据做点什么
61
+
62
+    const { data, config } = response;
63
+
64
+    if (config.download && !data.code) {
65
+      return downloadBlob(response, "下载文件");
66
+    }
67
+
68
+    if (data.code === 200) {
69
+      if (data.data?.token) {
70
+        setToken(data.data.token);
71
+      }
72
+
73
+      if (!config.silent) {
74
+        message.success("操作成功");
75
+      }
76
+
77
+      return data.data;
78
+    } else if (data.code === 401) {
79
+      if (!config.silent) {
80
+        message.error("未登录或者超时, 请重新登录");
81
+      }
82
+    } else {
83
+      console.log(config);
84
+      if (!config.silent) {
85
+        const errMsg = data.msg || "系统错误";
86
+        message.error(errMsg.indexOf("exception") > -1 ? "服务异常" : errMsg);
87
+      }
88
+    }
89
+
90
+    return Promise.reject(response);
91
+  },
92
+  function (error) {
93
+    // 超出 2xx 范围的状态码都会触发该函数。
94
+    // 对响应错误做点什么
95
+
96
+    console.error(error);
97
+
98
+    return Promise.reject("网络异常, 请重试...");
99
+  }
100
+);
101
+
102
+export default instance;
103
+
104
+export function queryTable (apiRequest) {
105
+  return function (params) {
106
+    const { pageSize } = params;
107
+    return apiRequest({
108
+      ...params,
109
+      pageSize,
110
+      pageNum: params.current,
111
+    })
112
+      .then((res) => {
113
+        return {
114
+          data: res.records,
115
+          success: true,
116
+          total: res.total,
117
+        };
118
+      })
119
+      .catch((err) => {
120
+        return {
121
+          success: false,
122
+        };
123
+      });
124
+  };
125
+}
126
+
127
+export function queryDict (
128
+  apiRequest,
129
+  { labelKey = "name", valueKey = "id" } = {}
130
+) {
131
+  return function (params) {
132
+    const { current, pageSize, ...leftParams } = params || {};
133
+    return apiRequest({
134
+      pageSize: 9999,
135
+      pageNum: 1,
136
+      ...(leftParams || {}),
137
+    })
138
+      .then((res) => {
139
+        return res?.records?.map((x) => ({
140
+          label: x[labelKey],
141
+          value: x[valueKey],
142
+          ...x,
143
+        }));
144
+      })
145
+      .catch((err) => {
146
+        return {
147
+          success: false,
148
+        };
149
+      });
150
+  };
151
+}
152
+export function restful (url) {
153
+  const list = (params) => instance.get(url, { params });
154
+  const get = (id) => instance.get(`${url}/${id}`);
155
+  const add = (data) => instance.post(url, data);
156
+  const update = (id, data) => instance.put(`${url}/${id}`, data);
157
+  const del = (id) => instance.delete(`${url}/${id}`);
158
+
159
+  return [list, get, add, update, del];
160
+}
161
+
162
+export function useRequest (fn) {
163
+  const [loading, setLoading] = React.useState(false);
164
+
165
+  const p = (...args) =>
166
+    new Promise((resolve, reject) => {
167
+      setLoading(true);
168
+      fn(...args)
169
+        .then((res) => {
170
+          setLoading(false);
171
+          resolve(res);
172
+        })
173
+        .catch((e) => {
174
+          setLoading(false);
175
+          reject(e);
176
+        });
177
+    });
178
+
179
+  return [loading, p];
180
+}
181
+
182
+function downloadBlob (response) {
183
+  let fileName = "未知文件";
184
+  const contentType = response.headers["content-type"];
185
+  const contentDisposition = response.headers["content-disposition"];
186
+  if (contentDisposition) {
187
+    const parts = contentDisposition.split(";filename=");
188
+    if (parts[1]) {
189
+      fileName = decodeURIComponent(parts[1]);
190
+    }
191
+  }
192
+
193
+  const url = window.URL.createObjectURL(
194
+    new Blob([response.data], { type: contentType })
195
+  );
196
+  const link = document.createElement("a");
197
+  link.href = url;
198
+  link.setAttribute("download", fileName);
199
+  link.click();
200
+  window.URL.revokeObjectURL(url);
201
+}

+ 70
- 0
src/utils/sso.js 查看文件

@@ -0,0 +1,70 @@
1
+import { getToken, setToken } from "./token";
2
+
3
+/**
4
+ * 异或加密, 可同时进行加密及解密
5
+ * @param {*} src 原始数据或待解密数据
6
+ * @param {*} key 密钥数组
7
+ * @returns 
8
+ */
9
+function xorDecrypt(src, key) {
10
+  let output = '';
11
+  for (var i = 0; i < src.length; i++) {
12
+    const c = src[i].charCodeAt();
13
+    const k = key[i % key.length];
14
+    output += String.fromCharCode(c ^ k);
15
+  }
16
+  return output;
17
+}
18
+
19
+/**
20
+ * 获取 token
21
+ * @param {*} url 
22
+ * @returns 
23
+ */
24
+function getTokenFromUrl(url) {
25
+  const matches = url.match(/sso-token=([^/&?]+)/);
26
+  return matches?.[1];
27
+}
28
+
29
+/**
30
+ * 初始化 token
31
+ * @returns 
32
+ */
33
+export function initTokenIfExists() {
34
+  // token 是 base64 格式
35
+  const base64Str = getTokenFromUrl(window.location.href);
36
+  if (!base64Str) return;
37
+
38
+  // base64 解码
39
+  const tkMixStr = window.atob(base64Str);
40
+  if (!tkMixStr) return;
41
+
42
+  // 解码后的格式为 xxxx-xxxxxxxxx
43
+  // 其中第一部分为密钥, 第二部分为 加密字串
44
+  const [keyStr, ...tkArr] = tkMixStr.split('-')
45
+  if (!keyStr || !tkArr.length) return;
46
+  
47
+  // 需要异或解密的是第二部分
48
+  const tkStr = tkArr.join('-');
49
+  const tk = xorDecrypt(tkStr, keyStr.split(''))
50
+  if (tk) {
51
+    setToken(tk);
52
+  }
53
+}
54
+
55
+/**
56
+ * 获取加密且可用于 URL 的 token
57
+ * @returns 
58
+ */
59
+export function getEncryptToken() {
60
+  const tk = getToken();
61
+  if (!tk) return;
62
+
63
+  const key = (new Date).valueOf();
64
+  
65
+  // 用 key 加密 token
66
+  const cipherText = xorDecrypt(tk, `${key}`.split(''));
67
+  const mixStr = [key, cipherText].join('-');
68
+
69
+  return window.btoa(mixStr);
70
+}

+ 8
- 0
src/utils/token.js 查看文件

@@ -0,0 +1,8 @@
1
+
2
+export function getToken() {
3
+  return localStorage.getItem("token") || ""
4
+}
5
+
6
+export function setToken(tk) {
7
+  localStorage.setItem("token", tk);
8
+}

+ 41
- 0
vite.config.js 查看文件

@@ -0,0 +1,41 @@
1
+import { defineConfig } from "vite";
2
+import path from "path";
3
+import react from "@vitejs/plugin-react";
4
+import vitePluginImp from "vite-plugin-imp";
5
+
6
+// https://vitejs.dev/config/
7
+export default defineConfig({
8
+  base: '',
9
+  server: {
10
+    port: 3000,
11
+    host: "0.0.0.0",
12
+    proxy: {
13
+      "/api": {
14
+        target: "http://192.168.89.25:7009",
15
+        changeOrigin: true,
16
+      },
17
+    },
18
+  },
19
+  plugins: [
20
+    react(),
21
+    vitePluginImp({
22
+      libList: [
23
+        {
24
+          libName: "antd",
25
+          style: (name) => `antd/es/${name}/style`,
26
+        },
27
+      ],
28
+    })
29
+  ],
30
+  resolve: {
31
+    alias: [{ find: "@", replacement: path.resolve(__dirname, "src") }],
32
+  },
33
+  css: {
34
+    preprocessorOptions: {
35
+      less: {
36
+        // modifyVars: { 'primary-color': '#13c2c2' },
37
+        javascriptEnabled: true,
38
+      },
39
+    },
40
+  },
41
+});

+ 2456
- 0
yarn.lock
文件差异内容过多而无法显示
查看文件