@lxzy/code-snippet 0.0.8 → 0.0.10

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.
@@ -0,0 +1,11 @@
1
+ - ts 类型不需要写详细,不要在 tsx 文件里定义 interface,组件里的方法参数不要写类型定义
2
+ - 组件的 props 不要直接在入参的地方解构,也不要定义 React.FC
3
+
4
+ ```ts
5
+ const AddDrawer: React.FC = ({ a, b, c }) => {}; // 错误
6
+
7
+ const AddDrawer = (props) => {
8
+ // 正确
9
+ const { a, b, c } = props;
10
+ };
11
+ ```
package/README.md CHANGED
@@ -1,15 +1,43 @@
1
- # umi project
2
-
3
- ## Getting Started
4
-
5
- Install dependencies,
6
-
7
- ```bash
8
- $ yarn
9
1
  ```
2
+ {
3
+ // Place your 全局 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
4
+ // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
5
+ // is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
6
+ // used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
7
+ // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
8
+ // Placeholders with the same ids are connected.
9
+ "快速打印": {
10
+ "scope": "javascript,javascriptreact,typescript,typescriptreact",
11
+ "prefix": "clg",
12
+ "body": ["console.log($1);"],
13
+ "description": "快速打印"
14
+ },
15
+ "react组件模版": {
16
+ "scope": "javascript, javascriptreact, typescript, typescriptreact",
17
+ "prefix": "react",
18
+ "body": [
19
+ "import React, {useState} from 'react'",
20
+ "",
21
+ "export default function ${TM_FILENAME_BASE/(.*)/${1:/capitalize}/}() {",
22
+ " return (",
23
+ " <div>",
24
+ " $1",
25
+ " </div>",
26
+ " )",
27
+ "}",
28
+ ],
29
+ "description": "react组件模版"
30
+ },
31
+ "formily模版": {
32
+ "scope": "javascript, javascriptreact, typescript, typescriptreact",
33
+ "prefix": "formily",
34
+ "body": [
35
+ "import { createForm, onFieldInputValueChange } from '@formily/core';",
36
+ "import { Form, FormItem, FormGrid } from '@formily/next';",
37
+ "import { Field } from '@formily/react';"
38
+ ],
39
+ "description": "formily模版"
40
+ }
41
+ }
10
42
 
11
- Start the dev server,
12
-
13
- ```bash
14
- $ yarn start
15
43
  ```
package/mock/activity.ts CHANGED
@@ -1,9 +1,30 @@
1
1
  import { MockMethod } from 'vite-plugin-mock';
2
2
 
