table.tsx
3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import type { ProColumns } from '@ant-design/pro-components';
import {
EditableProTable,
ProCard,
ProFormField,
} from '@ant-design/pro-components';
import React, { useState } from 'react';
import { zoningItem, zoningShowItem } from './constant';
import Modal from './modal';
const waitTime = (time: number = 100) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, time);
});
};
const defaultData: zoningItem[] = [
{
id: 1,
zoning: '华南地区',
orderProvinceVoList: [
{
pId: 1,
province: '广东省',
},
{
pId: 2,
province: '四川省',
},
{
pId: 3,
province: '北京市',
},
{
pId: 4,
province: '上海市',
},
],
orderUserVoList: [
{
uId: 1,
userName: '李华',
},
],
},
];
const defaultShowData: zoningShowItem[] = defaultData.map((item) => {
let orderProvinceShowList = '';
let orderUserShowList = '';
item.orderProvinceVoList.forEach((element, index) => {
orderProvinceShowList += element.province;
if (index < item.orderProvinceVoList.length - 1) {
orderProvinceShowList += '、';
}
});
item.orderUserVoList.forEach((event, index) => {
orderUserShowList += event.userName;
if (index < item.orderUserVoList.length - 1) {
orderUserShowList += '、';
}
});
return {
id: item.id,
zoning: item.zoning,
orderProvinceShowList,
orderUserShowList,
};
});
export default () => {
const [editableKeys, setEditableRowKeys] = useState<React.Key[]>([]);
const [dataSource, setDataSource] = useState<readonly zoningItem[]>([]);
const [position] = useState<'top' | 'bottom' | 'hidden'>('hidden');
const columns: ProColumns<zoningItem>[] = [
{
title: '区域名称',
dataIndex: 'zoning',
width: 200,
},
{
title: '管辖省份',
dataIndex: 'orderProvinceShowList',
readonly: true,
width: 600,
},
{
title: '负责销售',
key: 'state',
dataIndex: 'orderUserShowList',
valueType: 'select',
width: 200,
},
{
title: '操作',
valueType: 'option',
width: 200,
render: (text, record, _, action) => [
<a
key="editable"
onClick={() => {
action?.startEditable?.(record.id);
}}
>
编辑
</a>,
<a
key="delete"
onClick={() => {
setDataSource(dataSource.filter((item) => item.id !== record.id));
}}
>
删除
</a>,
],
},
];
return (
<>
<EditableProTable<zoningItem>
rowKey="id"
headerTitle={<Modal></Modal>}
maxLength={5}
scroll={{
x: 960,
}}
recordCreatorProps={
position !== 'hidden'
? {
position: position as 'top',
record: () => ({ id: (Math.random() * 1000000).toFixed(0) }),
}
: false
}
loading={false}
columns={columns}
request={async () => ({
data: defaultShowData,
})}
value={dataSource}
onChange={setDataSource}
editable={{
type: 'multiple',
editableKeys,
onSave: async (rowKey, data, row) => {
console.log(rowKey, data, row);
await waitTime(2000);
},
onChange: setEditableRowKeys,
}}
/>
<ProCard title="表格数据" headerBordered collapsible defaultCollapsed>
<ProFormField
ignoreFormItem
fieldProps={{
style: {
width: '100%',
},
}}
mode="read"
valueType="jsonCode"
text={JSON.stringify(dataSource)}
/>
</ProCard>
</>
);
};