zmdms-webui 2.4.4 → 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,
@@ -421,9 +429,10 @@ function CanvasTable(props) {
421
429
  },
422
430
  /** 获取滚动条位置信息 */
423
431
  getScrollPosition: function () {
432
+ // 返回 ref 中的值,确保在组件卸载过程中仍能获取到最后的滚动位置
424
433
  return {
425
- x: scrollState.scrollLeft,
426
- y: scrollState.scrollTop,
434
+ x: scrollPositionRef.current.x,
435
+ y: scrollPositionRef.current.y,
427
436
  };
428
437
  },
429
438
  /** 获取当前排序状态 */
@@ -455,8 +464,6 @@ function CanvasTable(props) {
455
464
  state.filters,
456
465
  setState,
457
466
  setScrollState,
458
- scrollState.scrollLeft,
459
- scrollState.scrollTop,
460
467
  ]);
461
468
  return (jsx(Spin, __assign({ spinning: loading }, { children: jsxs("div", __assign({ ref: containerRef, id: canvasTableId, className: "canvas-table-container ".concat(className || ""), tabIndex: 0, style: __assign(__assign({}, style), { position: "relative", width: width || "100%", height: containerHeight, overflow: "hidden", touchAction: "none", outline: "none" }) }, { children: [jsx("canvas", { ref: canvasRef, onMouseDown: handleCanvasMouseDown, onMouseMove: handleCanvasMouseMove, onMouseUp: handleCanvasMouseUp, onMouseLeave: handleCanvasMouseLeave, onContextMenu: handleCanvasContextMenu, style: {
462
469
  display: "block",
@@ -409,7 +409,7 @@ interface ICanvasTableProps<RecordType = any> {
409
409
  /**
410
410
  * 表格ref句柄,用于暴露表格的一些方法
411
411
  */
412
- tableRefHandle?: React__default.Ref<ICanvasTableRefHandle | undefined>;
412
+ tableRefHandle?: React__default.MutableRefObject<ICanvasTableRefHandle | undefined>;
413
413
  /**
414
414
  * 导出excel的一些配置
415
415
  */
@@ -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;
@@ -235,14 +237,17 @@ var Table = function (props) {
235
237
  var _a;
236
238
  var tableBody = (_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".ant-table-body");
237
239
  if (tableBody) {
238
- return {
240
+ // 更新 ref 缓存
241
+ scrollPositionRef.current = {
239
242
  x: tableBody.scrollLeft,
240
243
  y: tableBody.scrollTop,
241
244
  };
245
+ return scrollPositionRef.current;
242
246
  }
247
+ // 如果 DOM 已销毁,返回最后缓存的位置
243
248
  return {
244
- x: 0,
245
- y: 0,
249
+ x: scrollPositionRef.current.x,
250
+ y: scrollPositionRef.current.y,
246
251
  };
247
252
  });
248
253
  // 虚拟滚动选项
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-webui",
3
- "version": "2.4.4",
3
+ "version": "2.4.5",
4
4
  "private": false,
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",