张涛 1 yıl önce
ebeveyn
işleme
d037d6cfc2

+ 45
- 36
src/layouts/AuthLayout/components/Header/User.jsx Dosyayı Görüntüle

@@ -1,14 +1,20 @@
1
-import React, { useState, forwardRef, useRef, useImperativeHandle } from 'react'
2
-import { Avatar, Dropdown } from 'antd'
1
+import React, {
2
+  useState,
3
+  forwardRef,
4
+  useRef,
5
+  useImperativeHandle,
6
+} from "react";
7
+import { Avatar, Dropdown } from "antd";
3 8
 import {
4 9
   ModalForm,
5 10
   ProFormText,
6 11
   ProFormDependency,
7
-} from '@ant-design/pro-components'
8
-import md5 from 'md5'
9
-import { changePassword } from '@/services/login'
12
+} from "@ant-design/pro-components";
13
+import md5 from "md5";
14
+import { changePassword } from "@/services/login";
15
+import { useNavigate } from "react-router-dom";
10 16
 
11
-const DefaultAvatar = ({ color = '#1296db' }) => (
17
+const DefaultAvatar = ({ color = "#1296db" }) => (
12 18
   <svg
13 19
     viewBox="0 0 1024 1024"
14 20
     version="1.1"
@@ -21,31 +27,34 @@ const DefaultAvatar = ({ color = '#1296db' }) => (
21 27
       fill={color}
22 28
     ></path>
23 29
   </svg>
24
-)
30
+);
25 31
 
26 32
 const ChangePassword = forwardRef((props, ref) => {
27
-  const { user } = props
33
+  const { user } = props;
34
+  const navigate = useNavigate();
28 35
 
29
-  const [visible, setVisible] = useState(false)
36
+  const [visible, setVisible] = useState(false);
30 37
 
31 38
   const onFinish = async (values) => {
32
-    console.log('values', values);
39
+    console.log("values", values);
33 40
     const data = {
34 41
       // originPassword: values.password,
35 42
       // newPassword: values.newPassword,
36 43
       originPassword: md5(values.password),
37 44
       newPassword: md5(values.newPassword),
38
-    }
39
-    await changePassword(data)
40
-
41
-    return true
42
-  }
45
+    };
46
+    await changePassword(data);
47
+    const tenantId = localStorage.getItem("tenantId");
48
+    navigate(`/login?id=${tenantId}`);
49
+    localStorage.removeItem("token");
50
+    return true;
51
+  };
43 52
 
44 53
   useImperativeHandle(ref, () => {
45 54
     return {
46 55
       show: () => setVisible(true),
47
-    }
48
-  })
56
+    };
57
+  });
49 58
 
50 59
   return (
51 60
     <ModalForm
@@ -58,28 +67,28 @@ const ChangePassword = forwardRef((props, ref) => {
58 67
       <ProFormText.Password
59 68
         label="原始密码"
60 69
         name="password"
61
-        rules={[{ required: true, message: '请输入原始密码!' }]}
70
+        rules={[{ required: true, message: "请输入原始密码!" }]}
62 71
       />
63 72
       <ProFormText.Password
64 73
         label="新密码"
65 74
         name="newPassword"
66
-        rules={[{ required: true, message: '请输入新密码!' }]}
75
+        rules={[{ required: true, message: "请输入新密码!" }]}
67 76
       />
68 77
 
69
-      <ProFormDependency name={['newPassword']}>
78
+      <ProFormDependency name={["newPassword"]}>
70 79
         {({ newPassword }) => (
71 80
           <ProFormText.Password
72 81
             label="确认新密码"
73 82
             name="newPassword2"
74 83
             rules={[
75
-              { required: true, message: '请输入新密码!' },
84
+              { required: true, message: "请输入新密码!" },
76 85
               () => ({
77
-                validator (_, value) {
86
+                validator(_, value) {
78 87
                   if (!value || value == newPassword) {
79
-                    return Promise.resolve()
88
+                    return Promise.resolve();
80 89
                   }
81 90
 
82
-                  return Promise.reject('两次输入密码不一致')
91
+                  return Promise.reject("两次输入密码不一致");
83 92
                 },
84 93
               }),
85 94
             ]}
@@ -87,24 +96,24 @@ const ChangePassword = forwardRef((props, ref) => {
87 96
         )}
88 97
       </ProFormDependency>
89 98
     </ModalForm>
90
-  )
91
-})
99
+  );
100
+});
92 101
 
