张涛 1 年之前
當前提交
14109120fc
共有 100 個文件被更改,包括 10779 次插入0 次删除
  1. 2
    0
      .env
  2. 2
    0
      .env.production
  3. 24
    0
      .gitignore
  4. 19
    0
      index.html
  5. 8
    0
      jsconfig.json
  6. 6551
    0
      package-lock.json
  7. 37
    0
      package.json
  8. 7
    0
      public/config.js
  9. 二進制
      public/logo.png
  10. 110
    0
      public/particles/particles.json
  11. 9
    0
      public/particles/particles.min.js
  12. 1
    0
      public/qrcode.min.js
  13. 1
    0
      public/vite.svg
  14. 42
    0
      src/App.css
  15. 10
    0
      src/App.jsx
  16. 1
    0
      src/assets/react.svg
  17. 15
    0
      src/components/EditableTag/Tag.jsx
  18. 21
    0
      src/components/EditableTag/index.jsx
  19. 27
    0
      src/components/EditableTag/style.less
  20. 4
    0
      src/components/Money/float.js
  21. 30
    0
      src/components/Money/index.jsx
  22. 83
    0
      src/components/Page/Curd.jsx
  23. 93
    0
      src/components/Page/Edit.jsx
  24. 90
    0
      src/components/Page/List.jsx
  25. 23
    0
      src/components/Page/index.jsx
  26. 10
    0
      src/components/Upload/Upload.jsx
  27. 60
    0
      src/components/Upload/UploadImage.jsx
  28. 115
    0
      src/components/Upload/UploadImageList.jsx
  29. 94
    0
      src/components/Upload/UploadVideo.jsx
  30. 11
    0
      src/components/Upload/index.jsx
  31. 32
    0
      src/components/Upload/request.js
  32. 7
    0
      src/components/Upload/style.less
  33. 87
    0
      src/components/Wangeditor/index.jsx
  34. 81
    0
      src/components/chart/index.jsx
  35. 71
    0
      src/index.less
  36. 31
    0
      src/layouts/AuthLayout/Main.jsx
  37. 3
    0
      src/layouts/AuthLayout/RedirectLogin.jsx
  38. 31
    0
      src/layouts/AuthLayout/RequireLogin.jsx
  39. 72
    0
      src/layouts/AuthLayout/components/Background.jsx
  40. 31
    0
      src/layouts/AuthLayout/components/Container.jsx
  41. 15
    0
      src/layouts/AuthLayout/components/Footer.jsx
  42. 36
    0
      src/layouts/AuthLayout/components/Header/Exit.jsx
  43. 24
    0
      src/layouts/AuthLayout/components/Header/Title.jsx
  44. 120
    0
      src/layouts/AuthLayout/components/Header/User.jsx
  45. 28
    0
      src/layouts/AuthLayout/components/Header/index.jsx
  46. 19
    0
      src/layouts/AuthLayout/components/HtmlTitle.jsx
  47. 17
    0
      src/layouts/AuthLayout/components/Logo.jsx
  48. 31
    0
      src/layouts/AuthLayout/components/Menus.jsx
  49. 21
    0
      src/layouts/AuthLayout/components/PageTransition/index.jsx
  50. 21
    0
      src/layouts/AuthLayout/components/PageTransition/style.less
  51. 21
    0
      src/layouts/AuthLayout/components/SiderBar.jsx
  52. 55
    0
      src/layouts/AuthLayout/index.jsx
  53. 81
    0
      src/layouts/AuthLayout/style.less
  54. 27
    0
      src/layouts/AuthLayout/withLogin.jsx
  55. 22
    0
      src/main.jsx
  56. 29
    0
      src/pages/404/index.jsx
  57. 111
    0
      src/pages/fxuser/Edit.jsx
  58. 78
    0
      src/pages/fxuser/index.jsx
  59. 11
    0
      src/pages/login/Effect.jsx
  60. 187
    0
      src/pages/login/LoginForm.bak.jsx
  61. 67
    0
      src/pages/login/LoginForm.jsx
  62. 67
    0
      src/pages/login/LoginQrcode.bak.jsx
  63. 45
    0
      src/pages/login/LoginUse.jsx
  64. 24
    0
      src/pages/login/Particles.jsx
  65. 159
    0
      src/pages/login/components/LoginQrCode.jsx
  66. 28
    0
      src/pages/login/components/QrCode.jsx
  67. 29
    0
      src/pages/login/components/SuccessIcon.jsx
  68. 41
    0
      src/pages/login/components/qrcode.module.less
  69. 34
    0
      src/pages/login/foo.js
  70. 61
    0
      src/pages/login/index.jsx
  71. 77
    0
      src/pages/login/qrcode.less
  72. 99
    0
      src/pages/login/style.less
  73. 6
    0
      src/pages/menu/index.jsx
  74. 120
    0
      src/pages/tenant/Edit.jsx
  75. 109
    0
      src/pages/tenant/index.jsx
  76. 18
    0
      src/routes/Router.jsx
  77. 37
    0
      src/routes/hooks/usePrompt.jsx
  78. 17
    0
      src/routes/hooks/useRoute.jsx
  79. 44
    0
      src/routes/menus.jsx
  80. 14
    0
      src/routes/permissions.js
  81. 114
    0
      src/routes/routes.jsx
  82. 22
    0
      src/routes/utils.js
  83. 26
    0
      src/services/fxtenant.js
  84. 49
    0
      src/services/fxuser.js
  85. 31
    0
      src/services/login.js
  86. 14
    0
      src/store/index.js
  87. 20
    0
      src/store/models/system.js
  88. 40
    0
      src/store/models/user.js
  89. 11
    0
      src/theme.less
  90. 64
    0
      src/utils/array.js
  91. 8
    0
      src/utils/css.js
  92. 5
    0
      src/utils/float.js
  93. 23
    0
      src/utils/form.js
  94. 13
    0
      src/utils/hooks/useBool.js
  95. 19
    0
      src/utils/observe.js
  96. 199
    0
      src/utils/request.js
  97. 70
    0
      src/utils/sso.js
  98. 8
    0
      src/utils/token.js
  99. 47
    0
      vite.config.js
  100. 0
    0
      yarn.lock

+ 2
- 0
.env 查看文件

@@ -0,0 +1,2 @@
1
+VITE_SERVER_BASE=/api/platform
2
+VITE_LOGIN_URL=http://localhost:3009/admin/

+ 2
- 0
.env.production 查看文件

@@ -0,0 +1,2 @@
1
+VITE_SERVER_BASE=https://api.crm2.njyunzhi.com/api/platform
2
+VITE_LOGIN_URL=https://crm2.njyunzhi.com/admin/index.html

+ 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?

+ 19
- 0
index.html 查看文件

@@ -0,0 +1,19 @@
1
+<!DOCTYPE html>
2
+<html lang="en">
3
+
4
+<head>
5
+  <meta charset="UTF-8" />
6
+  
7
+  <link rel="icon" type="image/svg+xml" href="https://yz-crm.oss-cn-nanjing.aliyuncs.com/images/favicon.ico" />
8
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
9
+  <script src="./config.js"></script>
10
+  <script src="./qrcode.min.js"></script>
11
+  <title>平台管理</title>
12
+</head>
13
+
14
+<body>
15
+  <div id="root"></div>
16
+  <script type="module" src="/src/main.jsx"></script>
17
+</body>
18
+
19
+</html>

+ 8
- 0
jsconfig.json 查看文件

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

+ 6551
- 0
package-lock.json
文件差異過大導致無法顯示
查看文件


+ 37
- 0
package.json 查看文件

