zmdms-webui 2.5.3 → 2.5.5
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.
|
@@ -110,14 +110,24 @@ function CanvasTable(props) {
|
|
|
110
110
|
columns: processedColumns,
|
|
111
111
|
dataSource: newDataSource,
|
|
112
112
|
}), finalDataSource = _z.finalDataSource, hasSummaryRow = _z.hasSummaryRow;
|
|
113
|
+
// 用于存储计算后的表头高度(用于自动高度的精确计算)
|
|
114
|
+
var _0 = useState(undefined), preciseHeaderHeight = _0[0], setPreciseHeaderHeight = _0[1];
|
|
115
|
+
// 用于存储是否需要横向滚动条(用于自动高度的精确计算)
|
|
116
|
+
var _1 = useState(false), needHorizontalScrollbar = _1[0], setNeedHorizontalScrollbar = _1[1];
|
|
113
117
|
// 自动高度计算(需要在容器尺寸计算之前)
|
|
114
|
-
var autoHeight = useCanvasTableAutoHeight(isAutoScrollY, autoScrollYMarginBottom, canvasTableId
|
|
118
|
+
var autoHeight = useCanvasTableAutoHeight(isAutoScrollY, autoScrollYMarginBottom, canvasTableId, finalDataSource.length, // 数据行数(用于 content 模式)
|
|
119
|
+
headerHeight, // 表头基础高度(用于 content 模式的初始计算)
|
|
120
|
+
rowHeight, // 行高(用于 content 模式)
|
|
121
|
+
preciseHeaderHeight, // 计算后的表头高度(用于 content 模式的精确计算)
|
|
122
|
+
needHorizontalScrollbar // 是否需要横向滚动条(用于计算额外高度)
|
|
123
|
+
);
|
|
115
124
|
// 监听容器尺寸变化(提前计算,用于列宽自适应)
|
|
116
125
|
var containerSize = useContainerSize({
|
|
117
126
|
containerRef: containerRef,
|
|
118
127
|
width: width,
|
|
119
128
|
height: isAutoScrollY ? autoHeight || height : height,
|
|
120
129
|
});
|
|
130
|
+
console.log("containerSize", containerSize);
|
|
121
131
|
var containerWidth = containerSize.width;
|
|
122
132
|
var containerHeight = containerSize.height;
|
|
123
133
|
// 计算列的渲染信息(使用容器宽度进行自适应填充)
|
|
@@ -151,6 +161,13 @@ function CanvasTable(props) {
|
|
|
151
161
|
headerHeight: headerHeight,
|
|
152
162
|
columnRenderInfos: columnRenderInfos,
|
|
153
163
|
});
|
|
164
|
+
// 在 content 模式下,当计算后的表头高度变化时,更新精确高度以触发自动高度重新计算
|
|
165
|
+
useEffect(function () {
|
|
166
|
+
if (isAutoScrollY === "content" &&
|
|
167
|
+
calculatedHeaderHeight !== preciseHeaderHeight) {
|
|
168
|
+
setPreciseHeaderHeight(calculatedHeaderHeight);
|
|
169
|
+
}
|
|
170
|
+
}, [isAutoScrollY, calculatedHeaderHeight, preciseHeaderHeight]);
|
|
154
171
|
// 计算合并单元格信息
|
|
155
172
|
var mergeCellMap = useMergeCells({
|
|
156
173
|
dataSource: finalDataSource,
|
|
@@ -164,7 +181,7 @@ function CanvasTable(props) {
|
|
|
164
181
|
return calculateTotalHeight(calculatedHeaderHeight, finalDataSource.length, rowHeight);
|
|
165
182
|
}, [calculatedHeaderHeight, finalDataSource.length, rowHeight]);
|
|
166
183
|
// 计算滚动条指标
|
|
167
|
-
var
|
|
184
|
+
var _2 = useScrollbarMetrics({
|
|
168
185
|
containerWidth: containerWidth,
|
|
169
186
|
containerHeight: containerHeight,
|
|
170
187
|
totalWidth: totalWidth,
|
|
@@ -172,14 +189,14 @@ function CanvasTable(props) {
|
|
|
172
189
|
headerHeight: calculatedHeaderHeight,
|
|
173
190
|
scrollTop: 0,
|
|
174
191
|
scrollLeft: 0,
|
|
175
|
-
}), maxScrollTop =
|
|
192
|
+
}), maxScrollTop = _2.maxScrollTop, maxScrollLeft = _2.maxScrollLeft;
|
|
176
193
|
// 滚动管理(使用预先计算的maxScrollTop和maxScrollLeft)
|
|
177
|
-
var
|
|
194
|
+
var _3 = useTableScroll({
|
|
178
195
|
containerRef: containerRef,
|
|
179
196
|
maxScrollTop: maxScrollTop,
|
|
180
197
|
maxScrollLeft: maxScrollLeft,
|
|
181
198
|
onScroll: onScroll,
|
|
182
|
-
}), scrollState =
|
|
199
|
+
}), scrollState = _3.scrollState, setScrollState = _3.setScrollState;
|
|
183
200
|
// 使用 ref 保存最新的滚动位置,确保在组件卸载过程中仍能访问
|
|
184
201
|
var scrollPositionRef = useRef({ x: 0, y: 0 });
|
|
185
202
|
useEffect(function () {
|
|
@@ -207,13 +224,24 @@ function CanvasTable(props) {
|
|
|
207
224
|
scrollTop: scrollState.scrollTop,
|
|
208
225
|
scrollLeft: scrollState.scrollLeft,
|
|
209
226
|
}).actualMetrics;
|
|
227
|
+
// 在 content 模式下,当横向滚动条状态变化时,更新状态以触发自动高度重新计算
|
|
228
|
+
useEffect(function () {
|
|
229
|
+
if (isAutoScrollY === "content" &&
|
|
230
|
+
scrollbarMetrics.needHorizontalScrollbar !== needHorizontalScrollbar) {
|
|
231
|
+
setNeedHorizontalScrollbar(scrollbarMetrics.needHorizontalScrollbar);
|
|
232
|
+
}
|
|
233
|
+
}, [
|
|
234
|
+
isAutoScrollY,
|
|
235
|
+
scrollbarMetrics.needHorizontalScrollbar,
|
|
236
|
+
needHorizontalScrollbar,
|
|
237
|
+
]);
|
|
210
238
|
// 单元格框选
|
|
211
|
-
var
|
|
239
|
+
var _4 = useTableSelection({
|
|
212
240
|
state: state,
|
|
213
241
|
setState: setState,
|
|
214
242
|
}),
|
|
215
243
|
// selectionStartRef,
|
|
216
|
-
startSelection =
|
|
244
|
+
startSelection = _4.startSelection, updateSelection = _4.updateSelection, extendSelection = _4.extendSelection;
|
|
217
245
|
// 处理列宽调整
|
|
218
246
|
var handleColumnResize = useCallback(function (columnKey, newWidth) {
|
|
219
247
|
var _a;
|
|
@@ -268,20 +296,20 @@ function CanvasTable(props) {
|
|
|
268
296
|
onCurrentListChange,
|
|
269
297
|
]);
|
|
270
298
|
// 列宽调整
|
|
271
|
-
var
|
|
299
|
+
var _5 = useColumnResize({
|
|
272
300
|
columnRenderInfos: columnRenderInfos,
|
|
273
301
|
containerWidth: containerWidth,
|
|
274
302
|
headerHeight: calculatedHeaderHeight,
|
|
275
303
|
scrollLeft: scrollState.scrollLeft,
|
|
276
304
|
onColumnResize: handleColumnResize,
|
|
277
|
-
}), resizeState =
|
|
305
|
+
}), resizeState = _5.resizeState, checkResizeHandle = _5.checkResizeHandle, startResize = _5.startResize, updateResize = _5.updateResize, endResize = _5.endResize, setHoverResizeColumn = _5.setHoverResizeColumn, getColumnWidth = _5.getColumnWidth, RESIZE_HANDLE_WIDTH = _5.RESIZE_HANDLE_WIDTH;
|
|
278
306
|
// 复制到剪贴板
|
|
279
|
-
var
|
|
307
|
+
var _6 = useCopyToClipboard({
|
|
280
308
|
cellSelection: state.cellSelection,
|
|
281
309
|
processedDataSource: finalDataSource,
|
|
282
310
|
columns: processedColumns,
|
|
283
311
|
containerRef: containerRef,
|
|
284
|
-
}), getSelectedCellsText =
|
|
312
|
+
}), getSelectedCellsText = _6.getSelectedCellsText, copyToClipboard = _6.copyToClipboard;
|
|
285
313
|
// 处理右键菜单的复制操作
|
|
286
314
|
var handleCopy = useCallback(function () {
|
|
287
315
|
var text = getSelectedCellsText();
|
|
@@ -300,7 +328,7 @@ function CanvasTable(props) {
|
|
|
300
328
|
summaryConfig: (exportExcelConfig === null || exportExcelConfig === void 0 ? void 0 : exportExcelConfig.isExportNoSummary) ? undefined : [],
|
|
301
329
|
});
|
|
302
330
|
// 交互事件处理(使用baseScrollbarMetrics的maxScrollTop/maxScrollLeft以保持稳定)
|
|
303
|
-
var
|
|
331
|
+
var _7 = useTableInteraction({
|
|
304
332
|
state: state,
|
|
305
333
|
setState: setState,
|
|
306
334
|
scrollState: scrollState,
|
|
@@ -347,7 +375,7 @@ function CanvasTable(props) {
|
|
|
347
375
|
fixedRowsCount: fixedRowsCount,
|
|
348
376
|
fixedRowsConfig: fixedRowsConfig,
|
|
349
377
|
summaryFixed: summaryFixed,
|
|
350
|
-
}), handleCanvasMouseDown =
|
|
378
|
+
}), handleCanvasMouseDown = _7.handleCanvasMouseDown, handleCanvasMouseMove = _7.handleCanvasMouseMove, handleCanvasMouseUp = _7.handleCanvasMouseUp, handleCanvasMouseLeave = _7.handleCanvasMouseLeave, handleCanvasContextMenu = _7.handleCanvasContextMenu;
|
|
351
379
|
// 渲染表格
|
|
352
380
|
useTableRender(__assign(__assign({ canvasRef: canvasRef, processedDataSource: finalDataSource, columnRenderInfos: columnRenderInfos, columns: processedColumns, // 传递原始columns用于渲染多级表头
|
|
353
381
|
state: state, scrollState: scrollState, rowSelection: rowSelection, containerWidth: containerWidth, containerHeight: containerHeight, headerHeight: calculatedHeaderHeight, baseHeaderHeight: headerHeight, // 传入原始基础高度用于计算每层高度
|
|
@@ -3,19 +3,50 @@ import { useState, useEffect } from 'react';
|
|
|
3
3
|
/**
|
|
4
4
|
* CanvasTable 自动高度计算 Hook
|
|
5
5
|
*/
|
|
6
|
+
// 滚动条宽度常量
|
|
7
|
+
var SCROLLBAR_SIZE = 12;
|
|
6
8
|
/**
|
|
7
9
|
* 计算CanvasTable高度
|
|
8
|
-
* @param isAutoScrollY
|
|
9
|
-
* @param marginBottom canvas table
|
|
10
|
+
* @param isAutoScrollY 自动高度模式
|
|
11
|
+
* @param marginBottom canvas table下面留出的距离(仅在 viewport 模式下生效)
|
|
10
12
|
* @param canvasTableId 表格id
|
|
13
|
+
* @param dataLength 数据行数(用于 content 模式)
|
|
14
|
+
* @param headerHeight 表头基础高度(用于 content 模式的初始计算)
|
|
15
|
+
* @param rowHeight 行高(用于 content 模式)
|
|
16
|
+
* @param calculatedHeaderHeight 计算后的表头高度(优先使用,用于 content 模式的精确计算)
|
|
17
|
+
* @param needHorizontalScrollbar 是否需要横向滚动条(用于计算额外高度)
|
|
11
18
|
* @returns 计算出的表格高度
|
|
12
19
|
*/
|
|
13
|
-
function useCanvasTableAutoHeight(isAutoScrollY, marginBottom, canvasTableId) {
|
|
20
|
+
function useCanvasTableAutoHeight(isAutoScrollY, marginBottom, canvasTableId, dataLength, headerHeight, rowHeight, calculatedHeaderHeight, needHorizontalScrollbar) {
|
|
14
21
|
if (marginBottom === void 0) { marginBottom = 65; }
|
|
22
|
+
if (needHorizontalScrollbar === void 0) { needHorizontalScrollbar = false; }
|
|
15
23
|
var _a = useState(undefined), tableHeight = _a[0], setTableHeight = _a[1];
|
|
16
24
|
useEffect(function () {
|
|
17
|
-
|
|
25
|
+
// 归一化模式:true 转换为 'viewport'
|
|
26
|
+
var mode = isAutoScrollY === true ? "viewport" : isAutoScrollY;
|
|
27
|
+
if (!mode)
|
|
18
28
|
return;
|
|
29
|
+
// 内容模式:根据数据行数计算高度
|
|
30
|
+
if (mode === "content") {
|
|
31
|
+
if (dataLength !== undefined &&
|
|
32
|
+
headerHeight !== undefined &&
|
|
33
|
+
rowHeight !== undefined) {
|
|
34
|
+
// 优先使用计算后的表头高度(考虑了换行、多级表头等因素)
|
|
35
|
+
// 如果还未计算完成,使用基础高度作为初始值
|
|
36
|
+
var actualHeaderHeight = calculatedHeaderHeight || headerHeight;
|
|
37
|
+
// 计算总高度 = 表头高度 + (数据行数 * 行高) + (横向滚动条高度)
|
|
38
|
+
var calculatedHeight = actualHeaderHeight +
|
|
39
|
+
dataLength * rowHeight +
|
|
40
|
+
(needHorizontalScrollbar ? SCROLLBAR_SIZE : 0);
|
|
41
|
+
// 设置最小高度和最大高度
|
|
42
|
+
var minHeight = 200;
|
|
43
|
+
// 如果没有数据,使用最小高度(包含表头和空状态提示)
|
|
44
|
+
var finalHeight = dataLength === 0 ? minHeight : Math.max(calculatedHeight, minHeight);
|
|
45
|
+
setTableHeight(finalHeight);
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// 视口模式:根据页面位置计算高度
|
|
19
50
|
var calculateHeight = function () {
|
|
20
51
|
var _a, _b;
|
|
21
52
|
// 查找容器元素
|
|
@@ -60,7 +91,16 @@ function useCanvasTableAutoHeight(isAutoScrollY, marginBottom, canvasTableId) {
|
|
|
60
91
|
window.removeEventListener("resize", handleResize);
|
|
61
92
|
observer.disconnect();
|
|
62
93
|
};
|
|
63
|
-
}, [
|
|
94
|
+
}, [
|
|
95
|
+
isAutoScrollY,
|
|
96
|
+
marginBottom,
|
|
97
|
+
canvasTableId,
|
|
98
|
+
dataLength,
|
|
99
|
+
headerHeight,
|
|
100
|
+
rowHeight,
|
|
101
|
+
calculatedHeaderHeight,
|
|
102
|
+
needHorizontalScrollbar, // 当横向滚动条状态变化时,重新计算总高度
|
|
103
|
+
]);
|
|
64
104
|
return tableHeight;
|
|
65
105
|
}
|
|
66
106
|
|
|
@@ -105,6 +105,10 @@ interface ICanvasColumnType<RecordType = any> {
|
|
|
105
105
|
* 获取复制的值(用于自定义复制内容)
|
|
106
106
|
*/
|
|
107
107
|
getCopyValue?: (text: any, record: RecordType, index: number) => string;
|
|
108
|
+
/**
|
|
109
|
+
* 是否默认不勾选
|
|
110
|
+
*/
|
|
111
|
+
defaultUnChecked?: boolean;
|
|
108
112
|
/**
|
|
109
113
|
* 是否开启维度自定义
|
|
110
114
|
*/
|
|
@@ -395,11 +399,15 @@ interface ICanvasTableProps<RecordType = any> {
|
|
|
395
399
|
*/
|
|
396
400
|
summaryFixed?: boolean;
|
|
397
401
|
/**
|
|
398
|
-
*
|
|
402
|
+
* 自动计算Y轴高度模式
|
|
403
|
+
* - false: 不自动调整(默认)
|
|
404
|
+
* - true | 'viewport': 根据视口自动调整高度(距离页面底部的距离)
|
|
405
|
+
* - 'content': 根据内容自动撑开高度(表头 + 所有数据行)
|
|
399
406
|
*/
|
|
400
|
-
isAutoScrollY?: boolean;
|
|
407
|
+
isAutoScrollY?: boolean | "viewport" | "content";
|
|
401
408
|
/**
|
|
402
409
|
* 自动计算Y轴高度时,canvas table下面留出的距离
|
|
410
|
+
* 仅在 isAutoScrollY 为 true 或 'viewport' 时生效
|
|
403
411
|
*/
|
|
404
412
|
autoScrollYMarginBottom?: number;
|
|
405
413
|
/**
|
|
@@ -30,7 +30,7 @@ var formatCellValue = function (value, column, noEmptyText) {
|
|
|
30
30
|
formattedValue = formatDate(formattedValue, column.dateFormat);
|
|
31
31
|
}
|
|
32
32
|
// 数值精度
|
|
33
|
-
if (column.precision !== undefined) {
|
|
33
|
+
if (column.precision !== undefined && !isNaN(Number(formattedValue))) {
|
|
34
34
|
formattedValue = exactRound(formattedValue, column.precision);
|
|
35
35
|
}
|
|
36
36
|
// 千分符
|