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
@@ -62,6 +62,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
62
62
  return to;
63
63
  };
64
64
  import React, { useCallback, memo, useState, useEffect, useRef, useMemo, useImperativeHandle, } from 'react';
65
+ import { unstable_batchedUpdates } from 'react-dom';
65
66
  import { Table as AntTable } from 'antd';
66
67
  import { message } from '../../index';
67
68
  import { ERROR_TD_CLASSNAME } from './';
@@ -70,15 +71,26 @@ import TableDynamic from './table-dynamic';
70
71
  import TableEnhanceRow from './table-enhance-row';
71
72
  import TableEnhanceCell from './table-enhance-cell';
72
73
  import TableResizableTitle from './table-resizable-title';
73
- import useColumns, { setDynamicKey } from './hooks/useColumns';
74
+ import useColumns, { setDynamicKey, getStorage, } from './hooks/useColumns';
75
+ import useSelectSubtotal from './hooks/useSelectSubtotal';
74
76
  import getSummaryData from './utils/getSummaryData';
75
- import { domFind } from './utils/dom';
77
+ import { domFind,
78
+ // domParentsUntil,
79
+ // parseSliceData,
80
+ // appendSubtotalTr,
81
+ // deleteSubtotalTr,
82
+ // deleteSubtotalClassNameTr,
83
+ } from './utils/dom';
76
84
  import { tableValidate } from './utils/validate';
85
+ // import { shallowEqual } from './utils/shallowEqual';
77
86
  import classNames from 'classnames';
78
87
  import { HTML5Backend } from 'react-dnd-html5-backend';
79
88
  import { DndProvider } from 'react-dnd';
89
+ import { VList, scrollTo } from 'virtuallist-antd';
80
90
  // import update from 'immutability-helper';
81
91
  import useInnerPagination, { getInnerIndex } from './hooks/useInnerPagination';
92
+ import { INNER_PARENT_ROW_KEY, INNER_PARENT_ROW_KEY_NO } from './constants';
93
+ import useLastest from '../utils/useLastest';
82
94
  /**默认scroll配置 */
83
95
  // const _scroll = { y: 500, x: 1000 };
84
96
  var _scroll = { x: 1000 };
@@ -88,7 +100,7 @@ var _scroll = { x: 1000 };
88
100
  */
89
101
  var components = {
90
102
  body: {
91
- row: TableEnhanceRow,
103
+ // row: TableEnhanceRow,
92
104
  cell: TableEnhanceCell,
93
105
  },
94
106
  };