3
3
  let channelLinkList = [
4
- { id: 1, pageId: 1, nameCn: '商家A', nameEn: 'a', link: '/paths/detail?id=1&filed=a', createTime: '2026-03-01 10:00:00' },
5
- { id: 2, pageId: 1, nameCn: '商家B', nameEn: 'b', link: '/paths/detail?id=1&filed=b', createTime: '2026-03-02 11:00:00' },
6
- { id: 3, pageId: 1, nameCn: '商家C', nameEn: 'c', link: '/paths/detail?id=1&filed=c', createTime: '2026-03-03 12:00:00' },
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(rest.startTime || activityList[index].startTime, rest.endTime || activityList[index].endTime),
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
- { id: 1, name: '春季内购会-工业品专场', path: '/paths/detail?id=1', status: '已通过', updateTime: '' },
191
- { id: 2, name: '春季内购会-进口设备', path: '/paths/detail?id=2', status: '待提审', updateTime: '' },
192
- { id: 3, name: '春季内购会-新机专场', path: '/paths/detail?id=3', status: '已通过', updateTime: '' },
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: { list: list.slice(start, start + Number(pageSize)), total: list.length },
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
- { id: 1, name: '春季内购会-工业品专场', path: '/paths/detail?id=1', status: '已通过', activity: '春季内购会', canShare: true, updateTime: '' },
211
- { id: 2, name: '春季内购会-进口设备', path: '/paths/detail?id=2', status: '待提审', activity: '春季内购会', canShare: true, updateTime: '' },
212
- { id: 3, name: '年终大促-主会场', path: '/paths/detail?id=3', status: '已通过', activity: '年终大促', canShare: false, updateTime: '' },
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: { list: list.slice(start, start + Number(pageSize)), total: list.length },
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: { list: list.slice(start, start + Number(pageSize)), total: list.length },
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
- { id: 1, pageId: 1, nameCn: '商家A', nameEn: 'a', link: '/paths/detail?id=1&filed=a', createTime: '2026-03-01 10:00:00' },
251
- { id: 2, pageId: 1, nameCn: '商家B', nameEn: 'b', link: '/paths/detail?id=1&filed=b', createTime: '2026-03-02 11:00:00' },
252
- { id: 3, pageId: 1, nameCn: '商家C', nameEn: 'c', link: '/paths/detail?id=1&filed=c', createTime: '2026-03-03 12:00:00' },
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: { list: list.slice(start, start + Number(pageSize)), total: list.length },
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=${rest.nameEn || channelLinkList[index].nameEn}`,
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.8",
3
+ "version": "0.0.10",
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": "^6.3.0",
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": {
67
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
68
+ "@babel/plugin-proposal-decorators": "^7.29.7",
65
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": "^4.1.2",
74
- "vite": "^8.0.10",
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
  }
@@ -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,23 @@
1
+ export default [
2
+ {
3
+ path: '/home',
4
+ name: '首页',
5
+ component: 'home',
6
+ },
7
+ {
8
+ path: '/activityCenter',
9
+ name: '活动中心',
10
+ routes: [
11
+ {
12
+ path: '/activityCenter/activitySystemManagement',
13
+ name: '活动系统管理',
14
+ component: 'activityCenter/activitySystemManagement',
15
+ },
16
+ {
17
+ path: '/activityCenter/activitySystemManagement/addPages',
18
+ hideInMenu: true,
19
+ component: 'activityCenter/activitySystemManagement/addPages',
20
+ },
21
+ ],
22
+ },
23
+ ];
package/src/App.tsx CHANGED
@@ -1,33 +1,46 @@
1
- import React from 'react';
2
- import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
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 ActivitySystemManagement from '@/pages/activityCenter/activitySystemManagement';
5
- import ActivitySystemManagementAddPages from '@/pages/activityCenter/activitySystemManagement/addPages';
6
- import Page404 from '@/pages/404';
6
+ import routes from '../routes';
7
7
 
8
- const App: React.FC = () => {
8
+ const componentCache = {};
9
+ const loadComponent = (path) => {
10
+ if (!componentCache[path]) {
11
+ componentCache[path] = lazy(() => import(`./pages/${path}`));
12
+ }
13
+ return componentCache[path];
14
+ };
15
+
16
+ const App = () => {
9
17
  return (
10
- <BrowserRouter>
18
+ <Router history={history}>
11
19
  <BasicLayout>
12
- <Routes>
13
- <Route
14
- path="/"
15
- element={
16
- <Navigate to="/activityCenter/activitySystemManagement" replace />
17
- }
18
- />
19
- <Route
20
- path="/activityCenter/activitySystemManagement"
21
- element={<ActivitySystemManagement />}
22
- />
23
- <Route
24
- path="/activityCenter/activitySystemManagement/addPages"
25
- element={<ActivitySystemManagementAddPages />}
26
- />
27
- <Route path="*" element={<Page404 />} />
28
- </Routes>
20
+ <Suspense fallback={null}>
21
+ <Switch>
22
+ {routes.map((route, i) =>
23
+ route.redirect ? (
24
+ <Route key={route.path || i} path={route.path} exact>
25
+ <Redirect to={route.redirect} />
26
+ </Route>
27
+ ) : (
28
+ <Route
29
+ key={route.path || i}
30
+ path={route.path}
31
+ exact={route.path !== '/404'}
32
+ render={() => {
33
+ const Component = loadComponent(route.component);
34
+ return <Component />;
35
+ }}
36
+ />
37
+ ),
38
+ )}
39
+ <Redirect to="/404" />
40
+ </Switch>
41
+ </Suspense>
29
42
  </BasicLayout>
30
- </BrowserRouter>
43
+ </Router>
31
44
  );
32
45
  };
33
46
 
package/src/global.css CHANGED
@@ -1,4 +1,6 @@
1
- html, body, #root {
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
- }
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
- import { useNavigate } from 'react-router-dom';
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';
5
6
 
6
- const menuDataRender = (menuList: any[]) => {
7
+ const menuDataRender = (menuList) => {
7
8
  return menuList.map((item) => {
8
9
  const localItem = {
9
10
  ...item,
@@ -13,33 +14,22 @@ const menuDataRender = (menuList: any[]) => {
13
14
  });
14
15
  };
15
16
 
16
- const BasicLayout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
17
- const navigate = useNavigate();
17
+ const BasicLayout = (props) => {
18
+ const { children } = props;
18
19
 
19
20
  return (
20
21
  <ProLayout
21
- title="Code Snippet"
22
+ title="管理平台"
22
23
  logo={false}
23
24
  layout="mix"
24
- fixSiderbar
25
+ fixSiderbar={false}
25
26
  fixedHeader
26
27
  route={{
27
28
  path: '/',
28
- routes: [
29
- {
30
- path: '/activityCenter',
31
- name: '活动中心',
32
- routes: [
33
- {
34
- path: '/activityCenter/activitySystemManagement',
35
- name: '活动系统管理',
36
- },
37
- ],
38
- },
39
- ],
29
+ routes: menuRoutes,
40
30
  }}
41
31
  menuItemRender={(item, dom) => (
42
- <a onClick={() => navigate(item.path || '/')}>{dom}</a>
32
+ <a onClick={() => history.push(item.path || '/')}>{dom}</a>
43
33
  )}
44
34
  >
45
35
  {children}
package/src/main.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import App from './App';
4
+ import 'antd/es/notification/style';
4
5
  import './global.css';
5
6
 
6
7
  ReactDOM.render(
package/src/pages/404.tsx CHANGED
@@ -1,5 +1,17 @@
1
- import { Result } from 'antd';
1
+ import history from '@/umi';
2
+ import { Button, Result } from 'antd';
2
3
 
3
4
  export default function Page() {
4
- return <Result title="404"></Result>;
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
  }
@@ -29,19 +29,8 @@ const strategyTagOptions = ['常态化', '拉新', '促活', '促销', '品牌
29
29
  const ipTagOptions = ['品牌A', '品牌B', '品牌C', '品牌D'];
30
30
  const industryTagOptions = ['制造业', '轻工业', '重工业', '服务业', '农业'];
31
31
 
32
- interface AddDrawerProps {
33
- visible: boolean;
34
- editingItem: any;
35
- onClose: () => void;
36
- onSuccess: () => void;
37
- }
38
-
39
- const AddDrawer: React.FC<AddDrawerProps> = ({
40
- visible,
41
- editingItem,
42
- onClose,
43
- onSuccess,
44
- }) => {
32
+ const AddDrawer = (props) => {
33
+ const { visible, editingItem, onClose, onSuccess } = props;
45
34
  const formRef = useRef<any>();
46
35
 
47
36
  const handleSubmit = async (values) => {
@@ -5,23 +5,12 @@ import ProTable from '@ant-design/pro-table';
5
5
  import { ModalForm, ProFormText } from '@ant-design/pro-form';
6
6
  import axios from 'axios';
7
7
 
8
- interface ChannelLinkModalProps {
9
- visible: boolean;
10
- pageName: string;
11
- pageId: number;
12
- onClose: () => void;
13
- }
14
-
15
- const ChannelLinkModal: React.FC<ChannelLinkModalProps> = ({
16
- visible,
17
- pageName,
18
- pageId,
19
- onClose,
20
- }) => {
8
+ const ChannelLinkModal = (props) => {
9
+ const { visible, pageName, pageId, onClose } = props;
21
10
  const actionRef = useRef<any>();
22
11
  const [addVisible, setAddVisible] = useState(false);
23
12
  const [editVisible, setEditVisible] = useState(false);
24
- const [editingItem, setEditingItem] = useState<any>(null);
13
+ const [editingItem, setEditingItem] = useState(null);
25
14
 
26
15
  const handleAdd = async (values) => {
27
16
  await axios.post('/api/activity/channelLink/add', {