@arim-aisdc/public-components 2.3.17 → 2.3.18
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/CenterModal/CenterModal.d.ts +2 -2
- package/dist/components/CenterModal/CenterModal.js +70 -90
- package/dist/components/CenterModal/index.less +88 -0
- package/dist/components/CenterModal/type.d.ts +8 -0
- package/dist/components/CustomForm/CustomForm.js +5 -1
- package/dist/components/TableMax/hooks/useColumnWidth copy.d.ts +18 -0
- package/dist/components/TableMax/hooks/useColumnWidth copy.js +369 -0
- package/dist/components/TableMax/hooks/useColumnWidth.d.ts +7 -3
- package/dist/components/TableMax/hooks/useColumnWidth.js +218 -283
- package/dist/components/TableMax/type.d.ts +2 -0
- package/package.json +4 -1
|
@@ -10,24 +10,44 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
10
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
11
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import { useCallback, useEffect,
|
|
13
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
14
|
+
import { produce } from 'immer';
|
|
15
|
+
import { debounce } from 'lodash-es';
|
|
14
16
|
import { getSizeInfo } from "../utils";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var
|
|
18
|
-
var
|
|
17
|
+
|
|
18
|
+
// 可配置的常量
|
|
19
|
+
var DEFAULT_MIN_SIZE = 120;
|
|
20
|
+
var DEFAULT_MAX_SIZE = 240;
|
|
21
|
+
var DEFAULT_RESIZE_DEBOUNCE = 200;
|
|
22
|
+
var DEFAULT_TABLE_PADDING = 10;
|
|
23
|
+
/**
|
|
24
|
+
* 获取表格容器的有效宽度(减去边框)
|
|
25
|
+
*/
|
|
26
|
+
var useTableWidth = function useTableWidth(tableContentRef) {
|
|
27
|
+
return useCallback(function () {
|
|
28
|
+
if (!tableContentRef.current) return 0;
|
|
29
|
+
var width = tableContentRef.current.getBoundingClientRect().width;
|
|
30
|
+
var style = window.getComputedStyle(tableContentRef.current);
|
|
31
|
+
var horizontalBorderWidth = parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth);
|
|
32
|
+
return Math.floor(width - horizontalBorderWidth);
|
|
33
|
+
}, [tableContentRef]);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 自定义Hook:表格列宽计算和管理
|
|
38
|
+
*/
|
|
19
39
|
export var useColumnWidth = function useColumnWidth(_ref) {
|
|
20
40
|
var tableContentRef = _ref.tableContentRef,
|
|
21
41
|
tableId = _ref.tableId,
|
|
22
42
|
tableKeyPrefixCls = _ref.tableKeyPrefixCls,
|
|
23
43
|
_ref$columnVisibleCon = _ref.columnVisibleConfig,
|
|
24
44
|
columnVisibleConfig = _ref$columnVisibleCon === void 0 ? {} : _ref$columnVisibleCon,
|
|
25
|
-
tableKey = _ref.tableKey
|
|
45
|
+
tableKey = _ref.tableKey,
|
|
46
|
+
_ref$cacheMaxAge = _ref.cacheMaxAge,
|
|
47
|
+
cacheMaxAge = _ref$cacheMaxAge === void 0 ? 1 * 60 * 60 * 1000 : _ref$cacheMaxAge;
|
|
26
48
|
var _useState = useState({
|
|
27
49
|
columnSizing: {},
|
|
28
|
-
//显示列的列宽
|
|
29
50
|
allColumnSizing: {},
|
|
30
|
-
//所有列的列宽
|
|
31
51
|
allColumnCount: 0,
|
|
32
52
|
tableContainerWidth: undefined,
|
|
33
53
|
initColumnsSizeMap: {}
|
|
@@ -35,329 +55,244 @@ export var useColumnWidth = function useColumnWidth(_ref) {
|
|
|
35
55
|
_useState2 = _slicedToArray(_useState, 2),
|
|
36
56
|
state = _useState2[0],
|
|
37
57
|
setState = _useState2[1];
|
|
38
|
-
var getTableWidth =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var horizontalBorderWidth = parseFloat(style.getPropertyValue('border-left-width')) + parseFloat(style.getPropertyValue('border-right-width'));
|
|
43
|
-
return Math.floor(width - horizontalBorderWidth);
|
|
44
|
-
}, [tableContentRef]);
|
|
58
|
+
var getTableWidth = useTableWidth(tableContentRef);
|
|
59
|
+
var debouncedHandleResizeRef = useRef(debounce(function (newWidth) {
|
|
60
|
+
return handleResize(newWidth);
|
|
61
|
+
}, DEFAULT_RESIZE_DEBOUNCE));
|
|
45
62
|
|
|
46
63
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
* 计算可调整的列(排除展开列和选择列)
|
|
65
|
+
*/
|
|
66
|
+
var getAdjustableColumns = useCallback(function (columns) {
|
|
67
|
+
return Object.keys(columns).filter(function (key) {
|
|
68
|
+
return !['expander', 'selection-column'].includes(key);
|
|
69
|
+
});
|
|
70
|
+
}, []);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 计算可见列
|
|
74
|
+
*/
|
|
75
|
+
var getVisibleColumns = useCallback(function (columns) {
|
|
76
|
+
return Object.keys(columns).filter(function (key) {
|
|
77
|
+
return columnVisibleConfig[key] !== false;
|
|
78
|
+
});
|
|
79
|
+
}, [columnVisibleConfig]);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 处理容器宽度变化的逻辑
|
|
83
|
+
*/
|
|
84
|
+
var handleResize = useCallback(function (newWidth) {
|
|
59
85
|
if (!newWidth) return;
|
|
60
86
|
setState(function (prevState) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}).reduce(function (sum, key) {
|
|
68
|
-
return sum + (prevState.columnSizing[key] || 120);
|
|
69
|
-
}, 0);
|
|
70
|
-
|
|
71
|
-
// 容器变大时的逻辑
|
|
72
|
-
if (prevState.tableContainerWidth > 0 && newWidth > prevState.tableContainerWidth) {
|
|
73
|
-
if (totalVisibleWidth < newWidth) {
|
|
74
|
-
// 计算剩余宽度
|
|
75
|
-
var remainWidth = newWidth - totalVisibleWidth - 10;
|
|
76
|
-
var unselectedCount = visibleColumns.length;
|
|
87
|
+
return produce(prevState, function (draft) {
|
|
88
|
+
var visibleColumns = getVisibleColumns(draft.columnSizing);
|
|
89
|
+
var adjustableColumns = getAdjustableColumns(draft.columnSizing);
|
|
90
|
+
var totalVisibleWidth = visibleColumns.reduce(function (sum, key) {
|
|
91
|
+
return sum + (draft.columnSizing[key] || DEFAULT_MIN_SIZE);
|
|
92
|
+
}, 0);
|
|
77
93
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
tableContainerWidth: newWidth
|
|
89
|
-
});
|
|
94
|
+
// 容器变大时的逻辑
|
|
95
|
+
if (draft.tableContainerWidth && newWidth > draft.tableContainerWidth) {
|
|
96
|
+
if (totalVisibleWidth < newWidth - DEFAULT_TABLE_PADDING) {
|
|
97
|
+
var remainWidth = newWidth - totalVisibleWidth - DEFAULT_TABLE_PADDING;
|
|
98
|
+
if (adjustableColumns.length > 0) {
|
|
99
|
+
var averageWidth = remainWidth / adjustableColumns.length;
|
|
100
|
+
adjustableColumns.forEach(function (key) {
|
|
101
|
+
draft.columnSizing[key] = Math.min((draft.columnSizing[key] || 0) + averageWidth, DEFAULT_MAX_SIZE);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
90
104
|
}
|
|
91
105
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
103
|
-
columnSizing: _newVisibleColumnsSizing,
|
|
104
|
-
allColumnSizing: _objectSpread(_objectSpread({}, prevState.allColumnSizing || {}), _newVisibleColumnsSizing),
|
|
105
|
-
tableContainerWidth: newWidth
|
|
106
|
-
});
|
|
106
|
+
// 容器变小时的逻辑
|
|
107
|
+
else if (draft.tableContainerWidth && newWidth < draft.tableContainerWidth) {
|
|
108
|
+
var reducedWidth = newWidth - totalVisibleWidth - DEFAULT_TABLE_PADDING;
|
|
109
|
+
if (adjustableColumns.length > 0) {
|
|
110
|
+
var _averageWidth = reducedWidth / adjustableColumns.length;
|
|
111
|
+
adjustableColumns.forEach(function (key) {
|
|
112
|
+
var _draft$initColumnsSiz;
|
|
113
|
+
draft.columnSizing[key] = Math.max((draft.columnSizing[key] || 0) + _averageWidth, Math.max(((_draft$initColumnsSiz = draft.initColumnsSizeMap) === null || _draft$initColumnsSiz === void 0 ? void 0 : _draft$initColumnsSiz[key]) || 0, DEFAULT_MIN_SIZE));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
107
116
|
}
|
|
108
|
-
|
|
109
|
-
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
110
|
-
tableContainerWidth: newWidth
|
|
117
|
+
draft.tableContainerWidth = newWidth;
|
|
111
118
|
});
|
|
112
119
|
});
|
|
113
|
-
}, [
|
|
114
|
-
|
|
115
|
-
// 使用防抖处理容器宽度变化
|
|
116
|
-
var debouncedHandleResize = useMemo(function () {
|
|
117
|
-
return debounce(handleResize, 200);
|
|
118
|
-
}, [handleResize]);
|
|
119
|
-
useEffect(function () {
|
|
120
|
-
if (!tableContentRef.current) return;
|
|
121
|
-
var resizeObserver = new ResizeObserver(debouncedHandleResize);
|
|
122
|
-
resizeObserver.observe(tableContentRef.current);
|
|
123
|
-
return function () {
|
|
124
|
-
resizeObserver.disconnect();
|
|
125
|
-
debouncedHandleResize.cancel(); // 清理防抖
|
|
126
|
-
};
|
|
127
|
-
}, [tableContentRef.current, debouncedHandleResize]);
|
|
120
|
+
}, [getAdjustableColumns, getVisibleColumns]);
|
|
128
121
|
|
|
129
122
|
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
* 增加列,其余列宽度不变
|
|
134
|
-
* 减少列,列宽之和大于容器宽度,其余列宽不变
|
|
135
|
-
* 列宽之和小于容器宽度,除展开列和勾选列外,其余列平分列宽之和与容器宽度的差值
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
|
-
var handleVisibleConfigChange = function handleVisibleConfigChange(key, value) {
|
|
123
|
+
* 列显示隐藏后调整列宽
|
|
124
|
+
*/
|
|
125
|
+
var handleVisibleConfigChange = useCallback(function (key, value) {
|
|
139
126
|
setState(function (prevState) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
columnSizing: _objectSpread(_objectSpread({}, prevState.columnSizing), {}, {
|
|
145
|
-
key: prevState.allColumnSizing[key]
|
|
146
|
-
}),
|
|
147
|
-
allColumnSizing: _objectSpread(_objectSpread({}, prevState.allColumnSizing), {}, {
|
|
148
|
-
key: prevState.allColumnSizing[key] || 120
|
|
149
|
-
})
|
|
150
|
-
});
|
|
151
|
-
} else {
|
|
152
|
-
//列宽减少
|
|
153
|
-
var newVisibleColumnsSizing = prevState.columnSizing;
|
|
154
|
-
delete newVisibleColumnsSizing[key];
|
|
155
|
-
var containerWidth = getTableWidth() - 10 || 0;
|
|
156
|
-
// 计算当前总宽度
|
|
157
|
-
var totalWidth = Object.values(newVisibleColumnsSizing).reduce(function (sum, width) {
|
|
158
|
-
return Number(sum || 0) + Number(width || 0);
|
|
159
|
-
}, 0);
|
|
160
|
-
if (containerWidth < totalWidth) {
|
|
161
|
-
// 容器宽度小于增加列后的列总和,其他列宽度不变
|
|
162
|
-
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
163
|
-
columnSizing: newVisibleColumnsSizing
|
|
164
|
-
});
|
|
127
|
+
return produce(prevState, function (draft) {
|
|
128
|
+
if (value) {
|
|
129
|
+
// 显示列
|
|
130
|
+
draft.columnSizing[key] = draft.allColumnSizing[key] || DEFAULT_MIN_SIZE;
|
|
165
131
|
} else {
|
|
166
|
-
//
|
|
167
|
-
|
|
168
|
-
var
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
132
|
+
// 隐藏列
|
|
133
|
+
delete draft.columnSizing[key];
|
|
134
|
+
var containerWidth = getTableWidth() - DEFAULT_TABLE_PADDING || 0;
|
|
135
|
+
var totalWidth = Object.values(draft.columnSizing).reduce(function (sum, width) {
|
|
136
|
+
return sum + Number(width || 0);
|
|
137
|
+
}, 0);
|
|
138
|
+
if (containerWidth > totalWidth) {
|
|
139
|
+
var widthDifference = containerWidth - totalWidth;
|
|
140
|
+
var adjustableColumns = getAdjustableColumns(draft.columnSizing);
|
|
141
|
+
if (adjustableColumns.length > 0) {
|
|
142
|
+
var averageWidthIncrease = widthDifference / adjustableColumns.length;
|
|
143
|
+
adjustableColumns.forEach(function (colKey) {
|
|
144
|
+
draft.columnSizing[colKey] = Math.min((draft.columnSizing[colKey] || 0) + averageWidthIncrease, DEFAULT_MAX_SIZE);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
179
148
|
}
|
|
180
|
-
}
|
|
149
|
+
});
|
|
181
150
|
});
|
|
182
|
-
};
|
|
151
|
+
}, [getAdjustableColumns, getTableWidth]);
|
|
183
152
|
|
|
184
153
|
/**
|
|
185
|
-
*
|
|
186
|
-
|
|
187
|
-
* 平分后还存在剩余宽度,除展开列和勾选列外的其他列平分剩余宽度
|
|
188
|
-
* */
|
|
154
|
+
* 初始化列宽计算
|
|
155
|
+
*/
|
|
189
156
|
var calculateColumnSizing = useCallback(function (columnsSizeMap, allColumnCount, containerWidth) {
|
|
190
|
-
var _Object$keys$filter;
|
|
191
|
-
if (!tableContentRef.current || !columnsSizeMap) return {};
|
|
192
157
|
var currentWidth = containerWidth || state.tableContainerWidth || getTableWidth();
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
var remainColumnCount = allColumnCount - hasColumnCount;
|
|
197
|
-
var allColumnWidth = Object.values(columnsSizeMap).reduce(function (sum, width) {
|
|
198
|
-
return sum + Number(width || 0);
|
|
199
|
-
}, 0);
|
|
200
|
-
var remainTableContainerWidth = currentWidth - allColumnWidth - 10;
|
|
201
|
-
var newColumnSizeMap = _objectSpread({}, columnsSizeMap);
|
|
158
|
+
if (!currentWidth) return columnsSizeMap;
|
|
159
|
+
var result = _objectSpread({}, columnsSizeMap);
|
|
160
|
+
var adjustableColumns = getAdjustableColumns(result);
|
|
202
161
|
|
|
203
|
-
//
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
162
|
+
// 计算已设置宽度的列
|
|
163
|
+
var hasWidthColumns = Object.keys(result).filter(function (key) {
|
|
164
|
+
return result[key];
|
|
165
|
+
});
|
|
166
|
+
var noWidthColumns = Object.keys(result).filter(function (key) {
|
|
167
|
+
return !result[key];
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// 为未设置宽度的列分配初始宽度
|
|
171
|
+
if (noWidthColumns.length > 0) {
|
|
172
|
+
var availableWidth = currentWidth - DEFAULT_TABLE_PADDING - hasWidthColumns.reduce(function (sum, key) {
|
|
173
|
+
return sum + (result[key] || 0);
|
|
213
174
|
}, 0);
|
|
214
|
-
|
|
175
|
+
var averageSize = Math.min(Math.max(availableWidth / noWidthColumns.length, DEFAULT_MIN_SIZE), DEFAULT_MAX_SIZE);
|
|
176
|
+
noWidthColumns.forEach(function (key) {
|
|
177
|
+
result[key] = averageSize;
|
|
178
|
+
});
|
|
215
179
|
}
|
|
216
180
|
|
|
217
181
|
// 分配剩余宽度
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
182
|
+
var totalWidth = Object.values(result).reduce(function (sum, width) {
|
|
183
|
+
return sum + width;
|
|
184
|
+
}, 0);
|
|
185
|
+
var remainWidth = currentWidth - DEFAULT_TABLE_PADDING - totalWidth;
|
|
186
|
+
if (remainWidth > 0 && adjustableColumns.length > 0) {
|
|
187
|
+
var averageExtra = remainWidth / adjustableColumns.length;
|
|
188
|
+
adjustableColumns.forEach(function (key) {
|
|
189
|
+
result[key] = Math.min(result[key] + averageExtra, DEFAULT_MAX_SIZE);
|
|
222
190
|
});
|
|
223
|
-
if (adjustableColumns.length > 0) {
|
|
224
|
-
var averageExtra = remainTableContainerWidth / adjustableColumns.length;
|
|
225
|
-
adjustableColumns.forEach(function (key) {
|
|
226
|
-
newColumnSizeMap[key] += averageExtra;
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
191
|
}
|
|
230
|
-
return
|
|
231
|
-
}, [
|
|
192
|
+
return result;
|
|
193
|
+
}, [getAdjustableColumns, getTableWidth, state.tableContainerWidth]);
|
|
232
194
|
|
|
233
|
-
|
|
195
|
+
/**
|
|
196
|
+
* 初始化列宽信息
|
|
197
|
+
*/
|
|
234
198
|
var initializeColumnSizing = useCallback(function (columns) {
|
|
235
199
|
var _localStorage$getItem;
|
|
236
|
-
if (!Array.isArray(columns) || columns.length === 0)
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
var cache = JSON.parse((_localStorage$getItem = localStorage.getItem("".concat(tableKey))) !== null && _localStorage$getItem !== void 0 ? _localStorage$getItem : '{}');
|
|
200
|
+
if (!Array.isArray(columns) || columns.length === 0) return;
|
|
240
201
|
var _getSizeInfo = getSizeInfo(columns),
|
|
241
202
|
allCount = _getSizeInfo.allCount,
|
|
242
203
|
columnSizeMap = _getSizeInfo.columnSizeMap;
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
var cacheColumnSizing = cache.columnSizing,
|
|
268
|
-
cacheColumnVisibility = cache.columnVisibility;
|
|
269
|
-
var initColumnsSizeMap = _objectSpread(_objectSpread({}, columnSizeMap), cacheColumnSizing);
|
|
270
|
-
var initColumnsVisibility = _objectSpread(_objectSpread({}, columnVisibleConfig), cacheColumnVisibility);
|
|
271
|
-
var visibleColumnsSizeMap = {};
|
|
272
|
-
var notVisibleColumns = Object.keys(initColumnsVisibility).filter(function (key) {
|
|
273
|
-
return !initColumnsVisibility[key];
|
|
274
|
-
});
|
|
275
|
-
var newAllColumnCount = allCount - notVisibleColumns.length;
|
|
276
|
-
Object.keys(initColumnsSizeMap).forEach(function (key) {
|
|
277
|
-
if (!notVisibleColumns.includes(key)) {
|
|
278
|
-
visibleColumnsSizeMap[key] = initColumnsSizeMap[key];
|
|
204
|
+
var cache = JSON.parse((_localStorage$getItem = localStorage.getItem(tableKey)) !== null && _localStorage$getItem !== void 0 ? _localStorage$getItem : '{}');
|
|
205
|
+
var now = Date.now();
|
|
206
|
+
setState(produce(function (prevState) {
|
|
207
|
+
// 初始化列宽映射
|
|
208
|
+
var initColumnsSizeMap = _objectSpread({}, columnSizeMap);
|
|
209
|
+
var visibleColumnsSizeMap = {};
|
|
210
|
+
|
|
211
|
+
// 处理缓存过期或无效的情况
|
|
212
|
+
if (!(cache !== null && cache !== void 0 && cache.editTime) || now - cache.editTime > cacheMaxAge) {
|
|
213
|
+
Object.keys(initColumnsSizeMap).forEach(function (key) {
|
|
214
|
+
if (columnVisibleConfig[key] !== false) {
|
|
215
|
+
visibleColumnsSizeMap[key] = initColumnsSizeMap[key];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
} else {
|
|
219
|
+
// 使用缓存数据
|
|
220
|
+
Object.assign(initColumnsSizeMap, cache.columnSizing);
|
|
221
|
+
Object.assign(columnVisibleConfig, cache.columnVisibility);
|
|
222
|
+
Object.keys(initColumnsSizeMap).forEach(function (key) {
|
|
223
|
+
if (columnVisibleConfig[key] !== false) {
|
|
224
|
+
visibleColumnsSizeMap[key] = initColumnsSizeMap[key];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
279
227
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
var
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
228
|
+
|
|
229
|
+
// 计算可见列数
|
|
230
|
+
var visibleCount = allCount - Object.keys(columnVisibleConfig).filter(function (key) {
|
|
231
|
+
return !columnVisibleConfig[key];
|
|
232
|
+
}).length;
|
|
233
|
+
|
|
234
|
+
// 计算最终列宽
|
|
235
|
+
prevState.columnSizing = calculateColumnSizing(visibleColumnsSizeMap, visibleCount, prevState.tableContainerWidth);
|
|
236
|
+
prevState.allColumnSizing = _objectSpread(_objectSpread({}, initColumnsSizeMap), prevState.columnSizing);
|
|
237
|
+
prevState.allColumnCount = visibleCount;
|
|
238
|
+
prevState.initColumnsSizeMap = columnSizeMap;
|
|
239
|
+
}));
|
|
240
|
+
}, [calculateColumnSizing, columnVisibleConfig, tableKey, cacheMaxAge]);
|
|
292
241
|
|
|
293
242
|
/**
|
|
294
|
-
*
|
|
295
|
-
* 1。列宽增加,不重新计算其他列
|
|
296
|
-
* 2.列宽减小:
|
|
297
|
-
* 列宽之和大于容器宽度,不重新计算
|
|
298
|
-
* 列宽之和小于容器宽度,当前列的下一列/上一列,增加列宽之与大于容器宽度差值
|
|
243
|
+
* 列宽变化处理
|
|
299
244
|
*/
|
|
300
|
-
var handleColumnSizingChange = useCallback(function (
|
|
301
|
-
|
|
302
|
-
var changedColumn = data();
|
|
245
|
+
var handleColumnSizingChange = useCallback(function (updater) {
|
|
246
|
+
var changedColumn = updater();
|
|
303
247
|
if (!changedColumn) return;
|
|
304
|
-
setState(function (prevState) {
|
|
305
|
-
var
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
248
|
+
setState(produce(function (prevState) {
|
|
249
|
+
var _ref2 = Object.entries(changedColumn)[0],
|
|
250
|
+
_ref3 = _slicedToArray(_ref2, 2),
|
|
251
|
+
changedKey = _ref3[0],
|
|
252
|
+
newWidth = _ref3[1];
|
|
253
|
+
if (!changedKey) return;
|
|
254
|
+
var oldWidth = prevState.columnSizing[changedKey] || 0;
|
|
255
|
+
var widthDiff = newWidth - oldWidth;
|
|
310
256
|
|
|
311
|
-
//
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
// 计算当前总宽度
|
|
315
|
-
var totalWidth = Object.values(newVisibleColumnsSizing).reduce(function (sum, width) {
|
|
316
|
-
return Number(sum || 0) + Number(width || 0);
|
|
317
|
-
}, 0);
|
|
318
|
-
var containerWidth = getTableWidth() - 10 || 0;
|
|
319
|
-
|
|
320
|
-
// 处理列宽变大
|
|
321
|
-
if (widthDiff > 0) {
|
|
322
|
-
// 只更新变大的列的宽度
|
|
323
|
-
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
324
|
-
allColumnSizing: _objectSpread(_objectSpread({}, prevState.allColumnSizing || {}), newVisibleColumnsSizing),
|
|
325
|
-
columnSizing: newVisibleColumnsSizing
|
|
326
|
-
});
|
|
327
|
-
}
|
|
257
|
+
// 更新列宽
|
|
258
|
+
prevState.columnSizing[changedKey] = newWidth;
|
|
259
|
+
prevState.allColumnSizing[changedKey] = newWidth;
|
|
328
260
|
|
|
329
|
-
//
|
|
261
|
+
// 只处理列宽缩小的情况
|
|
330
262
|
if (widthDiff < 0) {
|
|
331
|
-
|
|
263
|
+
var totalWidth = Object.values(prevState.columnSizing).reduce(function (sum, width) {
|
|
264
|
+
return sum + width;
|
|
265
|
+
}, 0);
|
|
266
|
+
var containerWidth = getTableWidth() - DEFAULT_TABLE_PADDING || 0;
|
|
332
267
|
if (totalWidth < containerWidth) {
|
|
333
|
-
var widthDifference = containerWidth - totalWidth; // 计算差值
|
|
334
|
-
|
|
335
|
-
// 找到当前列的索引
|
|
336
268
|
var columns = Object.keys(prevState.columnSizing);
|
|
337
|
-
var currentIndex = columns.indexOf(
|
|
338
|
-
var
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
} else {
|
|
344
|
-
targetColumnKey = columns[currentIndex + 1]; // 下一列
|
|
345
|
-
}
|
|
346
|
-
// 增加目标列的宽度
|
|
347
|
-
if (targetColumnKey) {
|
|
348
|
-
newVisibleColumnsSizing[targetColumnKey] = (newVisibleColumnsSizing[targetColumnKey] || 0) + widthDifference;
|
|
269
|
+
var currentIndex = columns.indexOf(changedKey);
|
|
270
|
+
var targetKey = currentIndex < columns.length - 1 ? columns[currentIndex + 1] : columns[currentIndex - 1];
|
|
271
|
+
if (targetKey) {
|
|
272
|
+
var widthDifference = containerWidth - totalWidth;
|
|
273
|
+
prevState.columnSizing[targetKey] += widthDifference;
|
|
274
|
+
prevState.allColumnSizing[targetKey] += widthDifference;
|
|
349
275
|
}
|
|
350
276
|
}
|
|
277
|
+
}
|
|
278
|
+
}));
|
|
279
|
+
}, [getTableWidth]);
|
|
351
280
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
281
|
+
// 监听容器大小变化
|
|
282
|
+
useEffect(function () {
|
|
283
|
+
if (!tableContentRef.current) return;
|
|
284
|
+
var observer = new ResizeObserver(function (entries) {
|
|
285
|
+
var _entries$;
|
|
286
|
+
var newWidth = (_entries$ = entries[0]) === null || _entries$ === void 0 ? void 0 : _entries$.contentRect.width;
|
|
287
|
+
if (newWidth) {
|
|
288
|
+
debouncedHandleResizeRef.current(newWidth);
|
|
357
289
|
}
|
|
358
|
-
return prevState; // 如果没有变化,返回原状态
|
|
359
290
|
});
|
|
360
|
-
|
|
291
|
+
observer.observe(tableContentRef.current);
|
|
292
|
+
return function () {
|
|
293
|
+
return observer.disconnect();
|
|
294
|
+
};
|
|
295
|
+
}, [tableContentRef]);
|
|
361
296
|
return {
|
|
362
297
|
columnSizing: state.columnSizing,
|
|
363
298
|
allColumnCount: state.allColumnCount,
|
|
@@ -312,7 +312,9 @@ export type TableMaxProps = {
|
|
|
312
312
|
request?: (...params: any[]) => Promise<Blob>;
|
|
313
313
|
/**编辑时修改组件值时触发的事件 */
|
|
314
314
|
onEditValueChange?: (field: string, value: any, extra?: any) => void;
|
|
315
|
+
/**是否有总计行 */
|
|
315
316
|
hasTotalRow?: boolean;
|
|
317
|
+
/**总计行数据 { '列id': '数据' }*/
|
|
316
318
|
totalDatas?: any[];
|
|
317
319
|
};
|
|
318
320
|
export interface TableMaxColumnType {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arim-aisdc/public-components",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.18",
|
|
4
4
|
"description": "前端组件库",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"immer": "^10.0.3",
|
|
60
60
|
"jsep": "^1.3.8",
|
|
61
61
|
"lodash": "^4.17.21",
|
|
62
|
+
"lodash-es": "^4.17.21",
|
|
62
63
|
"lottie-web": "^5.12.2",
|
|
63
64
|
"path": "^0.12.7",
|
|
64
65
|
"react-activation": "^0.12.4",
|
|
@@ -66,6 +67,8 @@
|
|
|
66
67
|
"react-dnd": "^16.0.1",
|
|
67
68
|
"react-dnd-html5-backend": "^16.0.1",
|
|
68
69
|
"react-draggable": "^4.4.6",
|
|
70
|
+
"react-resizable": "^3.0.5",
|
|
71
|
+
"react-rnd": "^10.5.2",
|
|
69
72
|
"react-router-dom": "^6.22.3",
|
|
70
73
|
"react-split-pane": "^0.1.92"
|
|
71
74
|
},
|