@@ -102,34 +114,81 @@ var components = {
102
114
  * 实现可拖拽行 completed
103
115
  * 实现可编辑功能
104
116
  */
117
+ export function usePrevious(value) {
118
+ var ref = useRef();
119
+ useEffect(function () {
120
+ ref.current = value;
121
+ });
122
+ return ref.current;
123
+ }
105
124
  function Table(props) {
106
125
  var _this = this;
107
- var className = props.className, scroll = props.scroll, _a = props.pagination, pagination = _a === void 0 ? false : _a, _b = props.bordered, bordered = _b === void 0 ? true : _b, columns = props.columns, initColumns = props.initColumns, dataSource = props.dataSource, onAddAndDelHandle = props.onAddAndDelHandle, hideAddIcon = props.hideAddIcon, addIconText = props.addIconText, hideDelIcon = props.hideDelIcon, showDelAllBtn = props.showDelAllBtn, delAllChange = props.delAllChange, delIconText = props.delIconText, showColumnDynamic = props.showColumnDynamic, showColumnDynamicKey = props.showColumnDynamicKey, summaryConfig = props.summaryConfig, summaryFixed = props.summaryFixed, summary = props.summary, onMoveRow = props.onMoveRow, onEditableSave = props.onEditableSave, onDynamicChange = props.onDynamicChange, _c = props.isResizableColumn, isResizableColumn = _c === void 0 ? true : _c, configInfo = props.configInfo, tableHandleRef = props.tableHandleRef, tableName = props.tableName, isFlex = props.isFlex, onTableChange = props.onTableChange, rowSelection = props.rowSelection, showInnerPagination = props.showInnerPagination, defaultInnerPageSize = props.defaultInnerPageSize, restProps = __rest(props, ["className", "scroll", "pagination", "bordered", "columns", "initColumns", "dataSource", "onAddAndDelHandle", "hideAddIcon", "addIconText", "hideDelIcon", "showDelAllBtn", "delAllChange", "delIconText", "showColumnDynamic", "showColumnDynamicKey", "summaryConfig", "summaryFixed", "summary", "onMoveRow", "onEditableSave", "onDynamicChange", "isResizableColumn", "configInfo", "tableHandleRef", "tableName", "isFlex", "onTableChange", "rowSelection", "showInnerPagination", "defaultInnerPageSize"]);
108
- // console.log('table render');
126
+ var _a, _b;
127
+ var className = props.className, scroll = props.scroll, _c = props.pagination, pagination = _c === void 0 ? false : _c, _d = props.bordered, bordered = _d === void 0 ? true : _d, _columns = props.columns, initColumns = props.initColumns, dataSource = props.dataSource, onAddAndDelHandle = props.onAddAndDelHandle, hideAddIcon = props.hideAddIcon, addIconText = props.addIconText, hideDelIcon = props.hideDelIcon, showDelAllBtn = props.showDelAllBtn, delAllChange = props.delAllChange, delIconText = props.delIconText, hiddenColumnDynamicIcon = props.hiddenColumnDynamicIcon, showColumnDynamic = props.showColumnDynamic, showColumnDynamicKey = props.showColumnDynamicKey, summaryConfig = props.summaryConfig, summaryFixed = props.summaryFixed, summary = props.summary, onMoveRow = props.onMoveRow, onEditableSave = props.onEditableSave, onDynamicChange = props.onDynamicChange, _e = props.isResizableColumn, isResizableColumn = _e === void 0 ? true : _e, configInfo = props.configInfo, tableHandleRef = props.tableHandleRef, tableName = props.tableName, isFlex = props.isFlex, onTableChange = props.onTableChange, rowSelection = props.rowSelection, showInnerPagination = props.showInnerPagination, defaultInnerPageSize = props.defaultInnerPageSize, virtualTableKey = props.virtualTableKey, _f = props.isSort, isSort = _f === void 0 ? false : _f, onSortChange = props.onSortChange, onFillDownChange = props.onFillDownChange,
128
+ // onRow,
129
+ restProps = __rest(props, ["className", "scroll", "pagination", "bordered", "columns", "initColumns", "dataSource", "onAddAndDelHandle", "hideAddIcon", "addIconText", "hideDelIcon", "showDelAllBtn", "delAllChange", "delIconText", "hiddenColumnDynamicIcon", "showColumnDynamic", "showColumnDynamicKey", "summaryConfig", "summaryFixed", "summary", "onMoveRow", "onEditableSave", "onDynamicChange", "isResizableColumn", "configInfo", "tableHandleRef", "tableName", "isFlex", "onTableChange", "rowSelection", "showInnerPagination", "defaultInnerPageSize", "virtualTableKey", "isSort", "onSortChange", "onFillDownChange"]);
130
+ var onChange = restProps.onChange;
109
131
  var classes = classNames('zt-table', className, {
110
132
  'zt-table--flex': isFlex,
111
133
  });
112
- var _d = useState(false), dynamicVisible = _d[0], setDynamicVisible = _d[1];
113
- var _e = useState(columns), _columns = _e[0], setColumns = _e[1];
134
+ var _g = useState(false), dynamicVisible = _g[0], setDynamicVisible = _g[1];
114
135
  var showDynamicHandle = useCallback(function () { return setDynamicVisible(true); }, []);
115
136
  var hideDynamicHandle = useCallback(function () { return setDynamicVisible(false); }, []);
116
137
  var dataSourceRef = useRef();
138
+ var preDataSource = usePrevious(dataSource);
139
+ var _h = useState(), sortDataSource = _h[0], setSortDataSource = _h[1];
117
140
  // 内部分页相关配置
118
- var _f = useInnerPagination(showInnerPagination, defaultInnerPageSize), paginationConfig = _f.paginationConfig, currentPage = _f.currentPage, setCurrent = _f.setCurrent, pageSize = _f.pageSize;
141
+ var _j = useInnerPagination(showInnerPagination, defaultInnerPageSize), paginationConfig = _j.paginationConfig, currentPage = _j.currentPage, setCurrent = _j.setCurrent, pageSize = _j.pageSize;
119
142
  var rowSelectionDataSource = useRef({});
120
143
  var myScroll = useMemo(function () {
121
144
  if (scroll) {
122
- return isFlex ? __assign(__assign({}, scroll), { y: scroll.y || 100 }) : scroll;
145
+ return isFlex ? __assign(__assign({}, scroll), { y: scroll.y || 200 }) : scroll;
123
146
  }
124
- return isFlex ? __assign(__assign({}, _scroll), { y: 100 }) : _scroll;
147
+ return isFlex ? __assign(__assign({}, _scroll), { y: 200 }) : _scroll;
125
148
  }, [scroll, isFlex]);
149
+ var expandableDataSource = useMemo(function () {
150
+ var _a, _b;
151
+ if (!onEditableSave) {
152
+ return dataSource;
153
+ }
154
+ else {
155
+ try {
156
+ var childrenColumnName_1 = ((_a = props === null || props === void 0 ? void 0 : props.expandable) === null || _a === void 0 ? void 0 : _a.childrenColumnName) || 'children';
157
+ return (_b = dataSource === null || dataSource === void 0 ? void 0 : dataSource.slice()) === null || _b === void 0 ? void 0 : _b.map(function (item, index) {
158
+ var _a;
159
+ if (item) {
160
+ var itemRowKey_1 = typeof props.rowKey === 'string'
161
+ ? item[props.rowKey]
162
+ : "" + INNER_PARENT_ROW_KEY_NO + index;
163
+ var newChildren = item[childrenColumnName_1];
164
+ if (Array.isArray(newChildren)) {
165
+ newChildren = newChildren.map(function (childrenItem) {
166
+ var _a;
167
+ return __assign(__assign({}, childrenItem), (_a = {}, _a[INNER_PARENT_ROW_KEY] = itemRowKey_1, _a));
168
+ });
169
+ return __assign(__assign({}, item), (_a = {}, _a[childrenColumnName_1] = newChildren, _a));
170
+ }
171
+ }
172
+ return item;
173
+ });
174
+ }
175
+ catch (err) {
176
+ return dataSource;
177
+ }
178
+ }
179
+ }, [
180
+ onEditableSave,
181
+ dataSource,
182
+ (_a = props === null || props === void 0 ? void 0 : props.expandable) === null || _a === void 0 ? void 0 : _a.childrenColumnName,
183
+ props.rowKey,
184
+ ]);
126
185
  /**columns更新,重新设置columns */
127
186
  useEffect(function () {
128
- setColumns(columns);
129
- }, [columns]);
130
- useEffect(function () {
131
- dataSourceRef.current = dataSource;
132
- }, [dataSource]);
187
+ dataSourceRef.current = expandableDataSource;
188
+ // 2023-05-04 清空内部排序
189
+ setSortDataSource(null);
190
+ setCustomOrder(null);
191
+ }, [expandableDataSource]);
133
192
  var copyByKey = useCallback(function (key) {
134
193
  var _a, _b;
135
194
  if (Array.isArray(dataSourceRef.current)) {
@@ -161,12 +220,115 @@ function Table(props) {
161
220
  }
162
221
  }
163
222
  }, []);