@@ -0,0 +1,37 @@
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.3.13",
14
+    "@wangeditor/editor": "^5.1.23",
15
+    "@wangeditor/editor-for-react": "^1.0.6",
16
+    "@zjxpcyc/react-tiny-store": "^3.0.3",
17
+    "antd": "^4.23.4",
18
+    "axios": "^1.2.0",
19
+    "classnames": "^2.3.2",
20
+    "echarts": "^5.4.0",
21
+    "md5": "^2.3.0",
22
+    "moment": "^2.29.4",
23
+    "react": "18.2.0",
24
+    "react-dom": "18.2.0",
25
+    "react-helmet": "^6.1.0",
26
+    "react-router-dom": "^6.4.2",
27
+    "react-transition-group": "^4.4.5"
28
+  },
29
+  "devDependencies": {
30
+    "@types/react": "18.0.27",
31
+    "@types/react-dom": "18.0.10",
32
+    "@vitejs/plugin-react": "^2.0.0",
33
+    "less": "^4.1.3",
34
+    "vite": "^3.0.0",
35
+    "vite-plugin-imp": "^2.2.0"
36
+  }
37
+}

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

@@ -0,0 +1,7 @@
1
+
2
+var SERVER_BASE = 'http://api.crm.njyunzhi.com';
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
+}

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

@@ -0,0 +1,90 @@
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
+      fixed: 'right',
26
+      render: (_, record) => [
27
+        (
28
+          onEdit &&
29
+          <Button style={{ padding: 0 }} type="link" key={1} onClick={() => onEdit(record)}>
30
+            编辑
31
+          </Button>
32
+        ),
33
+        (
34
+          onDelete &&
35
+          <Popconfirm
36
+            key={3}
37
+            title="您是否确认删除 ?"
38
+            onConfirm={() => onDelete(record)}
39
+            okText="确定"
40
+            cancelText="取消"
41
+          >
42
+            <Button style={{ padding: 0 }} type="link">
43
+              删除
44
+            </Button>
45
+          </Popconfirm>
46
+        ),
47
+        ...(columnOptionRender ? columnOptionRender(_, record) : []),
48
+      ].filter(Boolean),
49
+    },
50
+  ], [columns, onEdit, onDelete]);
51
+
52
+  React.useImperativeHandle(ref, () => {
53
+    const showLoading = msg => (hideRef.current = message.loading(msg || '操作中, 请稍候...'));
54
+    const hideLoading = () => hideRef.current && hideRef.current();
55
+    const reload = () => actionRef.current?.reload && actionRef.current.reload();
56
+
57
+    return {
58
+      showLoading,
59
+      hideLoading,
60
+      reload,
61
+      actionRef: actionRef,
62
+    }
63
+  }, []);
64
+
65
+  return (
66
+    <Page>
67
+      <ProTable
68
+        rowKey={rowKey}
69
+        columns={cols}
70
+        request={api}
71
+        cardBordered
72
+        actionRef={actionRef}
73
+        toolBarRender={() => [
74
+          (
75
+            onAdd &&
76
+            <Button
77
+              key="1"
78
+              type="primary"
79
+              onClick={onAdd}
80
+            >
81
+              新增
82
+            </Button>
83
+          ),
84
+          ...(toolBarRender ? toolBarRender() : []),
85
+        ].filter(Boolean)}
86
+        {...leftProps}
87
+      />
88
+    </Page>
89
+  )
90
+});

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

@@ -0,0 +1,23 @@
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
+  const { meta = {} } = useRoute() || {};
14
+  const style = meta.noLayout ? { height: '100%' } : pageStyle;
15
+  const title = props.title || meta.title;
16
+
17
+  return (
18
+    <div style={style}>
19
+      { title && !meta.noLayout && <Title level={3} style={{ paddingBottom: '12px', fontWeight: 400 }}>{ title }</Title> }
20
+      {props.children}
21
+    </div>
22
+  )
23
+}

+ 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
+}

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

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

+ 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
+

+ 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
+}

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

@@ -0,0 +1,32 @@
1
+import request from '@/utils/request';
2
+
3
+const upload = (file, fileType = 'image') => {
4
+  const formData = new FormData();
5
+  formData.append("file", file);
6
+  formData.append("fileType", fileType);
7
+
8
+  return request('/api/admin/file', {
9
+    method: 'post',
10
+    data: formData,
11
+    headers: {
12
+      'Content-Type': 'multipart/form-data',
13
+    }
14
+  });
15
+}
16
+
17
+/**
18
+ * 上传文件
19
+ * @returns 
20
+ */
21
+export function uploadFile(params) {
22
+  const { file, onSuccess, onError } = params;
23
+  upload(file).then((res) => {
24
+    onSuccess(res, file)
25
+  }).catch((e) => {
26
+    onError(e)
27
+  });
28
+
29
+  return {
30
+    abort: () => {},
31
+  };
32
+}

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

@@ -0,0 +1,7 @@
1
+.video-uploader {
2
+  video {
3
+    margin-top: 2em;
4
+    width: 100%;
5
+    max-height: 360px;
6
+  }
7
+}

+ 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
+}

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

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

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

@@ -0,0 +1,31 @@
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
+import { authRoutes } from "@/routes/routes";
10
+import { getMenuItems } from "@/routes/menus";
11
+
12
+import "./style.less";
13
+
14
+export default (props) => {
15
+  const { theme } = useModel("system");
16
+  const { user } = useModel("user");
17
+  const navigate = useNavigate();
18
+  const location = useLocation();
19
+  const menus = getMenuItems(authRoutes);
20
+
21
+
22
+  return (
23
+    <Layout className={theme} style={{ height: "100vh" }}>
24
+      <Header theme={theme} user={user} />
25
+      <Layout style={{ height: "calc(100vh - var(--header-height))" }}>
26
+        <SiderBar theme={theme} menus={menus} location={location} />
27
+        <Container location={location} />
28
+      </Layout>
29
+    </Layout>
30
+  );
31
+};

+ 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" />;

+ 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
+      <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
+})

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

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

+ 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
+}

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

@@ -0,0 +1,120 @@
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
+import { useNavigate } from "react-router-dom";
16
+
17
+const DefaultAvatar = ({ color = "#1296db" }) => (
18
+  <svg
19
+    viewBox="0 0 1024 1024"
20
+    version="1.1"
21
+    xmlns="http://www.w3.org/2000/svg"
22
+    width="24"
23
+    height="24"
24
+  >
25
+    <path
26
+      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"
27
+      fill={color}
28
+    ></path>
29
+  </svg>
30
+);
31
+
32
+const ChangePassword = forwardRef((props, ref) => {
33
+  const [visible, setVisible] = useState(false);
34
+  const navigate = useNavigate();
35
+  const onFinish = async (values) => {
36
+    const data = {
37
+      originPassword: md5(values.password),
38
+      newPassword: md5(values.newPassword),
39
+    };
40
+    await changePassword(data);
41
+    navigate(`/login`);
42
+
43
+    return true;
44
+  };
45
+
46
+  useImperativeHandle(ref, () => {
47
+    return {
48
+      show: () => setVisible(true),
49
+    };
50
+  });
51
+
52
+  return (
53
+    <ModalForm
54
+      title="修改密码"
55
+      width="480px"
56
+      open={visible}
57
+      onOpenChange={setVisible}
58
+      onFinish={onFinish}
59
+    >
60
+      <ProFormText.Password
61
+        label="原始密码"
62
+        name="password"
63
+        rules={[{ required: true, message: "请输入原始密码!" }]}
64
+      />
65
+      <ProFormText.Password
66
+        label="新密码"
67
+        name="newPassword"
68
+        rules={[{ required: true, message: "请输入新密码!" }]}
69
+      />
70
+
71
+      <ProFormDependency name={["newPassword"]}>
72
+        {({ newPassword }) => (
73
+          <ProFormText.Password
74
+            label="确认新密码"
75
+            name="newPassword2"
76
+            rules={[
77
+              { required: true, message: "请输入新密码!" },
78
+              () => ({
79
+                validator(_, value) {
80
+                  if (!value || value == newPassword) {
81
+                    return Promise.resolve();
82
+                  }
83
+
84
+                  return Promise.reject("两次输入密码不一致");
85
+                },
86
+              }),
87
+            ]}
88
+          />
89
+        )}
90
+      </ProFormDependency>
91
+    </ModalForm>
92
+  );
93
+});
94
+
95
+export default (props) => {
96
+  const items = [
97
+    {
98
+      key: "changePassword",
99
+      label: "修改密码",
100
+    },
101
+  ];
102
+
103
+  const passRef = useRef();
104
+  const { user = {} } = props;
105
+
106
+  const onClick = ({ key }) => {
107
+    if (key === "changePassword") {
108
+      passRef.current.show();
109
+    }
110
+  };
111
+  return (
112
+    <Dropdown menu={{ items, onClick }}>
113
+      <div className="user-info">
114
+        <Avatar size={24} src={<DefaultAvatar />} />
115
+        <span className="font">{user?.user?.userName}</span>
116
+        <ChangePassword user={user} ref={passRef} />
117
+      </div>
118
+    </Dropdown>
119
+  );
120
+};

