@lxzy/code-snippet 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/commands/push-yw.md +1 -1
- package/mock/activity.ts +119 -18
- package/package.json +10 -6
- package/routes/index.ts +19 -0
- package/routes/menu.ts +25 -0
- package/src/App.tsx +45 -24
- package/src/global.css +3 -35
- package/src/layouts/index.tsx +19 -19
- package/src/main.tsx +1 -1
- package/src/pages/404.tsx +14 -2
- package/src/pages/activityCenter/activitySystemManagement/addPages/index.tsx +1 -1
- package/src/pages/activityCenter/activitySystemManagement/index.tsx +11 -4
- package/src/pages/home.tsx +5 -0
- package/src/umi/dispatcher.ts +17 -0
- package/src/umi/index.ts +7 -0
- package/src/umi/useModel.tsx +52 -0
- package/src/utils/getIcon.tsx +16 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +10 -8
- package/vite.config.ts +12 -1
package/mock/activity.ts
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { MockMethod } from 'vite-plugin-mock';
|
|
2
2
|
|
|
3
3
|
let channelLinkList = [
|
|
4
|
-
{
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
{
|
|
5
|
+
id: 1,
|
|
6
|
+
pageId: 1,
|
|
7
|
+
nameCn: '商家A',
|
|
8
|
+
nameEn: 'a',
|
|
9
|
+
link: '/paths/detail?id=1&filed=a',
|
|
10
|
+
createTime: '2026-03-01 10:00:00',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: 2,
|
|
14
|
+
pageId: 1,
|
|
15
|
+
nameCn: '商家B',
|
|
16
|
+
nameEn: 'b',
|
|
17
|
+
link: '/paths/detail?id=1&filed=b',
|
|
18
|
+
createTime: '2026-03-02 11:00:00',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: 3,
|
|
22
|
+
pageId: 1,
|
|
23
|
+
nameCn: '商家C',
|
|
24
|
+
nameEn: 'c',
|
|
25
|
+
link: '/paths/detail?id=1&filed=c',
|
|
26
|
+
createTime: '2026-03-03 12:00:00',
|
|
27
|
+
},
|
|
7
28
|
];
|
|
8
29
|
let channelLinkIdCounter = 4;
|
|
9
30
|
|
|
@@ -164,7 +185,10 @@ export default [
|
|
|
164
185
|
activityList[index] = {
|
|
165
186
|
...activityList[index],
|
|
166
187
|
...rest,
|
|
167
|
-
status: calcStatus(
|
|
188
|
+
status: calcStatus(
|
|
189
|
+
rest.startTime || activityList[index].startTime,
|
|
190
|
+
rest.endTime || activityList[index].endTime,
|
|
191
|
+
),
|
|
168
192
|
};
|
|
169
193
|
return { success: true, data: activityList[index] };
|
|
170
194
|
} else {
|
|
@@ -187,9 +211,27 @@ export default [
|
|
|
187
211
|
response: ({ query }) => {
|
|
188
212
|
const { current = 1, pageSize = 10, name } = query;
|
|
189
213
|
let list = [
|
|
190
|
-
{
|
|
191
|
-
|
|
192
|
-
|
|
214
|
+
{
|
|
215
|
+
id: 1,
|
|
216
|
+
name: '春季内购会-工业品专场',
|
|
217
|
+
path: '/paths/detail?id=1',
|
|
218
|
+
status: '已通过',
|
|
219
|
+
updateTime: '',
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
id: 2,
|
|
223
|
+
name: '春季内购会-进口设备',
|
|
224
|
+
path: '/paths/detail?id=2',
|
|
225
|
+
status: '待提审',
|
|
226
|
+
updateTime: '',
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
id: 3,
|
|
230
|
+
name: '春季内购会-新机专场',
|
|
231
|
+
path: '/paths/detail?id=3',
|
|
232
|
+
status: '已通过',
|
|
233
|
+
updateTime: '',
|
|
234
|
+
},
|
|
193
235
|
];
|
|
194
236
|
if (name) {
|
|
195
237
|
list = list.filter((item) => item.name.includes(name));
|
|
@@ -197,7 +239,10 @@ export default [
|
|
|
197
239
|
const start = (Number(current) - 1) * Number(pageSize);
|
|
198
240
|
return {
|
|
199
241
|
success: true,
|
|
200
|
-
data: {
|
|
242
|
+
data: {
|
|
243
|
+
list: list.slice(start, start + Number(pageSize)),
|
|
244
|
+
total: list.length,
|
|
245
|
+
},
|
|
201
246
|
};
|
|
202
247
|
},
|
|
203
248
|
},
|
|
@@ -207,9 +252,33 @@ export default [
|
|
|
207
252
|
response: ({ query }) => {
|
|
208
253
|
const { current = 1, pageSize = 10, name, id: pageId } = query;
|
|
209
254
|
let list = [
|
|
210
|
-
{
|
|
211
|
-
|
|
212
|
-
|
|
255
|
+
{
|
|
256
|
+
id: 1,
|
|
257
|
+
name: '春季内购会-工业品专场',
|
|
258
|
+
path: '/paths/detail?id=1',
|
|
259
|
+
status: '已通过',
|
|
260
|
+
activity: '春季内购会',
|
|
261
|
+
canShare: true,
|
|
262
|
+
updateTime: '',
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: 2,
|
|
266
|
+
name: '春季内购会-进口设备',
|
|
267
|
+
path: '/paths/detail?id=2',
|
|
268
|
+
status: '待提审',
|
|
269
|
+
activity: '春季内购会',
|
|
270
|
+
canShare: true,
|
|
271
|
+
updateTime: '',
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
id: 3,
|
|
275
|
+
name: '年终大促-主会场',
|
|
276
|
+
path: '/paths/detail?id=3',
|
|
277
|
+
status: '已通过',
|
|
278
|
+
activity: '年终大促',
|
|
279
|
+
canShare: false,
|
|
280
|
+
updateTime: '',
|
|
281
|
+
},
|
|
213
282
|
];
|
|
214
283
|
if (name) {
|
|
215
284
|
list = list.filter((item) => item.name.includes(name));
|
|
@@ -220,7 +289,10 @@ export default [
|
|
|
220
289
|
const start = (Number(current) - 1) * Number(pageSize);
|
|
221
290
|
return {
|
|
222
291
|
success: true,
|
|
223
|
-
data: {
|
|
292
|
+
data: {
|
|
293
|
+
list: list.slice(start, start + Number(pageSize)),
|
|
294
|
+
total: list.length,
|
|
295
|
+
},
|
|
224
296
|
};
|
|
225
297
|
},
|
|
226
298
|
},
|
|
@@ -237,7 +309,10 @@ export default [
|
|
|
237
309
|
const start = (Number(current) - 1) * Number(pageSize);
|
|
238
310
|
return {
|
|
239
311
|
success: true,
|
|
240
|
-
data: {
|
|
312
|
+
data: {
|
|
313
|
+
list: list.slice(start, start + Number(pageSize)),
|
|
314
|
+
total: list.length,
|
|
315
|
+
},
|
|
241
316
|
};
|
|
242
317
|
},
|
|
243
318
|
},
|
|
@@ -247,9 +322,30 @@ export default [
|
|
|
247
322
|
response: ({ query }) => {
|
|
248
323
|
const { current = 1, pageSize = 10, pageId } = query;
|
|
249
324
|
let list = [
|
|
250
|
-
{
|
|
251
|
-
|
|
252
|
-
|
|
325
|
+
{
|
|
326
|
+
id: 1,
|
|
327
|
+
pageId: 1,
|
|
328
|
+
nameCn: '商家A',
|
|
329
|
+
nameEn: 'a',
|
|
330
|
+
link: '/paths/detail?id=1&filed=a',
|
|
331
|
+
createTime: '2026-03-01 10:00:00',
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
id: 2,
|
|
335
|
+
pageId: 1,
|
|
336
|
+
nameCn: '商家B',
|
|
337
|
+
nameEn: 'b',
|
|
338
|
+
link: '/paths/detail?id=1&filed=b',
|
|
339
|
+
createTime: '2026-03-02 11:00:00',
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
id: 3,
|
|
343
|
+
pageId: 1,
|
|
344
|
+
nameCn: '商家C',
|
|
345
|
+
nameEn: 'c',
|
|
346
|
+
link: '/paths/detail?id=1&filed=c',
|
|
347
|
+
createTime: '2026-03-03 12:00:00',
|
|
348
|
+
},
|
|
253
349
|
];
|
|
254
350
|
if (pageId) {
|
|
255
351
|
list = list.filter((item) => String(item.pageId) === String(pageId));
|
|
@@ -257,7 +353,10 @@ export default [
|
|
|
257
353
|
const start = (Number(current) - 1) * Number(pageSize);
|
|
258
354
|
return {
|
|
259
355
|
success: true,
|
|
260
|
-
data: {
|
|
356
|
+
data: {
|
|
357
|
+
list: list.slice(start, start + Number(pageSize)),
|
|
358
|
+
total: list.length,
|
|
359
|
+
},
|
|
261
360
|
};
|
|
262
361
|
},
|
|
263
362
|
},
|
|
@@ -286,7 +385,9 @@ export default [
|
|
|
286
385
|
channelLinkList[index] = {
|
|
287
386
|
...channelLinkList[index],
|
|
288
387
|
...rest,
|
|
289
|
-
link: `/paths/detail?id=${channelLinkList[index].pageId}&filed=${
|
|
388
|
+
link: `/paths/detail?id=${channelLinkList[index].pageId}&filed=${
|
|
389
|
+
rest.nameEn || channelLinkList[index].nameEn
|
|
390
|
+
}`,
|
|
290
391
|
};
|
|
291
392
|
return { success: true, data: channelLinkList[index] };
|
|
292
393
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lxzy/code-snippet",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"files": [
|
|
5
5
|
"*",
|
|
6
6
|
"!dist",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"exceljs": "^4.3.0",
|
|
40
40
|
"fs-extra": "^10.0.0",
|
|
41
41
|
"got": "^11.8.2",
|
|
42
|
+
"history-with-query": "^4.10.4",
|
|
42
43
|
"jotai": "^1.6.1",
|
|
43
44
|
"lodash": "^4.17.0",
|
|
44
45
|
"lodash-es": "^4.17.21",
|
|
@@ -55,23 +56,26 @@
|
|
|
55
56
|
"react-dom": "^17.0.0",
|
|
56
57
|
"react-helmet-async": "^1.2.0",
|
|
57
58
|
"react-infinite-scroll-component": "^6.1.0",
|
|
58
|
-
"react-router-dom": "
|
|
59
|
+
"react-router-dom": "5",
|
|
59
60
|
"swagger-typescript-api": "10.0.2",
|
|
61
|
+
"tslib": "^2.8.1",
|
|
60
62
|
"unstated-next": "^1.1.0",
|
|
61
63
|
"validator": "^13.7.0",
|
|
62
64
|
"wangeditor": "^4.7.11"
|
|
63
65
|
},
|
|
64
66
|
"devDependencies": {
|
|
65
|
-
"@
|
|
67
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
68
|
+
"@babel/plugin-proposal-decorators": "^7.29.7",
|
|
69
|
+
"@types/node": "^22.1.0",
|
|
66
70
|
"@types/react": "^17.0.0",
|
|
67
71
|
"@types/react-dom": "^17.0.0",
|
|
72
|
+
"@types/react-router-dom": "5",
|
|
68
73
|
"@vitejs/plugin-react": "^6.0.0",
|
|
69
|
-
"esbuild": "^0.28.0",
|
|
70
74
|
"less": "^4.6.7",
|
|
71
75
|
"lint-staged": "^10.0.7",
|
|
72
76
|
"prettier": "^2.2.0",
|
|
73
|
-
"typescript": "^
|
|
74
|
-
"vite": "^8.
|
|
77
|
+
"typescript": "^5.0.0",
|
|
78
|
+
"vite": "^8.1.4",
|
|
75
79
|
"vite-plugin-mock": "^3.0.2",
|
|
76
80
|
"yorkie": "^2.0.0"
|
|
77
81
|
}
|
package/routes/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import menuRoutes from './menu';
|
|
2
|
+
|
|
3
|
+
const flattenRoutes = (routes) => {
|
|
4
|
+
const result = [];
|
|
5
|
+
routes.forEach((route) => {
|
|
6
|
+
if (route.component) {
|
|
7
|
+
result.push({ path: route.path, component: route.component });
|
|
8
|
+
}
|
|
9
|
+
if (route.routes) {
|
|
10
|
+
result.push(...flattenRoutes(route.routes));
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default [
|
|
17
|
+
...flattenRoutes(menuRoutes),
|
|
18
|
+
{ path: '/404', component: '404' },
|
|
19
|
+
];
|
package/routes/menu.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default [
|
|
2
|
+
{
|
|
3
|
+
path: '/home',
|
|
4
|
+
name: '首页',
|
|
5
|
+
component: 'home',
|
|
6
|
+
icon: 'smile',
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
path: '/activityCenter',
|
|
10
|
+
name: '活动中心',
|
|
11
|
+
icon: 'sound',
|
|
12
|
+
routes: [
|
|
13
|
+
{
|
|
14
|
+
path: '/activityCenter/activitySystemManagement',
|
|
15
|
+
name: '活动系统管理',
|
|
16
|
+
component: 'activityCenter/activitySystemManagement',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
path: '/activityCenter/activitySystemManagement/addPages',
|
|
20
|
+
hideInMenu: true,
|
|
21
|
+
component: 'activityCenter/activitySystemManagement/addPages',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
];
|
package/src/App.tsx
CHANGED
|
@@ -1,33 +1,54 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { Suspense, lazy } from 'react';
|
|
2
|
+
import { Switch, Route, Redirect } from 'react-router-dom';
|
|
3
|
+
import { Router } from 'react-router-dom';
|
|
4
|
+
import history from '@/umi';
|
|
3
5
|
import BasicLayout from '@/layouts/index';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import routes from '../routes';
|
|
7
|
+
|
|
8
|
+
const pageModules = import.meta.glob('./pages/**/*.tsx');
|
|
9
|
+
|
|
10
|
+
const componentCache = {};
|
|
11
|
+
const loadComponent = (path) => {
|
|
12
|
+
if (!componentCache[path]) {
|
|
13
|
+
const factory: any =
|
|
14
|
+
pageModules[`./pages/${path}.tsx`] ||
|
|
15
|
+
pageModules[`./pages/${path}/index.tsx`];
|
|
16
|
+
if (!factory) {
|
|
17
|
+
throw new Error(`Page component not found: ${path}`);
|
|
18
|
+
}
|
|
19
|
+
componentCache[path] = lazy(factory);
|
|
20
|
+
}
|
|
21
|
+
return componentCache[path];
|
|
22
|
+
};
|
|
7
23
|
|
|
8
24
|
const App = () => {
|
|
9
25
|
return (
|
|
10
|
-
<
|
|
26
|
+
<Router history={history}>
|
|
11
27
|
<BasicLayout>
|
|
12
|
-
<
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
<Suspense fallback={null}>
|
|
29
|
+
<Switch>
|
|
30
|
+
{routes.map((route, i) =>
|
|
31
|
+
route.redirect ? (
|
|
32
|
+
<Route key={route.path || i} path={route.path} exact>
|
|
33
|
+
<Redirect to={route.redirect} />
|
|
34
|
+
</Route>
|
|
35
|
+
) : (
|
|
36
|
+
<Route
|
|
37
|
+
key={route.path || i}
|
|
38
|
+
path={route.path}
|
|
39
|
+
exact={route.path !== '/404'}
|
|
40
|
+
render={() => {
|
|
41
|
+
const Component = loadComponent(route.component);
|
|
42
|
+
return <Component />;
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
),
|
|
46
|
+
)}
|
|
47
|
+
<Redirect to="/404" />
|
|
48
|
+
</Switch>
|
|
49
|
+
</Suspense>
|
|
29
50
|
</BasicLayout>
|
|
30
|
-
</
|
|
51
|
+
</Router>
|
|
31
52
|
);
|
|
32
53
|
};
|
|
33
54
|
|
package/src/global.css
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
html,
|
|
1
|
+
html,
|
|
2
|
+
body,
|
|
3
|
+
#root {
|
|
2
4
|
height: 100%;
|
|
3
5
|
margin: 0;
|
|
4
6
|
padding: 0;
|
|
@@ -8,37 +10,3 @@ html, body, #root {
|
|
|
8
10
|
#root > div {
|
|
9
11
|
height: 100%;
|
|
10
12
|
}
|
|
11
|
-
|
|
12
|
-
.ant-pro-layout,
|
|
13
|
-
.ant-layout {
|
|
14
|
-
height: 100% !important;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.ant-pro-layout .ant-layout-content {
|
|
18
|
-
display: flex !important;
|
|
19
|
-
flex-direction: column !important;
|
|
20
|
-
flex: 1 !important;
|
|
21
|
-
min-height: 0 !important;
|
|
22
|
-
overflow: auto !important;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.ant-pro-page-container {
|
|
26
|
-
display: flex !important;
|
|
27
|
-
flex-direction: column !important;
|
|
28
|
-
flex: 1 !important;
|
|
29
|
-
min-height: 0 !important;
|
|
30
|
-
height: auto !important;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.ant-pro-page-container .ant-pro-page-container-children-content {
|
|
34
|
-
display: flex !important;
|
|
35
|
-
flex-direction: column !important;
|
|
36
|
-
flex: 1 !important;
|
|
37
|
-
min-height: 0 !important;
|
|
38
|
-
margin: 0 !important;
|
|
39
|
-
padding: 24px !important;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.ant-pro-page-container .ant-pro-page-container-children-content > div {
|
|
43
|
-
flex: 1 !important;
|
|
44
|
-
}
|
package/src/layouts/index.tsx
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useNavigate } from 'react-router-dom';
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
3
2
|
import { Avatar, Dropdown, Menu, Space } from 'antd';
|
|
4
3
|
import ProLayout from '@ant-design/pro-layout';
|
|
4
|
+
import history from '@/umi';
|
|
5
|
+
import menuRoutes from '../../routes/menu';
|
|
6
|
+
import getIcon from '@/utils/getIcon';
|
|
5
7
|
|
|
6
|
-
const menuDataRender = (menuList
|
|
8
|
+
const menuDataRender = (menuList) => {
|
|
7
9
|
return menuList.map((item) => {
|
|
8
10
|
const localItem = {
|
|
9
11
|
...item,
|
|
12
|
+
icon: item.icon ? getIcon(item.icon) : undefined,
|
|
10
13
|
children: item.children ? menuDataRender(item.children) : undefined,
|
|
11
14
|
};
|
|
12
15
|
return localItem;
|
|
@@ -15,32 +18,29 @@ const menuDataRender = (menuList: any[]) => {
|
|
|
15
18
|
|
|
16
19
|
const BasicLayout = (props) => {
|
|
17
20
|
const { children } = props;
|
|
18
|
-
const
|
|
21
|
+
const [location, setLocation] = useState(history.location);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const unlisten = history.listen((location) => {
|
|
25
|
+
setLocation(location);
|
|
26
|
+
});
|
|
27
|
+
return () => unlisten();
|
|
28
|
+
}, []);
|
|
19
29
|
|
|
20
30
|
return (
|
|
21
31
|
<ProLayout
|
|
22
|
-
title="
|
|
32
|
+
title="管理平台"
|
|
23
33
|
logo={false}
|
|
24
34
|
layout="mix"
|
|
25
|
-
fixSiderbar
|
|
35
|
+
fixSiderbar={false}
|
|
26
36
|
fixedHeader
|
|
37
|
+
location={location}
|
|
27
38
|
route={{
|
|
28
39
|
path: '/',
|
|
29
|
-
routes:
|
|
30
|
-
{
|
|
31
|
-
path: '/activityCenter',
|
|
32
|
-
name: '活动中心',
|
|
33
|
-
routes: [
|
|
34
|
-
{
|
|
35
|
-
path: '/activityCenter/activitySystemManagement',
|
|
36
|
-
name: '活动系统管理',
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
],
|
|
40
|
+
routes: menuDataRender(menuRoutes),
|
|
41
41
|
}}
|
|
42
42
|
menuItemRender={(item, dom) => (
|
|
43
|
-
<a onClick={() =>
|
|
43
|
+
<a onClick={() => history.push(item.path || '/')}>{dom}</a>
|
|
44
44
|
)}
|
|
45
45
|
>
|
|
46
46
|
{children}
|
package/src/main.tsx
CHANGED
package/src/pages/404.tsx
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import history from '@/umi';
|
|
2
|
+
import { Button, Result } from 'antd';
|
|
2
3
|
|
|
3
4
|
export default function Page() {
|
|
4
|
-
return
|
|
5
|
+
return (
|
|
6
|
+
<Result
|
|
7
|
+
title="404"
|
|
8
|
+
extra={
|
|
9
|
+
<Button
|
|
10
|
+
onClick={() => {
|
|
11
|
+
history.push('/');
|
|
12
|
+
}}
|
|
13
|
+
></Button>
|
|
14
|
+
}
|
|
15
|
+
></Result>
|
|
16
|
+
);
|
|
5
17
|
}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Button,
|
|
4
|
+
DatePicker,
|
|
5
|
+
message,
|
|
6
|
+
Modal,
|
|
7
|
+
notification,
|
|
8
|
+
Select,
|
|
9
|
+
Space,
|
|
10
|
+
} from 'antd';
|
|
3
11
|
import ProTable, { ActionType } from '@ant-design/pro-table';
|
|
4
|
-
import { useNavigate } from 'react-router-dom';
|
|
5
12
|
import axios from 'axios';
|
|
6
13
|
import AddDrawer from './add';
|
|
14
|
+
import history from '@/umi';
|
|
7
15
|
|
|
8
16
|
const ipTagOptions = ['品牌A', '品牌B', '品牌C', '品牌D'];
|
|
9
17
|
|
|
10
18
|
const ActivitySystemManagement = () => {
|
|
11
|
-
const navigate = useNavigate();
|
|
12
19
|
const actionRef = useRef<ActionType>();
|
|
13
20
|
const [drawerVisible, setDrawerVisible] = useState(false);
|
|
14
21
|
const [editingItem, setEditingItem] = useState(null);
|
|
@@ -159,7 +166,7 @@ const ActivitySystemManagement = () => {
|
|
|
159
166
|
type="link"
|
|
160
167
|
size="small"
|
|
161
168
|
onClick={() =>
|
|
162
|
-
|
|
169
|
+
history.push(
|
|
163
170
|
'/activityCenter/activitySystemManagement/addPages',
|
|
164
171
|
)
|
|
165
172
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class Dispatcher {
|
|
2
|
+
data = {};
|
|
3
|
+
callbacks = {};
|
|
4
|
+
|
|
5
|
+
update(namespace) {
|
|
6
|
+
if (this.callbacks[namespace]) {
|
|
7
|
+
this.callbacks[namespace].forEach((cb) => cb(this.data[namespace]));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
setData(namespace, data) {
|
|
12
|
+
this.data[namespace] = data;
|
|
13
|
+
this.update(namespace);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default new Dispatcher();
|
package/src/umi/index.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import dispatcher from './dispatcher';
|
|
3
|
+
|
|
4
|
+
function useModel(namespace) {
|
|
5
|
+
const [state, setState] = useState(() => dispatcher.data[namespace]);
|
|
6
|
+
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const handler = (data) => setState(data);
|
|
9
|
+
dispatcher.callbacks[namespace] = dispatcher.callbacks[namespace] || [];
|
|
10
|
+
dispatcher.callbacks[namespace].push(handler);
|
|
11
|
+
return () => {
|
|
12
|
+
dispatcher.callbacks[namespace] = dispatcher.callbacks[namespace].filter(
|
|
13
|
+
(h) => h !== handler,
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
}, [namespace]);
|
|
17
|
+
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function Executor(props) {
|
|
22
|
+
const { hook, namespace } = props;
|
|
23
|
+
const data = hook();
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
dispatcher.setData(namespace, data);
|
|
26
|
+
}, [data, namespace]);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function ModelProvider(props) {
|
|
31
|
+
const { children } = props;
|
|
32
|
+
const modules = import.meta.glob('/src/models/**/*.ts', { eager: true });
|
|
33
|
+
const modelList = Object.entries(modules)
|
|
34
|
+
.filter(([path, module]) => {
|
|
35
|
+
return module && module.default;
|
|
36
|
+
})
|
|
37
|
+
.map(([path, module]) => {
|
|
38
|
+
const namespace = path.replace(/^\/src\/models\//, '').replace(/\.ts$/, '');
|
|
39
|
+
return { namespace, hook: module.default };
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
{modelList.map(({ namespace, hook }) => (
|
|
45
|
+
<Executor key={namespace} hook={hook} namespace={namespace} />
|
|
46
|
+
))}
|
|
47
|
+
{children}
|
|
48
|
+
</>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { useModel, ModelProvider };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as Icons from '@ant-design/icons';
|
|
3
|
+
|
|
4
|
+
const getIcon = (name) => {
|
|
5
|
+
if (!name) return undefined;
|
|
6
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
7
|
+
const parts = name.split('-');
|
|
8
|
+
const baseName = parts.map(capitalize).join('');
|
|
9
|
+
const hasSuffix = name.endsWith('Filled') || name.endsWith('TwoTone');
|
|
10
|
+
const componentName = hasSuffix ? baseName : baseName + 'Outlined';
|
|
11
|
+
const IconComp = Icons[componentName];
|
|
12
|
+
if (!IconComp) return undefined;
|
|
13
|
+
return React.createElement(IconComp);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default getIcon;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/tsconfig.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"module": "ESNext",
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"lib": ["DOM", "ESNext", "DOM.Iterable"],
|
|
6
|
+
"moduleResolution": "bundler",
|
|
6
7
|
"resolveJsonModule": true,
|
|
7
8
|
"importHelpers": true,
|
|
8
9
|
"jsx": "react-jsx",
|
|
@@ -12,12 +13,13 @@
|
|
|
12
13
|
"strict": false,
|
|
13
14
|
"noImplicitAny": false,
|
|
14
15
|
"paths": {
|
|
15
|
-
"@/*": ["src/*"]
|
|
16
|
+
"@/*": ["src/*"],
|
|
17
|
+
"umi": ["src/umi"]
|
|
16
18
|
},
|
|
17
19
|
"allowSyntheticDefaultImports": true,
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
+
"experimentalDecorators": true,
|
|
21
|
+
"emitDecoratorMetadata": true,
|
|
22
|
+
"skipLibCheck": true
|
|
20
23
|
},
|
|
21
|
-
"include": ["mock/**/*", "src/**/*", "typings.d.ts", "vite.*.ts"]
|
|
22
|
-
"exclude": ["node_modules", "lib", "es", "dist", "typings"]
|
|
24
|
+
"include": ["mock/**/*", "src/**/*", "routes/**/*", "typings.d.ts", "vite.*.ts"]
|
|
23
25
|
}
|
package/vite.config.ts
CHANGED
|
@@ -4,8 +4,14 @@ import { viteMockServe } from 'vite-plugin-mock';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
|
|
6
6
|
export default defineConfig(({ command }) => ({
|
|
7
|
+
define: {
|
|
8
|
+
'process.env': {},
|
|
9
|
+
'process.env.NODE_ENV': JSON.stringify(
|
|
10
|
+
command === 'serve' ? 'development' : 'production',
|
|
11
|
+
),
|
|
12
|
+
},
|
|
7
13
|
plugins: [
|
|
8
|
-
react(),
|
|
14
|
+
react({}),
|
|
9
15
|
viteMockServe({
|
|
10
16
|
mockPath: 'mock',
|
|
11
17
|
enable: command === 'serve',
|
|
@@ -14,6 +20,7 @@ export default defineConfig(({ command }) => ({
|
|
|
14
20
|
resolve: {
|
|
15
21
|
alias: {
|
|
16
22
|
'@': path.resolve(__dirname, './src'),
|
|
23
|
+
umi: path.resolve(__dirname, './src/umi'),
|
|
17
24
|
'~antd': path.resolve(__dirname, './node_modules/antd'),
|
|
18
25
|
},
|
|
19
26
|
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
|
|
@@ -23,10 +30,14 @@ export default defineConfig(({ command }) => ({
|
|
|
23
30
|
less: {
|
|
24
31
|
javascriptEnabled: true,
|
|
25
32
|
math: 'always',
|
|
33
|
+
modifyVars: {
|
|
34
|
+
'@root-entry-name': 'default',
|
|
35
|
+
},
|
|
26
36
|
},
|
|
27
37
|
},
|
|
28
38
|
},
|
|
29
39
|
server: {
|
|
30
40
|
port: 8000,
|
|
41
|
+
open: true,
|
|
31
42
|
},
|
|
32
43
|
}));
|