ztxkui 3.1.4 → 3.1.7
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/dist/DemoCom/SinaturesDemo.js +110 -18
- package/dist/DemoCom/TableDemo.js +138 -36
- package/dist/TableDemo/BasicTable.d.ts +7 -0
- package/dist/TableDemo/BasicTable.js +95 -0
- package/dist/TableDemo/EditableTable.d.ts +7 -0
- package/dist/TableDemo/EditableTable.js +336 -0
- package/dist/TableDemo/data.d.ts +17 -0
- package/dist/TableDemo/data.js +57 -0
- package/dist/TableDemo/index.d.ts +7 -0
- package/dist/TableDemo/index.js +19 -0
- package/dist/components/Table/hooks/useColumns.d.ts +17 -1
- package/dist/components/Table/hooks/useColumns.js +91 -7
- package/dist/components/Table/index.d.ts +28 -4
- package/dist/components/Table/index.js +4 -1
- package/dist/components/Table/table-enhance-cell.js +18 -3
- package/dist/components/Table/table-resizable-title.d.ts +11 -0
- package/dist/components/Table/table-resizable-title.js +39 -0
- package/dist/components/Table/table.d.ts +15 -0
- package/dist/components/Table/table.js +189 -31
- package/dist/components/Table/utils/dom.d.ts +7 -0
- package/dist/components/Table/utils/dom.js +24 -0
- package/dist/components/Table/utils/validate.d.ts +1 -0
- package/dist/components/Table/utils/validate.js +151 -0
- package/dist/components/business/Signatures/components/CompareResult.d.ts +0 -2
- package/dist/components/business/Signatures/components/CompareResult.js +15 -17
- package/dist/components/business/Signatures/components/ElectronicSeal.js +1 -1
- package/dist/components/business/Signatures/components/QunjSeal.js +2 -1
- package/dist/components/business/Signatures/components/TemplateAttach.d.ts +1 -1
- package/dist/components/business/Signatures/components/TemplateAttach.js +4 -7
- package/dist/components/business/Signatures/index.js +60 -13
- package/dist/components/business/Signatures/props.d.ts +1 -1
- package/dist/components/business/Signatures/utils.d.ts +2 -1
- package/dist/components/business/Signatures/utils.js +7 -1
- package/dist/index.css +23 -0
- package/dist/index.css.map +1 -1
- package/dist/index.js +4 -0
- package/package.json +2 -1
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* @author 陈亚雄
|
|
50
|
+
* @description 可编辑表格
|
|
51
|
+
*/
|
|
52
|
+
import React, { useState, useCallback, useRef, useEffect } from 'react';
|
|
53
|
+
// redux
|
|
54
|
+
// ztxkui公共组件
|
|
55
|
+
import { Table, EnhanceSelect, Button, message } from '../index';
|
|
56
|
+
// 路由配置
|
|
57
|
+
// store
|
|
58
|
+
// 自定义组件
|
|
59
|
+
// 其他文件
|
|
60
|
+
import update from 'immutability-helper';
|
|
61
|
+
import { dataSource, list1 } from './data';
|
|
62
|
+
var EditableTable = function () {
|
|
63
|
+
var _a = useState(dataSource), records = _a[0], setRecords = _a[1];
|
|
64
|
+
var recordsRef = useRef([]);
|
|
65
|
+
// 初始化渲染,针对配置了editable、editableConfig的列配置
|
|
66
|
+
var _b = useState(false), firstRender = _b[0], setFirstRender = _b[1];
|
|
67
|
+
// 新增删除行改变
|
|
68
|
+
var _c = useState(false), lengthChange = _c[0], setLengthChange = _c[1];
|
|
69
|
+
// 表格行拖拽改变
|
|
70
|
+
var _d = useState(false), moveChange = _d[0], setMoveChange = _d[1];
|
|
71
|
+
// 表格
|
|
72
|
+
var tableHandleRef = useRef({});
|
|
73
|
+
// 表格配置
|
|
74
|
+
var _e = useState({
|
|
75
|
+
test1: { isChangeable: 1, isDisplay: 1, isRequired: 1 },
|
|
76
|
+
test2: { isChangeable: 1, isDisplay: 1, isRequired: 1 },
|
|
77
|
+
}), tableConfig = _e[0], setTableConfig = _e[1];
|
|
78
|
+
useEffect(function () {
|
|
79
|
+
setTimeout(function () {
|
|
80
|
+
setTableConfig({
|
|
81
|
+
test1: { isChangeable: 1, isDisplay: 1, isRequired: 0 },
|
|
82
|
+
test2: { isChangeable: 1, isDisplay: 1, isRequired: 0 },
|
|
83
|
+
});
|
|
84
|
+
}, 5000);
|
|
85
|
+
}, []);
|
|
86
|
+
var columns = [
|
|
87
|
+
{
|
|
88
|
+
title: '序号',
|
|
89
|
+
width: 62,
|
|
90
|
+
fixed: 'left',
|
|
91
|
+
key: 'index',
|
|
92
|
+
render: function (_text, _record, index) { return "" + (index + 1); },
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
title: '测试1',
|
|
96
|
+
width: 100,
|
|
97
|
+
dataIndex: 'test1',
|
|
98
|
+
key: 'test1',
|
|
99
|
+
editable: true,
|
|
100
|
+
validate: {},
|
|
101
|
+
shouldCellUpdate: function (record, preRecord) {
|
|
102
|
+
if (firstRender) {
|
|
103
|
+
setFirstRender(false);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
if (lengthChange) {
|
|
107
|
+
setLengthChange(false);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
if (moveChange) {
|
|
111
|
+
setMoveChange(false);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return record.test1 !== preRecord.test1;
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
title: '测试2',
|
|
119
|
+
width: 100,
|
|
120
|
+
dataIndex: 'test2',
|
|
121
|
+
key: 'test2',
|
|
122
|
+
editable: true,
|
|
123
|
+
editableConfig: {
|
|
124
|
+
type: 'inputNumber',
|
|
125
|
+
},
|
|
126
|
+
validate: {
|
|
127
|
+
validate: function (value, record, index, title) {
|
|
128
|
+
if (value === 102) {
|
|
129
|
+
return Promise.reject({
|
|
130
|
+
errorFields: [
|
|
131
|
+
{
|
|
132
|
+
errors: "\u91C7\u8D2D\u57FA\u672C\u6570\u636E-\u660E\u7EC6\u8868 \u7B2C" + index + "\u884C \u91C7\u8D2D\u4ED8\u6B3E\u6761\u4EF62 \u5FC5\u586B\uFF01",
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return Promise.resolve();
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
shouldCellUpdate: function (record, preRecord) {
|
|
141
|
+
if (firstRender) {
|
|
142
|
+
setFirstRender(false);
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
if (lengthChange) {
|
|
146
|
+
setLengthChange(false);
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
if (moveChange) {
|
|
150
|
+
setMoveChange(false);
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
return record.test2 !== preRecord.test2;
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
title: '测试3',
|
|
158
|
+
width: 100,
|
|
159
|
+
dataIndex: 'test3',
|
|
160
|
+
key: 'test3',
|
|
161
|
+
shouldCellUpdate: function (record, preRecord) {
|
|
162
|
+
if (lengthChange) {
|
|
163
|
+
setLengthChange(false);
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
if (moveChange) {
|
|
167
|
+
setMoveChange(false);
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
return record.test3 !== preRecord.test3;
|
|
171
|
+
},
|
|
172
|
+
validate: {},
|
|
173
|
+
render: function (text, record, index) {
|
|
174
|
+
return (React.createElement(EnhanceSelect, { value: text, list: list1, dataKey: "id", titleKey: "name", dropdownMatchSelectWidth: 130, onChange: function (value, option, fullData) {
|
|
175
|
+
tableHandleRef.current.clearErrorClass(index);
|
|
176
|
+
var newRecord = {
|
|
177
|
+
test3: value,
|
|
178
|
+
test3Name: fullData === null || fullData === void 0 ? void 0 : fullData.name,
|
|
179
|
+
};
|
|
180
|
+
onEditableSaveHandle(newRecord, index);
|
|
181
|
+
} }));
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
title: '测试4',
|
|
186
|
+
width: 100,
|
|
187
|
+
dataIndex: 'test4',
|
|
188
|
+
key: 'test4',
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
title: '测试5',
|
|
192
|
+
width: 100,
|
|
193
|
+
dataIndex: 'test5',
|
|
194
|
+
key: 'test5',
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
title: '测试6',
|
|
198
|
+
width: 100,
|
|
199
|
+
dataIndex: 'test6',
|
|
200
|
+
key: 'test6',
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
title: '测试7',
|
|
204
|
+
width: 100,
|
|
205
|
+
dataIndex: 'test7',
|
|
206
|
+
key: 'test7',
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
title: '测试8',
|
|
210
|
+
width: 100,
|
|
211
|
+
dataIndex: 'test8',
|
|
212
|
+
key: 'test8',
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
title: '测试9',
|
|
216
|
+
width: 100,
|
|
217
|
+
dataIndex: 'test9',
|
|
218
|
+
key: 'test9',
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
title: '测试10',
|
|
222
|
+
width: 100,
|
|
223
|
+
dataIndex: 'test10',
|
|
224
|
+
key: 'test10',
|
|
225
|
+
},
|
|
226
|
+
];
|
|
227
|
+
// 初始化渲染,针对配置了editable、editableConfig的列配置
|
|
228
|
+
useEffect(function () {
|
|
229
|
+
setFirstRender(true);
|
|
230
|
+
}, []);
|
|
231
|
+
// 将表格最新数据赋值给ref引用
|
|
232
|
+
useEffect(function () {
|
|
233
|
+
recordsRef.current = records;
|
|
234
|
+
}, [records]);
|
|
235
|
+
// 表格数据改变相关
|
|
236
|
+
var onEditableSaveHandle = useCallback(function (record, index, _dataIndex) {
|
|
237
|
+
var _a;
|
|
238
|
+
if (_dataIndex === void 0) { _dataIndex = ''; }
|
|
239
|
+
if (typeof index === 'number') {
|
|
240
|
+
var newRecords = recordsRef.current.slice();
|
|
241
|
+
var item = newRecords[index];
|
|
242
|
+
newRecords.splice(index, 1, _dataIndex
|
|
243
|
+
? __assign(__assign(__assign({}, record), item), (_a = {}, _a[_dataIndex] = record[_dataIndex], _a)) : __assign(__assign({}, item), record));
|
|
244
|
+
setRecords(newRecords);
|
|
245
|
+
}
|
|
246
|
+
}, [setRecords]);
|
|
247
|
+
// 新增删除行
|
|
248
|
+
var onAddAndDelHandle = useCallback(function (type, index) {
|
|
249
|
+
var newRecords = recordsRef.current.slice();
|
|
250
|
+
if (type === 'add') {
|
|
251
|
+
var newItem = __assign(__assign({}, newRecords[index]), { _isNewData: true, id: Date.now() + "-" + index });
|
|
252
|
+
newRecords.splice(index + 1, 0, newItem);
|
|
253
|
+
setRecords(newRecords);
|
|
254
|
+
setLengthChange(true);
|
|
255
|
+
}
|
|
256
|
+
else if (type === 'del') {
|
|
257
|
+
if (newRecords.length === 1) {
|
|
258
|
+
newRecords.splice(index, 1, {
|
|
259
|
+
_isNewData: true,
|
|
260
|
+
id: Date.now() + "-" + index,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
newRecords.splice(index, 1);
|
|
265
|
+
}
|
|
266
|
+
setRecords(newRecords);
|
|
267
|
+
setLengthChange(true);
|
|
268
|
+
}
|
|
269
|
+
}, [setRecords]);
|
|
270
|
+
// 表格拖拽排序功能函数
|
|
271
|
+
var onMoveRowHandle = useCallback(function (dragIndex, hoverIndex) {
|
|
272
|
+
var newRecords = recordsRef.current.slice();
|
|
273
|
+
var dragRow = newRecords[dragIndex];
|
|
274
|
+
var newDataSource = update(newRecords, {
|
|
275
|
+
$splice: [
|
|
276
|
+
[dragIndex, 1],
|
|
277
|
+
[hoverIndex, 0, dragRow],
|
|
278
|
+
],
|
|
279
|
+
});
|
|
280
|
+
setRecords(newDataSource);
|
|
281
|
+
setMoveChange(true);
|
|
282
|
+
}, [setRecords]);
|
|
283
|
+
return (React.createElement("div", null,
|
|
284
|
+
React.createElement("div", null,
|
|
285
|
+
"\u53EF\u7F16\u8F91\u8868\u683C\uFF1B\u5982\u679C\u662F\u8F93\u5165\u6846\uFF0C\u53EF\u4F7F\u7528\u8868\u683C\u9ED8\u8BA4\u63D0\u4F9B\u7684\u7F16\u8F91\u6846\uFF1B \u914D\u7F6Eeditable\u4E3Atrue\u5373\u53EF\uFF0C\u8FD8\u53EF\u914D\u7F6EeditableConfig\u914D\u7F6E\u6267\u884C\u7C7B\u578B\u7B49\uFF1B\u5177\u4F53editableConfig\u53EF\u67E5\u770B\u8BE6\u7EC6\u7B7E\u540D",
|
|
286
|
+
React.createElement("br", null),
|
|
287
|
+
React.createElement("b", null, "\u5BF9\u4E8E\u914D\u7F6E\u4E86\u7F16\u8F91\u7684\u8868\u683C\uFF0C\u4E00\u5B9A\u8981\u4F7F\u7528SCU\u6765\u4F18\u5316\u8868\u683C\u6E32\u67D3\uFF0C\u6B64\u4E3E\u53EF\u4EE5\u4F18\u5316\u8868\u683C\u6E32\u67D3"),
|
|
288
|
+
React.createElement("br", null),
|
|
289
|
+
React.createElement("b", null, "\u5982\u679C\u914D\u7F6E\u4E86editable\uFF0C\u5E76\u4E14\u914D\u7F6E\u4E86SCU\u6765\u4F18\u5316\u6E32\u67D3\uFF0C\u90A3\u4E48\u521D\u59CB\u5316\u7684\u65F6\u5019\u9700\u8981\u7528\u4E00\u4E2A\u53D8\u91CF\u6807\u8BC6\u9996\u6B21\u9700\u8981\u6E32\u67D3"),
|
|
290
|
+
React.createElement("br", null),
|
|
291
|
+
React.createElement("b", null, "\u65B0\u589E\u5220\u9664\u884C\uFF0C\u8868\u683C\u62D6\u62FD\u6392\u5E8F\uFF1B"),
|
|
292
|
+
"\u5BF9\u4E8E\u914D\u7F6E\u4E86SCU\u7684\u5217\uFF0C\u9700\u8981\u5728\u65B0\u589E\u5220\u9664\u7684\u65F6\u5019\u91CD\u65B0\u6E32\u67D3\uFF0C\u901A\u8FC7\u8BBE\u7F6Estate\u6807\u8BC6",
|
|
293
|
+
React.createElement("br", null),
|
|
294
|
+
React.createElement("b", null, "\u8868\u683C\u81EA\u5B9A\u4E49\u9A8C\u8BC1\uFF0C\u4F20\u5165tableHandleRef\u4E00\u4E2ARef\u5BF9\u8C61\uFF0C\u53EF\u83B7\u53D6\u8868\u683C\u63D0\u4F9B\u76F8\u5173\u65B9\u6CD5"),
|
|
295
|
+
React.createElement("p", null, "1.\u7F16\u5199\u9A8C\u8BC1\u89C4\u5219\uFF0C\u5728\u5217\u91CC\u9762\u7F16\u5199\uFF0C\u901A\u8FC7\u4F20\u5165validate\u5C5E\u6027\u914D\u7F6E,\u5177\u4F53\u53EF\u67E5\u770B\u7B7E\u540D \u5982\u679C\u53EA\u662F\u7B80\u5355\u7684\u975E\u7A7A\u9A8C\u8BC1\uFF0C\u90A3\u4E48\u53EF\u4F20\u5165\u4E00\u4E2A\u7A7A\u5BF9\u8C61\u5373\u53EF \u5982\u679C\u662F\u590D\u6742\u9A8C\u8BC1\u53EF\u901A\u8FC7validate\u4F20\u5165\u66F4\u591A\u914D\u7F6E"),
|
|
296
|
+
React.createElement("p", null, "2.\u5982\u679C\u4F20\u5165\u4E86\u81EA\u5B9A\u4E49render\u51FD\u6570\uFF0C\u7EC4\u4EF6\u65E0\u6CD5\u638C\u63E1\u5728\u4F55\u65F6\u6E05\u7A7A\u9519\u8BEF\u4FE1\u606F\uFF0C\u6240\u4EE5\u9700\u8981\u8C03\u7528\u65B9\u4E3B\u52A8\u6E05\u7A7A\u9519\u8BEF\u4FE1\u606F")),
|
|
297
|
+
React.createElement(Button, { onClick: function () {
|
|
298
|
+
(function () {
|
|
299
|
+
var _a;
|
|
300
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
+
var err_1, errorFields;
|
|
302
|
+
return __generator(this, function (_b) {
|
|
303
|
+
switch (_b.label) {
|
|
304
|
+
case 0:
|
|
305
|
+
_b.trys.push([0, 2, , 3]);
|
|
306
|
+
return [4 /*yield*/, ((_a = tableHandleRef.current) === null || _a === void 0 ? void 0 : _a.validate())];
|
|
307
|
+
case 1:
|
|
308
|
+
_b.sent();
|
|
309
|
+
return [3 /*break*/, 3];
|
|
310
|
+
case 2:
|
|
311
|
+
err_1 = _b.sent();
|
|
312
|
+
console.log(err_1);
|
|
313
|
+
errorFields = err_1.errorFields;
|
|
314
|
+
if (errorFields) {
|
|
315
|
+
message.warning(errorFields[0].errors + '');
|
|
316
|
+
}
|
|
317
|
+
return [3 /*break*/, 3];
|
|
318
|
+
case 3: return [2 /*return*/];
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
})();
|
|
323
|
+
} }, "\u9A8C\u8BC1"),
|
|
324
|
+
React.createElement(Table, { dataSource: records, columns: columns, rowKey: "id",
|
|
325
|
+
// 表格项可输入
|
|
326
|
+
onEditableSave: onEditableSaveHandle,
|
|
327
|
+
// 新增删除行
|
|
328
|
+
onAddAndDelHandle: onAddAndDelHandle,
|
|
329
|
+
// 表格行拖拽
|
|
330
|
+
onMoveRow: onMoveRowHandle,
|
|
331
|
+
// tableValidate
|
|
332
|
+
tableHandleRef: tableHandleRef, tableName: "\u6211\u662F\u4E00\u4E2A\u8868\u683C",
|
|
333
|
+
// 显隐配置
|
|
334
|
+
configInfo: tableConfig })));
|
|
335
|
+
};
|
|
336
|
+
export default EditableTable;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const dataSource: {
|
|
2
|
+
id: string;
|
|
3
|
+
test1: string;
|
|
4
|
+
test2: number;
|
|
5
|
+
test3: string;
|
|
6
|
+
test4: string;
|
|
7
|
+
test5: string;
|
|
8
|
+
test6: string;
|
|
9
|
+
test7: string;
|
|
10
|
+
test8: string;
|
|
11
|
+
test9: string;
|
|
12
|
+
test10: string;
|
|
13
|
+
}[];
|
|
14
|
+
export declare const list1: {
|
|
15
|
+
name: string;
|
|
16
|
+
id: string;
|
|
17
|
+
}[];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export var dataSource = new Array(10).fill(1).map(function (item, index) {
|
|
2
|
+
return {
|
|
3
|
+
id: "test-" + index,
|
|
4
|
+
test1: "test1-" + index,
|
|
5
|
+
test2: index + 100,
|
|
6
|
+
test3: "test3-" + index,
|
|
7
|
+
test4: "test4-" + index,
|
|
8
|
+
test5: "test5-" + index,
|
|
9
|
+
test6: "test6-" + index,
|
|
10
|
+
test7: "test7-" + index,
|
|
11
|
+
test8: "test8-" + index,
|
|
12
|
+
test9: "test9-" + index,
|
|
13
|
+
test10: "test10-" + index,
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
export var list1 = [
|
|
17
|
+
{
|
|
18
|
+
name: '张三',
|
|
19
|
+
id: 'test3-0',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: '李四',
|
|
23
|
+
id: 'test3-1',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: '王五',
|
|
27
|
+
id: 'test3-2',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: '赵六',
|
|
31
|
+
id: 'test3-3',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: '张飞',
|
|
35
|
+
id: 'test3-4',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: '赵云',
|
|
39
|
+
id: 'test3-5',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: '刘备',
|
|
43
|
+
id: 'test3-6',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: '关羽',
|
|
47
|
+
id: 'test3-7',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: '曹操',
|
|
51
|
+
id: 'test3-8',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: '诸葛亮',
|
|
55
|
+
id: 'test3-9',
|
|
56
|
+
},
|
|
57
|
+
];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author 陈亚雄
|
|
3
|
+
* @description
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
// redux
|
|
7
|
+
// ztxkui公共组件
|
|
8
|
+
// 路由配置
|
|
9
|
+
// store
|
|
10
|
+
// 自定义组件
|
|
11
|
+
import BasicTable from './BasicTable';
|
|
12
|
+
import EditableTable from './EditableTable';
|
|
13
|
+
// 其他文件
|
|
14
|
+
var TableDemo = function () {
|
|
15
|
+
return (React.createElement("div", null,
|
|
16
|
+
React.createElement(BasicTable, null),
|
|
17
|
+
React.createElement(EditableTable, null)));
|
|
18
|
+
};
|
|
19
|
+
export default TableDemo;
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { ColumnsType } from '../';
|
|
3
|
+
export interface IConfigInfo {
|
|
4
|
+
[props: string]: {
|
|
5
|
+
isChangeable?: any;
|
|
6
|
+
isDisplay?: any;
|
|
7
|
+
isRequired?: any;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
2
10
|
interface IProps<RecordType> {
|
|
3
11
|
columns: ColumnsType<RecordType> | undefined;
|
|
4
12
|
showColumnDynamic?: boolean;
|
|
13
|
+
showColumnDynamicKey?: string;
|
|
5
14
|
/**新增行删除行方法 */
|
|
6
15
|
onAddAndDelHandle?: (type: 'add' | 'del', index: number) => void;
|
|
7
16
|
/**隐藏新增icon */
|
|
@@ -11,6 +20,13 @@ interface IProps<RecordType> {
|
|
|
11
20
|
showDynamicHandle?: () => void;
|
|
12
21
|
/**表格列编辑事件 */
|
|
13
22
|
onEditableSave?: (record: RecordType, index: number | undefined, dataIndex: string) => void;
|
|
23
|
+
/** 表格列配置相关信息 */
|
|
24
|
+
configInfo?: IConfigInfo;
|
|
14
25
|
}
|
|
15
|
-
declare
|
|
26
|
+
export declare const getTableLayoutFullData: (columns: any, tableLayout: any) => any;
|
|
27
|
+
declare function useColumns<RecordType>(props: IProps<RecordType>): {
|
|
28
|
+
newColumns: any;
|
|
29
|
+
dynamicColumns: any;
|
|
30
|
+
setNewColumns: React.Dispatch<any>;
|
|
31
|
+
};
|
|
16
32
|
export default useColumns;
|
|
@@ -9,25 +9,98 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
13
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
14
|
+
to[j] = from[i];
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
12
17
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
13
18
|
import { PicRightOutlined } from '@ant-design/icons';
|
|
14
19
|
import TableAddDelColumn from '../table-adddel-column';
|
|
20
|
+
// 获取表格columns完整数据
|
|
21
|
+
export var getTableLayoutFullData = function (columns, tableLayout) {
|
|
22
|
+
if (Array.isArray(tableLayout) && tableLayout.length > 0) {
|
|
23
|
+
var newColumns = tableLayout.map(function (item) {
|
|
24
|
+
if ((item === null || item === void 0 ? void 0 : item.key) || (item === null || item === void 0 ? void 0 : item.dataIndex)) {
|
|
25
|
+
var result = columns.find(function (column) {
|
|
26
|
+
if (column.key) {
|
|
27
|
+
return column.key === (item === null || item === void 0 ? void 0 : item.key);
|
|
28
|
+
}
|
|
29
|
+
if (column.dataIndex) {
|
|
30
|
+
return column.dataIndex === (item === null || item === void 0 ? void 0 : item.dataIndex);
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
});
|
|
34
|
+
return __assign(__assign({}, result), item);
|
|
35
|
+
}
|
|
36
|
+
return __assign({}, item);
|
|
37
|
+
});
|
|
38
|
+
var newAddColumns = columns.filter(function (column) { return !tableLayout.find(function (item) { return item.key === column.key; }); });
|
|
39
|
+
return __spreadArray(__spreadArray([], newColumns), newAddColumns);
|
|
40
|
+
}
|
|
41
|
+
return columns;
|
|
42
|
+
};
|
|
43
|
+
function getStorage(key) {
|
|
44
|
+
try {
|
|
45
|
+
var result = localStorage.getItem(key) || '';
|
|
46
|
+
return JSON.parse(result);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
15
52
|
function useColumns(props) {
|
|
16
|
-
var columns = props.columns, showColumnDynamic = props.showColumnDynamic, onAddAndDelHandle = props.onAddAndDelHandle, hideAddIcon = props.hideAddIcon, hideDelIcon = props.hideDelIcon, showDynamicHandle = props.showDynamicHandle, onEditableSave = props.onEditableSave;
|
|
53
|
+
var columns = props.columns, showColumnDynamic = props.showColumnDynamic, showColumnDynamicKey = props.showColumnDynamicKey, onAddAndDelHandle = props.onAddAndDelHandle, hideAddIcon = props.hideAddIcon, hideDelIcon = props.hideDelIcon, showDynamicHandle = props.showDynamicHandle, onEditableSave = props.onEditableSave, configInfo = props.configInfo;
|
|
54
|
+
var tableLayout = getStorage(showColumnDynamicKey);
|
|
17
55
|
// 新的columns
|
|
18
|
-
var _a = useState(columns), newColumns = _a[0], setNewColumns = _a[1];
|
|
56
|
+
var _a = useState(getTableLayoutFullData(columns, tableLayout)), newColumns = _a[0], setNewColumns = _a[1];
|
|
19
57
|
// 需要动态配置的列
|
|
20
|
-
var _b = useState(columns), dynamicColumns = _b[0], setDynamicColumns = _b[1];
|
|
58
|
+
var _b = useState(getTableLayoutFullData(columns, tableLayout)), dynamicColumns = _b[0], setDynamicColumns = _b[1];
|
|
21
59
|
// 动态列配置显隐
|
|
22
60
|
var ColumnDynamicCom = useCallback(function () { return (React.createElement(PicRightOutlined, { className: "zt-column--daynamic-icon", onClick: showDynamicHandle })); }, [showDynamicHandle]);
|
|
23
61
|
useEffect(function () {
|
|
24
|
-
|
|
62
|
+
var tableLayout = getStorage(showColumnDynamicKey);
|
|
63
|
+
var catchColumns = getTableLayoutFullData(columns, tableLayout);
|
|
64
|
+
if (!Array.isArray(catchColumns)) {
|
|
25
65
|
throw new Error('columns 必须为一个数组');
|
|
26
66
|
}
|
|
67
|
+
// 根据配置处理columns
|
|
68
|
+
// 主要处理是否隐藏
|
|
69
|
+
// 是否添加required配置
|
|
70
|
+
var _columns = [];
|
|
71
|
+
if (configInfo && Object.keys(configInfo).length > 0) {
|
|
72
|
+
catchColumns.forEach(function (col) {
|
|
73
|
+
var _a, _b, _c, _d;
|
|
74
|
+
var _column = __assign({}, col);
|
|
75
|
+
var dataIndex = _column.dataIndex;
|
|
76
|
+
if (!dataIndex) {
|
|
77
|
+
_columns.push(__assign({}, _column));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// 如果没有配置,或者配置isRequired为存在
|
|
81
|
+
if (((_a = configInfo[dataIndex]) === null || _a === void 0 ? void 0 : _a.isRequired) === 1 ||
|
|
82
|
+
((_b = configInfo[dataIndex]) === null || _b === void 0 ? void 0 : _b.isRequired) === '1') {
|
|
83
|
+
_column.required = true;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
_column.validate = undefined;
|
|
87
|
+
}
|
|
88
|
+
// 如果没有配置,或者配置isDisplay为存在
|
|
89
|
+
if (!configInfo[dataIndex] ||
|
|
90
|
+
((_c = configInfo[dataIndex]) === null || _c === void 0 ? void 0 : _c.isDisplay) === 1 ||
|
|
91
|
+
((_d = configInfo[dataIndex]) === null || _d === void 0 ? void 0 : _d.isDisplay) === '1') {
|
|
92
|
+
_columns.push(__assign({}, _column));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
_columns = catchColumns;
|
|
99
|
+
}
|
|
27
100
|
var _newColumns = [];
|
|
28
101
|
var _dynamicColumns = [];
|
|
29
102
|
// 处理columns
|
|
30
|
-
|
|
103
|
+
_columns.forEach(function (col) {
|
|
31
104
|
var _column = __assign({}, col);
|
|
32
105
|
// 添加超出隐藏
|
|
33
106
|
// !_column.render 兼容下拉框滚动行为,设置了ellipsis的话,会导致overflow:hidden,导致一些问题
|
|
@@ -58,7 +131,16 @@ function useColumns(props) {
|
|
|
58
131
|
_dynamicColumns.push(__assign({}, col));
|
|
59
132
|
}
|
|
60
133
|
// 添加必填标识
|
|
61
|
-
if (_column.required) {
|
|
134
|
+
if (typeof _column.required === 'function') {
|
|
135
|
+
var res = _column.required();
|
|
136
|
+
var _res = typeof res === 'boolean' ? res : res === 1 || res === '1';
|
|
137
|
+
if (_res) {
|
|
138
|
+
_column.title = (React.createElement(React.Fragment, null,
|
|
139
|
+
React.createElement("i", { className: "zt-column--required" }, "*"),
|
|
140
|
+
_column.title));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if (_column.required) {
|
|
62
144
|
_column.title = (React.createElement(React.Fragment, null,
|
|
63
145
|
React.createElement("i", { className: "zt-column--required" }, "*"),
|
|
64
146
|
_column.title));
|
|
@@ -112,7 +194,9 @@ function useColumns(props) {
|
|
|
112
194
|
hideDelIcon,
|
|
113
195
|
ColumnDynamicCom,
|
|
114
196
|
onEditableSave,
|
|
197
|
+
configInfo,
|
|
198
|
+
showColumnDynamicKey,
|
|
115
199
|
]);
|
|
116
|
-
return
|
|
200
|
+
return { newColumns: newColumns, dynamicColumns: dynamicColumns, setNewColumns: setNewColumns };
|
|
117
201
|
}
|
|
118
202
|
export default useColumns;
|
|
@@ -4,15 +4,36 @@ import { ColumnType } from 'antd/lib/table';
|
|
|
4
4
|
import { TableRowSelection as AntTableRowSelection } from 'antd/lib/table/interface';
|
|
5
5
|
import { ISummaryConfig as TableISummaryConfig } from './utils/getSummaryData';
|
|
6
6
|
import { IEditableConfig } from './table-enhance-cell';
|
|
7
|
-
export interface
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export interface IValidate {
|
|
8
|
+
/** 需要验证得key, 如果不传,组件会取当前列配置的dataIndex */
|
|
9
|
+
dataIndex?: string;
|
|
10
|
+
/** 提示的列头,如果不传,组件会取当前列配置的title */
|
|
11
|
+
title?: string;
|
|
12
|
+
/**
|
|
13
|
+
* 验证方式
|
|
14
|
+
* required 如果只传入这个key 那么已这个为准
|
|
15
|
+
* validate 验证函数 返回一个promise对象
|
|
16
|
+
* 也可以传入一个对象,对象有两个key 一个pattern正则 一个message提示信息
|
|
17
|
+
*/
|
|
11
18
|
required?: boolean;
|
|
19
|
+
validate?: (value: any, record: any, index: any, title: any) => Promise<any> | {
|
|
20
|
+
pattern: any;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
/** 当前index位置 */
|
|
24
|
+
index?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface IColumnType<RecordType> extends ColumnType<RecordType> {
|
|
27
|
+
/**是否隐藏该列 可以传入一个返回boolean值得函数 */
|
|
28
|
+
hideColumn?: boolean | (() => boolean);
|
|
29
|
+
/**是否增加必填title, 可以传入一个返回boolean值的函数 */
|
|
30
|
+
required?: boolean | (() => boolean);
|
|
12
31
|
/**是否可以编辑 */
|
|
13
32
|
editable?: boolean;
|
|
14
33
|
/**可编辑列配置 */
|
|
15
34
|
editableConfig?: IEditableConfig;
|
|
35
|
+
/** 表格单元格验证逻辑 */
|
|
36
|
+
validate?: IValidate;
|
|
16
37
|
}
|
|
17
38
|
export interface IColumnGroupType<RecordType> extends Omit<IColumnType<RecordType>, ''> {
|
|
18
39
|
children: ColumnsType<RecordType>;
|
|
@@ -21,6 +42,8 @@ export declare type ISummaryConfig = TableISummaryConfig;
|
|
|
21
42
|
export declare type ColumnsTypeProp<RecordType> = IColumnGroupType<RecordType> | IColumnType<RecordType>;
|
|
22
43
|
export declare type ColumnsType<RecordType = unknown> = ColumnsTypeProp<RecordType>[];
|
|
23
44
|
export declare type TableRowSelection<T> = AntTableRowSelection<T>;
|
|
45
|
+
export declare const DIFF_CLASSNAME = "zt-table--diff-row";
|
|
46
|
+
export declare const ERROR_TD_CLASSNAME = "zt-error-validate-td";
|
|
24
47
|
export declare type ITableComponent = typeof Table & {
|
|
25
48
|
SELECTION_ALL: typeof AntTable.SELECTION_ALL;
|
|
26
49
|
SELECTION_INVERT: typeof AntTable.SELECTION_INVERT;
|
|
@@ -29,6 +52,7 @@ export declare type ITableComponent = typeof Table & {
|
|
|
29
52
|
ColumnGroup: typeof AntTable.ColumnGroup;
|
|
30
53
|
Summary: typeof AntTable.Summary;
|
|
31
54
|
DiffClassName: string;
|
|
55
|
+
ErrorTdCallName: string;
|
|
32
56
|
};
|
|
33
57
|
declare const TransTable: ITableComponent;
|
|
34
58
|
export default TransTable;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Table from './table';
|
|
2
2
|
import { Table as AntTable } from 'antd';
|
|
3
|
+
export var DIFF_CLASSNAME = 'zt-table--diff-row';
|
|
4
|
+
export var ERROR_TD_CLASSNAME = 'zt-error-validate-td';
|
|
3
5
|
var TransTable = Table;
|
|
4
6
|
TransTable.SELECTION_ALL = AntTable.SELECTION_ALL;
|
|
5
7
|
TransTable.SELECTION_INVERT = AntTable.SELECTION_INVERT;
|
|
@@ -7,5 +9,6 @@ TransTable.SELECTION_NONE = AntTable.SELECTION_NONE;
|
|
|
7
9
|
TransTable.Column = AntTable.Column;
|
|
8
10
|
TransTable.ColumnGroup = AntTable.ColumnGroup;
|
|
9
11
|
TransTable.Summary = AntTable.Summary;
|
|
10
|
-
TransTable.DiffClassName =
|
|
12
|
+
TransTable.DiffClassName = DIFF_CLASSNAME;
|
|
13
|
+
TransTable.ErrorTdCallName = ERROR_TD_CLASSNAME;
|
|
11
14
|
export default TransTable;
|