+ 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
+}

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

@@ -0,0 +1,31 @@
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 selectedKeys = [location.pathname];
22
+  return (
23
+    <Menu
24
+      mode="inline"
25
+      style={menuStyle}
26
+      theme={theme}
27
+      items={items}
28
+      selectedKeys={selectedKeys}
29
+    />
30
+  )
31
+}

+ 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
+}

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

@@ -0,0 +1,21 @@
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
+
9
+export default (props) => {
10
+  const { theme, location, menus } = props;
11
+
12
+  const width = useMemo(() => {
13
+    return /\d+/.exec(getPropertyValue('--siderbar-width'))[0] - 0;
14
+  }, []);
15
+
16
+  return (
17
+    <Sider className='layout-sidebar' theme={theme} collapsible width={width}>
18
+      <Menus theme={theme} items={menus} location={location} />
19
+    </Sider>
20
+  );
21
+}

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

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

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

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

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

@@ -0,0 +1,27 @@
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
+    if (loged) {
9
+      resolve(factory);
10
+    } else {
11
+      let ticket = undefined;
12
+      const match = window.location?.href?.match(/ticket=([^?&/]*)/);
13
+      if (match?.length > 0) {
14
+        ticket = match[1];
15
+      }
16
+
17
+      getCurrentUser({ ticket: ticket })
18
+        .then(() => {
19
+          resolve(factory);
20
+        })
21
+        .catch((e) => {
22
+          console.error(e);
23
+          resolve(import("./RedirectLogin"));
24
+        });
25
+    }
26
+  });
27
+}

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

@@ -0,0 +1,22 @@
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
+import { ConfigProvider } from "antd";
10
+import zhCN from "antd/es/locale/zh_CN";
11
+import "moment/dist/locale/zh-cn";
12
+
13
+initTokenIfExists();
14
+
15
+ReactDOM.createRoot(document.getElementById("root")).render(
16
+  <ConfigProvider locale={zhCN}>
17
+    <Provider>
18
+      <Background />
19
+      <Router />
20
+    </Provider>
21
+  </ConfigProvider>
22
+);

+ 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
+}

+ 111
- 0
src/pages/fxuser/Edit.jsx 查看文件

@@ -0,0 +1,111 @@
1
+import React, { useMemo } from "react";
2
+import { Button, Card, Form, Input, Select } from "antd";
3
+import useBool from "@/utils/hooks/useBool";
4
+import { useSearchParams, useNavigate } from "react-router-dom";
5
+import Page from "@/components/Page";
6
+import { formItemLayout, tailFormItemLayout } from "@/utils/form";
7
+import {
8
+  getFxUserId,
9
+  postFxUser,
10
+  putFxUser,
11
+  postFxUserAndLogin,
12
+  putFxUserAndLogin,
13
+} from "@/services/fxuser";
14
+const { Option } = Select;
15
+
16
+export default (props) => {
17
+  const [loading, startLoading, cancelLoading] = useBool();
18
+  const [submiting, startSubmit, cancelSubmit] = useBool();
19
+
20
+  const [searchParams] = useSearchParams();
21
+  const [form] = Form.useForm();
22
+  const navigate = useNavigate();
23
+
24
+  const id = searchParams.get("id");
25
+
26
+  React.useEffect(() => {
27
+    if (id) {
28
+      getFxUserId(id).then((res) => {
29
+        form.setFieldsValue(res);
30
+      });
31
+    }
32
+  });
33
+
34
+  const onFinish = (values) => {
35
+    console.log(values);
36
+    startSubmit();
37
+    if (id) {
38
+      //修改
39
+      putFxUserAndLogin(id, values)
40
+        .then((res) => {
41
+          cancelSubmit();
42
+          navigate(-1);
43
+        })
44
+        .catch(() => {
45
+          cancelSubmit();
46
+        });
47
+    } else {
48
+      //新增
49
+      postFxUserAndLogin(values)
50
+        .then((res) => {
51
+          cancelSubmit();
52
+          navigate(-1);
53
+        })
54
+        .catch(() => {
55
+          cancelSubmit();
56
+        });
57
+    }
58
+  };
59
+
60
+  return (
61
+    <Page>
62
+      <Card loading={loading}>
63
+        <Form
64
+          onFinish={onFinish}
65
+          form={form}
66
+          {...formItemLayout}
67
+          scrollToFirstError
68
+          style={{ maxWidth: "1000px" }}
69
+        >
70
+          <Form.Item
71
+            name="userName"
72
+            label="用户名称"
73
+            rules={[
74
+              {
75
+                required: true,
76
+                message: "请填写用户名称",
77
+              },
78
+            ]}
79
+          >
80
+            <Input placeholder="请输入用户名称" />
81
+          </Form.Item>
82
+          <Form.Item
83
+            name="phone"
84
+            label="手机号"
85
+            rules={[
86
+              {
87
+                required: true,
88
+                message: "请填写手机号",
89
+              },
90
+            ]}
91
+          >
92
+            <Input placeholder="请输入手机号" />
93
+          </Form.Item>
94
+          {id ? null : (
95
+            <Form.Item label="账 户">
96
+              <div style={{ color: "#333" }}>手机号;默认密码:123456</div>
97
+            </Form.Item>
98
+          )}
99
+          <Form.Item {...tailFormItemLayout}>
100
+            <Button loading={submiting} type="primary" htmlType="submit">
101
+              保存
102
+            </Button>
103
+            <Button style={{ marginLeft: "2em" }} onClick={() => navigate(-1)}>
104
+              返回
105
+            </Button>
106
+          </Form.Item>
107
+        </Form>
108
+      </Card>
109
+    </Page>
110
+  );
111
+};

+ 78
- 0
src/pages/fxuser/index.jsx 查看文件

