@arim-aisdc/public-components 2.3.61 → 2.3.63
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/components/BaseInfo/BaseInfo.d.ts +1 -1
- package/dist/components/TableMax/TableBody/VirtualTableBody.js +0 -1
- package/dist/components/TableMax/TableBody/index.less +5 -2
- package/dist/components/TableMax/TableHeader/index.less +11 -2
- package/dist/components/TableMax/TableMax.js +4 -1
- package/dist/components/TableMax/components/ColumnSort/customSortFns.d.ts +8 -8
- package/dist/components/TableMax/hooks/useColumnWidth.d.ts +1 -1
- package/dist/components/TableMax/hooks/useColumnWidth.js +81 -59
- package/package.json +1 -1
|
@@ -17,7 +17,7 @@ export declare const foramtBaseInfoField: (data: any, dataField: BaseInfoFieldTy
|
|
|
17
17
|
value: any;
|
|
18
18
|
field: string;
|
|
19
19
|
label?: string;
|
|
20
|
-
text: string | Element |
|
|
20
|
+
text: string | JSX.Element | Element;
|
|
21
21
|
units?: string;
|
|
22
22
|
width?: string;
|
|
23
23
|
labelWidth?: string;
|
|
@@ -93,7 +93,6 @@ var VirtualTableBody = function VirtualTableBody(_ref) {
|
|
|
93
93
|
// 从 Provider 中获取虚拟化数据
|
|
94
94
|
var rowVirtualizer = state.rowVirtualizer;
|
|
95
95
|
var virtualRows = rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.getVirtualItems();
|
|
96
|
-
console.log(rowVirtualizer, virtualRows, 'virtualRows');
|
|
97
96
|
var _useState = useState({
|
|
98
97
|
visible: false,
|
|
99
98
|
clientX: 0,
|
|
@@ -28,6 +28,8 @@ table {
|
|
|
28
28
|
height: 0;
|
|
29
29
|
border-bottom: 1px solid @tableColor2;
|
|
30
30
|
z-index: 210;
|
|
31
|
+
display: block;
|
|
32
|
+
box-sizing: border-box;
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -38,9 +40,10 @@ table {
|
|
|
38
40
|
left: 0;
|
|
39
41
|
top: 0;
|
|
40
42
|
width: 100%;
|
|
41
|
-
height:
|
|
43
|
+
height: var(--cell-height);
|
|
44
|
+
border-top: 1px solid @tableColor2;
|
|
42
45
|
border-bottom: 1px solid @tableColor2;
|
|
43
|
-
z-index:
|
|
46
|
+
z-index: 260;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
.tbody-tr-highlight {
|
|
@@ -213,8 +213,6 @@ table {
|
|
|
213
213
|
width: 2px;
|
|
214
214
|
position: fixed;
|
|
215
215
|
z-index: 99999;
|
|
216
|
-
// background-color: #000;
|
|
217
|
-
background-color: green;
|
|
218
216
|
}
|
|
219
217
|
.column-resizing-divide-line {
|
|
220
218
|
will-change: transform;
|
|
@@ -236,5 +234,16 @@ thead {
|
|
|
236
234
|
align-items: center;
|
|
237
235
|
padding: var(--cell-padding);
|
|
238
236
|
height: var(--cell-height);
|
|
237
|
+
position: relative;
|
|
238
|
+
}
|
|
239
|
+
tr::after{
|
|
240
|
+
content: '';
|
|
241
|
+
display: block;
|
|
242
|
+
position: absolute;
|
|
243
|
+
left: 0;
|
|
244
|
+
top: 0;
|
|
245
|
+
width: 100%;
|
|
246
|
+
height: var(--cell-height);
|
|
247
|
+
background-color: var(--globalColor_14);
|
|
239
248
|
}
|
|
240
249
|
}
|
|
@@ -648,6 +648,8 @@ var TableMax = function TableMax(_ref) {
|
|
|
648
648
|
// onChange: row.getToggleSelectedHandler(),
|
|
649
649
|
onChange: function onChange(e) {
|
|
650
650
|
var _e$nativeEvent;
|
|
651
|
+
// 阻止点击事件冒泡,监听行双击事件时,点击这里会有问题
|
|
652
|
+
e.stopPropagation();
|
|
651
653
|
var currentRowIsSelected,
|
|
652
654
|
currentSelectedRows = [],
|
|
653
655
|
allSelectedRows = [];
|
|
@@ -704,7 +706,8 @@ var TableMax = function TableMax(_ref) {
|
|
|
704
706
|
onRowCheckboxClick === null || onRowCheckboxClick === void 0 || onRowCheckboxClick(currentSelectedRows, currentSelectedRows.map(function (row) {
|
|
705
707
|
return row.original;
|
|
706
708
|
}), currentRowIsSelected, allSelectedRows);
|
|
707
|
-
|
|
709
|
+
},
|
|
710
|
+
onClick: function onClick(e) {
|
|
708
711
|
e.stopPropagation();
|
|
709
712
|
}
|
|
710
713
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { TableMaxColumnType } from "../../type";
|
|
2
|
-
export declare const numberSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
3
|
-
export declare const stringSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
4
|
-
export declare const numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
5
|
-
export declare const timeSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
2
|
+
export declare const numberSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
3
|
+
export declare const stringSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
4
|
+
export declare const numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
5
|
+
export declare const timeSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
6
6
|
declare const customSortFns: {
|
|
7
|
-
numberSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
8
|
-
stringSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
9
|
-
timeSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
10
|
-
numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
7
|
+
numberSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
8
|
+
stringSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
9
|
+
timeSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
10
|
+
numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
11
11
|
};
|
|
12
12
|
export default customSortFns;
|
|
13
13
|
export type SortFnType = keyof typeof customSortFns | undefined;
|
|
@@ -16,7 +16,7 @@ export declare const useColumnWidth: ({ tableContentRef, tableId, tableKeyPrefix
|
|
|
16
16
|
allColumnCount: number;
|
|
17
17
|
onColumnSizingChange: (updater: any) => void;
|
|
18
18
|
tableContainerWidth: number;
|
|
19
|
-
initializeColumnSizing: (columns: any) => void;
|
|
19
|
+
initializeColumnSizing: (columns: any) => () => void;
|
|
20
20
|
handleVisibleConfigChange: (key: string, value: boolean) => void;
|
|
21
21
|
};
|
|
22
22
|
export {};
|
|
@@ -57,7 +57,13 @@ export var useColumnWidth = function useColumnWidth(_ref) {
|
|
|
57
57
|
_useState2 = _slicedToArray(_useState, 2),
|
|
58
58
|
state = _useState2[0],
|
|
59
59
|
setState = _useState2[1];
|
|
60
|
-
var getTableWidth =
|
|
60
|
+
var getTableWidth = useCallback(function () {
|
|
61
|
+
if (!tableContentRef.current) return 0;
|
|
62
|
+
var width = tableContentRef.current.getBoundingClientRect().width;
|
|
63
|
+
var style = window.getComputedStyle(tableContentRef.current);
|
|
64
|
+
var horizontalBorderWidth = parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth);
|
|
65
|
+
return Math.floor(width - horizontalBorderWidth);
|
|
66
|
+
}, [tableContentRef.current]);
|
|
61
67
|
var debouncedHandleResizeRef = useRef(debounce(function (newWidth) {
|
|
62
68
|
return handleResize(newWidth);
|
|
63
69
|
}, DEFAULT_RESIZE_DEBOUNCE));
|
|
@@ -157,7 +163,7 @@ export var useColumnWidth = function useColumnWidth(_ref) {
|
|
|
157
163
|
*/
|
|
158
164
|
var calculateColumnSizing = useCallback(function (columnsSizeMap, allColumnCount, containerWidth) {
|
|
159
165
|
var currentWidth = containerWidth || state.tableContainerWidth || getTableWidth();
|
|
160
|
-
|
|
166
|
+
console.log(containerWidth, tableContentRef.current.clientWidth, state.tableContainerWidth, getTableWidth());
|
|
161
167
|
if (!currentWidth) return columnsSizeMap;
|
|
162
168
|
var result = _objectSpread({}, columnsSizeMap);
|
|
163
169
|
var adjustableColumns = getAdjustableColumns(result);
|
|
@@ -211,71 +217,87 @@ export var useColumnWidth = function useColumnWidth(_ref) {
|
|
|
211
217
|
* 初始化列宽信息
|
|
212
218
|
*/
|
|
213
219
|
var initializeColumnSizing = useCallback(function (columns) {
|
|
214
|
-
var _localStorage$getItem;
|
|
215
220
|
if (!Array.isArray(columns) || columns.length === 0) return;
|
|
216
|
-
var
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (!(cache !== null && cache !== void 0 && cache.editTime) || now - cache.editTime > cacheMaxAge) {
|
|
228
|
-
Object.keys(initColumnsSizeMap).forEach(function (key) {
|
|
229
|
-
if (columnVisibleConfig[key] !== false) {
|
|
230
|
-
visibleColumnsSizeMap[key] = initColumnsSizeMap[key];
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
} else {
|
|
234
|
-
var _cache$columnSizing, _cache$columnVisibili;
|
|
235
|
-
var columnsIdSet = new Set(columns.map(function (column) {
|
|
236
|
-
return column.id;
|
|
237
|
-
}));
|
|
221
|
+
var initializeWithWidth = function initializeWithWidth(width) {
|
|
222
|
+
var _localStorage$getItem;
|
|
223
|
+
var _getSizeInfo = getSizeInfo(columns),
|
|
224
|
+
allCount = _getSizeInfo.allCount,
|
|
225
|
+
columnSizeMap = _getSizeInfo.columnSizeMap;
|
|
226
|
+
var cache = JSON.parse((_localStorage$getItem = localStorage.getItem(tableKey)) !== null && _localStorage$getItem !== void 0 ? _localStorage$getItem : '{}');
|
|
227
|
+
var now = +Date.now();
|
|
228
|
+
setState(produce(function (prevState) {
|
|
229
|
+
// 初始化列宽映射
|
|
230
|
+
var initColumnsSizeMap = _objectSpread({}, columnSizeMap);
|
|
231
|
+
var visibleColumnsSizeMap = {};
|
|
238
232
|
|
|
239
|
-
//
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
key =
|
|
244
|
-
|
|
233
|
+
// 处理缓存过期或无效的情况
|
|
234
|
+
if (!(cache !== null && cache !== void 0 && cache.editTime) || now - cache.editTime > cacheMaxAge) {
|
|
235
|
+
Object.keys(initColumnsSizeMap).forEach(function (key) {
|
|
236
|
+
if (columnVisibleConfig[key] !== false) {
|
|
237
|
+
visibleColumnsSizeMap[key] = initColumnsSizeMap[key];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
} else {
|
|
241
|
+
var _cache$columnSizing, _cache$columnVisibili;
|
|
242
|
+
var columnsIdSet = new Set(columns.map(function (column) {
|
|
243
|
+
return column.id;
|
|
245
244
|
}));
|
|
246
|
-
};
|
|
247
245
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
246
|
+
// 工具函数
|
|
247
|
+
var pickByKeys = function pickByKeys(obj, keys) {
|
|
248
|
+
return Object.fromEntries(Object.entries(obj).filter(function (_ref2) {
|
|
249
|
+
var _ref3 = _slicedToArray(_ref2, 1),
|
|
250
|
+
key = _ref3[0];
|
|
251
|
+
return keys.has(key);
|
|
252
|
+
}));
|
|
253
|
+
};
|
|
257
254
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
255
|
+
// 主逻辑
|
|
256
|
+
Object.assign(initColumnsSizeMap, pickByKeys((_cache$columnSizing = cache.columnSizing) !== null && _cache$columnSizing !== void 0 ? _cache$columnSizing : {}, columnsIdSet));
|
|
257
|
+
Object.assign(columnVisibleConfig, pickByKeys((_cache$columnVisibili = cache.columnVisibility) !== null && _cache$columnVisibili !== void 0 ? _cache$columnVisibili : {}, columnsIdSet));
|
|
258
|
+
Object.keys(initColumnsSizeMap).forEach(function (key) {
|
|
259
|
+
if (columnVisibleConfig[key] !== false) {
|
|
260
|
+
visibleColumnsSizeMap[key] = initColumnsSizeMap[key];
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
265
264
|
|
|
266
|
-
|
|
265
|
+
// console.log({
|
|
266
|
+
// prevState,
|
|
267
|
+
// initColumnsSizeMap,
|
|
268
|
+
// visibleColumnsSizeMap,
|
|
269
|
+
// cache,
|
|
270
|
+
// cacheMaxAge,
|
|
271
|
+
// tableContentRef: tableContentRef.current
|
|
267
272
|
|
|
268
|
-
|
|
269
|
-
var visibleCount = allCount - Object.keys(columnVisibleConfig).filter(function (key) {
|
|
270
|
-
return !columnVisibleConfig[key];
|
|
271
|
-
}).length;
|
|
273
|
+
// }, 'columnSizeMap123')
|
|
272
274
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
275
|
+
// 计算可见列数
|
|
276
|
+
var visibleCount = allCount - Object.keys(columnVisibleConfig).filter(function (key) {
|
|
277
|
+
return !columnVisibleConfig[key];
|
|
278
|
+
}).length;
|
|
279
|
+
|
|
280
|
+
// 计算最终列宽
|
|
281
|
+
prevState.columnSizing = calculateColumnSizing(visibleColumnsSizeMap, visibleCount, width);
|
|
282
|
+
prevState.tableContainerWidth = width;
|
|
283
|
+
prevState.allColumnSizing = _objectSpread(_objectSpread({}, initColumnsSizeMap), prevState.columnSizing);
|
|
284
|
+
prevState.allColumnCount = visibleCount;
|
|
285
|
+
prevState.initColumnsSizeMap = columnSizeMap;
|
|
286
|
+
}));
|
|
287
|
+
};
|
|
288
|
+
var currentWidth = getTableWidth();
|
|
289
|
+
if (currentWidth) {
|
|
290
|
+
initializeWithWidth(currentWidth);
|
|
291
|
+
} else {
|
|
292
|
+
// 简单延迟重试
|
|
293
|
+
var timer = setTimeout(function () {
|
|
294
|
+
var retryWidth = getTableWidth() || 1000; // 回退默认宽度
|
|
295
|
+
initializeWithWidth(retryWidth);
|
|
296
|
+
}, 100);
|
|
297
|
+
return function () {
|
|
298
|
+
return clearTimeout(timer);
|
|
299
|
+
};
|
|
300
|
+
}
|
|
279
301
|
}, [calculateColumnSizing, columnVisibleConfig, tableKey, cacheMaxAge]);
|
|
280
302
|
|
|
281
303
|
/**
|