93 102
 export default (props) => {
94 103
   const items = [
95 104
     {
96
-      key: 'changePassword',
97
-      label: '修改密码',
105
+      key: "changePassword",
106
+      label: "修改密码",
98 107
     },
99
-  ]
108
+  ];
100 109
 
101
-  const passRef = useRef()
102
-  const { user = {} } = props
110
+  const passRef = useRef();
111
+  const { user = {} } = props;
103 112
   const onClick = ({ key }) => {
104
-    if (key === 'changePassword') {
105
-      passRef.current.show()
113
+    if (key === "changePassword") {
114
+      passRef.current.show();
106 115
     }
107
-  }
116
+  };
108 117
   return (
109 118
     <Dropdown menu={{ items, onClick }}>
110 119
       <div className="user-info">
@@ -113,5 +122,5 @@ export default (props) => {
113 122
         <ChangePassword user={user} ref={passRef} />
114 123
       </div>
115 124
     </Dropdown>
116
-  )
117
-}
125
+  );
126
+};

+ 9
- 7
src/layouts/AuthLayout/components/Menus.jsx Dosyayı Görüntüle

@@ -1,10 +1,10 @@
1
-import React from 'react'
2
-import { Menu } from 'antd'
1
+import React from "react";
2
+import { Menu } from "antd";
3 3
 
4
-const menuStyle = { height: '100%' }
4
+const menuStyle = { height: "100%" };
5 5
 
6 6
 export default (props) => {
7
-  const { theme, items, location } = props
7
+  const { theme, items, location } = props;
8 8
 
9 9
   // const selectedKeys = React.useMemo(() => {
10 10
   //   const parts = location.pathname.split('/').filter(Boolean);
@@ -17,7 +17,9 @@ export default (props) => {
17 17
 
18 18
   //   return keys;
19 19
   // }, [location.pathname]);
20
-  const selectedKeys = [location.pathname]
20
+  const selectedKeys = [location.pathname];
21
+
22
+
21 23
   return (
22 24
     <Menu
23 25
       mode="inline"
@@ -26,5 +28,5 @@ export default (props) => {
26 28
       items={items}
27 29
       selectedKeys={selectedKeys}
28 30
     />
29
-  )
30
-}
31
+  );
32
+};

+ 15
- 11
src/layouts/AuthLayout/components/SiderBar.jsx Dosyayı Görüntüle

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

+ 112
- 110
src/routes/routes.jsx Dosyayı Görüntüle

@@ -11,36 +11,39 @@ import {
11 11
   PayCircleOutlined,
12 12
   TabletOutlined,
13 13
   HddOutlined,
14
-  WalletOutlined
15
-} from '@ant-design/icons'
16
-import { Outlet, Navigate } from 'react-router-dom'
17
-import AuthLayout from '@/layouts/AuthLayout'
18
-import Login from '@/pages/login'
19
-import Page404 from '@/pages/404'
20
-import AdUser from '@/pages/adUser'
21
-import AdUserEdit from '@/pages/adUser/Edit'
22
-import Project from '@/pages/project'
23
-import ProjectEdit from '@/pages/project/Edit'
24
-import ProjectContact from '@/pages/projectContact'
25
-import ProjectContactEdit from '@/pages/projectContact/Edit'
26
-import ProjectDeploy from '@/pages/projectDeploy'
27
-import ProjectDeployEdit from '@/pages/project/components/ProjectDeployEdit'
28
-import ProjectNode from '@/pages/projectNode'
14
+  WalletOutlined,
15
+  BorderInnerOutlined,
16
+  HeatMapOutlined,
17
+  MediumOutlined,
18
+} from "@ant-design/icons";
19
+import { Outlet, Navigate } from "react-router-dom";
20
+import AuthLayout from "@/layouts/AuthLayout";
21
+import Login from "@/pages/login";
22
+import Page404 from "@/pages/404";
23
+import AdUser from "@/pages/adUser";
24
+import AdUserEdit from "@/pages/adUser/Edit";
25
+import Project from "@/pages/project";
26
+import ProjectEdit from "@/pages/project/Edit";
27
+import ProjectContact from "@/pages/projectContact";
28
+import ProjectContactEdit from "@/pages/projectContact/Edit";
29
+import ProjectDeploy from "@/pages/projectDeploy";
30
+import ProjectDeployEdit from "@/pages/project/components/ProjectDeployEdit";
31
+import ProjectNode from "@/pages/projectNode";
29 32
 