@@ -0,0 +1,78 @@
1
+import List from "@/components/Page/List";
2
+import React from "react";
3
+
4
+import { getFxUser, deleteFxUserAndLogin } from "@/services/fxuser";
5
+
6
+import { useNavigate } from "react-router-dom";
7
+import { Button } from "antd";
8
+import moment from "moment";
9
+export default (props) => {
10
+  const navigate = useNavigate();
11
+  const actionRef = React.useRef();
12
+  const columns = [
13
+    {
14
+      title: "用户名",
15
+      dataIndex: "userName",
16
+      key: "userName",
17
+    },
18
+    {
19
+      title: "手机号",
20
+      dataIndex: "phone",
21
+      key: "phone",
22
+    },
23
+    // {
24
+    //   title: "创建人",
25
+    //   dataIndex: "createdBy",
26
+    //   key: "createdBy",
27
+    //   search: false,
28
+    // },
29
+    {
30
+      title: "创建时间",
31
+      dataIndex: "createdAt",
32
+      key: "createdAy",
33
+      search: false,
34
+      render: (t) => moment(t).format("YYYY-MM-DD HH:mm:ss"),
35
+      // new Date(t).toLocaleString("zh")
36
+    },
37
+    // {
38
+    //   title: "更新人",
39
+    //   dataIndex: "updatedBy",
40
+    //   key: "updatedBy",
41
+    //   search: false,
42
+    // },
43
+    // {
44
+    //   title: "更新时间",
45
+    //   dataIndex: "updatedAt",
46
+    //   key: "updatedAt",
47
+    //   search: false,
48
+    //   render: (t) => moment(t).format("YYYY-MM-DD HH:mm:ss"),
49
+    // },
50
+  ];
51
+
52
+  const DeleteFxUser = (record) => {
53
+    deleteFxUserAndLogin(record.userId).then((res) => {
54
+      actionRef.current.reload();
55
+    });
56
+  };
57
+  return (
58
+    <List
59
+      rowKey="userId"
60
+      actionRef={actionRef}
61
+      request={getFxUser}
62
+      onEdit={(record) => navigate(`/fxuser/edit?id=${record.userId}`)}
63
+      onDelete={DeleteFxUser}
64
+      toolBarRender={() => [
65
+        <Button
66
+          key="1"
67
+          type="primary"
68
+          onClick={() => {
69
+            navigate("edit");
70
+          }}
71
+        >
72
+          新增
73
+        </Button>,
74
+      ]}
75
+      columns={columns}
76
+    />
77
+  );
78
+};

+ 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
+};

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

@@ -0,0 +1,187 @@
1
+import React, { useEffect, useRef, useState } from "react";
2
+import md5 from "md5";
3
+import { Form } from "antd";
4
+import { login, qrCode, postQrCode } from "@/services/login";
5
+import { json, useSearchParams } from "react-router-dom";
6
+import LoginUse from "./LoginUse";
7
+import LoginQrcode from "./LoginQrcode.bak";
8
+export default (props) => {
9
+  const [searchParams] = useSearchParams();
10
+  const appid = searchParams.get("appid");
11
+  const { onSuccess, mode } = props;
12
+  const [form] = Form.useForm();
13
+  const [loading, setLoading] = useState(false);
14
+  const [showLogin, setShowLogin] = useState(true);
15
+  const [codeLapse, setCodeLapse] = useState(0); //0 未扫码,1 扫码, 2确认扫码 3取消扫码 4已删除
16
+
17
+  const qrcodeRef = useRef();
18
+  const refData = useRef();
19
+  useEffect(() => {
20
+    getQrCode();
21
+    console.log(refData);
22
+  }, [refData.id]);
23
+
24
+  const onFinish = (values) => {
25
+    const formData = new FormData();
26
+    formData.append("name", values.name);
27
+    formData.append("pwd", md5(values.pwd));
28
+    if (mode) {
29
+      formData.append("mode", mode);
30
+    }
31
+    formData.append("client", appid);
32
+
33
+    setLoading(true);
34
+    login(formData)
35
+      .then((res) => {
36
+        onSuccess(res);
37
+        setLoading(false);
38
+      })
39
+      .catch((err) => {
40
+        console.log("----err--", err);
41
+        setLoading(false);
42
+      });
43
+  };
44
+
45
+  const getQrCode = () => {
46
+    qrCode({ client: appid || "authcenter" })
47
+      .then((res) => {
48
+        refData.current = res;
49
+        createdCode(res);
50
+        checkTimeUp();
51
+
52
+        console.log(res);
53
+      })
54
+      .catch((err) => {
55
+        setCodeLapse(4);
56
+      });
57
+  };
58
+
59
+  const createdCode = (res) => {
60
+    new QRCode(qrcodeRef.current, {
61
+      width: 150,
62
+      height: 150,
63
+      text: res.qrCode,
64
+      correctLevel: 3,
65
+    });
66
+  };
67
+  /**
68
+   * @param {*轮询方法}
69
+   */
70
+  //  检测二维码状态 业务代码
71
+  const checkStatus = () => {
72
+    const { current } = refData;
73
+    return new Promise((resolve, reject) => {
74
+      postQrCode(current.id, mode)
75
+        .then((it) => {
76
+          if (current.expire >= 0) {
77
+            // 二维码还没有失效
78
+            current.expire--;
79
+            if (it.state == 0) {
80
+              // console.log("未扫码");
81
+              setCodeLapse(0);
82
+              resolve();
83
+            } else if (it.state == 1) {
84
+              // console.log("已扫码");
85
+              setCodeLapse(1);
86
+              resolve();
87
+            } else if (it.state == 3 || it.state == 4) {
88
+              setCodeLapse(4);
89
+              reject();
90
+            } else if (it.token) {
91
+              onSuccess(it);
92
+            } else if (it == null) {
93
+              console.log("null");
94
+              setCodeLapse(4);
95
+            }
96
+          } else {
97
+            // 二维码失效
98
+            console.log("二维码失效");
99
+            qrStop();
100
+            setCodeLapse(4);
101
+            reject();
102
+          }
103
+        })
104
+        .catch((err) => {
105
+          console.log(err);
106
+          qrStop();
107
+          setCodeLapse(4);
108
+          reject();
109
+        });
110
+    });
111
+  };
112
+
113
+  // 检测二维码状态 逻辑代码
114
+  let time = useRef();
115
+  const checkTimeUp = () => {
116
+    checkStatus()
117
+      .then(() => {
118
+        // console.log("===================");
119
+        // console.log("最上面的", time.current);
120
+        time.current = setTimeout(() => {
121
+          // console.log("上面的", time.current);
122
+          if (time.current) {
123
+            // console.log("下面的", time.current);
124
+            console.log("我先清除一下定时器");
125
+            clearTimeout(time.current);
126
+            checkTimeUp();
127
+          }
128
+        }, 1000);
129
+      })
130
+      .catch(() => {
131
+        if (time.current) {
132
+          clearTimeout(time.current);
133
+        }
134
+      });
135
+  };
136
+
137
+  // 删除二维码
138
+  const qrStop = () => {
139
+    if (qrcodeRef.current) {
140
+      const idv = qrcodeRef.current.children;
141
+      for (var i = idv.length - 1; i >= 0; i--) {
142
+        qrcodeRef.current.removeChild(idv[i]);
143
+      }
144
+    } else {
145
+      return;
146
+    }
147
+  };
148
+  // 重新刷新二维码
149
+  const onRenovate4 = () => {
150
+    // 重新查询
151
+    getQrCode();
152
+    setCodeLapse(0);
153
+  };
154
+  // 重新刷新二维码
155
+  const onRenovate1 = () => {
156
+    // 重新查询
157
+    clearTimeout(time.current);
158
+    setCodeLapse(0);
159
+    getQrCode();
160
+  };
161
+  // 切换账号登录
162
+  const checkLoginUse = () => {
163
+    setShowLogin(false);
164
+    clearTimeout(time.current);
165
+  };
166
+  // 切换二维码登录
167
+  const checkLoginwx = () => {
168
+    setShowLogin(true);
169
+    setCodeLapse(0);
170
+    getQrCode();
171
+  };
172
+  return (
173
+    <Form form={form} layout="vertical" onFinish={onFinish}>
174
+      {showLogin ? (
175
+        <LoginQrcode
176
+          qrcodeRef={qrcodeRef}
177
+          codeLapse={codeLapse}
178
+          onRenovate4={onRenovate4}
179
+          onRenovate1={onRenovate1}
180
+          checkLoginUse={checkLoginUse}
181
+        />
182
+      ) : (
183
+        <LoginUse loading={loading} checkLoginwx={checkLoginwx} />
184
+      )}
185
+    </Form>
186
+  );
187
+};

+ 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
+};

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

