zmdms-webui 2.4.3 → 2.4.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.
@@ -1,6 +1,6 @@
1
1
  import { __assign } from '../_virtual/_tslib.js';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { useRef, useState, useCallback, useMemo, useImperativeHandle } from 'react';
3
+ import { useRef, useState, useCallback, useMemo, useEffect, useImperativeHandle } from 'react';
4
4
  import { Spin } from 'antd';
5
5
  import './components/FilterPopover.js';
6
6
  import CellOverlay from './components/CellOverlay.js';
@@ -161,6 +161,14 @@ function CanvasTable(props) {
161
161
  maxScrollLeft: maxScrollLeft,
162
162
  onScroll: onScroll,
163
163
  }), scrollState = _1.scrollState, setScrollState = _1.setScrollState;
164
+ // 使用 ref 保存最新的滚动位置,确保在组件卸载过程中仍能访问
165
+ var scrollPositionRef = useRef({ x: 0, y: 0 });
166
+ useEffect(function () {
167
+ scrollPositionRef.current = {
168
+ x: scrollState.scrollLeft,
169
+ y: scrollState.scrollTop,
170
+ };
171
+ }, [scrollState.scrollLeft, scrollState.scrollTop]);
164
172
  // 数据变化时重置滚动位置(筛选、排序、数据源更新等操作后)
165
173
  useScrollReset({
166
174
  dataSourceLength: dataSource.length,
@@ -249,21 +257,19 @@ function CanvasTable(props) {
249
257
  onColumnResize: handleColumnResize,
250
258
  }), resizeState = _3.resizeState, checkResizeHandle = _3.checkResizeHandle, startResize = _3.startResize, updateResize = _3.updateResize, endResize = _3.endResize, setHoverResizeColumn = _3.setHoverResizeColumn, getColumnWidth = _3.getColumnWidth, RESIZE_HANDLE_WIDTH = _3.RESIZE_HANDLE_WIDTH;
251
259
  // 复制到剪贴板
252
- var getSelectedCellsText = useCopyToClipboard({
260
+ var _4 = useCopyToClipboard({
253
261
  cellSelection: state.cellSelection,
254
262
  processedDataSource: finalDataSource,
255
263
  columns: processedColumns,
256
264
  containerRef: containerRef,
257
- }).getSelectedCellsText;
265
+ }), getSelectedCellsText = _4.getSelectedCellsText, copyToClipboard = _4.copyToClipboard;
258
266
  // 处理右键菜单的复制操作
259
267
  var handleCopy = useCallback(function () {
260
268
  var text = getSelectedCellsText();
261
- if (text && navigator.clipboard) {
262
- navigator.clipboard.writeText(text).catch(function (err) {
263
- console.error("Failed to copy:", err);
264
- });
269
+ if (text) {
270
+ copyToClipboard(text);
265
271
  }
266
- }, [getSelectedCellsText]);
272
+ }, [getSelectedCellsText, copyToClipboard]);
267
273
  // 过滤勾选框和index行给导出用
