ztxkui 4.2.18-2 → 4.2.18-21

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.
Files changed (75) hide show
  1. package/README.md +57 -57
  2. package/dist/DemoCom/SyhDemo.d.ts +3 -0
  3. package/dist/DemoCom/SyhDemo.js +257 -0
  4. package/dist/DemoCom/TableDemo.js +8 -4
  5. package/dist/TableDemo/BasicTable.js +2 -1
  6. package/dist/TableDemo/EditableTable.js +83 -67
  7. package/dist/TableDemo/ProEditableTable.d.ts +21 -0
  8. package/dist/TableDemo/ProEditableTable.js +482 -0
  9. package/dist/TableDemo/data.d.ts +15 -0
  10. package/dist/TableDemo/data.js +33 -1
  11. package/dist/TableDemo/index.js +6 -5
  12. package/dist/components/DatePicker/data-picker.d.ts +7 -8
  13. package/dist/components/Menu/menu.d.ts +3 -3
  14. package/dist/components/PrintContainer/utils.js +3 -3
  15. package/dist/components/ProTable/hooks.d.ts +28 -0
  16. package/dist/components/ProTable/hooks.js +279 -0
  17. package/dist/components/ProTable/index.d.ts +8 -0
  18. package/dist/components/ProTable/index.js +77 -0
  19. package/dist/components/ProTable/interface.d.ts +51 -0
  20. package/dist/components/ProTable/interface.js +1 -0
  21. package/dist/components/Table/components/FillDown.d.ts +8 -0
  22. package/dist/components/Table/components/FillDown.js +10 -0
  23. package/dist/components/Table/components/FilterDropdown.d.ts +14 -0
  24. package/dist/components/Table/components/FilterDropdown.js +69 -0
  25. package/dist/components/Table/constants.d.ts +2 -0
  26. package/dist/components/Table/constants.js +2 -0
  27. package/dist/components/Table/hooks/useColumns.d.ts +20 -8
  28. package/dist/components/Table/hooks/useColumns.js +484 -182
  29. package/dist/components/Table/hooks/useDropRef.js +2 -1
  30. package/dist/components/Table/hooks/useInnerPagination.js +1 -0
  31. package/dist/components/Table/hooks/useSelectSubtotal.d.ts +4 -0
  32. package/dist/components/Table/hooks/useSelectSubtotal.js +178 -0
  33. package/dist/components/Table/index.d.ts +7 -0
  34. package/dist/components/Table/table-adddel-column.d.ts +8 -5
  35. package/dist/components/Table/table-adddel-column.js +15 -5
  36. package/dist/components/Table/table-dynamic.js +63 -5
  37. package/dist/components/Table/table-enhance-cell.d.ts +6 -3
  38. package/dist/components/Table/table-enhance-cell.js +196 -109
  39. package/dist/components/Table/table-enhance-row.d.ts +4 -4
  40. package/dist/components/Table/table-enhance-row.js +10 -11
  41. package/dist/components/Table/table-headTooltip.d.ts +6 -0
  42. package/dist/components/Table/table-headTooltip.js +13 -0
  43. package/dist/components/Table/table-resizable-title.d.ts +4 -5
  44. package/dist/components/Table/table-resizable-title.js +32 -6
  45. package/dist/components/Table/table-sort.d.ts +11 -0
  46. package/dist/components/Table/table-sort.js +65 -0
  47. package/dist/components/Table/table.d.ts +20 -4
  48. package/dist/components/Table/table.js +478 -176
  49. package/dist/components/Table/utils/dom.d.ts +26 -0
  50. package/dist/components/Table/utils/dom.js +122 -0
  51. package/dist/components/Table/utils/filterHandle.d.ts +1 -0
  52. package/dist/components/Table/utils/filterHandle.js +51 -0
  53. package/dist/components/Table/utils/getSummaryData.d.ts +1 -0
  54. package/dist/components/Table/utils/getSummaryData.js +3 -1
  55. package/dist/components/Table/utils/shallowEqual.d.ts +2 -0
  56. package/dist/components/Table/utils/shallowEqual.js +34 -0
  57. package/dist/components/Table/utils/validate.d.ts +1 -1
  58. package/dist/components/Table/utils/validate.js +5 -5
  59. package/dist/components/TimePicker/time-picker.d.ts +0 -1
  60. package/dist/components/ZtIcon/index.d.ts +1 -1
  61. package/dist/components/business/Common/UserForgetPassword/index.js +17 -6
  62. package/dist/components/business/Common/UserInfo/index.js +3 -1
  63. package/dist/components/business/Common/UserPassword/index.d.ts +1 -0
  64. package/dist/components/business/Common/UserPassword/index.js +42 -14
  65. package/dist/components/business/Common/validatePassword.d.ts +8 -0
  66. package/dist/components/business/Common/validatePassword.js +168 -0
  67. package/dist/components/utils/index.d.ts +1 -0
  68. package/dist/components/utils/index.js +20 -0
  69. package/dist/components/utils/useLastest.d.ts +2 -0
  70. package/dist/components/utils/useLastest.js +6 -0
  71. package/dist/index.css +96 -7
  72. package/dist/index.css.map +1 -1
  73. package/dist/index.d.ts +1 -0
  74. package/dist/index.js +5 -0
  75. package/package.json +4 -3