@@ -0,0 +1,67 @@
1
+import React from "react";
2
+import "./qrcode.less";
3
+export default (props) => {
4
+  const { qrcodeRef, codeLapse, onRenovate4, onRenovate1, checkLoginUse } =
5
+    props;
6
+  console.log(codeLapse);
7
+
8
+  return (
9
+    <>
10
+      <span className="pageUse" onClick={checkLoginUse}>
11
+        使用账号登录
12
+      </span>
13
+      <div className="pageQr">
14
+        {codeLapse == 0 ? (
15
+          <div className="qrcode">
16
+            <div className="qrBoder">
17
+              <div ref={qrcodeRef}></div>
18
+            </div>
19
+            <span>微信扫一扫登录</span>
20
+          </div>
21
+        ) : codeLapse == 1 ? (
22
+          <div className="loginSvg">
23
+            <svg
24
+              className="svg"
25
+              width="74"
26
+              height="74"
27
+              viewBox="0 0 18 18"
28
+              xmlns="http://www.w3.org/2000/svg"
29
+            >
30
+              <path
31
+                d="M18 9.111C18 13.971 13.97 18 8.889 18 4.029 18 0 13.97 0 9.111 0 4.03 4.03 0 8.889 0 13.97 0 18 4.03 18 9.111zM4.788 9.79l2.876 2.976c.041.043.109.047.15.007l6.327-6.227a.196.196 0 00-.006-.275l-.236-.233a.221.221 0 00-.291-.017l-5.792 4.825c-.037.032-.114.034-.161-.002L5.329 9.06c-.09-.068-.207-.043-.274.048l-.28.38a.234.234 0 00.013.3z"
32
+                fill="#09BB07"
33
+                fillRule="evenodd"
34
+              ></path>
35
+              <path
36
+                d="M18 9.111C18 13.971 13.97 18 8.889 18 4.029 18 0 13.97 0 9.111 0 4.03 4.03 0 8.889 0 13.97 0 18 4.03 18 9.111zM4.788 9.79l2.876 2.976c.041.043.109.047.15.007l6.327-6.227a.196.196 0 00-.006-.275l-.236-.233a.221.221 0 00-.291-.017l-5.792 4.825c-.037.032-.114.034-.161-.002L5.329 9.06c-.09-.068-.207-.043-.274.048l-.28.38a.234.234 0 00.013.3z"
37
+                fill="#09BB07"
38
+                fillRule="evenodd"
39
+              ></path>
40
+              <path
41
+                d="M18 9.111C18 13.971 13.97 18 8.889 18 4.029 18 0 13.97 0 9.111 0 4.03 4.03 0 8.889 0 13.97 0 18 4.03 18 9.111zM4.788 9.79l2.876 2.976c.041.043.109.047.15.007l6.327-6.227a.196.196 0 00-.006-.275l-.236-.233a.221.221 0 00-.291-.017l-5.792 4.825c-.037.032-.114.034-.161-.002L5.329 9.06c-.09-.068-.207-.043-.274.048l-.28.38a.234.234 0 00.013.3z"
42
+                fill="#09BB07"
43
+                fillRule="evenodd"
44
+              ></path>
45
+            </svg>
46
+            <span className="ScanningCode">已扫码成功</span>
47
+
48
+            <a className="newCode" onClick={onRenovate1}>
49
+              重新扫码
50
+            </a>
51
+          </div>
52
+        ) : codeLapse == 4 ? (
53
+          <div className="loginPage">
54
+            <div className="loginLap">
55
+              <p>二维码已过期</p>
56
+              <p>
57
+                <a onClick={onRenovate4}>点击刷新</a>
58
+              </p>
59
+            </div>
60
+          </div>
61
+        ) : (
62
+          <div></div>
63
+        )}
64
+      </div>
65
+    </>
66
+  );
67
+};

+ 45
- 0
src/pages/login/LoginUse.jsx 查看文件

@@ -0,0 +1,45 @@
1
+import React from "react";
2
+import { Button, Form, Input } from "antd";
3
+export default (props) => {
4
+  const { loading, checkLoginwx } = props;
5
+  console.log(loading);
6
+  const style = {
7
+    display: "flex",
8
+    justifyContent: "flex-end",
9
+    cursor: "pointer",
10
+    color: "#576b95",
11
+    position: "absolute",
12
+    top: "0",
13
+    right: "0",
14
+    height: "33px",
15
+    lineHeight: "33px",
16
+  };
17
+  return (
18
+    <>
19
+      <span style={style} onClick={checkLoginwx}>
20
+        使用二维码登录
21
+      </span>
22
+
23
+      <Form.Item label="用户名" name="name" required>
24
+        <Input placeholder="请输入用户名" style={{ borderRadius: "4px" }} />
25
+      </Form.Item>
26
+      <Form.Item label="密 码" name="pwd" required>
27
+        <Input.Password
28
+          placeholder="请输入密码"
29
+          style={{ borderRadius: "4px" }}
30
+        />
31
+      </Form.Item>
32
+      <Form.Item>
33
+        <Button
34
+          type="primary"
35
+          size="large"
36
+          style={{ width: "100%", marginTop: "24px", borderRadius: "4px" }}
37
+          loading={loading}
38
+          htmlType="submit"
39
+        >
40
+          登录
41
+        </Button>
42
+      </Form.Item>
43
+    </>
44
+  );
45
+};

+ 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
+}

+ 159
- 0
src/pages/login/components/LoginQrCode.jsx 查看文件

@@ -0,0 +1,159 @@
1
+import React from 'react';
2
+import { Button } from 'antd';
3
+// import { qrCode, postQrCode } from "@/services/login";
4
+import QrCode from './QrCode';
5
+import SuccessIcon from './SuccessIcon';
6
+import styles from './qrcode.module.less';
7
+
8
+// 轮询
9
+const polling = (p, delay) => {
10
+  let t = null;
11
+  let cancelled = false;
12
+
13
+  const clearTicker = () => {
14
+    if (t) {
15
+      clearTimeout(t);
16
+      t = null;
17
+    }
18
+  }
19
+
20
+  const cancel = () => {
21
+    cancelled = true;
22
+    clearTimeout(t);
23
+  };
24
+
25
+  const fn = () => {
26
+    p().then((done) => {
27
+      clearTicker();
28
+
29
+      if (!done && !cancelled) {
30
+        t = setTimeout(fn, delay);
31
+      }
32
+    }).catch(() => {
33
+      clearTicker();
34
+    });
35
+  }
36
+
37
+  fn();
38
+
39
+  return cancel;
40
+};
41
+
42
+export default (props) => {
43
+  const { onSuccess, mode, appid } = props;
44
+
45
+  // 二维码是否初始化
46
+  const [qrInited, setQrInited] = React.useState(false);
47
+  // 是否扫码
48
+  const [scaned, setScaned] = React.useState(false);
49
+  // 二维码数据
50
+  const [qrData, setQrData] = React.useState();
51
+  // 是否发生错误
52
+  const [hasError, setHasError] = React.useState(false);
53
+  // 提示信息
54
+  const [tips, setTips] = React.useState();
55
+  // 停止轮询控制器
56
+  const pollingCancel = React.useRef();
57
+
58
+  // 重新开始
59
+  const onReset = () => {
60
+    // 停止轮询
61
+    if (pollingCancel.current) {
62
+      pollingCancel.current();
63
+    }
64
+
65
+    setQrInited(false);
66
+    setScaned(false);
67
+    setHasError(false);
68
+  }
69
+
70
+  // 校验二维码各种状态
71
+  // const checkQrCode = React.useCallback((qrId, params) => {
72
+  //   return new Promise((resolve, reject) => {
73
+  //     postQrCode(qrId, params).then(res => {
74
+  //       // 带有 token 说明扫码登录成功
75
+  //       if (res.token) {
76
+  //         onSuccess(res);
77
+  //         resolve(true);
78
+  //         return ;
79
+  //       } else {
80
+  //         // state 与 stateLabels 是对应关系
81
+  //         const { state } = res;
82
+  //         const stateLabels = [
83
+  //           '未扫码',
84
+  //           '扫码成功, 请确认登录',
85
+  //           '扫码确认',
86
+  //           '已取消',
87
+  //           '已删除',
88
+  //         ]
89
+
90
+  //         const isError = state > 2;
91
+  //         setScaned(state == 1);
92
+  //         setHasError(isError);
93
+  //         setTips(stateLabels[state]);
94
+
95
+  //         if (isError) {
96
+  //           reject();
97
+  //         } else {
98
+  //           resolve();
99
+  //         }
100
+  //       }
101
+  //     }).catch((err) => {
102
+  //       console.error(err);
103
+  //       setTips(err.data.msg || err.message || err);
104
+
105
+  //       setScaned(false);
106
+  //       setHasError(true);
107
+  //       reject();
108
+  //     });
109
+  //   });
110
+  // }, []);
111
+
112
+  // 请求二维码
113
+  // React.useEffect(() => {
114
+  //   if (!qrInited) {
115
+  //     qrCode({ client: appid || "authcenter" }).then(res => {
116
+  //       setQrData(res);
117
+  //       setQrInited(true);
118
+
119
+  //       // 开启轮询
120
+  //       const fn = () => checkQrCode(res.id, { mode });
121
+  //       pollingCancel.current = polling(fn, 1000);
122
+  //     })
123
+  //   }
124
+  // }, [qrInited, mode]);
125
+
126
+  return (
127
+    <div className={styles['qr-form']}>
128
+      <div className={styles['qr-form-wrapper']}>
129
+
130
+        <div className={styles['qr-box']}>
131
+          <QrCode text={qrData?.qrCode} />
132
+        </div>
133
+
134
+        {
135
+          (scaned || hasError) && (
136
+            <div className={styles['status-box']}>
137
+              <div>
138
+                {
139
+                  scaned && !hasError && <SuccessIcon />
140
+                }
141
+                <div className={styles['status-tip']}>{tips}</div>
142
+                <Button type='link' onClick={onReset}>点击刷新</Button>
143
+              </div>
144
+            </div>
145
+          )
146
+        }
147
+
148
+      </div>
149
+
150
+      <div className={styles['tip-box']}>
151
+        {
152
+          qrInited && !hasError && (
153
+            <div>请使用行信扫码登录</div>
154
+          )
155
+        }
156
+      </div>
157
+    </div>
158
+  )
159
+}

