@lxzy/code-snippet 0.0.7 → 0.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lxzy/code-snippet",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "files": [
5
5
  "*",
6
6
  "!dist",
package/src/App.tsx CHANGED
@@ -5,7 +5,7 @@ import ActivitySystemManagement from '@/pages/activityCenter/activitySystemManag
5
5
  import ActivitySystemManagementAddPages from '@/pages/activityCenter/activitySystemManagement/addPages';
6
6
  import Page404 from '@/pages/404';
7
7
 
8
- const App: React.FC = () => {
8
+ const App = () => {
9
9
  return (
10
10
  <BrowserRouter>
11
11
  <BasicLayout>
@@ -13,7 +13,8 @@ const menuDataRender = (menuList: any[]) => {
13
13
  });
14
14
  };
15
15
 
16
- const BasicLayout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
16
+ const BasicLayout = (props) => {
17
+ const { children } = props;
17
18
  const navigate = useNavigate();
18
19
 
19
20
  return (
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/dist/antd.css';
4
5
  import './global.css';
5
6
 
6
7
  ReactDOM.render(
@@ -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', {
@@ -1,39 +1,144 @@
1
- import React from 'react';
2
- import { Button } from 'antd';
1
+ import React, { useRef, useState } from 'react';
2
+ import { Button, Modal, Radio, Input, message, Space } from 'antd';
3
+ import { PlusOutlined } from '@ant-design/icons';
3
4
  import ProTable from '@ant-design/pro-table';
5
+ import { ModalForm } from '@ant-design/pro-form';
4
6
  import axios from 'axios';
5
7
 
6
- const CustomLink: React.FC = () => {
8
+ const CustomLink = () => {
9
+ const actionRef = useRef<any>();
10
+ const [addVisible, setAddVisible] = useState(false);
11
+ const [editVisible, setEditVisible] = useState(false);
12
+ const [editingItem, setEditingItem] = useState(null);
13
+
14
+ const handleAdd = async (values) => {
15
+ await axios.post('/api/activity/customLink/add', values);
16
+ message.success('新增成功');
17
+ setAddVisible(false);
18
+ actionRef.current?.reload();
19
+ return true;
20
+ };
21
+
22
+ const handleEdit = async (values) => {
23
+ await axios.post('/api/activity/customLink/update', {
24
+ ...values,
25
+ id: editingItem?.id,
26
+ });
27
+ message.success('编辑成功');
28
+ setEditVisible(false);
29
+ setEditingItem(null);
30
+ actionRef.current?.reload();
31
+ return true;
32
+ };
33
+
34
+ const handleDelete = async (record) => {
35
+ Modal.confirm({
36
+ title: '确认删除',
37
+ content: '确定要删除这条自定义链接吗?',
38
+ onOk: async () => {
39
+ await axios.post('/api/activity/customLink/delete', { id: record.id });
40
+ message.success('删除成功');
41
+ actionRef.current?.reload();
42
+ },
43
+ });
44
+ };
45
+
46
+ const getTypeName = (type: number) => {
47
+ return type === 1 ? '小程序' : 'H5链接';
48
+ };
49
+
7
50
  return (
8
51
  <div>
9
- <ProTable
52
+ <ProTable<any>
10
53
  headerTitle={false}
11
54
  toolBarRender={() => [
12
- <Button key="add" type="primary">新建自定义链接</Button>,
55
+ <Button
56
+ key="add"
57
+ type="primary"
58
+ icon={<PlusOutlined />}
59
+ onClick={() => setAddVisible(true)}
60
+ >
61
+ 新建自定义链接
62
+ </Button>,
13
63
  ]}
64
+ actionRef={actionRef}
14
65
  rowKey="id"
15
66
  request={async (params) => {
16
67
  const { data: result } = await axios.get('/api/activity/customLinkList', { params });
17
68
  return { data: result.data.list, total: result.data.total, success: result.success };
18
69
  }}
19
70
  columns={[
20
- { title: '跳转类型', dataIndex: 'type' },
71
+ { title: '跳转类型', dataIndex: 'type', render: (_, record) => getTypeName(record.type) },
21
72
  { title: '页面路径', dataIndex: 'path' },
22
73
  { title: '最近更新时间', dataIndex: 'updateTime' },
23
74
  {
24
75
  title: '操作',
25
76
  valueType: 'option',
26
- render: () => (
27
- <>
28
- <Button type="link" size="small">编辑</Button>
29
- <Button type="link" danger size="small">删除</Button>
30
- </>
77
+ render: (_, record) => (
78
+ <Space>
79
+ <Button
80
+ type="link"
81
+ size="small"
82
+ onClick={() => {
83
+ setEditingItem(record);
84
+ setEditVisible(true);
85
+ }}
86
+ >
87
+ 编辑
88
+ </Button>
89
+ <Button type="link" danger size="small" onClick={() => handleDelete(record)}>
90
+ 删除
91
+ </Button>
92
+ </Space>
31
93
  ),
32
94
  },
33
95
  ]}
34
96
  pagination={false}
35
97
  options={false}
98
+ search={false}
36
99
  />
100
+
101
+ <ModalForm
102
+ title="新建自定义链接"
103
+ visible={addVisible}
104
+ onVisibleChange={setAddVisible}
105
+ onFinish={handleAdd}
106
+ modalProps={{ destroyOnClose: true }}
107
+ >
108
+ <div style={{ marginBottom: 24 }}>
109
+ <div style={{ marginBottom: 8, fontWeight: 500 }}><span style={{ color: '#ff4d4f' }}>*</span> 跳转类型</div>
110
+ <Radio.Group name="type" defaultValue={1}>
111
+ <Radio value={1}>小程序</Radio>
112
+ <Radio value={2}>H5链接</Radio>
113
+ </Radio.Group>
114
+ </div>
115
+ <div style={{ marginBottom: 24 }}>
116
+ <div style={{ marginBottom: 8, fontWeight: 500 }}><span style={{ color: '#ff4d4f' }}>*</span> 页面路径</div>
117
+ <Input name="path" placeholder="请输入页面路径" />
118
+ </div>
119
+ </ModalForm>
120
+
121
+ <ModalForm
122
+ title="编辑自定义链接"
123
+ visible={editVisible}
124
+ onVisibleChange={setEditVisible}
125
+ onFinish={handleEdit}
126
+ initialValues={editingItem ? { type: editingItem.type, path: editingItem.path } : {}}
127
+ key={editingItem?.id}
128
+ modalProps={{ destroyOnClose: true }}
129
+ >
130
+ <div style={{ marginBottom: 24 }}>
131
+ <div style={{ marginBottom: 8, fontWeight: 500 }}><span style={{ color: '#ff4d4f' }}>*</span> 跳转类型</div>
132
+ <Radio.Group name="type">
133
+ <Radio value={1}>小程序</Radio>
134
+ <Radio value={2}>H5链接</Radio>
135
+ </Radio.Group>
136
+ </div>
137
+ <div style={{ marginBottom: 24 }}>
138
+ <div style={{ marginBottom: 8, fontWeight: 500 }}><span style={{ color: '#ff4d4f' }}>*</span> 页面路径</div>
139
+ <Input name="path" placeholder="请输入页面路径" />
140
+ </div>
141
+ </ModalForm>
37
142
  </div>
38
143
  );
39
144
  };
@@ -4,9 +4,9 @@ import ProTable from '@ant-design/pro-table';
4
4
  import axios from 'axios';
5
5
  import ChannelLinkModal from './ChannelLinkModal';
6
6
 
7
- const CustomPage: React.FC = () => {
7
+ const CustomPage = () => {
8
8
  const [channelLinkVisible, setChannelLinkVisible] = useState(false);
9
- const [currentPage, setCurrentPage] = useState<any>(null);
9
+ const [currentPage, setCurrentPage] = useState(null);
10
10
 
11
11
  return (
12
12
  <div>
@@ -3,7 +3,7 @@ import { Button } from 'antd';
3
3
  import ProTable from '@ant-design/pro-table';
4
4
  import axios from 'axios';
5
5
 
6
- const SystemPage: React.FC = () => {
6
+ const SystemPage = () => {
7
7
  return (
8
8
  <div>
9
9
  <ProTable
@@ -4,7 +4,7 @@ import SystemPage from './components/SystemPage';
4
4
  import CustomPage from './components/CustomPage';
5
5
  import CustomLink from './components/CustomLink';
6
6
 
7
- const AddPages: React.FC = () => {
7
+ const AddPages = () => {
8
8
  const [activeTab, setActiveTab] = useState('system');
9
9
 
10
10
  const tabContent = {
@@ -1,4 +1,4 @@
1
- import React, { useRef, useState } from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
2
  import { Button, DatePicker, message, Modal, Select, Space } from 'antd';
3
3
  import ProTable, { ActionType } from '@ant-design/pro-table';
4
4
  import { useNavigate } from 'react-router-dom';
@@ -158,7 +158,11 @@ const ActivitySystemManagement = () => {
158
158
  <Button
159
159
  type="link"
160
160
  size="small"
161
- onClick={() => navigate('/activityCenter/activitySystemManagement/addPages')}
161
+ onClick={() =>
162
+ navigate(
163
+ '/activityCenter/activitySystemManagement/addPages',
164
+ )
165
+ }
162
166
  >
163
167
  添加页面
164
168
  </Button>
package/mock/.gitkeep DELETED
File without changes