zmdms-webui 2.5.3 → 2.5.4
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,8 +110,14 @@ 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];
|
|
113
115
|
// 自动高度计算(需要在容器尺寸计算之前)
|
|
114
|
-
var autoHeight = useCanvasTableAutoHeight(isAutoScrollY, autoScrollYMarginBottom, canvasTableId
|
|
116
|
+
var autoHeight = useCanvasTableAutoHeight(isAutoScrollY, autoScrollYMarginBottom, canvasTableId, finalDataSource.length, // 数据行数(用于 content 模式)
|
|
117
|
+
headerHeight, // 表头基础高度(用于 content 模式的初始计算)
|
|
118
|
+
rowHeight, // 行高(用于 content 模式)
|
|
119
|
+
preciseHeaderHeight // 计算后的表头高度(用于 content 模式的精确计算)
|
|
120
|
+
);
|
|
115
121
|
// 监听容器尺寸变化(提前计算,用于列宽自适应)
|
|
116
122
|
var containerSize = useContainerSize({
|
|
117
123
|
containerRef: containerRef,
|
|
@@ -151,6 +157,13 @@ function CanvasTable(props) {
|
|
|
151
157
|
headerHeight: headerHeight,
|
|
152
158
|
columnRenderInfos: columnRenderInfos,
|
|
153
159
|
});
|
|
160
|
+
// 在 content 模式下,当计算后的表头高度变化时,更新精确高度以触发自动高度重新计算
|
|
161
|
+
useEffect(function () {
|
|
162
|
+
if (isAutoScrollY === "content" &&
|
|
163
|
+
calculatedHeaderHeight !== preciseHeaderHeight) {
|
|
164
|
+
setPreciseHeaderHeight(calculatedHeaderHeight);
|
|
165
|
+
}
|
|
166
|
+
}, [isAutoScrollY, calculatedHeaderHeight, preciseHeaderHeight]);
|
|
154
167
|
// 计算合并单元格信息
|
|
155
168
|
var mergeCellMap = useMergeCells({
|
|
156
169
|
dataSource: finalDataSource,
|
|
@@ -164,7 +177,7 @@ function CanvasTable(props) {
|
|
|
164
177
|
return calculateTotalHeight(calculatedHeaderHeight, finalDataSource.length, rowHeight);
|
|
165
178
|
}, [calculatedHeaderHeight, finalDataSource.length, rowHeight]);
|
|
166
179
|
// 计算滚动条指标
|
|
167
|
-
var
|
|
180
|
+
var _1 = useScrollbarMetrics({
|
|
168
181
|
containerWidth: containerWidth,
|
|
169
182
|
containerHeight: containerHeight,
|
|
170
183
|
totalWidth: totalWidth,
|
|
@@ -172,14 +185,14 @@ function CanvasTable(props) {
|
|
|
172
185
|
headerHeight: calculatedHeaderHeight,
|
|
173
186
|
scrollTop: 0,
|
|
174
187
|
scrollLeft: 0,
|
|
175
|
-
}), maxScrollTop =
|
|
188
|
+
}), maxScrollTop = _1.maxScrollTop, maxScrollLeft = _1.maxScrollLeft;
|
|
176
189
|
// 滚动管理(使用预先计算的maxScrollTop和maxScrollLeft)
|
|
177
|
-
var
|
|
190
|
+
var _2 = useTableScroll({
|
|
178
191
|
containerRef: containerRef,
|
|
179
192
|
maxScrollTop: maxScrollTop,
|
|
180
193
|
maxScrollLeft: maxScrollLeft,
|
|
181
194
|
onScroll: onScroll,
|
|
182
|
-
}), scrollState =
|
|
195
|
+
}), scrollState = _2.scrollState, setScrollState = _2.setScrollState;
|
|
183
196
|
// 使用 ref 保存最新的滚动位置,确保在组件卸载过程中仍能访问
|
|
184
197
|
var scrollPositionRef = useRef({ x: 0, y: 0 });
|
|
185
198
|
useEffect(function () {
|
|
@@ -208,12 +221,12 @@ function CanvasTable(props) {
|
|
|
208
221
|
scrollLeft: scrollState.scrollLeft,
|
|
209
222
|
}).actualMetrics;
|
|
210
223
|
// 单元格框选
|
|
211
|
-
var
|
|
224
|
+
var _3 = useTableSelection({
|
|
212
225
|
state: state,
|
|
213
226
|
setState: setState,
|
|
214
227
|
}),
|
|
215
228
|
// selectionStartRef,
|
|
216
|
-
startSelection =
|
|
229
|
+
startSelection = _3.startSelection, updateSelection = _3.updateSelection, extendSelection = _3.extendSelection;
|
|
217
230
|
// 处理列宽调整
|
|
218
231
|
var handleColumnResize = useCallback(function (columnKey, newWidth) {
|
|
219
232
|
var _a;
|
|
@@ -268,20 +281,20 @@ function CanvasTable(props) {
|
|
|
268
281
|
onCurrentListChange,
|
|
269
282
|
]);
|
|
270
283
|
// 列宽调整
|
|
271
|
-
var
|
|
284
|
+
var _4 = useColumnResize({
|
|
272
285
|
columnRenderInfos: columnRenderInfos,
|
|
273
286
|
containerWidth: containerWidth,
|
|
274
287
|
headerHeight: calculatedHeaderHeight,
|
|
275
288
|
scrollLeft: scrollState.scrollLeft,
|
|
276
289
|
onColumnResize: handleColumnResize,
|
|
277
|
-
}), resizeState =
|
|
290
|
+
}), resizeState = _4.resizeState, checkResizeHandle = _4.checkResizeHandle, startResize = _4.startResize, updateResize = _4.updateResize, endResize = _4.endResize, setHoverResizeColumn = _4.setHoverResizeColumn, getColumnWidth = _4.getColumnWidth, RESIZE_HANDLE_WIDTH = _4.RESIZE_HANDLE_WIDTH;
|
|
278
291
|
// 复制到剪贴板
|
|
279
|
-
var
|
|
292
|
+
var _5 = useCopyToClipboard({
|
|
280
293
|
cellSelection: state.cellSelection,
|
|
281
294
|
processedDataSource: finalDataSource,
|
|
282
295
|
columns: processedColumns,
|
|
283
296
|
containerRef: containerRef,
|
|
284
|
-
}), getSelectedCellsText =
|
|
297
|
+
}), getSelectedCellsText = _5.getSelectedCellsText, copyToClipboard = _5.copyToClipboard;
|
|
285
298
|
// 处理右键菜单的复制操作
|
|
286
299
|
var handleCopy = useCallback(function () {
|
|
287
300
|
var text = getSelectedCellsText();
|
|
@@ -300,7 +313,7 @@ function CanvasTable(props) {
|
|
|
300
313
|
summaryConfig: (exportExcelConfig === null || exportExcelConfig === void 0 ? void 0 : exportExcelConfig.isExportNoSummary) ? undefined : [],
|
|
301
314
|
});
|
|
302
315
|
// 交互事件处理(使用baseScrollbarMetrics的maxScrollTop/maxScrollLeft以保持稳定)
|
|
303
|
-
var
|
|
316
|
+
var _6 = useTableInteraction({
|
|
304
317
|
state: state,
|
|
305
318
|
setState: setState,
|
|
306
319
|
scrollState: scrollState,
|
|
@@ -347,7 +360,7 @@ function CanvasTable(props) {
|
|
|
347
360
|
fixedRowsCount: fixedRowsCount,
|
|
348
361
|
fixedRowsConfig: fixedRowsConfig,
|
|
349
362
|
summaryFixed: summaryFixed,
|
|
350
|
-
}), handleCanvasMouseDown =
|
|
363
|
+
}), handleCanvasMouseDown = _6.handleCanvasMouseDown, handleCanvasMouseMove = _6.handleCanvasMouseMove, handleCanvasMouseUp = _6.handleCanvasMouseUp, handleCanvasMouseLeave = _6.handleCanvasMouseLeave, handleCanvasContextMenu = _6.handleCanvasContextMenu;
|
|
351
364
|
// 渲染表格
|
|
352
365
|
useTableRender(__assign(__assign({ canvasRef: canvasRef, processedDataSource: finalDataSource, columnRenderInfos: columnRenderInfos, columns: processedColumns, // 传递原始columns用于渲染多级表头
|
|
353
366
|
state: state, scrollState: scrollState, rowSelection: rowSelection, containerWidth: containerWidth, containerHeight: containerHeight, headerHeight: calculatedHeaderHeight, baseHeaderHeight: headerHeight, // 传入原始基础高度用于计算每层高度
|
|
@@ -5,17 +5,45 @@ import { useState, useEffect } from 'react';
|
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* 计算CanvasTable高度
|
|
8
|
-
* @param isAutoScrollY
|
|
9
|
-
* @param marginBottom canvas table
|
|
8
|
+
* @param isAutoScrollY 自动高度模式
|
|
9
|
+
* @param marginBottom canvas table下面留出的距离(仅在 viewport 模式下生效)
|
|
10
10
|
* @param canvasTableId 表格id
|
|
11
|
+
* @param dataLength 数据行数(用于 content 模式)
|
|
12
|
+
* @param headerHeight 表头基础高度(用于 content 模式的初始计算)
|
|
13
|
+
* @param rowHeight 行高(用于 content 模式)
|
|
14
|
+
* @param calculatedHeaderHeight 计算后的表头高度(优先使用,用于 content 模式的精确计算)
|
|
11
15
|
* @returns 计算出的表格高度
|
|
12
16
|
*/
|
|
13
|
-
function useCanvasTableAutoHeight(isAutoScrollY, marginBottom, canvasTableId) {
|
|
17
|
+
function useCanvasTableAutoHeight(isAutoScrollY, marginBottom, canvasTableId, dataLength, headerHeight, rowHeight, calculatedHeaderHeight) {
|
|
14
18
|
if (marginBottom === void 0) { marginBottom = 65; }
|
|
15
19
|
var _a = useState(undefined), tableHeight = _a[0], setTableHeight = _a[1];
|
|
16
20
|
useEffect(function () {
|
|
17
|
-
|
|
21
|
+
// 归一化模式:true 转换为 'viewport'
|
|
22
|
+
var mode = isAutoScrollY === true ? "viewport" : isAutoScrollY;
|
|
23
|
+
if (!mode)
|
|
18
24
|
return;
|
|
25
|
+
// 内容模式:根据数据行数计算高度
|
|
26
|
+
if (mode === "content") {
|
|
27
|
+
if (dataLength !== undefined &&
|
|
28
|
+
headerHeight !== undefined &&
|
|
29
|
+
rowHeight !== undefined) {
|
|
30
|
+
// 优先使用计算后的表头高度(考虑了换行、多级表头等因素)
|
|
31
|
+
// 如果还未计算完成,使用基础高度作为初始值
|
|
32
|
+
var actualHeaderHeight = calculatedHeaderHeight || headerHeight;
|
|
33
|
+
// 计算总高度 = 表头高度 + (数据行数 * 行高)
|
|
34
|
+
var calculatedHeight = actualHeaderHeight + dataLength * rowHeight;
|
|
35
|
+
// 设置最小高度和最大高度
|
|
36
|
+
var minHeight = 200;
|
|
37
|
+
var maxHeight = 5000; // 防止数据过多时表格过高
|
|
38
|
+
// 如果没有数据,使用最小高度(包含表头和空状态提示)
|
|
39
|
+
var finalHeight = dataLength === 0
|
|
40
|
+
? minHeight
|
|
41
|
+
: Math.min(Math.max(calculatedHeight, minHeight), maxHeight);
|
|
42
|
+
setTableHeight(finalHeight);
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// 视口模式:根据页面位置计算高度
|
|
19
47
|
var calculateHeight = function () {
|
|
20
48
|
var _a, _b;
|
|
21
49
|
// 查找容器元素
|
|
@@ -60,7 +88,15 @@ function useCanvasTableAutoHeight(isAutoScrollY, marginBottom, canvasTableId) {
|
|
|
60
88
|
window.removeEventListener("resize", handleResize);
|
|
61
89
|
observer.disconnect();
|
|
62
90
|
};
|
|
63
|
-
}, [
|
|
91
|
+
}, [
|
|
92
|
+
isAutoScrollY,
|
|
93
|
+
marginBottom,
|
|
94
|
+
canvasTableId,
|
|
95
|
+
dataLength,
|
|
96
|
+
headerHeight,
|
|
97
|
+
rowHeight,
|
|
98
|
+
calculatedHeaderHeight, // 当计算后的表头高度变化时,重新计算总高度
|
|
99
|
+
]);
|
|
64
100
|
return tableHeight;
|
|
65
101
|
}
|
|
66
102
|
|
|
@@ -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
|
// 千分符
|