+ 28
- 0
src/pages/login/components/QrCode.jsx 查看文件

@@ -0,0 +1,28 @@
1
+import React from 'react';
2
+
3
+export default (props) => {
4
+  const { text, width = 200, height = 200 } = props;
5
+
6
+  const ref = React.useRef();
7
+  const qrRef = React.useRef();
8
+
9
+  React.useEffect(() => {
10
+    if (text) {
11
+      if (qrRef.current) {
12
+        qrRef.current.clear();
13
+        qrRef.current.makeCode(text);
14
+      } else {
15
+        qrRef.current = new QRCode(ref.current, {
16
+          text,
17
+          width,
18
+          height,
19
+          correctLevel: QRCode.CorrectLevel.Q
20
+        });
21
+      }
22
+    }
23
+  }, [text, width, height]);
24
+
25
+  return (
26
+    <div ref={ref}></div>
27
+  )
28
+}

+ 29
- 0
src/pages/login/components/SuccessIcon.jsx 查看文件

@@ -0,0 +1,29 @@
1
+import React from 'react'
2
+
3
+export default (props) => {
4
+  return (
5
+    <svg
6
+      className="svg"
7
+      width="74"
8
+      height="74"
9
+      viewBox="0 0 18 18"
10
+      xmlns="http://www.w3.org/2000/svg"
11
+    >
12
+      <path
13
+        d="M18 9.111C18 13.971 13.97 18 8.889 18 4.029 18 0 13.97 0 9.111 0 4.03 4.03 0 8.889 0 13.97 0 18 4.03 18 9.111zM4.788 9.79l2.876 2.976c.041.043.109.047.15.007l6.327-6.227a.196.196 0 00-.006-.275l-.236-.233a.221.221 0 00-.291-.017l-5.792 4.825c-.037.032-.114.034-.161-.002L5.329 9.06c-.09-.068-.207-.043-.274.048l-.28.38a.234.234 0 00.013.3z"
14
+        fill="#09BB07"
15
+        fillRule="evenodd"
16
+      ></path>
17
+      <path
18
+        d="M18 9.111C18 13.971 13.97 18 8.889 18 4.029 18 0 13.97 0 9.111 0 4.03 4.03 0 8.889 0 13.97 0 18 4.03 18 9.111zM4.788 9.79l2.876 2.976c.041.043.109.047.15.007l6.327-6.227a.196.196 0 00-.006-.275l-.236-.233a.221.221 0 00-.291-.017l-5.792 4.825c-.037.032-.114.034-.161-.002L5.329 9.06c-.09-.068-.207-.043-.274.048l-.28.38a.234.234 0 00.013.3z"
19
+        fill="#09BB07"
20
+        fillRule="evenodd"
21
+      ></path>
22
+      <path
23
+        d="M18 9.111C18 13.971 13.97 18 8.889 18 4.029 18 0 13.97 0 9.111 0 4.03 4.03 0 8.889 0 13.97 0 18 4.03 18 9.111zM4.788 9.79l2.876 2.976c.041.043.109.047.15.007l6.327-6.227a.196.196 0 00-.006-.275l-.236-.233a.221.221 0 00-.291-.017l-5.792 4.825c-.037.032-.114.034-.161-.002L5.329 9.06c-.09-.068-.207-.043-.274.048l-.28.38a.234.234 0 00.013.3z"
24
+        fill="#09BB07"
25
+        fillRule="evenodd"
26
+      ></path>
27
+    </svg>
28
+  )
29
+}

+ 41
- 0
src/pages/login/components/qrcode.module.less 查看文件

@@ -0,0 +1,41 @@
1
+
2
+.qr-form {
3
+  position: relative;
4
+  line-height: 2em;
5
+  text-align: center;
6
+  margin-top: 24px;
7
+
8
+  .qr-form-wrapper {
9
+    margin: 0 auto;
10
+    width: 240px;
11
+    height: 240px;
12
+    display: grid;
13
+    place-items: center;
14
+  }
15
+
16
+  .qr-box {
17
+    position: absolute;
18
+    padding: 15px;
19
+    box-sizing: border-box;
20
+    border: 1px solid #e2e2e2;
21
+    z-index: 1;
22
+  }
23
+
24
+  .status-box {
25
+    background: rgba(255, 255, 255, 0.98);
26
+    position: relative;
27
+    width: 100%;
28
+    height: 100%;
29
+    z-index: 10;
30
+    display: grid;
31
+    place-items: center;
32
+  
33
+    // .status-tip {
34
+    // }
35
+  }
36
+
37
+  .tip-box {
38
+    margin-top: 1em;
39
+    letter-spacing: 1.4px;
40
+  }
41
+}

+ 34
- 0
src/pages/login/foo.js 查看文件

@@ -0,0 +1,34 @@
1
+const { postQrCode } = require("@/services/login");
2
+
3
+const foo = (fp, delay) => {
4
+
5
+    let t = null;
6
+
7
+    const fn = () => {
8
+        fp().then(() => {
9
+            if (t) {
10
+                clearTimeout(t);
11
+            }
12
+    
13
+            t = setTimeout(fn, delay);
14
+        }).catch(() => {
15
+            if (t) {
16
+                clearTimeout(t);
17
+            }
18
+        });
19
+    }
20
+}
21
+
22
+const fp = () => {
23
+    return new Promise((resovle, reject) => {
24
+        postQrCode().then(() => {
25
+            if (succes) {
26
+                resovle()
27
+            } else {
28
+                reject()
29
+            }
30
+        }).catch(() => {
31
+            reject()
32
+        });
33
+    });
34
+}

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

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

+ 77
- 0
src/pages/login/qrcode.less 查看文件