30
-import Role from '@/pages/role'
31
-import Dept from '@/pages/dept'
32
-import Package from '@/pages/package'
33
-import PackageEdit from '@/pages/package/Edit'
34
-import Member from '@/pages/member'
35
-import MemberEdit from '@/pages/member/Edit'
36
-import Custom from '@/pages/custom'
37
-import CustomEdit from '@/pages/custom/Edit'
38
-import Finance from '@/pages/finance'
39
-import FinanceEdit from '@/pages/finance/Edit'
40
-import FinanceItem from '@/pages/financeItem'
41
-import FinanceItemEdit from '@/pages/financeItem/Edit'
42
-import Tenant from '@/pages/tenant'
43
-import TenantEdit from '@/pages/tenant/Edit'
33
+import Role from "@/pages/role";
34
+import Dept from "@/pages/dept";
35
+import Package from "@/pages/package";
36
+import PackageEdit from "@/pages/package/Edit";
37
+import Member from "@/pages/member";
38
+import MemberEdit from "@/pages/member/Edit";
39
+import Custom from "@/pages/custom";
40
+import CustomEdit from "@/pages/custom/Edit";
41
+import Finance from "@/pages/finance";
42
+import FinanceEdit from "@/pages/finance/Edit";
43
+import FinanceItem from "@/pages/financeItem";
44
+import FinanceItemEdit from "@/pages/financeItem/Edit";
45
+import Tenant from "@/pages/tenant";
46
+import TenantEdit from "@/pages/tenant/Edit";
44 47
 
45 48
 // import RoleEdit from "@/pages/role/Edit";