223
+ var tableRef = useRef();
224
+ var getCurrentTable = useCallback(function () {
225
+ var _a;
226
+ var tableContent = domFind(tableRef.current, '.ant-table-content');
227
+ if (!tableContent) {
228
+ tableContent = domFind(tableRef.current, '.ant-table-container');
229
+ }
230
+ var tableBody = domFind(tableContent, '.ant-table-tbody');
231
+ var tr = tableBody === null || tableBody === void 0 ? void 0 : tableBody.children;
232
+ var arrTr = Array.prototype.slice.call(tr);
233
+ var resultTr = ((_a = arrTr === null || arrTr === void 0 ? void 0 : arrTr.filter) === null || _a === void 0 ? void 0 : _a.call(arrTr, function (item) { return item.className.includes('ant-table-row'); })) || [];
234
+ return { tableBody: tableBody, resultTr: resultTr };
235
+ }, []);
236
+ var clearErrorClass = useCallback(function (index) {
237
+ try {
238
+ var resultTr = getCurrentTable().resultTr;
239
+ if (typeof index === 'number') {
240
+ var tds = resultTr[index].querySelectorAll('td');
241
+ for (var i = 0; i < tds.length; i++) {
242
+ tds[i].classList.remove(ERROR_TD_CLASSNAME);
243
+ }
244
+ }
245
+ else {
246
+ for (var i = 0; i < resultTr.length; i++) {
247
+ var tds = resultTr[i].querySelectorAll('td');
248
+ for (var j = 0; j < tds.length; j++) {
249
+ tds[j].classList.remove(ERROR_TD_CLASSNAME);
250
+ }
251
+ }
252
+ }
253
+ }
254
+ catch (err) {
255
+ console.log(err);
256
+ }
257
+ }, [getCurrentTable]);
258
+ var onTableChangeHandle = useCallback(function (resultTextList, startIndex) {
259
+ clearErrorClass();
260
+ onTableChange && onTableChange(resultTextList, startIndex);
261
+ }, [clearErrorClass, onTableChange]);
262
+ // 2023-05-04 自定义表格排序方法
263
+ var _k = useState(), customOrder = _k[0], setCustomOrder = _k[1];
264
+ var customSortHandle = useCallback(function (info, options) {
265
+ if (Array.isArray(expandableDataSource) &&
266
+ expandableDataSource.length > 1) {
267
+ var field_1 = info.field, order = info.order;
268
+ var sorterHandle_1 = (options || {}).sorterHandle;
269
+ // 说明是前端排序
270
+ if (sorterHandle_1) {
271
+ if (order === 'ascend') {
272
+ setSortDataSource(expandableDataSource.slice().sort(function (a, b) {
273
+ return sorterHandle_1(a, b);
274
+ }));
275
+ }
276
+ else if (order === 'descend') {
277
+ setSortDataSource(expandableDataSource.slice().sort(function (a, b) {
278
+ return -sorterHandle_1(a, b);
279
+ }));
280
+ }
281
+ else {
282
+ setSortDataSource(null);
283
+ }
284
+ return;
285
+ }
286
+ // 如果传入了onSortChange方法,排序规则交给业务自行处理
287
+ if (onSortChange) {
288
+ onSortChange({ order: order, field: field_1 });
289
+ return;
290
+ }
291
+ // 如果传入了onChange函数,说明也是外部排序
292
+ if (onChange) {
293
+ onChange(null, null, { field: field_1, order: order }, null);
294
+ return;
295
+ }
296
+ var handle_1 = function (a, b) {
297
+ var result = a[field_1] - b[field_1];
298
+ if (!isNaN(result)) {
299
+ return result;
300
+ }
301
+ if (a[field_1] < b[field_1]) {
302
+ return -1;
303
+ }
304
+ else if (a[field_1] > b[field_1]) {
305
+ return 1;
306
+ }
307
+ return 0;
308
+ };
309
+ if (order === 'ascend') {
310
+ setSortDataSource(expandableDataSource.slice().sort(function (a, b) {
311
+ return handle_1(a, b);
312
+ }));
313
+ }
314
+ else if (order === 'descend') {
315
+ setSortDataSource(expandableDataSource.slice().sort(function (a, b) {
316
+ return -handle_1(a, b);
317
+ }));
318
+ }
319
+ else {
320
+ setSortDataSource(null);
321
+ }
322
+ }
323
+ }, [expandableDataSource, onSortChange, onChange]);
164
324
  /**
165
325
  * @description 根据配置生成一个新的columns
166
326
  * 以及一个需要动态列配置的columns
167
327
  */