@@ -0,0 +1,77 @@
1
+ .pageQr{
2
+  position: relative;
3
+  width: 180px;
4
+  height: 180px;
5
+  margin: 0 auto;
6
+  // top: 50%;
7
+  .loginPage,.loginSvg{
8
+    display: table;
9
+      position: absolute;
10
+      top: 100%;
11
+      left: 40%;
12
+      text-align: center;
13
+      width: 180px;
14
+      height: 180px;
15
+      margin-left: -61px;
16
+      margin-top: -132px;
17
+      background-color: #fffffff5;
18
+      .loginLap{
19
+        display: table-cell;
20
+    vertical-align: middle;
21
+      }
22
+
23
+  }
24
+
25
+  .loginSvg{
26
+.ScanningCode{
27
+  display: block;
28
+  // cursor: pointer;
29
+}
30
+
31
+  }
32
+  .newCode{
33
+    position: absolute;
34
+    top: 100%;
35
+    right: 37%;
36
+    cursor: pointer;
37
+    color: #576b95;
38
+    text-decoration: none;
39
+  }
40
+  .qrcode{
41
+    width: 178px;
42
+    height: 150px;
43
+    margin: auto;
44
+    position: absolute;
45
+    top: 30%;
46
+    span{
47
+      display: block;
48
+      text-align: center; 
49
+      padding-top:10px ;
50
+    }
51
+    .qrBoder{
52
+      box-sizing: border-box;
53
+    border: 1px solid #e2e2e2;
54
+    width: 180px;
55
+    height: 180px;
56
+    text-align: -webkit-center;
57
+    img{
58
+      position: absolute;
59
+    top: 10%;
60
+    right: 6%;
61
+    }
62
+    }
63
+  }
64
+ }
65
+
66
+ .pageUse{
67
+  display: flex;
68
+  justify-content: flex-end;
69
+  cursor: pointer;
70
+  color: #576b95;
71
+  
72
+  position: absolute;
73
+  top: 0;
74
+  right: 0;
75
+  height: 33px;
76
+  line-height: 33px;
77
+}

+ 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
+}

+ 6
- 0
src/pages/menu/index.jsx 查看文件

@@ -0,0 +1,6 @@
1
+import React from 'react'
2
+export default (props) => {
3
+return (
4
+<div>11111</div>
5
+)
6
+}

+ 120
- 0
src/pages/tenant/Edit.jsx 查看文件

@@ -0,0 +1,120 @@
1
+import React, { useEffect, useState } from "react";
2
+import { postFxTenant, putFxTenant, getFxTenantId } from "@/services/fxtenant";
3
+import { useNavigate, useSearchParams } from "react-router-dom";
4
+import {
5
+  ProForm,
6
+  ProFormText,
7
+  ProFormDateRangePicker,
8
+  ProFormSelect,
9
+} from "@ant-design/pro-components";
10
+import { Card, Form, Row, Col, Button, DatePicker, Select } from "antd";
11
+import Page from "@/components/Page";
12
+import { formItemLayout, tailFormItemLayout } from "@/utils/form";
13
+import moment from "moment";
14
+
15
+const dateFormat = "YYYY-MM-DD";
16
+
17
+export default (props) => {
18
+  const formRef = React.useRef();
19
+  const navigate = useNavigate();
20
+  const [searchParams] = useSearchParams();
21
+  const id = searchParams.get("id");
22
+  useEffect(() => {
23
+    formRef.current?.resetFields();
24
+    if (id) {
25
+      getFxTenantId(id).then((res) => {
26
+        formRef.current?.setFieldsValue({
27
+          ...res,
28
+          time: [
29
+            moment(res.startTime, dateFormat),
30
+            moment(res.endTime, dateFormat),
31
+          ],
32
+
33
+        });
34
+      });
35
+    }
36
+  }, []);
37
+
38
+  const onFinish = (x) => {
39
+    formRef.current?.validateFieldsReturnFormatValue?.().then((values) => {
40
+      console.log("values", values);
41
+      const data = {
42
+        ...values,
43
+        startTime: values?.time[0],
44
+        endTime: values?.time[1],
45
+      };
46
+      const tenantId = id;
47
+      if (!tenantId) {
48
+        postFxTenant(data).then((res) => {
49
+          navigate(-1);
50
+        });
51
+      } else {
52
+        putFxTenant(tenantId, { tenantId, ...data }).then((res) => {
53
+          navigate(-1);
54
+        });
55
+      }
56
+    });
57
+  };
58
+
59
+  return (
60
+    <Page>
61
+      <Card>
62
+        <ProForm
63
+          formRef={formRef}
64
+          onFinish={onFinish}
65
+          layout="horizontal"
66
+          {...formItemLayout}
67
+          submitter={{
68
+            render: (_, doms) => [
69
+              <Row>
70
+                <Col offset={8}>
71
+                  <Button type="primary" htmlType="submit">
72
+                    提交
73
+                  </Button>
74
+                </Col>
75
+                <Col offset={1}>
76
+                  <Button onClick={() => navigate(-1)}>返回</Button>
77
+                </Col>
78
+              </Row>,
79
+            ],
80
+          }}
81
+        >
82
+          <ProFormText
83
+            name="tenantName"
84
+            label="租户名称"
85
+            placeholder="请输入租户名称"
86
+            rules={[{ required: true, message: "租户名称不能为空" }]}
87
+          />
88
+          <Form.Item
89
+            name={["time"]}
90
+            label="合同生效时间"
91
+            rules={[{ required: true, message: "合同生效时间不能为空" }]}
92
+          >
93
+            <DatePicker.RangePicker />
94
+          </Form.Item>
95
+
96
+          <ProFormText
97
+            name="manager"
98
+            label="管理员名称"
99
+            placeholder="请输入管理员名称"
100
+          />
101
+          <ProFormText
102
+            name="phone"
103
+            label="手机号(租户账号)"
104
+            placeholder="请输入手机号"
105
+            rules={[{ required: true, message: "手机号不能为空" }]}
106
+          />
107
+          <ProFormSelect
108
+            label="状态"
109
+            name="status"
110
+            options={[
111
+              { label: '未激活', value: 0 },
112
+              { label: '已激活', value: 1 },
113
+              { label: '停用', value: 2 }
114
+            ]}
115
+          />
116
+        </ProForm>
117
+      </Card>
118
+    </Page>
119
+  );
120
+};

+ 109
- 0
src/pages/tenant/index.jsx 查看文件