268
274
  var exportColumns = useMemo(function () {
269
275
  return processedColumns.filter(function (item) { return !item.key.includes("__"); });
@@ -272,10 +278,10 @@ function CanvasTable(props) {
272
278
  var exportExcel = useExcelExport(newDataSource, {
273
279
  columns: exportColumns,
274
280
  isAutoMerge: isAutoMerge,
275
- summaryConfig: [],
281
+ summaryConfig: (exportExcelConfig === null || exportExcelConfig === void 0 ? void 0 : exportExcelConfig.isExportNoSummary) ? undefined : [],
276
282
  });
277
283
  // 交互事件处理(使用baseScrollbarMetrics的maxScrollTop/maxScrollLeft以保持稳定)
278
- var _4 = useTableInteraction({
284
+ var _5 = useTableInteraction({
279
285
  state: state,
280
286
  setState: setState,
281
287
  scrollState: scrollState,
@@ -322,7 +328,7 @@ function CanvasTable(props) {
322
328
  fixedRowsCount: fixedRowsCount,
323
329
  fixedRowsConfig: fixedRowsConfig,
324
330
  summaryFixed: summaryFixed,
325
- }), handleCanvasMouseDown = _4.handleCanvasMouseDown, handleCanvasMouseMove = _4.handleCanvasMouseMove, handleCanvasMouseUp = _4.handleCanvasMouseUp, handleCanvasMouseLeave = _4.handleCanvasMouseLeave, handleCanvasContextMenu = _4.handleCanvasContextMenu;
331
+ }), handleCanvasMouseDown = _5.handleCanvasMouseDown, handleCanvasMouseMove = _5.handleCanvasMouseMove, handleCanvasMouseUp = _5.handleCanvasMouseUp, handleCanvasMouseLeave = _5.handleCanvasMouseLeave, handleCanvasContextMenu = _5.handleCanvasContextMenu;
326
332
  // 渲染表格
327
333
  useTableRender(__assign(__assign({ canvasRef: canvasRef, processedDataSource: finalDataSource, columnRenderInfos: columnRenderInfos, columns: processedColumns, // 传递原始columns用于渲染多级表头
328
334
  state: state, scrollState: scrollState, rowSelection: rowSelection, containerWidth: containerWidth, containerHeight: containerHeight, headerHeight: calculatedHeaderHeight, baseHeaderHeight: headerHeight, // 传入原始基础高度用于计算每层高度
@@ -421,6 +427,14 @@ function CanvasTable(props) {
421
427
  scrollTo: function (params) {
422
428
  setScrollState(function (prev) { return (__assign(__assign({}, prev), { scrollLeft: params.x !== undefined ? params.x : prev.scrollLeft, scrollTop: params.y !== undefined ? params.y : prev.scrollTop })); });
423
429
  },
430
+ /** 获取滚动条位置信息 */
431
+ getScrollPosition: function () {
432
+ // 返回 ref 中的值,确保在组件卸载过程中仍能获取到最后的滚动位置
433
+ return {
434
+ x: scrollPositionRef.current.x,
435
+ y: scrollPositionRef.current.y,
436
+ };
437
+ },
424
438
  /** 获取当前排序状态 */
425
439
  getSortState: function () {
426
440
  return {
@@ -173,6 +173,10 @@ interface ICanvasColumnType<RecordType = any> {
173
173
  * 是否加上千分符
174
174
  */
175
175
  thousand?: boolean;
176
+ /**
177
+ * 空值时显示的文本,默认为 "—"
178
+ */
179
+ emptyText?: string;
176
180
  /**
177
181
  * 设置单元格属性(用于合并单元格等)
178
182
  * 参考 antd table 的 onCell 用法
@@ -405,7 +409,7 @@ interface ICanvasTableProps<RecordType = any> {
405
409
  /**
406
410
  * 表格ref句柄,用于暴露表格的一些方法
407
411
  */
408
- tableRefHandle?: React__default.Ref<ICanvasTableRefHandle | undefined>;
412
+ tableRefHandle?: React__default.MutableRefObject<ICanvasTableRefHandle | undefined>;
409
413
  /**
410
414
  * 导出excel的一些配置
411
415
  */
@@ -414,6 +418,7 @@ interface ICanvasTableProps<RecordType = any> {
414
418
  time?: string;
415
419
  topDescriptionRowHeight?: number;
416
420
  fileName: string;
421
+ isExportNoSummary?: boolean;
417
422
  };
418
423
  }
419
424
  /**
@@ -463,6 +468,16 @@ interface ICanvasTableRefHandle {
463
468
  x?: number;
464
469
  y?: number;
465
470
  }) => void;
471
+ /**
472
+ * 获取滚动条位置信息
473
+ * @returns 包含 x(水平) 和 y(垂直) 滚动位置的对象
474
+ */
475
+ getScrollPosition: () => {
476
+ /** 水平滚动位置 */
477
+ x: number;
478
+ /** 垂直滚动位置 */
479
+ y: number;
480
+ };
466
481
  /**
467
482
  * 获取当前排序状态
468
483
  */
@@ -18,8 +18,10 @@ var formatDate = function (value, format) {
18
18
  * 格式化单元格值
19
19
  */
20
20
  var formatCellValue = function (value, column) {
21
- if (value === null || value === undefined)
22
- return "";
21
+ // 空值处理:nullundefined、空字符串
22
+ if (value === null || value === undefined || value === "") {
23
+ return column.emptyText !== undefined ? column.emptyText : "— —";
24
+ }
23
25
  var formattedValue = value;
24
26
  // 日期格式化
25
27
  if (column.dateFormat) {
@@ -245,6 +245,10 @@ interface IColumnType<RecordType> extends Omit<ColumnType<RecordType>, "render">
245
245
  dateFormat?: string;
246
246
  precision?: number;
247
247
  thousand?: boolean;
248
+ /**
249
+ * 空值时显示的文本,默认为 "—"
250
+ */
251
+ emptyText?: string;
248
252
  }
249
253
  interface IRenderOptions {
250
254
  insertTableFromClipboard: IFuncInsertTableFromClipboard;
@@ -305,6 +309,16 @@ interface ITableRefHandel {
305
309
  vid?: string;
306
310
  index?: number;
307
311
  }) => void;
312
+ /**
313
+ * 获取滚动条位置信息
314
+ * @returns 包含 x(水平) 和 y(垂直) 滚动位置的对象
315
+ */
316
+ getScrollPosition?: () => {
317
+ /** 水平滚动位置 */
318
+ x: number;
319
+ /** 垂直滚动位置 */
320
+ y: number;
321
+ };
308
322
  /**
309
323
  * 重置
310
324
  */
@@ -193,6 +193,8 @@ var Table = function (props) {
193
193
  });
194
194
  // 表格验证
195
195
  var _y = useTableValidate(), tableRef = _y.tableRef, getCurrentTable = _y.getCurrentTable, clearErrorClass = _y.clearErrorClass;
196
+ // 使用 ref 缓存最新的滚动位置,确保在组件卸载过程中仍能访问
197
+ var scrollPositionRef = useRef({ x: 0, y: 0 });
196
198
  // 滚动条控制方法
197
199
  var scrollToPosition = useMemoizedFn(function (options) {
198
200
  var _a;
@@ -230,6 +232,24 @@ var Table = function (props) {
230
232
  }
231
233
  }
232
234
  });
235
+ // 获取滚动条位置
236
+ var getScrollPosition = useMemoizedFn(function () {
237
+ var _a;
238
+ var tableBody = (_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".ant-table-body");
239
+ if (tableBody) {
240
+ // 更新 ref 缓存
241
+ scrollPositionRef.current = {
242
+ x: tableBody.scrollLeft,
243
+ y: tableBody.scrollTop,
244
+ };
245
+ return scrollPositionRef.current;
246
+ }
247
+ // 如果 DOM 已销毁,返回最后缓存的位置
248
+ return {
249
+ x: scrollPositionRef.current.x,
250
+ y: scrollPositionRef.current.y,
251
+ };
252
+ });
233
253
  // 虚拟滚动选项
234
254
  var vComponents = useMemo(function () {
235
255
  if (virtualKey) {
@@ -352,6 +372,13 @@ var Table = function (props) {
352
372
  scrollTo: function (options) {
353
373
  scrollToPosition(options);
354
374
  },
375
+ /**
376
+ * 获取滚动条位置信息
377
+ * @returns 包含滚动位置和容器尺寸的对象
378
+ */
379
+ getScrollPosition: function () {
380
+ return getScrollPosition();
381
+ },
355
382
  /** 动态列配置重置 */
356
383
  onResetDynamicList: function () {
357
384
  var _a, _b;
@@ -324,8 +324,10 @@ function useColumns(columns, options) {
324
324
  if (typeof text === "object") {
325
325
  return PLACEHOLDER_NULL;
326
326
  }
327
- if (text == null || text === "")
328
- return PLACEHOLDER_NULL;
327
+ // 空值处理:null、undefined、空字符串
328
+ if (text == null || text === "") {
329
+ return _column.emptyText !== undefined ? _column.emptyText : "—";
330
+ }
329
331
  if (_column.dateFormat)
330
332
  return dayjs(text).format(_column.dateFormat);
331
333
  if (_column.precision)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-webui",
3
- "version": "2.4.3",
3
+ "version": "2.4.5",
4
4
  "private": false,
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",