168
- var _g = useColumns({
328
+ var onFillDownChangeRef = useLastest(onFillDownChange);
329
+ var _l = useColumns({
169
330
  columns: _columns,
331
+ hiddenColumnDynamicIcon: hiddenColumnDynamicIcon,
170
332
  showColumnDynamic: showColumnDynamic,
171
333
  showColumnDynamicKey: showColumnDynamicKey,
172
334
  onAddAndDelHandle: onAddAndDelHandle,
@@ -180,40 +342,45 @@ function Table(props) {
180
342
  onEditableSave: onEditableSave,
181
343
  configInfo: configInfo,
182
344
  copyByKey: copyByKey,
183
- onTableChange: onTableChange
184
- ? function (resultTextList, startIndex) {
185
- clearErrorClass();
186
- onTableChange && onTableChange(resultTextList, startIndex);
187
- }
188
- : undefined,
345
+ onTableChange: onTableChange ? onTableChangeHandle : undefined,
189
346
  currentPage: currentPage,
190
- }), newColumns = _g.newColumns, dynamicColumns = _g.dynamicColumns, setNewColumns = _g.setNewColumns;
347
+ currentDataSource: dataSource,
348
+ preDataSource: preDataSource,
349
+ dataSourceRef: dataSourceRef,
350
+ rowKey: props.rowKey,
351
+ expandableChildrenColumnName: ((_b = props === null || props === void 0 ? void 0 : props.expandable) === null || _b === void 0 ? void 0 : _b.childrenColumnName) || 'children',
352
+ customSortHandle: customSortHandle,
353
+ customOrder: customOrder,
354
+ setCustomOrder: setCustomOrder,
355
+ isSort: isSort,
356
+ onFillDownChangeRef: onFillDownChangeRef,
357
+ }), newColumns = _l.newColumns, dynamicColumns = _l.dynamicColumns, refreshColumnsHandle = _l.refreshColumnsHandle;
191
358
  /**
192
359
  * @description 保存列配置
193
360
  */
194
361
  var saveDynamicHandle = useCallback(function (dynamicColumns) {
195
362
  if (Array.isArray(_columns)) {
196
- var leftArr_1 = [];
197
- var rightArr_1 = [];
198
- _columns.forEach(function (column) {
199
- if (column.fixed === 'left') {
200
- leftArr_1.push(column);
201
- }
202
- if (column.fixed === 'right') {
203
- rightArr_1.push(column);
204
- }
205
- });
363
+ // const leftArr: ColumnsType<RecordType> = [];
364
+ // const rightArr: ColumnsType<RecordType> = [];
365
+ // _columns.forEach((column) => {
366
+ // if (column.fixed === 'left') {
367
+ // leftArr.push(column);
368
+ // }
369
+ // if (column.fixed === 'right') {
370
+ // rightArr.push(column);
371
+ // }
372
+ // });
206
373
  // 记录width信息
207
- var _newColumns = __spreadArray(__spreadArray(__spreadArray([], leftArr_1), dynamicColumns), rightArr_1);
374
+ // let _newColumns = [...leftArr, ...dynamicColumns, ...rightArr];
208
375
  // 同步width
209
- _newColumns = _newColumns.map(function (item) {
376
+ var _newColumns = dynamicColumns.map(function (item) {
210
377
  var column = newColumns.find(function (column) {
211
- return column.dataIndex === item.dataIndex || column.key === item.key;
378
+ return (column.dataIndex && column.dataIndex === item.dataIndex) ||
379
+ (column.key && column.key === item.key);
212
380
  });
213
381
  return column && column.width
214
382
  ? __assign(__assign({}, item), { width: column.width }) : item;
215
383
  });
216
- setColumns(_newColumns);
217
384
  var catchColumns = _newColumns.map(function (item) {
218
385
  if (item.dataIndex || item.key) {
219
386
  return {
@@ -221,29 +388,29 @@ function Table(props) {
221
388
  key: item.key,
222
389
  hideColumn: item.hideColumn,
223
390
  width: item.width,
391
+ fixed: item.fixed,
224
392
  };
225
393
  }
226
394
  return __assign({}, item);
227
395
  });
228
396
  if (showColumnDynamicKey) {
229
- // let catchColumnsStr = '{}';
230
- // try {
231
- // catchColumnsStr = JSON.stringify(catchColumns);
232
- // } catch (err) {
233
- // console.log(err);
234
- // }
235
- // localStorage.setItem(showColumnDynamicKey, catchColumnsStr);
236
397
  setDynamicKey(showColumnDynamicKey, catchColumns);
237
398
  }
399
+ refreshColumnsHandle();
238
400
  onDynamicChange && onDynamicChange(catchColumns);
239
401
  }
240
- }, [_columns, newColumns, onDynamicChange, showColumnDynamicKey]);
402
+ }, [
403
+ _columns,
404
+ newColumns,
405
+ onDynamicChange,
406
+ showColumnDynamicKey,
407
+ refreshColumnsHandle,
408
+ ]);
241
409
  /**
242
410
  * @description 动态列配置重置功能
243
411
  */
244
412
  var resetDynamicHandle = useCallback(function () {
245
- var _initColumns = initColumns || columns || [];
246
- setColumns(__spreadArray([], _initColumns));
413
+ var _initColumns = initColumns || _columns || [];
247
414
  var catchColumns = (_initColumns || []).map(function (item) {
248
415
  if (item.dataIndex || item.key) {
249
416
  return {
@@ -251,36 +418,103 @@ function Table(props) {
251
418
  key: item.key,
252
419
  hideColumn: item.hideColumn,
253
420
  width: item.width,
421
+ fixed: item.fixed,
254
422
  };
255
423
  }
424
+ // 20230815 去掉没有赋key的默认赋title的逻辑
425
+ // 这个逻辑会引发一些bug
426
+ // return { ...item, dataIndex: item.title, key: item.title };
256
427
  return __assign({}, item);
257
428
  });
258
429
  if (showColumnDynamicKey) {
259
- // let catchColumnsStr = '{}';
260
- // try {
261
- // catchColumnsStr = JSON.stringify(catchColumns);
262
- // } catch (err) {
263
- // console.log(err);
264
- // }
265
- // localStorage.setItem(showColumnDynamicKey, catchColumnsStr);
266
430
  setDynamicKey(showColumnDynamicKey, catchColumns);
267
431
  }
432
+ refreshColumnsHandle();
268
433
  onDynamicChange && onDynamicChange(catchColumns);
269
434
  hideDynamicHandle();
270
435
  }, [
271
436
  initColumns,
272
- columns,
437
+ _columns,
273
438
  hideDynamicHandle,
274
439
  onDynamicChange,
275
440
  showColumnDynamicKey,
441
+ refreshColumnsHandle,
276
442
  ]);
443
+ // // 点击行行为
444
+ // const checkedRowRef = useRef<any>({});
445
+ // const subtotalIndexRef = useRef<any>([]);
446
+ // const getColumnData = useCallback(
447
+ // (pageData: any) => {
448
+ // const summaryData = getSummaryData(summaryConfig, pageData, newColumns, {
449
+ // hasRowSelection: props.rowSelection ? true : false,
450
+ // hasExpandable: props.expandable ? true : false,
451
+ // });
452
+ // return summaryData;
453
+ // },
454
+ // [summaryConfig, props.rowSelection, props.expandable, newColumns]
455
+ // );
456
+ // const onRowFn = useCallback(
457
+ // (record, index) => {
458
+ // let result: any = {};
459
+ // if (onRow) {
460
+ // result = onRow(record);
461
+ // }
462
+ // const { onDoubleClick, ...resetResult } = result;
463
+ // return {
464
+ // onDoubleClick: (event) => {
465
+ // onDoubleClick && onDoubleClick(event);
466
+ // if (onEditableSave) {
467
+ // return;
468
+ // }
469
+ // // 选中的数据添加一些样式规则
470
+ // const tr = domParentsUntil(event.target, '.ant-table-row');
471
+ // if (tr.classList.contains('ant-table-row-doubleClick')) {
472
+ // tr.classList.remove('ant-table-row-doubleClick');
473
+ // const removeIndex = subtotalIndexRef.current.findIndex(
474
+ // (item) => item === index
475
+ // );
476
+ // subtotalIndexRef.current.splice(removeIndex, 1);
477
+ // Reflect.deleteProperty(checkedRowRef.current, index);
478
+ // } else {
479
+ // subtotalIndexRef.current.push(index);
480
+ // tr.classList.add('ant-table-row-doubleClick');
481
+ // checkedRowRef.current[index] = record;
482
+ // }
483
+ // // 将索引排序好 按相邻规则分段
484
+ // const sliceArr = parseSliceData(
485
+ // subtotalIndexRef.current,
486
+ // checkedRowRef.current
487
+ // );
488
+ // // 按切片数据 插入到表格中
489
+ // appendSubtotalTr(tr, sliceArr, getColumnData);
490
+ // },
491
+ // ...resetResult,
492
+ // };
493
+ // },
494
+ // // eslint-disable-next-line react-hooks/exhaustive-deps
495
+ // [onRow, getColumnData]
496
+ // );
497
+ // // 数据更新时,做一下清空操作
498
+ // useEffect(() => {
499
+ // const { tableBody, resultTr } = getCurrentTable();
500
+ // deleteSubtotalTr(tableBody);
501
+ // deleteSubtotalClassNameTr(resultTr);
502
+ // checkedRowRef.current = {};
503
+ // subtotalIndexRef.current = [];
504
+ // // eslint-disable-next-line react-hooks/exhaustive-deps
505
+ // }, [sortDataSource, expandableDataSource]);
277
506
  /**
278
507
  * @description 切换行位置
279
508
  */
280
509
  var moveRowHandle = useCallback(function (dragIndex, hoverIndex) {
281
510
  var innerDragIndex = getInnerIndex(currentPage, dragIndex);
282
511
  var innerHoverIndex = getInnerIndex(currentPage, hoverIndex);
283
- onMoveRow && onMoveRow(innerDragIndex, innerHoverIndex);
512
+ if (innerDragIndex === innerHoverIndex) {
513
+ return;
514
+ }
515
+ unstable_batchedUpdates(function () {
516
+ onMoveRow && onMoveRow(innerDragIndex, innerHoverIndex);
517
+ });
284
518
  // if (dataSource) {
285
519
  // const dragRow = dataSource[dragIndex];
286
520
  // const newDataSource = update(dataSource, {
@@ -291,11 +525,15 @@ function Table(props) {
291
525
  // });
292
526
  // onMoveRow && onMoveRow(newDataSource);
293
527
  // }
294
- },
295
- // eslint-disable-next-line react-hooks/exhaustive-deps
296
- [onMoveRow]);
528
+ }, [currentPage, onMoveRow]);
529
+ var onRowHandle = useCallback(function (record, index) {
530
+ return ({
531
+ index: index,
532
+ moverow: moveRowHandle,
533
+ });
534
+ }, [moveRowHandle]);
297
535
  /** 伸缩列 */
298
- var handleResize = function (index) {
536
+ var handleResize = useCallback(function (index) {
299
537
  return function (_, _a) {
300
538
  var size = _a.size;
301
539
  var _newColumns = __spreadArray([], (newColumns || []));
@@ -314,7 +552,8 @@ function Table(props) {
314
552
  }
315
553
  var catchColumns = __spreadArray(__spreadArray(__spreadArray([], leftArr), dynamicColumns), rightArr).map(function (item) {
316
554
  var column = _newColumns.find(function (column) {
317
- return column.dataIndex === item.dataIndex || column.key === item.key;
555
+ return (column.dataIndex && column.dataIndex === item.dataIndex) ||
556
+ (column.key && column.key === item.key);
318
557
  });
319
558
  if (item.dataIndex || item.key) {
320
559
  return {
@@ -322,29 +561,34 @@ function Table(props) {
322
561
  key: item.key,
323
562
  hideColumn: item.hideColumn,
324
563
  width: column && column.width ? column.width : item.width,
564
+ fixed: item.fixed,
325
565
  };
326
566
  }
327
567
  return __assign({}, item);
328
568
  });
329
569
  if (showColumnDynamicKey) {
330
- // let catchColumnsStr = '{}';
331
- // try {
332
- // catchColumnsStr = JSON.stringify(catchColumns);
333
- // } catch (err) {
334
- // console.log(err);
335
- // }
336
- // localStorage.setItem(showColumnDynamicKey, catchColumnsStr);
337
570
  setDynamicKey(showColumnDynamicKey, catchColumns);
571
+ refreshColumnsHandle();
572
+ }
573
+ else {
574
+ refreshColumnsHandle(catchColumns);
338
575
  }
339
- setNewColumns(_newColumns);
340
576
  };
341
- };
342
- var mergeColumns = isResizableColumn
343
- ? (newColumns || []).map(function (col, index) { return (__assign(__assign({}, col), { onHeaderCell: function (column) { return ({
344
- width: column.width,
345
- onResize: handleResize(index),
346
- }); } })); })
347
- : newColumns;
577
+ }, [
578
+ _columns,
579
+ dynamicColumns,
580
+ newColumns,
581
+ refreshColumnsHandle,
582
+ showColumnDynamicKey,
583
+ ]);
584
+ var mergeColumns = useMemo(function () {
585
+ return isResizableColumn
586
+ ? (newColumns || []).map(function (col, index) { return (__assign(__assign({}, col), { onHeaderCell: function (column) { return ({
587
+ width: column.width,
588
+ onResize: handleResize(index),
589
+ }); } })); })
590
+ : newColumns;
591
+ }, [handleResize, isResizableColumn, newColumns]);
348
592
  if (isResizableColumn) {
349
593
  components.header = {
350
594
  cell: TableResizableTitle,
@@ -353,42 +597,6 @@ function Table(props) {
353
597
  /**
354
598
  * 表格暴露方法给外部使用
355
599
  */
356
- var tableRef = useRef();
357
- function getCurrentTable() {
358
- var _a;
359
- // 获取表格元素
360
- var tableContent = domFind(tableRef.current, '.ant-table-content');
361
- if (!tableContent) {
362
- tableContent = domFind(tableRef.current, '.ant-table-container');
363
- }
364
- var tableBody = domFind(tableContent, '.ant-table-tbody');
365
- var tr = tableBody === null || tableBody === void 0 ? void 0 : tableBody.children;
366
- var arrTr = Array.prototype.slice.call(tr);
367
- var resultTr = ((_a = arrTr === null || arrTr === void 0 ? void 0 : arrTr.filter) === null || _a === void 0 ? void 0 : _a.call(arrTr, function (item) { return item.className.includes('ant-table-row'); })) || [];
368
- return { tableBody: tableBody, resultTr: resultTr };
369
- }
370
- function clearErrorClass(index) {
371
- try {
372
- var resultTr = getCurrentTable().resultTr;
373
- if (typeof index === 'number') {
374
- var tds = resultTr[index].querySelectorAll('td');
375
- for (var i = 0; i < tds.length; i++) {
376
- tds[i].classList.remove(ERROR_TD_CLASSNAME);
377
- }
378
- }
379
- else {
380
- for (var i = 0; i < resultTr.length; i++) {
381
- var tds = resultTr[i].querySelectorAll('td');
382
- for (var j = 0; j < tds.length; j++) {
383
- tds[j].classList.remove(ERROR_TD_CLASSNAME);
384
- }
385
- }
386
- }
387
- }
388
- catch (err) {
389
- console.log(err);
390
- }
391
- }
392
600
  useImperativeHandle(tableHandleRef, function () { return ({
393
601
  /** 错误提示 */
394
602
  validate: function () { return __awaiter(_this, void 0, void 0, function () {
@@ -411,6 +619,27 @@ function Table(props) {
411
619
  }
412
620
  });
413
621
  }); },
622
+ /**自定义错误提示数据 */
623
+ customizeDataValidate: function (isDataItemValidate) { return __awaiter(_this, void 0, void 0, function () {
624
+ return __generator(this, function (_a) {
625
+ switch (_a.label) {
626
+ case 0:
627
+ clearErrorClass();
628
+ return [4 /*yield*/, tableValidate(dataSource, mergeColumns, {
629
+ getCurrentTable: getCurrentTable,
630
+ rowSelection: props.rowSelection,
631
+ expandable: props.expandable,
632
+ tableName: tableName,
633
+ showInnerPagination: showInnerPagination,
634
+ setCurrent: setCurrent,
635
+ pageSize: pageSize,
636
+ }, isDataItemValidate)];
637
+ case 1:
638
+ _a.sent();
639
+ return [2 /*return*/];
640
+ }
641
+ });
642
+ }); },
414
643
  /** 获取当前表格 */
415
644
  getCurrentTable: function () {
416
645
  return getCurrentTable();
@@ -428,6 +657,26 @@ function Table(props) {
428
657
  }
429
658
  return index;
430
659
  },
660
+ /** 获取自定义列配置当前配置 */
661
+ getColumns: function () {
662
+ var columns = [];
663
+ mergeColumns.forEach(function (column) {
664
+ if (column.dataIndex) {
665
+ columns.push({
666
+ dataIndex: column.dataIndex || column.key,
667
+ });
668
+ }
669
+ });
670
+ return columns;
671
+ },
672
+ /** 虚拟滚动 滚动到顶部方法 */
673
+ scrollTo: function (obj) {
674
+ scrollTo(obj);
675
+ },
676
+ /** 获取动态列配置信息 */
677
+ getStorage: function () {
678
+ return getStorage(showColumnDynamicKey);
679
+ },
431
680
  }); });
432
681
  var tableResizableTitle = useMemo(function () {
433
682
  return {
@@ -436,6 +685,115 @@ function Table(props) {
436
685
  },
437
686
  };
438
687
  }, []);
688
+ // 表格合计
689
+ var onSummaryHandle = useCallback(function (pageData) {
690
+ var _a;
691
+ var _b = rowSelectionDataSource.current || {}, isChange = _b.isChange, selectedRowKeys = _b.selectedRowKeys, selectedRows = _b.selectedRows;
692
+ var rowKey = restProps.rowKey;
693
+ var resultDataSoure = typeof rowKey === 'string' && Array.isArray(selectedRowKeys)
694
+ ? pageData.filter(function (item) {
695
+ return selectedRowKeys.find(function (key) { return item[rowKey] === key; });
696
+ })
697
+ : selectedRows;
698
+ var summaryData = getSummaryData(summaryConfig, isChange && Array.isArray(resultDataSoure) && resultDataSoure.length > 0
699
+ ? resultDataSoure
700
+ : pageData, newColumns, {
701
+ hasRowSelection: props.rowSelection ? true : false,
702
+ hasExpandable: (props === null || props === void 0 ? void 0 : props.expandable) && ((_a = props === null || props === void 0 ? void 0 : props.expandable) === null || _a === void 0 ? void 0 : _a.expandedRowRender)
703
+ ? true
704
+ : false,
705
+ });
706
+ return (React.createElement(AntTable.Summary, { fixed: summaryFixed ? summaryFixed : virtualTableKey ? true : false }, summaryData.map(function (summary) {
707
+ var title = summary.title, key = summary.key, titleIndex = summary.titleIndex, list = summary.list, columnList = summary.columnList, onClickHandle = summary.onClickHandle;
708
+ return (React.createElement(AntTable.Summary.Row, { key: key }, Array.isArray(list) &&
709
+ list.map(function (item, index) {
710
+ var data = {
711
+ index: index,
712
+ column: Array.isArray(columnList)
713
+ ? columnList[index]
714
+ : null,
715
+ num: item,
716
+ };
717
+ if (titleIndex === index) {
718
+ return (React.createElement(AntTable.Summary.Cell, { key: index, index: index }, onClickHandle ? (React.createElement("div", { onClick: function () { return onClickHandle === null || onClickHandle === void 0 ? void 0 : onClickHandle(data); } }, title)) : (title)));
719
+ }
720
+ else {
721
+ return (React.createElement(AntTable.Summary.Cell, { key: index, index: index },
722
+ React.createElement("div", { style: {
723
+ color: '#333',
724
+ }, onClick: function () {
725
+ return onClickHandle && (onClickHandle === null || onClickHandle === void 0 ? void 0 : onClickHandle(data));
726
+ } }, item)));
727
+ }
728
+ })));
729
+ })));
730
+ }, [
731
+ newColumns,
732
+ props === null || props === void 0 ? void 0 : props.expandable,
733
+ props === null || props === void 0 ? void 0 : props.rowSelection,
734
+ restProps === null || restProps === void 0 ? void 0 : restProps.rowKey,
735
+ summaryConfig,
736
+ summaryFixed,
737
+ virtualTableKey,
738
+ ]);
739
+ // 多选
740
+ var rowSelectionObj = useMemo(function () { return (__assign(__assign({}, rowSelection), { onChange: function (selectedRowKeys, selectedRows) {
741
+ rowSelectionDataSource.current = {
742
+ selectedRows: selectedRows,
743
+ selectedRowKeys: selectedRowKeys,
744
+ isChange: true,
745
+ };
746
+ (rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.onChange) &&
747
+ rowSelection.onChange(selectedRowKeys, selectedRows);
748
+ } })); }, [rowSelection]);
749
+ // 虚拟滚动选项
750
+ var vComponents = useMemo(function () {
751
+ if (virtualTableKey) {
752
+ // 使用VList 即可有虚拟列表的效果
753
+ return VList({
754
+ vid: virtualTableKey,
755
+ height: myScroll.y ? myScroll.y : 200,
756
+ resetTopWhenDataChange: false,
757
+ });
758
+ }
759
+ else {
760
+ return null;
761
+ }
762
+ // eslint-disable-next-line react-hooks/exhaustive-deps
763
+ }, [virtualTableKey]);
764
+ var tableComponents = useMemo(function () {
765
+ var _a, _b;
766
+ var result = onMoveRow || onEditableSave
767
+ ? components
768
+ : isResizableColumn
769
+ ? tableResizableTitle
770
+ : undefined;
771
+ if (onMoveRow && result.body) {
772
+ result.body.row = TableEnhanceRow;
773
+ }
774
+ if (vComponents) {
775
+ // 需要支持编辑
776
+ if ((_a = result === null || result === void 0 ? void 0 : result.body) === null || _a === void 0 ? void 0 : _a.cell) {
777
+ vComponents.body.cell = result.body.cell;
778
+ }
779
+ // 需要支持拖拽
780
+ if ((_b = result === null || result === void 0 ? void 0 : result.body) === null || _b === void 0 ? void 0 : _b.row) {
781
+ var row_1 = vComponents.body.row;
782
+ vComponents.body.row = function (props) {
783
+ return React.createElement(TableEnhanceRow, __assign({}, props, { vRow: row_1 }));
784
+ };
785
+ }
786
+ return __assign(__assign({}, result), vComponents);
787
+ }
788
+ return result;
789
+ }, [
790
+ isResizableColumn,
791
+ onEditableSave,
792
+ onMoveRow,
793
+ tableResizableTitle,
794
+ vComponents,
795
+ ]);
796
+ var tipRef = useSelectSubtotal(tableRef, { onMoveRow: onMoveRow, onEditableSave: onEditableSave }).tipRef;
439
797
  return (React.createElement("div", { style: isFlex
440
798
  ? { position: 'relative', overflow: 'hidden', flex: 1 }
441
799
  : { position: 'relative', overflow: 'hidden' }, ref: tableRef },
@@ -444,69 +802,13 @@ function Table(props) {
444
802
  ? pagination
445
803
  ? pagination
446
804
  : paginationConfig
447
- : pagination, scroll: myScroll, columns: mergeColumns, dataSource: dataSource, components: onMoveRow || onEditableSave
448
- ? components
449
- : isResizableColumn
450
- ? tableResizableTitle
451
- : undefined, onRow: onMoveRow
452
- ? function (record, index) {
453
- return ({
454
- index: index,
455
- moverow: moveRowHandle,
456
- });
457
- }
458
- : undefined, summary: summaryConfig
459
- ? function (pageData) {
460
- var _a = rowSelectionDataSource.current || {}, isChange = _a.isChange, selectedRowKeys = _a.selectedRowKeys, selectedRows = _a.selectedRows;
461
- var rowKey = restProps.rowKey;
462
- var resultDataSoure = typeof rowKey === 'string' && Array.isArray(selectedRowKeys)
463
- ? pageData.filter(function (item) {
464
- return selectedRowKeys.find(function (key) { return item[rowKey] === key; });
465
- })
466
- : selectedRows;
467
- var summaryData = getSummaryData(summaryConfig, isChange &&
468
- Array.isArray(resultDataSoure) &&
469
- resultDataSoure.length > 0
470
- ? resultDataSoure
471
- : pageData, newColumns, {
472
- hasRowSelection: props.rowSelection ? true : false,
473
- hasExpandable: props.expandable ? true : false,
474
- });
475
- return (React.createElement(AntTable.Summary, { fixed: summaryFixed }, summaryData.map(function (summary) {
476
- var title = summary.title, key = summary.key, titleIndex = summary.titleIndex, list = summary.list, columnList = summary.columnList, onClickHandle = summary.onClickHandle;
477
- return (React.createElement(AntTable.Summary.Row, { key: key }, Array.isArray(list) &&
478
- list.map(function (item, index) {
479
- var data = {
480
- index: index,
481
- column: Array.isArray(columnList)
482
- ? columnList[index]
483
- : null,
484
- num: item,
485
- };
486
- if (titleIndex === index) {
487
- return (React.createElement(AntTable.Summary.Cell, { key: index, index: index }, onClickHandle ? (React.createElement("div", { onClick: function () { return onClickHandle === null || onClickHandle === void 0 ? void 0 : onClickHandle(data); } }, title)) : (title)));
488
- }
489
- else {
490
- return (React.createElement(AntTable.Summary.Cell, { key: index, index: index },
491
- React.createElement("div", { style: {
492
- color: '#333',
493
- }, onClick: function () {
494
- return onClickHandle && (onClickHandle === null || onClickHandle === void 0 ? void 0 : onClickHandle(data));
495
- } }, item)));
496
- }
497
- })));
498
- })));
499
- }
500
- : summary, rowSelection: rowSelection
501
- ? __assign(__assign({}, rowSelection), { onChange: function (selectedRowKeys, selectedRows) {
502
- rowSelectionDataSource.current = {
503
- selectedRows: selectedRows,
504
- selectedRowKeys: selectedRowKeys,
505
- isChange: true,
506
- };
507
- rowSelection.onChange &&
508
- rowSelection.onChange(selectedRowKeys, selectedRows);
509
- } }) : rowSelection }, restProps)),
510
- showColumnDynamic && (React.createElement(TableDynamic, { visible: dynamicVisible, onClose: hideDynamicHandle, onSave: saveDynamicHandle, onReset: resetDynamicHandle, columns: dynamicColumns })))));
805
+ : pagination, scroll: myScroll, columns: mergeColumns, dataSource: sortDataSource ? sortDataSource : expandableDataSource, components: tableComponents, onRow: onMoveRow ? onRowHandle : undefined,
806
+ // onRow={onMoveRow ? onRowHandle : onRowFn}
807
+ summary: summaryConfig ? onSummaryHandle : summary, rowSelection: rowSelection ? rowSelectionObj : rowSelection }, restProps)),
808
+ showColumnDynamic && dynamicVisible && (React.createElement(TableDynamic, { visible: dynamicVisible, onClose: hideDynamicHandle, onSave: saveDynamicHandle, onReset: resetDynamicHandle, columns: dynamicColumns }))),
809
+ React.createElement("div", { ref: tipRef, className: "table-subtotal--tip" })));
511
810
  }
811
+ // export default memo(Table, (prevProps, nextProps) => {
812
+ // return shallowEqual(prevProps, nextProps);
813
+ // });
512
814
  export default memo(Table);