@@ -56,12 +56,14 @@ var __rest = (this && this.__rest) || function (s, e) {
56
56
  }
57
57
  return t;
58
58
  };
59
- import React, { useContext, useEffect, memo, useRef } from 'react';
60
- import { EditableContext } from './table-enhance-row';
61
- import { Form, Input, InputNumber, Select, message } from '../../index';
59
+ import React, { useEffect, memo, useRef, useCallback, useMemo, useState, } from 'react';
60
+ // import { EditableContext } from './table-enhance-row';
61
+ import { InputNumber, Select, message } from '../../index';
62
+ import { Input } from 'antd';
62
63
  import { ERROR_TD_CLASSNAME } from './index';
63
64
  import { getInnerIndex } from './hooks/useInnerPagination';
64
65
  import { exactRound } from 'ztxkutils/dist/tools';
66
+ import { INNER_PARENT_ROW_KEY_NO, INNER_PARENT_ROW_KEY } from './constants';
65
67
  /**
66
68
  * 数据转换 将粘贴过来的数据格式化处理
67
69
  */
@@ -85,74 +87,109 @@ function transformData(data, config) {
85
87
  }
86
88
  return newData;
87
89
  }
88
- var TableEnhanceCell = memo(function (_a) {
89
- var title = _a.title, index = _a.index, editable = _a.editable, editableConfig = _a.editableConfig, children = _a.children, dataIndex = _a.dataIndex, record = _a.record, handleSave = _a.handleSave, onTableChange = _a.onTableChange, columns = _a.columns, currentpage = _a.currentpage, restProps = __rest(_a, ["title", "index", "editable", "editableConfig", "children", "dataIndex", "record", "handleSave", "onTableChange", "columns", "currentpage"]);
90
- var form = useContext(EditableContext);
90
+ var TableEnhanceCell = function (_a) {
91
+ var title = _a.title, index = _a.index, editable = _a.editable, editableConfig = _a.editableConfig, children = _a.children, dataIndex = _a.dataIndex, record = _a.record, handleSave = _a.handleSave, dataSource = _a.dataSource, onTableChange = _a.onTableChange, columns = _a.columns, currentpage = _a.currentpage, onMouseEnter = _a.onMouseEnter, onMouseLeave = _a.onMouseLeave, rowKey = _a.rowKey, expandableChildrenColumnName = _a.expandableChildrenColumnName, restProps = __rest(_a, ["title", "index", "editable", "editableConfig", "children", "dataIndex", "record", "handleSave", "dataSource", "onTableChange", "columns", "currentpage", "onMouseEnter", "onMouseLeave", "rowKey", "expandableChildrenColumnName"]);
91
92
  var tdRef = useRef();
93
+ var valueRef = useRef({});
94
+ var _b = useState(), val = _b[0], setVal = _b[1];
92
95
  useEffect(function () {
93
- var _a;
94
96
  if (dataIndex) {
95
- form === null || form === void 0 ? void 0 : form.setFieldsValue((_a = {}, _a[dataIndex] = record[dataIndex], _a));
97
+ // form?.setFieldsValue({ [dataIndex]: record[dataIndex] });
98
+ // form?.setFieldValue(dataIndex, record[dataIndex]);
99
+ setVal(record[dataIndex]);
100
+ valueRef.current[dataIndex] = record[dataIndex];
96
101
  }
97
- }, [dataIndex, form, record]);
102
+ }, [dataIndex, record]);
98
103
  /**
99
104
  * @description 保存事件
100
105
  */
101
- var save = function (info) { return __awaiter(void 0, void 0, void 0, function () {
102
- var innerIndex, values, result, currentInputNumberValue, result, currentInputNumberValue, err_1;
103
- var _a, _b;
104
- return __generator(this, function (_c) {
105
- switch (_c.label) {
106
- case 0:
107
- innerIndex = getInnerIndex(currentpage, index);
108
- _c.label = 1;
109
- case 1:
110
- _c.trys.push([1, 3, , 4]);
111
- return [4 /*yield*/, (form === null || form === void 0 ? void 0 : form.validateFields())];
112
- case 2:
113
- values = _c.sent();
114
- if (!handleSave) {
115
- console.error('Table props onEditableSave is not a function');
106
+ var save = useCallback(function (info) { return __awaiter(void 0, void 0, void 0, function () {
107
+ var innerIndex, newDataSource, newRecord, parentId_1, currentParentItem, parentIndex, currentParentItemChildren, childrenRecord, values, result, currentInputNumberValue, result, currentInputNumberValue;
108
+ var _a, _b, _c;
109
+ return __generator(this, function (_d) {
110
+ innerIndex = getInnerIndex(currentpage, index);
111
+ newDataSource = dataSource ? dataSource() : undefined;
112
+ newRecord = record;
113
+ // 代表当前修改的是子项,需要通过rowKey找到父项中对应的子项,取到最新值
114
+ if (newRecord && newRecord[INNER_PARENT_ROW_KEY]) {
115
+ try {
116
+ innerIndex = typeof index === 'number' ? index : innerIndex;
117
+ parentId_1 = newRecord[INNER_PARENT_ROW_KEY];
118
+ currentParentItem = null;
119
+ // 代表没有配置rowKey,那需要找到父级index
120
+ if (parentId_1.startsWith(INNER_PARENT_ROW_KEY_NO)) {
121
+ parentIndex = parentId_1.slice(INNER_PARENT_ROW_KEY_NO.length) - 0;
122
+ currentParentItem = newDataSource[parentIndex];
116
123
  }
117
- if (info && info.maxResult) {
118
- result = info.maxResult;
119
- currentInputNumberValue = values[dataIndex];
120
- if (currentInputNumberValue > (result === null || result === void 0 ? void 0 : result.number)) {
121
- message.warning((result.tableName ? "\u60A8\u4FEE\u6539" + result.tableName + "\u8868\u683C\u7684" : '表格') + " \u7B2C" + (typeof index === 'number' ? index + 1 : index) + "\u884C \u7684" + title + "\u5B57\u6BB5\uFF0C\u8F93\u5165\u7684\u6570\u503C\uFF0C\u5DF2\u8D85\u8FC7\u6700\u5927\u503C\uFF0C\u5DF2\u5E2E\u60A8\u4FEE\u6539\u4E3A\u6700\u5927\u503C!");
122
- handleSave(__assign(__assign(__assign({}, record), values), (_a = {}, _a[dataIndex] = result === null || result === void 0 ? void 0 : result.number, _a)),
123
- // index,
124
- innerIndex, dataIndex);
125
- return [2 /*return*/];
126
- }
124
+ else {
125
+ currentParentItem = newDataSource.find(function (item) { return item[rowKey] === parentId_1; });
127
126
  }
128
- if (info && info.minResult) {
129
- result = info.minResult;
130
- currentInputNumberValue = values[dataIndex];
131
- if (currentInputNumberValue < (result === null || result === void 0 ? void 0 : result.number)) {
132
- message.warning((result.tableName ? "\u60A8\u4FEE\u6539" + result.tableName + "\u8868\u683C\u7684" : '表格') + " \u7B2C" + (index ? index + 1 : index) + "\u884C \u7684" + title + "\u5B57\u6BB5\uFF0C\u8F93\u5165\u7684\u6570\u503C\uFF0C\u5DF2\u4F4E\u4E8E\u6700\u5C0F\u503C\uFF0C\u5DF2\u5E2E\u60A8\u4FEE\u6539\u4E3A\u6700\u5C0F\u503C!");
133
- handleSave(__assign(__assign(__assign({}, record), values), (_b = {}, _b[dataIndex] = result === null || result === void 0 ? void 0 : result.number, _b)),
134
- // index,
135
- innerIndex, dataIndex);
136
- return [2 /*return*/];
137
- }
127
+ currentParentItemChildren = currentParentItem[expandableChildrenColumnName];
128
+ childrenRecord = typeof index === 'number'
129
+ ? __assign({}, currentParentItemChildren[index]) : record;
130
+ Reflect.deleteProperty(childrenRecord, INNER_PARENT_ROW_KEY);
131
+ newRecord = typeof index === 'number' ? childrenRecord : record;
132
+ }
133
+ catch (err) {
134
+ console.log(err);
135
+ }
136
+ }
137
+ else {
138
+ // 直接取父级元素即可
139
+ newRecord =
140
+ Array.isArray(newDataSource) && typeof innerIndex === 'number'
141
+ ? newDataSource[innerIndex]
142
+ : record;
143
+ }
144
+ try {
145
+ values = valueRef.current;
146
+ if (!handleSave) {
147
+ console.error('Table props onEditableSave is not a function');
148
+ }
149
+ if (info && info.maxResult) {
150
+ result = info.maxResult;
151
+ currentInputNumberValue = values[dataIndex];
152
+ if (currentInputNumberValue > (result === null || result === void 0 ? void 0 : result.number)) {
153
+ message.warning((result.tableName ? "\u60A8\u4FEE\u6539" + result.tableName + "\u8868\u683C\u7684" : '表格') + " \u7B2C" + (typeof index === 'number' ? index + 1 : index) + "\u884C \u7684" + title + "\u5B57\u6BB5\uFF0C\u8F93\u5165\u7684\u6570\u503C\uFF0C\u5DF2\u8D85\u8FC7\u6700\u5927\u503C\uFF0C\u5DF2\u5E2E\u60A8\u4FEE\u6539\u4E3A\u6700\u5927\u503C!");
154
+ handleSave(__assign(__assign({}, newRecord), (_a = {}, _a[dataIndex] = result === null || result === void 0 ? void 0 : result.number, _a)), innerIndex, dataIndex, { isInner: true });
155
+ return [2 /*return*/];
156
+ }
157
+ }
158
+ if (info && info.minResult) {
159
+ result = info.minResult;
160
+ currentInputNumberValue = values[dataIndex];
161
+ if (currentInputNumberValue < (result === null || result === void 0 ? void 0 : result.number)) {
162
+ message.warning((result.tableName ? "\u60A8\u4FEE\u6539" + result.tableName + "\u8868\u683C\u7684" : '表格') + " \u7B2C" + (index ? index + 1 : index) + "\u884C \u7684" + title + "\u5B57\u6BB5\uFF0C\u8F93\u5165\u7684\u6570\u503C\uFF0C\u5DF2\u4F4E\u4E8E\u6700\u5C0F\u503C\uFF0C\u5DF2\u5E2E\u60A8\u4FEE\u6539\u4E3A\u6700\u5C0F\u503C!");
163
+ handleSave(__assign(__assign({}, newRecord), (_b = {}, _b[dataIndex] = result === null || result === void 0 ? void 0 : result.number, _b)), innerIndex, dataIndex, { isInner: true });
164
+ return [2 /*return*/];
138
165
  }
139
- // handleSave({ ...record, ...values }, index, dataIndex);
140
- handleSave(__assign(__assign({}, record), values), innerIndex, dataIndex);
141
- return [3 /*break*/, 4];
142
- case 3:
143
- err_1 = _c.sent();
144
- console.error('Save failed:', err_1);
145
- return [3 /*break*/, 4];
146
- case 4: return [2 /*return*/];
166
+ }
167
+ handleSave(__assign(__assign({}, newRecord), (_c = {}, _c[dataIndex] = values[dataIndex], _c)), innerIndex, dataIndex, { isInner: true });
147
168
  }
169
+ catch (err) {
170
+ console.error('Save failed:', err);
171
+ }
172
+ return [2 /*return*/];
148
173
  });
149
- }); };
150
- function removeErrorClass() {
151
- if (tdRef.current) {
174
+ }); }, [
175
+ currentpage,
176
+ dataIndex,
177
+ handleSave,
178
+ index,
179
+ record,
180
+ title,
181
+ dataSource,
182
+ expandableChildrenColumnName,
183
+ rowKey,
184
+ ]);
185
+ var removeErrorClass = useCallback(function () {
186
+ var _a, _b;
187
+ if (tdRef.current &&
188
+ ((_b = (_a = tdRef.current.classList).contains) === null || _b === void 0 ? void 0 : _b.call(_a, ERROR_TD_CLASSNAME))) {
152
189
  tdRef.current.classList.remove(ERROR_TD_CLASSNAME);
153
190
  }
154
- }
155
- function onPasteHandle(e) {
191
+ }, []);
192
+ var onPasteHandle = useCallback(function (e) {
156
193
  if (!onTableChange) {
157
194
  return;
158
195
  }
@@ -211,22 +248,38 @@ var TableEnhanceCell = memo(function (_a) {
211
248
  return result;
212
249
  });
213
250
  // onTableChange && onTableChange(resultTextList, index, record);
251
+ setVal(resultTextList[0][dataIndex]);
252
+ valueRef.current[dataIndex] = resultTextList[0][dataIndex];
214
253
  onTableChange && onTableChange(resultTextList, innerIndex, record);
215
254
  }
216
255
  }
217
- }
256
+ }, [columns, currentpage, dataIndex, index, onTableChange, record]);
218
257
  /**
219
258
  * @description 生成编辑框
220
259
  */
221
- var createEditableDom = function (editableConfig) {
260
+ var createEditableDom = useMemo(function () {
261
+ // 执行优化,减少生成无意义的组件rerender次数
262
+ if (!editable) {
263
+ return null;
264
+ }
222
265
  if (!editableConfig) {
223
- return (React.createElement(Form.Item, { className: "zt-table__enhance-cell", name: dataIndex },
224
- React.createElement(Input, { autoComplete: "new-password", maxLength: 50, onPressEnter: save, onBlur: save, allowClear: true, onPaste: onPasteHandle, onChange: function (e) {
225
- removeErrorClass();
226
- if (!e.target.value) {
227
- e.target.focus();
228
- }
229
- } })));
266
+ return (React.createElement(Input, { autoComplete: "new-password", maxLength: 50, onPressEnter: save, onBlur: save, allowClear: true, onPaste: onPasteHandle, value: val, onMouseUp: function (e) {
267
+ e === null || e === void 0 ? void 0 : e.stopPropagation();
268
+ },
269
+ // draggable
270
+ // onDragStart={(e) => {
271
+ // e?.stopPropagation?.();
272
+ // e?.preventDefault?.();
273
+ // e?.nativeEvent?.stopImmediatePropagation?.();
274
+ // }}
275
+ onChange: function (e) {
276
+ setVal(e.target.value);
277
+ removeErrorClass();
278
+ valueRef.current[dataIndex] = e.target.value;
279
+ if (!e.target.value) {
280
+ e.target.focus();
281
+ }
282
+ } }));
230
283
  }
231
284
  var type = editableConfig.type, data = editableConfig.data, keyValue = editableConfig.keyValue, maxHandle = editableConfig.maxHandle, minHandle = editableConfig.minHandle, overMaxTip = editableConfig.overMaxTip, lowMinTip = editableConfig.lowMinTip, disabledHandle = editableConfig.disabledHandle, editableProps = __rest(editableConfig, ["type", "data", "keyValue", "maxHandle", "minHandle", "overMaxTip", "lowMinTip", "disabledHandle"]);
232
285
  var selectData = data; // 下拉框使用到得数据
@@ -278,53 +331,87 @@ var TableEnhanceCell = memo(function (_a) {
278
331
  }
279
332
  // 处理各种类型
280
333
  if (type === 'select') {
281
- return (React.createElement(Form.Item, { className: "zt-table__enhance-cell", name: dataIndex },
282
- React.createElement(Select, __assign({ allowClear: true }, editableProps, { disabled: disabledResult, onChange: function (value, option) {
283
- removeErrorClass();
284
- save(value);
285
- } }), Array.isArray(selectData) &&
286
- selectData.map(function (item) { return (React.createElement(Select.Option, { key: item[selectKeyValue.key] + '', value: item[selectKeyValue === null || selectKeyValue === void 0 ? void 0 : selectKeyValue.key] }, item[selectKeyValue === null || selectKeyValue === void 0 ? void 0 : selectKeyValue.label])); }))));
334
+ return (React.createElement(Select, __assign({ allowClear: true }, editableProps, { disabled: disabledResult, value: val, onChange: function (value, option) {
335
+ removeErrorClass();
336
+ save(value);
337
+ valueRef.current[dataIndex] = value;
338
+ } }), Array.isArray(selectData) &&
339
+ selectData.map(function (item) { return (React.createElement(Select.Option, { key: item[selectKeyValue.key] + '', value: item[selectKeyValue === null || selectKeyValue === void 0 ? void 0 : selectKeyValue.key] }, item[selectKeyValue === null || selectKeyValue === void 0 ? void 0 : selectKeyValue.label])); })));
287
340
  }
288
341
  else if (type === 'inputNumber') {
289
- return (React.createElement(Form.Item, { className: "zt-table__enhance-cell", name: dataIndex },
290
- React.createElement(InputNumber, __assign({ autoComplete: "new-password", maxLength: 50 }, inputNumMaxMin, editableProps, inputNumberRangeTip, { disabled: disabledResult, onPressEnter: function (e) {
291
- var _a;
292
- editableProps.onPressEnter && ((_a = editableProps.onPressEnter) === null || _a === void 0 ? void 0 : _a.call(editableProps, e));
293
- save({ maxResult: maxResult, minResult: minResult });
294
- }, onBlur: function (e) {
295
- var _a;
296
- editableProps.onBlur && ((_a = editableProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(editableProps, e));
297
- save({ maxResult: maxResult, minResult: minResult });
298
- }, onFocus: function (e) {
299
- var _a;
300
- editableProps.onFocus && ((_a = editableProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(editableProps, e));
301
- }, onPaste: onPasteHandle, onChange: function () {
302
- removeErrorClass();
303
- } }))));
342
+ return (React.createElement(InputNumber, __assign({ autoComplete: "new-password", maxLength: 50 }, inputNumMaxMin, editableProps, inputNumberRangeTip, { disabled: disabledResult,
343
+ // draggable
344
+ // onDragStart={(e) => {
345
+ // e?.stopPropagation?.();
346
+ // e?.preventDefault?.();
347
+ // e?.nativeEvent?.stopImmediatePropagation?.();
348
+ // }}
349
+ onPressEnter: function (e) {
350
+ var _a;
351
+ editableProps.onPressEnter && ((_a = editableProps.onPressEnter) === null || _a === void 0 ? void 0 : _a.call(editableProps, e));
352
+ save({ maxResult: maxResult, minResult: minResult });
353
+ }, onBlur: function (e) {
354
+ var _a;
355
+ editableProps.onBlur && ((_a = editableProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(editableProps, e));
356
+ save({ maxResult: maxResult, minResult: minResult });
357
+ }, onFocus: function (e) {
358
+ var _a;
359
+ editableProps.onFocus && ((_a = editableProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(editableProps, e));
360
+ }, onPaste: onPasteHandle, value: val, onChange: function (value) {
361
+ setVal(value);
362
+ valueRef.current[dataIndex] = value;
363
+ removeErrorClass();
364
+ } })));
304
365
  }
305
366
  else if (type === 'textArea') {
306
- return (React.createElement(Form.Item, { className: "zt-table__enhance-cell", name: dataIndex },
307
- React.createElement(Input.TextArea, __assign({ autoComplete: "new-password", maxLength: 200, autoSize: { maxRows: 3 } }, editableProps, { disabled: disabledResult, onPressEnter: save, onBlur: save, onPaste: onPasteHandle, onChange: function (e) {
308
- removeErrorClass();
309
- if (!e.target.value) {
310
- e.target.focus();
311
- }
312
- }, allowClear: true }))));
367
+ return (React.createElement(Input.TextArea, __assign({ autoComplete: "new-password", maxLength: 200, autoSize: { maxRows: 3 } }, editableProps, { disabled: disabledResult, onPressEnter: save, onBlur: save, onPaste: onPasteHandle, value: val, onMouseUp: function (e) {
368
+ e === null || e === void 0 ? void 0 : e.stopPropagation();
369
+ },
370
+ // draggable
371
+ // onDragStart={(e) => {
372
+ // e?.stopPropagation?.();
373
+ // e?.preventDefault?.();
374
+ // e?.nativeEvent?.stopImmediatePropagation?.();
375
+ // }}
376
+ onChange: function (e) {
377
+ setVal(e.target.value);
378
+ valueRef.current[dataIndex] = e.target.value;
379
+ removeErrorClass();
380
+ if (!e.target.value) {
381
+ e.target.focus();
382
+ }
383
+ }, allowClear: true })));
313
384
  }
314
385
  else {
315
- return (React.createElement(Form.Item, { className: "zt-table__enhance-cell", name: dataIndex },
316
- React.createElement(Input, __assign({ autoComplete: "new-password", maxLength: 50 }, editableProps, { disabled: disabledResult, onPressEnter: save, onBlur: save, allowClear: true, onPaste: onPasteHandle, onChange: function (e) {
317
- removeErrorClass();
318
- if (!e.target.value) {
319
- e.target.focus();
320
- }
321
- } }))));
386
+ return (React.createElement(Input, __assign({ autoComplete: "new-password", maxLength: 50 }, editableProps, { disabled: disabledResult, onPressEnter: save, onBlur: save, allowClear: true, onPaste: onPasteHandle, value: val, onMouseUp: function (e) {
387
+ e === null || e === void 0 ? void 0 : e.stopPropagation();
388
+ },
389
+ // draggable
390
+ // onDragStart={(e) => {
391
+ // e?.stopPropagation?.();
392
+ // e?.preventDefault?.();
393
+ // e?.nativeEvent?.stopImmediatePropagation?.();
394
+ // }}
395
+ onChange: function (e) {
396
+ setVal(e.target.value);
397
+ valueRef.current[dataIndex] = e.target.value;
398
+ removeErrorClass();
399
+ if (!e.target.value) {
400
+ e.target.focus();
401
+ }
402
+ } })));
322
403
  }
323
- };
324
- var childNode = children;
325
- if (editable) {
326
- childNode = createEditableDom(editableConfig);
327
- }
328
- return (React.createElement("td", __assign({ ref: tdRef }, restProps), childNode));
329
- });
330
- export default TableEnhanceCell;
404
+ }, [
405
+ val,
406
+ editable,
407
+ editableConfig,
408
+ dataIndex,
409
+ index,
410
+ onPasteHandle,
411
+ record,
412
+ removeErrorClass,
413
+ save,
414
+ ]);
415
+ return (React.createElement("td", __assign({ ref: tdRef }, restProps), editable ? (React.createElement("div", { className: "zt-table__enhance-cell" }, createEditableDom)) : (children)));
416
+ };
417
+ export default memo(TableEnhanceCell);
@@ -1,13 +1,13 @@
1
1
  import React from 'react';
2
2
  import { IMoveRow as _IMoveRow } from './hooks/useDropRef';
3
- import { FormInstance } from 'antd/lib/form';
4
3
  export declare type IMoveRow = _IMoveRow;
5
4
  interface IProps {
6
5
  index: number;
7
6
  moverow: IMoveRow;
8
7
  className?: string;
9
8
  style?: any;
9
+ vRow?: any;
10
+ [prop: string]: any;
10
11
  }
11
- export declare const EditableContext: React.Context<FormInstance<any>>;
12
- declare const TableEnhanceRow: React.FC<IProps>;
13
- export default TableEnhanceRow;
12
+ declare const _default: React.NamedExoticComponent<IProps>;
13
+ export default _default;
@@ -20,16 +20,15 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  }
21
21
  return t;
22
22
  };
23
- import React, { memo } from 'react';
23
+ import React, { memo, useMemo } from 'react';
24
24
  import useDropRef from './hooks/useDropRef';
25
- import { Form } from '../../index';
26
- export var EditableContext = React.createContext(null);
27
- var TableEnhanceRow = memo(function (props) {
28
- var index = props.index, moverow = props.moverow, className = props.className, style = props.style, restProps = __rest(props, ["index", "moverow", "className", "style"]);
25
+ var TableEnhanceRow = function (props) {
26
+ var index = props.index, moverow = props.moverow, className = props.className, style = props.style, vRow = props.vRow, restProps = __rest(props, ["index", "moverow", "className", "style", "vRow"]);
29
27
  var _a = useDropRef(index, moverow), ref = _a.ref, isOver = _a.isOver, dropClassName = _a.dropClassName;
30
- var form = Form.useForm()[0];
31
- return (React.createElement(Form, { autoComplete: "off", form: form, component: false, name: props['data-row-key'] },
32
- React.createElement(EditableContext.Provider, { value: form },
33
- React.createElement("tr", __assign({ ref: ref, className: "" + className + (isOver ? dropClassName : ''), style: __assign({ cursor: !moverow ? 'default' : 'move' }, style) }, restProps)))));
34
- });
35
- export default TableEnhanceRow;
28
+ var memoStyle = useMemo(function () { return (__assign({ cursor: !moverow ? 'default' : 'move' }, style)); }, [moverow, style]);
29
+ var tempProps = useMemo(function () {
30
+ return __assign({ ref: ref, className: "" + className + (isOver ? dropClassName : ''), style: memoStyle }, restProps);
31
+ }, [className, dropClassName, restProps, memoStyle, isOver, ref]);
32
+ return vRow ? (vRow(tempProps, ref)) : (React.createElement("tr", __assign({ ref: ref, className: "" + className + (isOver ? dropClassName : ''), style: memoStyle }, restProps)));
33
+ };
34
+ export default memo(TableEnhanceRow);
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ declare const TableHeadTooltip: React.FC<{
3
+ children: React.ReactNode;
4
+ headTooltip: React.ReactNode;
5
+ }>;
6
+ export default TableHeadTooltip;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { QuestionCircleOutlined } from '@ant-design/icons';
3
+ import { Tooltip } from '../../index';
4
+ var TableHeadTooltip = function (_a) {
5
+ var children = _a.children, headTooltip = _a.headTooltip;
6
+ return (React.createElement(React.Fragment, null,
7
+ children,
8
+ React.createElement(Tooltip, { title: headTooltip },
9
+ React.createElement(QuestionCircleOutlined, { style: {
10
+ marginLeft: '5px',
11
+ } }))));
12
+ };
13
+ export default TableHeadTooltip;
@@ -3,9 +3,8 @@
3
3
  * @description
4
4
  */
5
5
  import React from 'react';
6
- import type { ResizeCallbackData } from 'react-resizable';
7
- declare const TableResizableTitle: (props: React.HTMLAttributes<any> & {
8
- onResize: (e: React.SyntheticEvent<Element>, data: any) => void;
6
+ declare const _default: React.MemoExoticComponent<(props: React.HTMLAttributes<any> & {
7
+ onResize: (e: React.SyntheticEvent<Element, Event>, data: any) => void;
9
8
  width: number;
10
- }) => JSX.Element;
11
- export default TableResizableTitle;
9
+ }) => JSX.Element>;
10
+ export default _default;
@@ -24,16 +24,42 @@ var __rest = (this && this.__rest) || function (s, e) {
24
24
  * @author 陈亚雄
25
25
  * @description
26
26
  */
27
- import React from 'react';
27
+ import React, { useState } from 'react';
28
28
  import { Resizable } from 'react-resizable';
29
+ import classnames from 'classnames';
29
30
  var TableResizableTitle = function (props) {
30
- var onResize = props.onResize, width = props.width, restProps = __rest(props, ["onResize", "width"]);
31
+ var onResize = props.onResize, width = props.width, onMouseEnter = props.onMouseEnter, onMouseLeave = props.onMouseLeave, restProps = __rest(props, ["onResize", "width", "onMouseEnter", "onMouseLeave"]);
32
+ // 添加偏移量
33
+ var _a = useState(0), offset = _a[0], setOffset = _a[1];
31
34
  if (!width) {
32
35
  return React.createElement("th", __assign({}, restProps));
33
36
  }
34
- return (React.createElement(Resizable, { width: width, height: 0, handle: React.createElement("span", { className: "react-resizable-handle", onClick: function (e) {
37
+ return (React.createElement(Resizable, { width: Number(width) + Number(offset), height: 0, handle: React.createElement("span", {
38
+ // 有偏移量显示竖线
39
+ // className="react-resizable-handle"
40
+ className: classnames(['react-resizable-handle', offset && 'active']),
41
+ // 拖拽层偏移
42
+ style: { transform: "translateX(" + offset + "px)" }, onClick: function (e) {
35
43
  e.stopPropagation();
36
- } }), onResize: onResize, draggableOpts: { enableUserSelectHack: false } },
37
- React.createElement("th", __assign({}, restProps))));
44
+ e.preventDefault();
45
+ } }), onResize: function (e, _a) {
46
+ var size = _a.size;
47
+ // 这里只更新偏移量,数据列表其实并没有伸缩
48
+ setOffset(size.width - width);
49
+ }, onResizeStop: function (e, data) {
50
+ // 拖拽结束以后偏移量归零
51
+ setOffset(0);
52
+ // 这里是props传进来的事件,在外部是列数据中的onHeaderCell方法提供的事件,请自行研究官方提供的案例
53
+ onResize(e, data);
54
+ }, draggableOpts: { enableUserSelectHack: false } },
55
+ React.createElement("th", __assign({}, restProps, { style: __assign({ overflow: 'visible' }, restProps.style) }),
56
+ React.createElement("div", { style: {
57
+ width: '100%',
58
+ overflow: 'hidden',
59
+ whiteSpace: 'pre-wrap',
60
+ // whiteSpace: 'nowrap',
61
+ // textOverflow: 'ellipsis',
62
+ // 此处样式是在th中增加div块,为了解决拖拉时偏移虚线在右侧不出现问题
63
+ } }, restProps.children))));
38
64
  };
39
- export default TableResizableTitle;
65
+ export default React.memo(TableResizableTitle);
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ interface IProps {
3
+ title?: any;
4
+ field?: any;
5
+ onChange?: any;
6
+ customOrder?: any;
7
+ setCustomOrder?: any;
8
+ align?: any;
9
+ }
10
+ export default function TableSortTitle(props: IProps): JSX.Element;
11
+ export {};
@@ -0,0 +1,65 @@
1
+ import React, { useMemo } from 'react';
2
+ import classNames from 'classnames';
3
+ import CaretDownOutlined from '@ant-design/icons/CaretDownOutlined';
4
+ import CaretUpOutlined from '@ant-design/icons/CaretUpOutlined';
5
+ var ASCEND = 'ascend';
6
+ var DESCEND = 'descend';
7
+ export default function TableSortTitle(props) {
8
+ var title = props.title, field = props.field, onChange = props.onChange, customOrder = props.customOrder, setCustomOrder = props.setCustomOrder, align = props.align;
9
+ // const [order, setOrder] = useState<any>();
10
+ var order = !customOrder
11
+ ? null
12
+ : customOrder.field === field
13
+ ? customOrder.order
14
+ : null;
15
+ var handleSortClick = function (e) {
16
+ e.stopPropagation();
17
+ var currentOrd;
18
+ if (order === ASCEND) {
19
+ currentOrd = DESCEND;
20
+ setCustomOrder({
21
+ field: field,
22
+ order: currentOrd,
23
+ });
24
+ // setOrder(DESCEND);
25
+ }
26
+ else if (order === DESCEND) {
27
+ currentOrd = null;
28
+ setCustomOrder({
29
+ field: field,
30
+ order: currentOrd,
31
+ });
32
+ // setOrder(null);
33
+ }
34
+ else {
35
+ currentOrd = ASCEND;
36
+ setCustomOrder({
37
+ field: field,
38
+ order: currentOrd,
39
+ });
40
+ // setOrder(ASCEND);
41
+ }
42
+ onChange && onChange({ field: field, order: currentOrd });
43
+ };
44
+ var currentTitle = useMemo(function () {
45
+ if (order === ASCEND) {
46
+ return '点击降序';
47
+ }
48
+ else if (order === DESCEND) {
49
+ return '取消排序';
50
+ }
51
+ else {
52
+ return '点击升序';
53
+ }
54
+ }, [order]);
55
+ return (React.createElement("div", { className: "zt-table_sorter" },
56
+ align === 'center' ? React.createElement("div", null) : null,
57
+ React.createElement("div", { className: "sorter_title" }, typeof title === 'function' ? title() : title),
58
+ React.createElement("div", { className: "sorter_icon", onClick: handleSortClick, title: currentTitle },
59
+ React.createElement(CaretUpOutlined, { className: classNames("ant-table-column-sorter-up", {
60
+ active: order === ASCEND,
61
+ }) }),
62
+ React.createElement(CaretDownOutlined, { className: classNames("ant-table-column-sorter-down", {
63
+ active: order === DESCEND,
64
+ }) }))));
65
+ }
@@ -7,13 +7,15 @@ export interface IProps<RecordType> extends Omit<TableProps<RecordType>, 'column
7
7
  /**新增行删除行方法 */
8
8
  onAddAndDelHandle?: (type: 'add' | 'del', index: number) => void;
9
9
  /**隐藏新增icon */
10
- hideAddIcon?: boolean;
10
+ hideAddIcon?: boolean | ((record: any, index: number) => boolean);
11
11
  /**新增icon提示文字 */
12
- addIconText?: string;
12
+ addIconText?: string | ((record: any, index: number) => string);
13
13
  /**隐藏删除icon */
14
- hideDelIcon?: boolean;
14
+ hideDelIcon?: boolean | ((record: any, index: number) => boolean);
15
15
  /**删除icon提示文字 */
16
- delIconText?: string;
16
+ delIconText?: string | ((record: any, index: number) => string);
17
+ /** 是否隐藏图标 */
18
+ hiddenColumnDynamicIcon?: boolean;
17
19
  /**是否显示动态表头配置 */
18
20
  showColumnDynamic?: boolean;
19
21
  /**动态表头配置,是否缓存,动态列配置如果要缓存得话,必须得使用一个全局唯一得key来标识 */
@@ -57,6 +59,19 @@ export interface IProps<RecordType> extends Omit<TableProps<RecordType>, 'column
57
59
  /** 是否显示删除全部按钮 */
58
60
  showDelAllBtn?: boolean;
59
61
  delAllChange?: () => void;
62
+ /** 开启虚拟滚动 */
63
+ virtualTableKey?: string;
64
+ /** 是否需要排序 内部会有一个排序功能。自定义的 这个在某些条件下不会开启。但是还需要别的条件也不开启 */
65
+ isSort?: boolean;
66
+ /** 排序方法 ascend 升序 descend 降序 */
67
+ onSortChange?: (info: {
68
+ order: 'ascend' | 'descend' | null;
69
+ field: string;
70
+ }) => void;
71
+ /** 填充方法 */
72
+ onFillDownChange?: (info: {
73
+ field: string;
74
+ }) => void;
60
75
  }
61
76
  /**
62
77
  * TodoList
@@ -68,6 +83,7 @@ export interface IProps<RecordType> extends Omit<TableProps<RecordType>, 'column
68
83
  * 实现可拖拽行 completed
69
84
  * 实现可编辑功能
70
85
  */
86
+ export declare function usePrevious(value: any): undefined;
71
87
  declare function Table<RecordType extends object = any>(props: IProps<RecordType>): JSX.Element;
72
88
  declare const _default: React.MemoExoticComponent<typeof Table>;
73
89
  export default _default;