46 49
 /**
@@ -62,201 +65,201 @@ export const authRoutes = [
62 65
     element: <Navigate to="/aduser" replace={true} />,
63 66
   },
64 67
   {
65
-    path: '/custom',
68
+    path: "/custom",
66 69
     element: <Outlet />,
67 70
     meta: {
68
-      title: '客户管理',
69
-      menuType: 'group',
71
+      title: "客户管理",
72
+      menuType: "group",
73
+      icon: <HeatMapOutlined />,
70 74
     },
71 75
     children: [
72 76
       {
73
-        path: 'aduser',
77
+        path: "aduser",
74 78
         element: <AdUser />,
75 79
         meta: {
76
-          title: '用户管理',
80
+          title: "用户管理",
77 81
           icon: <SolutionOutlined />,
78 82
         },
79 83
       },
80 84
       {
81
-        path: 'aduser/edit',
85
+        path: "aduser/edit",
82 86
         element: <AdUserEdit />,
83 87
         meta: {
84
-          title: '用户维护',
88
+          title: "用户维护",
85 89
           hideInMenu: true,
86 90
         },
87 91
       },
88 92
       {
89
-        path: 'dept',
93
+        path: "dept",
90 94
         element: <Dept />,
91 95
         meta: {
92
-          title: '部门管理',
96
+          title: "部门管理",
93 97
           icon: <TabletOutlined />,
94 98
         },
95 99
       },
96 100
       {
97
-        path: 'tenant/edit',
101
+        path: "tenant/edit",
98 102
         element: <TenantEdit />,
99 103
         meta: {
100
-          title: '租户编辑',
104
+          title: "租户编辑",
101 105
           hideInMenu: true,
102 106
         },
103 107
       },
104 108
       {
105
-        path: 'role',
109
+        path: "role",
106 110
         element: <Role />,
107 111
         meta: {
108
-          title: '角色管理',
112
+          title: "角色管理",
109 113
           icon: <UserOutlined />,
110 114
         },
111 115
       },
112 116
 
113 117
       {
114
-        path: 'package',
118
+        path: "package",
115 119
         element: <Package />,
116 120
         meta: {
117
-          title: '套餐管理',
121
+          title: "套餐管理",
118 122
           icon: <HddOutlined />,
119 123
         },
120 124
       },
121 125
       {
122
-        path: 'package/edit',
126
+        path: "package/edit",
123 127
         element: <PackageEdit />,
124 128
         meta: {
125
-          title: '套餐维护',
129
+          title: "套餐维护",
126 130
           hideInMenu: true,
127 131
         },
128 132
       },
129 133
       {
130
-        path: 'member',
134
+        path: "member",
131 135
         element: <Member />,
132 136
         meta: {
133
-          title: '会员管理',
137
+          title: "会员管理",
134 138
           icon: <WalletOutlined />,
135 139
         },
136 140
       },
137 141
       {
138
-        path: 'member/edit',
142
+        path: "member/edit",
139 143
         element: <MemberEdit />,
140 144
         meta: {
141
-          title: '会员详情',
145
+          title: "会员详情",
142 146
           hideInMenu: true,
143 147
         },
144
-      }
145
-    ]
148
+      },
149
+    ],
146 150
   },
147 151
   {
148
-    path: '/project',
152
+    path: "/project",
149 153
     element: <Outlet />,
150 154
     meta: {
151
-      title: '项目管理',
152
-      menuType: 'group',
155
+      title: "项目管理",
156
+      menuType: "group",
157
+      icon: <BorderInnerOutlined />,
153 158
     },
154 159
     children: [
155 160
       {
156
-        path: 'project',
161
+        path: "project",
157 162
         element: <Project />,
158 163
         meta: {
159
-          title: '项目管理',
164
+          title: "项目管理",
160 165
           icon: <FileTextOutlined />,
161 166
         },
162 167
       },
163 168
       {
164
-        path: 'project/edit',
169
+        path: "project/edit",
165 170
         element: <ProjectEdit />,
166 171
         meta: {
167
-          title: '项目维护',
172
+          title: "项目维护",
168 173
           hideInMenu: true,
169 174
         },
170 175
       },
171 176
       {
172
-        path: 'projectDeploy/edit',
177
+        path: "projectDeploy/edit",
173 178
         element: <ProjectDeployEdit />,
174 179
         meta: {
175
-          title: '部署维护',
180
+          title: "部署维护",
176 181
           hideInMenu: true,
177 182
         },
178 183
       },
179 184
       {
180
-        path: 'projectContact',
185
+        path: "projectContact",
181 186
         element: <ProjectContact />,
182 187
         meta: {
183
-          title: '项目联系人管理',
188
+          title: "项目联系人管理",
184 189
           icon: <UserAddOutlined />,
185 190
         },
186 191
       },
187 192
       {
188
-        path: 'projectContact/edit',
193
+        path: "projectContact/edit",
189 194
         element: <ProjectContactEdit />,
190 195
         meta: {
191
-          title: '项目联系人维护',
196
+          title: "项目联系人维护",
192 197
           hideInMenu: true,
193 198
         },
194 199
       },
195 200
 
196 201
       {
197
-        path: 'custom',
202
+        path: "custom",
198 203
         element: <Custom />,
199 204
         meta: {
200
-          title: '客户管理',
205
+          title: "客户管理",
201 206
           icon: <UsergroupAddOutlined />,
202 207
         },
203 208
       },
204 209
       {
205
-        path: 'custom/edit',
210
+        path: "custom/edit",
206 211
         element: <CustomEdit />,
207 212
         meta: {
208
-          title: '客户维护',
213
+          title: "客户维护",
209 214
           hideInMenu: true,
210 215
         },
211 216
       },
212
-    ]
217
+    ],
213 218
   },
214 219
   {
215
-    path: '/finance',
220
+    path: "/finance",
216 221
     element: <Outlet />,
217 222
     meta: {
218
-      title: '财务管理',
219
-      menuType: 'group',
223
+      title: "财务管理",
224
+      menuType: "group",
225
+      icon: <MediumOutlined />,
220 226
     },
221 227
     children: [
222
-      ,
223 228
       {
224
-        path: 'finance',
229
+        path: "finance",
225 230
         element: <Finance />,
226 231
         meta: {
227
-          title: '公司财务管理',
232
+          title: "公司财务管理",
228 233
           icon: <TransactionOutlined />,
229 234
         },
230 235
       },
231 236
       {
232
-        path: 'finance/edit',
237
+        path: "finance/edit",
233 238
         element: <FinanceEdit />,
234 239
         meta: {
235
-          title: '财务维护',
240
+          title: "财务维护",
236 241
           hideInMenu: true,
237 242
         },
238 243
       },
239 244
       {
240
-        path: 'financeItem',
245
+        path: "financeItem",
241 246
         element: <FinanceItem />,
242 247
         meta: {
243
-          title: '收付款管理',
248
+          title: "收付款管理",
244 249
           icon: <PayCircleOutlined />,
245 250
         },
246 251
       },
247 252
       {
248
-        path: 'financeItem/edit',
253
+        path: "financeItem/edit",
249 254
         element: <FinanceItemEdit />,
250 255
         meta: {
251
-          title: '收付款维护',
256
+          title: "收付款维护",
252 257
           hideInMenu: true,
253 258
         },
254 259
       },
255
-    ]
260
+    ],
256 261
   },
257 262
 
258
-
259
-
260 263
   // {
261 264
   //   path: 'projectDeploy',
262 265
   //   element: <ProjectDeploy />,
@@ -282,55 +285,54 @@ export const authRoutes = [
282 285
   //     icon: <UserOutlined />,
283 286
   //   },
284 287
   // },
285
-
286
-]
288
+];
287 289
 
288 290
 export const defaultRoutes = [
289 291
   {
290
-    path: '/',
292
+    path: "/",
291 293
     element: <AuthLayout />,
292 294
     children: [
293 295
       {
294
-        path: '*',
296
+        path: "*",
295 297
         element: <Page404 />,
296 298
       },
297 299
     ],
298 300
   },
299 301
   {
300
-    path: '/login',
302
+    path: "/login",
301 303
     element: <Login />,
302 304
   },
303 305
   {
304
-    path: '*',
306
+    path: "*",
305 307
     element: <Page404 />,
306 308
   },
307
-]
309
+];
308 310
 
309
-export function mergeAuthRoutes (r1, r2) {
310
-  const r = r1.slice()
311
-  const children = r1[0].children.slice()
312
-  r[0].children = children.concat(r2)
313
-  return r
311
+export function mergeAuthRoutes(r1, r2) {
312
+  const r = r1.slice();
313
+  const children = r1[0].children.slice();
314
+  r[0].children = children.concat(r2);
315
+  return r;
314 316
 }
315 317
 
316 318
 // 全部路由
317
-export const routes = mergeAuthRoutes(defaultRoutes, authRoutes)
318
-function getPath (parent = '/', current = '') {
319
-  if (current.indexOf('/') === 0 || current.indexOf('http') === 0)
320
-    return current
321
-  return `${parent}/${current}`.replace(/\/\//g, '/')
319
+export const routes = mergeAuthRoutes(defaultRoutes, authRoutes);
320
+function getPath(parent = "/", current = "") {
321
+  if (current.indexOf("/") === 0 || current.indexOf("http") === 0)
322
+    return current;
323
+  return `${parent}/${current}`.replace(/\/\//g, "/");
322 324
 }
323 325
 
324 326
 // 路由数组, 一维数组
325 327
 export const routeArr = (() => {
326
-  const flatten = (routes, parentPath = '/') => {
328
+  const flatten = (routes, parentPath = "/") => {
327 329
     return routes.reduce((acc, route) => {
328
-      const path = getPath(parentPath, route.path)
329
-      const children = route.children ? flatten(route.children, path) : []
330
+      const path = getPath(parentPath, route.path);
331
+      const children = route.children ? flatten(route.children, path) : [];
330 332
 
331
-      return acc.concat([{ ...route, path }].concat(children))
332
-    }, [])
333
-  }
333
+      return acc.concat([{ ...route, path }].concat(children));
334
+    }, []);
335
+  };
334 336
 
335
-  return flatten(routes)
336
-})()
337
+  return flatten(routes);
338
+})();