Commit 8496500b4ef5bfa2471477561e7e10c87a3e5418
1 parent
40198833
feat: 客户管理系统开发
Showing
2 changed files
with
249 additions
and
0 deletions
.umirc.ts
src/pages/Client/index.tsx
0 → 100644
1 | +import { EllipsisOutlined, PlusOutlined } from '@ant-design/icons'; | |
2 | +import type { ActionType, ProColumns } from '@ant-design/pro-components'; | |
3 | +import { ProTable, TableDropdown } from '@ant-design/pro-components'; | |
4 | +import { request } from '@umijs/max'; | |
5 | +import { Button, Dropdown, Space, Tag } from 'antd'; | |
6 | +import { useRef } from 'react'; | |
7 | + | |
8 | +export const waitTimePromise = async (time: number = 100) => { | |
9 | + return new Promise((resolve) => { | |
10 | + setTimeout(() => { | |
11 | + resolve(true); | |
12 | + }, time); | |
13 | + }); | |
14 | +}; | |
15 | + | |
16 | +export const waitTime = async (time: number = 100) => { | |
17 | + await waitTimePromise(time); | |
18 | +}; | |
19 | + | |
20 | +type GithubIssueItem = { | |
21 | + url: string; | |
22 | + id: number; | |
23 | + number: number; | |
24 | + title: string; | |
25 | + labels: { | |
26 | + name: string; | |
27 | + color: string; | |
28 | + }[]; | |
29 | + state: string; | |
30 | + comments: number; | |
31 | + created_at: string; | |
32 | + updated_at: string; | |
33 | + closed_at?: string; | |
34 | +}; | |
35 | + | |
36 | +const columns: ProColumns<GithubIssueItem>[] = [ | |
37 | + { | |
38 | + dataIndex: 'index', | |
39 | + valueType: 'indexBorder', | |
40 | + width: 48, | |
41 | + }, | |
42 | + { | |
43 | + title: '标题', | |
44 | + dataIndex: 'title', | |
45 | + copyable: true, | |
46 | + ellipsis: true, | |
47 | + tooltip: '标题过长会自动收缩', | |
48 | + formItemProps: { | |
49 | + rules: [ | |
50 | + { | |
51 | + required: true, | |
52 | + message: '此项为必填项', | |
53 | + }, | |
54 | + ], | |
55 | + }, | |
56 | + }, | |
57 | + { | |
58 | + disable: true, | |
59 | + title: '状态', | |
60 | + dataIndex: 'state', | |
61 | + filters: true, | |
62 | + onFilter: true, | |
63 | + ellipsis: true, | |
64 | + valueType: 'select', | |
65 | + valueEnum: { | |
66 | + all: { text: '超长'.repeat(50) }, | |
67 | + open: { | |
68 | + text: '未解决', | |
69 | + status: 'Error', | |
70 | + }, | |
71 | + closed: { | |
72 | + text: '已解决', | |
73 | + status: 'Success', | |
74 | + disabled: true, | |
75 | + }, | |
76 | + processing: { | |
77 | + text: '解决中', | |
78 | + status: 'Processing', | |
79 | + }, | |
80 | + }, | |
81 | + }, | |
82 | + { | |
83 | + disable: true, | |
84 | + title: '标签', | |
85 | + dataIndex: 'labels', | |
86 | + search: false, | |
87 | + renderFormItem: (_, { defaultRender }) => { | |
88 | + return defaultRender(_); | |
89 | + }, | |
90 | + render: (_, record) => ( | |
91 | + <Space> | |
92 | + {record.labels.map(({ name, color }) => ( | |
93 | + <Tag color={color} key={name}> | |
94 | + {name} | |
95 | + </Tag> | |
96 | + ))} | |
97 | + </Space> | |
98 | + ), | |
99 | + }, | |
100 | + { | |
101 | + title: '创建时间', | |
102 | + key: 'showTime', | |
103 | + dataIndex: 'created_at', | |
104 | + valueType: 'date', | |
105 | + sorter: true, | |
106 | + hideInSearch: true, | |
107 | + }, | |
108 | + { | |
109 | + title: '创建时间', | |
110 | + dataIndex: 'created_at', | |
111 | + valueType: 'dateRange', | |
112 | + hideInTable: true, | |
113 | + search: { | |
114 | + transform: (value) => { | |
115 | + return { | |
116 | + startTime: value[0], | |
117 | + endTime: value[1], | |
118 | + }; | |
119 | + }, | |
120 | + }, | |
121 | + }, | |
122 | + { | |
123 | + title: '操作', | |
124 | + valueType: 'option', | |
125 | + key: 'option', | |
126 | + render: (text, record, _, action) => [ | |
127 | + <a | |
128 | + key="editable" | |
129 | + onClick={() => { | |
130 | + action?.startEditable?.(record.id); | |
131 | + }} | |
132 | + > | |
133 | + 编辑 | |
134 | + </a>, | |
135 | + <a href={record.url} target="_blank" rel="noopener noreferrer" key="view"> | |
136 | + 查看 | |
137 | + </a>, | |
138 | + <TableDropdown | |
139 | + key="actionGroup" | |
140 | + onSelect={() => action?.reload()} | |
141 | + menus={[ | |
142 | + { key: 'copy', name: '复制' }, | |
143 | + { key: 'delete', name: '删除' }, | |
144 | + ]} | |
145 | + />, | |
146 | + ], | |
147 | + }, | |
148 | +]; | |
149 | + | |
150 | +export default () => { | |
151 | + const actionRef = useRef<ActionType>(); | |
152 | + return ( | |
153 | + <ProTable<GithubIssueItem> | |
154 | + columns={columns} | |
155 | + actionRef={actionRef} | |
156 | + cardBordered | |
157 | + request={async (params, sort, filter) => { | |
158 | + console.log(sort, filter); | |
159 | + await waitTime(2000); | |
160 | + return request<{ | |
161 | + data: GithubIssueItem[]; | |
162 | + }>('https://proapi.azurewebsites.net/github/issues', { | |
163 | + params, | |
164 | + }); | |
165 | + }} | |
166 | + editable={{ | |
167 | + type: 'multiple', | |
168 | + }} | |
169 | + columnsState={{ | |
170 | + persistenceKey: 'pro-table-singe-demos', | |
171 | + persistenceType: 'localStorage', | |
172 | + defaultValue: { | |
173 | + option: { fixed: 'right', disable: true }, | |
174 | + }, | |
175 | + onChange(value) { | |
176 | + console.log('value: ', value); | |
177 | + }, | |
178 | + }} | |
179 | + rowKey="id" | |
180 | + search={{ | |
181 | + labelWidth: 'auto', | |
182 | + }} | |
183 | + options={{ | |
184 | + setting: { | |
185 | + listsHeight: 400, | |
186 | + }, | |
187 | + }} | |
188 | + form={{ | |
189 | + // 由于配置了 transform,提交的参与与定义的不同这里需要转化一下 | |
190 | + syncToUrl: (values, type) => { | |
191 | + if (type === 'get') { | |
192 | + return { | |
193 | + ...values, | |
194 | + created_at: [values.startTime, values.endTime], | |
195 | + }; | |
196 | + } | |
197 | + return values; | |
198 | + }, | |
199 | + }} | |
200 | + pagination={{ | |
201 | + pageSize: 5, | |
202 | + onChange: (page) => console.log(page), | |
203 | + }} | |
204 | + dateFormatter="string" | |
205 | + headerTitle="高级表格" | |
206 | + toolBarRender={() => [ | |
207 | + <Button | |
208 | + key="button" | |
209 | + icon={<PlusOutlined />} | |
210 | + onClick={() => { | |
211 | + actionRef.current?.reload(); | |
212 | + }} | |
213 | + type="primary" | |
214 | + > | |
215 | + 新建 | |
216 | + </Button>, | |
217 | + <Dropdown | |
218 | + key="menu" | |
219 | + menu={{ | |
220 | + items: [ | |
221 | + { | |
222 | + label: '1st item', | |
223 | + key: '1', | |
224 | + }, | |
225 | + { | |
226 | + label: '2nd item', | |
227 | + key: '1', | |
228 | + }, | |
229 | + { | |
230 | + label: '3rd item', | |
231 | + key: '1', | |
232 | + }, | |
233 | + ], | |
234 | + }} | |
235 | + > | |
236 | + <Button> | |
237 | + <EllipsisOutlined /> | |
238 | + </Button> | |
239 | + </Dropdown>, | |
240 | + ]} | |
241 | + /> | |
242 | + ); | |
243 | +}; | ... | ... |