@@ -0,0 +1,109 @@
1
+import List from "@/components/Page/List";
2
+import React from "react";
3
+
4
+import { getFxTenant, deleteFxTenant } from "@/services/fxtenant";
5
+
6
+import { useNavigate } from "react-router-dom";
7
+import { Button, Typography } from "antd";
8
+import moment from "moment";
9
+export default (props) => {
10
+  const { Text } = Typography;
11
+  const navigate = useNavigate();
12
+  const actionRef = React.useRef();
13
+
14
+  const columns = [
15
+    {
16
+      title: "时间",
17
+      dataIndex: "time",
18
+      valueType: "dateRange",
19
+      hideInTable: true,
20
+      search: {
21
+        transform: (value) => {
22
+          return {
23
+            startTime: value[0],
24
+            endTime: value[1],
25
+          };
26
+        },
27
+      },
28
+    },
29
+    {
30
+      title: "租户名称",
31
+      dataIndex: "tenantName",
32
+    },
33
+    {
34
+      title: "开始时间",
35
+      dataIndex: "startTime",
36
+      render: (t) => moment(t).format("YYYY-MM-DD"),
37
+      search: false,
38
+    },
39
+    {
40
+      title: "结束时间",
41
+      dataIndex: "endTime",
42
+      render: (t) => moment(t).format("YYYY-MM-DD"),
43
+      search: false,
44
+    },
45
+    {
46
+      title: "管理人名称",
47
+      dataIndex: "manager",
48
+      search: false,
49
+    },
50
+    {
51
+      title: "手机号",
52
+      dataIndex: "phone",
53
+    },
54
+    {
55
+      title: "登录地址",
56
+      dataIndex: "tenantId",
57
+      render: (_, record) => {
58
+        const url = `${import.meta.env.VITE_LOGIN_URL}#/${record.tenantId}/login`
59
+        console.log(url)
60
+        return <Text copyable={{ text: url }} ellipsis={true}>{url}</Text>;
61
+      },
62
+      search: false,
63
+    },
64
+    {
65
+      title: "状态",
66
+      dataIndex: "status",
67
+      valueType: "select",
68
+      render: (_, record) =>
69
+        record.status == 0 ? "未激活" : record.status == 1 ? "已激活" : "停用",
70
+      valueEnum: {
71
+        0: "未激活",
72
+        1: "已激活",
73
+        2: "停用",
74
+      },
75
+    }
76
+  ];
77
+
78
+  const DeleteFxUser = (record) => {
79
+    deleteFxTenant(record.tenantId).then((res) => {
80
+      actionRef.current.reload();
81
+    });
82
+  };
83
+
84
+
85
+  return (
86
+    <List
87
+      rowKey="tenantId"
88
+      actionRef={actionRef}
89
+      request={getFxTenant}
90
+      onEdit={(record) => navigate(`/tenant/edit?id=${record.tenantId}`)}
91
+      onDelete={DeleteFxUser}
92
+      toolBarRender={() => [
93
+        <Button
94
+          key="1"
95
+          type="primary"
96
+          onClick={() => {
97
+            navigate("edit");
98
+          }}
99
+        >
100
+          新增
101
+        </Button>,
102
+      ]}
103
+      columnOptionRender={(_, record) => [
104
+        <a href={`${import.meta.env.VITE_LOGIN_URL}#/${record.tenantId}/login`} target='_blank'>登录</a>
105
+      ]}
106
+      columns={columns}
107
+    />
108
+  );
109
+};

+ 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
+// console.log(routes)
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
+}

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

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

+ 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
+};

+ 26
- 0
src/services/fxtenant.js 查看文件

@@ -0,0 +1,26 @@
1
+import request from "@/utils/request";
2
+
3
+/*
4
+ * 分页查询
5
+ */
6
+export const getFxTenant = (params) => request(`/fxTenant`, { params });
7
+
8
+/*
9
+ * 新增数据
10
+ */
11
+export const postFxTenant = (data) => request('/fxTenant', { data, method: 'post' });
12
+
13
+/*
14
+ * 更新数据
15
+ */
16
+export const putFxTenant = (id, data) => request(`/fxTenant/${id}`, { data, method: 'put' });
17
+
18
+/*
19
+ * 通过主键删除数据
20
+ */
21
+export const deleteFxTenant = (id) => request(`/fxTenant/${id}`, { method: 'delete' });
22
+
23
+/*
24
+ * 通过ID查询单条数据
25
+ */
26
+export const getFxTenantId = (id) => request(`/fxTenant/${id}`);

+ 49
- 0
src/services/fxuser.js 查看文件

@@ -0,0 +1,49 @@
1
+import request from "@/utils/request";
2
+
3
+/*
4
+ * 分页查询
5
+ */
6
+export const getFxUser = (params) => request(`/fxUser`, { params });
7
+
8
+/*
9
+ * 新增数据
10
+ */
11
+export const postFxUser = (data) => request('fxUser', { data, method: 'post' });
12
+
13
+/*
14
+ * 更新数据
15
+ */
16
+export const putFxUser = (id, data) => request(`/fxUser/${id}`, { data, method: 'put' });
17
+
18
+/*
19
+ * 通过主键删除数据
20
+ */
21
+export const deleteFxUser = (id) => request(`/fxUser/${id}`, { method: 'delete' });
22
+
23
+/*
24
+ * 通过ID查询单条数据
25
+ */
26
+export const getFxUserId = (id) => request(`/fxUser/${id}`);
27
+
28
+
29
+
30
+/**
31
+ * 更新 fxUser和fxLogin  用户信息
32
+ */
33
+
34
+export const putFxUserAndLogin = (id, data) => request(`/fxUserLogin/${id}`, { data, method: 'put'})
35
+
36
+
37
+/**
38
+ * 新增fxUser和fxLogin  用户信息
39
+ */
40
+export const postFxUserAndLogin = (data) => request('/fxUserLogin', { data, method: 'post' });
41
+
42
+
43
+
44
+
45
+/*
46
+ * 通过主键删除 fxUser和fxLogin  
47
+
48
+ */
49
+export const deleteFxUserAndLogin = (id) => request(`/fxUserLogin/${id}`, { method: 'delete' });

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

@@ -0,0 +1,31 @@
1
+import request from "@/utils/request";
2
+
3
+/*
4
+ * 修改密码
5
+ */
6
+export const changePassword = (data) =>
7
+  request(`/change-password`, { data, method: "put" });
8
+
9
+/*
10
+ * 后台登录
11
+ */
12
+export const login = (data) =>
13
+  request("/login", { data, method: "post" });
14
+
15
+/*
16
+* 登出
17
+*/
18
+export const logout = (data) =>
19
+  request("/logout", { data, method: "post" });
20
+
21
+
22
+/*
23
+ *查询当前登录状态
24
+ */
25
+// export const isLogin = (params) => request("//isLogin", { params })
26
+
27
+
28
+/**
29
+ * 获取当前用户信息
30
+ */
31
+export const currentUser = (params) => request("/current", { params })

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

@@ -0,0 +1,14 @@
1
+import { createStore } from "@zjxpcyc/react-tiny-store";
2
+import useSystem from "./models/system";
3
+import useUser from "./models/user";
4
+
5
+const store = createStore({
6
+  system: useSystem,
7
+  user: useUser,
8
+});
9
+
10
+export default store
11
+export const useModel = store.useModel
12
+export const addModel = store.addModel
13
+export const removeModel = store.removeModel
14
+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
+}

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

@@ -0,0 +1,40 @@
1
+import { useState, useRef } 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(null);
9
+  const menusRef = useRef();
10
+  const routesRef = useRef();
11
+  const dbMenusRef = useRef([]);
12
+
13
+  const getCurrentUser = () =>
14
+    new Promise((resolve, reject) => {
15
+      currentUser()
16
+        .then((res) => {
17
+          dbMenusRef.current = res?.menuList || [];
18
+          const permissions = dbMenusRef.current.map((x) => x.menuCode);
19
+
20
+          // authRoutes 是所有待验证授权的路由
21
+          // authedRoutes 是已经被授权的路由
22
+          const authedRoutes = getAuthedRoutes(authRoutes, permissions||[]);
23
+
24
+          menusRef.current = getMenuItems(authedRoutes);
25
+          routesRef.current = mergeAuthRoutes(defaultRoutes, authedRoutes);
26
+
27
+          setUser(res);
28
+          resolve(res);
29
+        })
30
+        .catch(reject);
31
+    });
32
+
33
+  return {
34
+    user,
35
+    setUser,
36
+    getCurrentUser,
37
+    menus: menusRef.current || [],
38
+    routes: routesRef.current || [],
39
+  };
40
+}

+ 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: 4 },
6
+  },
7
+  wrapperCol: {
8
+    xs: { span: 24 },
9
+    sm: { span: 12 },
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
+}

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

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

+ 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
+}

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

@@ -0,0 +1,47 @@
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: '/platform/',
9
+  server: {
10
+    port: 3001,
11
+    host: "0.0.0.0",
12
+    proxy: {
13
+      '/api/platform': {
14
+        target: 'http://192.168.89.25:9110',
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
+  build: {
42
+    outDir: 'dist', // 打包输出目录
43
+    assetsDir: 'assets', // 静态资源目录 (相对于 outputDir)
44
+    minify: true, // 是否进行代码压缩
45
+    
46
+  }
47
+});

+ 0
- 0
yarn.lock 查看文件


部分文件因文件數量過多而無法顯示