@nokecy/qc-ui 1.1.0 → 1.1.1
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.
|
@@ -376,6 +376,53 @@ function AgGridPlus(props) {
|
|
|
376
376
|
};
|
|
377
377
|
}, [gridKey, currentColumnScheme === null || currentColumnScheme === void 0 ? void 0 : currentColumnScheme.id, derivedColumnState, ready // 添加 ready 依赖,确保 Grid 初始化完成后再应用方案
|
|
378
378
|
]);
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* 【新增】监听当前方案 ID 变化,当方案被删除时重置列状态
|
|
382
|
+
*
|
|
383
|
+
* 场景:
|
|
384
|
+
* - 用户删除当前正在使用的方案
|
|
385
|
+
* - currentColumnScheme?.id 从有值变为 null
|
|
386
|
+
*
|
|
387
|
+
* 行为:
|
|
388
|
+
* - 重置列状态为初始状态(默认顺序、宽度等)
|
|
389
|
+
* - 清除所有过滤器
|
|
390
|
+
* - 清除列样式配置
|
|
391
|
+
*
|
|
392
|
+
* 优势:
|
|
393
|
+
* - 符合单向数据流架构
|
|
394
|
+
* - 适用于所有方案切换场景(删除/取消选择)
|
|
395
|
+
* - 用户体验好,自动恢复到初始状态
|
|
396
|
+
*/
|
|
397
|
+
var prevSchemeIdRef = (0, _react.useRef)(currentColumnScheme === null || currentColumnScheme === void 0 ? void 0 : currentColumnScheme.id);
|
|
398
|
+
(0, _react.useEffect)(function () {
|
|
399
|
+
if (!gridKey || !apiRef.current || !ready) return;
|
|
400
|
+
var prevSchemeId = prevSchemeIdRef.current;
|
|
401
|
+
var currentSchemeId = currentColumnScheme === null || currentColumnScheme === void 0 ? void 0 : currentColumnScheme.id;
|
|
402
|
+
// 检测方案被删除:从有值变为 null/undefined
|
|
403
|
+
if (prevSchemeId && !currentSchemeId) {
|
|
404
|
+
Promise.resolve().then(function () {
|
|
405
|
+
if (!apiRef.current) return;
|
|
406
|
+
|
|
407
|
+
// 1. 重置列状态为初始状态
|
|
408
|
+
|
|
409
|
+
apiRef.current.resetColumnState();
|
|
410
|
+
|
|
411
|
+
// 2. 清除所有过滤器
|
|
412
|
+
|
|
413
|
+
apiRef.current.setFilterModel(null);
|
|
414
|
+
|
|
415
|
+
// 3. 清除列样式配置
|
|
416
|
+
setColumnCellClass({});
|
|
417
|
+
}).catch(function (error) {
|
|
418
|
+
console.error('[AgGridPlus] 重置列状态失败:', error);
|
|
419
|
+
_logger.logger.error('[AgGridPlus] 重置列状态失败', error);
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// 更新引用
|
|
424
|
+
prevSchemeIdRef.current = currentSchemeId;
|
|
425
|
+
}, [gridKey, currentColumnScheme === null || currentColumnScheme === void 0 ? void 0 : currentColumnScheme.id, ready]);
|
|
379
426
|
(0, _react.useEffect)(function () {
|
|
380
427
|
setRowData(dataSource || propRowData || []);
|
|
381
428
|
}, [dataSource, propRowData]);
|
|
@@ -17,8 +17,6 @@ var _preview = _interopRequireDefault(require("./preview"));
|
|
|
17
17
|
var _antd = require("antd");
|
|
18
18
|
var _setting = _interopRequireDefault(require("../ag-grid-plus/setting"));
|
|
19
19
|
var _gridContext = require("../ag-grid-plus/context/gridContext");
|
|
20
|
-
var _useSchemeManager = require("../ag-grid-plus/context/useSchemeManager");
|
|
21
|
-
var _localStorageAdapter = require("../ag-grid-plus/shared/storage/localStorageAdapter");
|
|
22
20
|
var _columnGroupUtils = require("../ag-grid-plus/setting/columnGroupUtils");
|
|
23
21
|
var _theme = require("../ag-grid-plus/theme");
|
|
24
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -38,7 +36,14 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
38
36
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // 导入 AG-Grid v33 主题
|
|
39
37
|
//@ts-ignore
|
|
40
38
|
var ArrayTableInner = (0, _react2.observer)(function (props) {
|
|
41
|
-
var height = props.height
|
|
39
|
+
var height = props.height,
|
|
40
|
+
gridKey = props.gridKey;
|
|
41
|
+
|
|
42
|
+
// 【新增】运行时验证 gridKey
|
|
43
|
+
if (!gridKey) {
|
|
44
|
+
console.error('[ArrayTable] gridKey 是必需的属性,用于方案管理和状态持久化');
|
|
45
|
+
throw new Error('[ArrayTable] gridKey 属性是必需的。请在 x-component-props 中提供 gridKey');
|
|
46
|
+
}
|
|
42
47
|
var _useState = (0, _react.useState)(false),
|
|
43
48
|
_useState2 = _slicedToArray(_useState, 2),
|
|
44
49
|
isAdd = _useState2[0],
|
|
@@ -71,10 +76,12 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
|
|
|
71
76
|
var _useRowDrag = (0, _hooks.useRowDrag)(field),
|
|
72
77
|
handleRowDragMove = _useRowDrag.handleRowDragMove;
|
|
73
78
|
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
// 直接使用 Context 获取方案管理状态
|
|
80
|
+
// ArrayTable 外层已经提供了完整的 GridPlusContext.Provider
|
|
81
|
+
var context = (0, _react.useContext)(_gridContext.GridPlusContext);
|
|
82
|
+
var _ref = context || {},
|
|
83
|
+
currentSchemes = _ref.currentSchemes,
|
|
84
|
+
columnSchemes = _ref.columnSchemes;
|
|
78
85
|
|
|
79
86
|
// 获取当前表格的激活方案
|
|
80
87
|
var currentScheme = (0, _react.useMemo)(function () {
|
|
@@ -294,8 +301,8 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
|
|
|
294
301
|
' <span data-ref="eSortAsc" class="ag-header-icon ag-sort-ascending-icon"></span>' + ' <span data-ref="eSortDesc" class="ag-header-icon ag-sort-descending-icon"></span>' + ' <span data-ref="eSortNone" class="ag-header-icon ag-sort-none-icon"></span>' + " </div>" + "</div>"
|
|
295
302
|
}
|
|
296
303
|
},
|
|
297
|
-
getRowId: function getRowId(
|
|
298
|
-
var data =
|
|
304
|
+
getRowId: function getRowId(_ref2) {
|
|
305
|
+
var data = _ref2.data;
|
|
299
306
|
return data._id || data.id;
|
|
300
307
|
}
|
|
301
308
|
// rowDragEntireRow={true}
|
|
@@ -329,43 +336,36 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
|
|
|
329
336
|
ArrayTableInner.displayName = "ArrayTableInner";
|
|
330
337
|
|
|
331
338
|
/**
|
|
332
|
-
* ArrayTable 组件
|
|
339
|
+
* ArrayTable 组件
|
|
340
|
+
*
|
|
341
|
+
* 注意:需要在外部使用 GridPlusContext.Provider 包裹以提供方案管理功能
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```tsx
|
|
345
|
+
* const adapter = useMemo(() => new LocalStorageSchemeAdapter({
|
|
346
|
+
* storageKey: `array-table-schemes-${gridKey}`
|
|
347
|
+
* }), [gridKey]);
|
|
348
|
+
*
|
|
349
|
+
* const schemeManager = useSchemeManager({ adapter, autoLoad: true });
|
|
350
|
+
*
|
|
351
|
+
* const contextValue = useMemo(() => ({
|
|
352
|
+
* extensibleColumns: [],
|
|
353
|
+
* columnState: undefined,
|
|
354
|
+
* onSaveColumnState: () => {},
|
|
355
|
+
* applyToGlobal: () => {},
|
|
356
|
+
* resetCurrent: () => {},
|
|
357
|
+
* resetAll: () => {},
|
|
358
|
+
* queryFormItems: [],
|
|
359
|
+
* ...schemeManager
|
|
360
|
+
* }), [schemeManager]);
|
|
333
361
|
*
|
|
334
|
-
*
|
|
362
|
+
* <GridPlusContext.Provider value={contextValue}>
|
|
363
|
+
* <ArrayTable gridKey="my-table" height={400} />
|
|
364
|
+
* </GridPlusContext.Provider>
|
|
365
|
+
* ```
|
|
335
366
|
*/
|
|
336
367
|
//@ts-ignore
|
|
337
|
-
var ArrayTable =
|
|
338
|
-
// 创建 LocalStorage 适配器实例 (使用 useMemo 避免重复创建)
|
|
339
|
-
var adapter = (0, _react.useMemo)(function () {
|
|
340
|
-
return new _localStorageAdapter.LocalStorageSchemeAdapter({
|
|
341
|
-
storageKey: "array-table-schemes-".concat(props.gridKey || 'default'),
|
|
342
|
-
enableDebugLog: false
|
|
343
|
-
});
|
|
344
|
-
}, [props.gridKey]);
|
|
345
|
-
|
|
346
|
-
// 初始化方案管理器
|
|
347
|
-
var schemeManager = (0, _useSchemeManager.useSchemeManager)({
|
|
348
|
-
adapter: adapter,
|
|
349
|
-
autoLoad: true,
|
|
350
|
-
showErrorMessage: true
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
// 构建 Context Value
|
|
354
|
-
var contextValue = (0, _react.useMemo)(function () {
|
|
355
|
-
return _objectSpread({
|
|
356
|
-
extensibleColumns: [],
|
|
357
|
-
columnState: undefined,
|
|
358
|
-
onSaveColumnState: function onSaveColumnState() {},
|
|
359
|
-
applyToGlobal: function applyToGlobal() {},
|
|
360
|
-
resetCurrent: function resetCurrent() {},
|
|
361
|
-
resetAll: function resetAll() {},
|
|
362
|
-
queryFormItems: []
|
|
363
|
-
}, schemeManager);
|
|
364
|
-
}, [schemeManager]);
|
|
365
|
-
return /*#__PURE__*/_react.default.createElement(_gridContext.GridPlusContext.Provider, {
|
|
366
|
-
value: contextValue
|
|
367
|
-
}, /*#__PURE__*/_react.default.createElement(ArrayTableInner, props));
|
|
368
|
-
});
|
|
368
|
+
var ArrayTable = ArrayTableInner;
|
|
369
369
|
ArrayTable.displayName = "ArrayTable";
|
|
370
370
|
ArrayTable.Column = function () {
|
|
371
371
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null);
|
|
@@ -368,6 +368,53 @@ function AgGridPlus(props) {
|
|
|
368
368
|
};
|
|
369
369
|
}, [gridKey, currentColumnScheme === null || currentColumnScheme === void 0 ? void 0 : currentColumnScheme.id, derivedColumnState, ready // 添加 ready 依赖,确保 Grid 初始化完成后再应用方案
|
|
370
370
|
]);
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* 【新增】监听当前方案 ID 变化,当方案被删除时重置列状态
|
|
374
|
+
*
|
|
375
|
+
* 场景:
|
|
376
|
+
* - 用户删除当前正在使用的方案
|
|
377
|
+
* - currentColumnScheme?.id 从有值变为 null
|
|
378
|
+
*
|
|
379
|
+
* 行为:
|
|
380
|
+
* - 重置列状态为初始状态(默认顺序、宽度等)
|
|
381
|
+
* - 清除所有过滤器
|
|
382
|
+
* - 清除列样式配置
|
|
383
|
+
*
|
|
384
|
+
* 优势:
|
|
385
|
+
* - 符合单向数据流架构
|
|
386
|
+
* - 适用于所有方案切换场景(删除/取消选择)
|
|
387
|
+
* - 用户体验好,自动恢复到初始状态
|
|
388
|
+
*/
|
|
389
|
+
var prevSchemeIdRef = useRef(currentColumnScheme === null || currentColumnScheme === void 0 ? void 0 : currentColumnScheme.id);
|
|
390
|
+
useEffect(function () {
|
|
391
|
+
if (!gridKey || !apiRef.current || !ready) return;
|
|
392
|
+
var prevSchemeId = prevSchemeIdRef.current;
|
|
393
|
+
var currentSchemeId = currentColumnScheme === null || currentColumnScheme === void 0 ? void 0 : currentColumnScheme.id;
|
|
394
|
+
// 检测方案被删除:从有值变为 null/undefined
|
|
395
|
+
if (prevSchemeId && !currentSchemeId) {
|
|
396
|
+
Promise.resolve().then(function () {
|
|
397
|
+
if (!apiRef.current) return;
|
|
398
|
+
|
|
399
|
+
// 1. 重置列状态为初始状态
|
|
400
|
+
|
|
401
|
+
apiRef.current.resetColumnState();
|
|
402
|
+
|
|
403
|
+
// 2. 清除所有过滤器
|
|
404
|
+
|
|
405
|
+
apiRef.current.setFilterModel(null);
|
|
406
|
+
|
|
407
|
+
// 3. 清除列样式配置
|
|
408
|
+
setColumnCellClass({});
|
|
409
|
+
}).catch(function (error) {
|
|
410
|
+
console.error('[AgGridPlus] 重置列状态失败:', error);
|
|
411
|
+
logger.error('[AgGridPlus] 重置列状态失败', error);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// 更新引用
|
|
416
|
+
prevSchemeIdRef.current = currentSchemeId;
|
|
417
|
+
}, [gridKey, currentColumnScheme === null || currentColumnScheme === void 0 ? void 0 : currentColumnScheme.id, ready]);
|
|
371
418
|
useEffect(function () {
|
|
372
419
|
setRowData(dataSource || propRowData || []);
|
|
373
420
|
}, [dataSource, propRowData]);
|
|
@@ -25,8 +25,6 @@ import PreviewArrayTable from "./preview";
|
|
|
25
25
|
import { Space } from "antd";
|
|
26
26
|
import Setting from "../ag-grid-plus/setting";
|
|
27
27
|
import { GridPlusContext } from "../ag-grid-plus/context/gridContext";
|
|
28
|
-
import { useSchemeManager } from "../ag-grid-plus/context/useSchemeManager";
|
|
29
|
-
import { LocalStorageSchemeAdapter } from "../ag-grid-plus/shared/storage/localStorageAdapter";
|
|
30
28
|
import { flatConfigToColumnState, flatConfigToGridState } from "../ag-grid-plus/setting/columnGroupUtils";
|
|
31
29
|
|
|
32
30
|
// 导入 AG-Grid v33 主题
|
|
@@ -34,7 +32,14 @@ import { agGridTheme } from "../ag-grid-plus/theme";
|
|
|
34
32
|
|
|
35
33
|
//@ts-ignore
|
|
36
34
|
var ArrayTableInner = observer(function (props) {
|
|
37
|
-
var height = props.height
|
|
35
|
+
var height = props.height,
|
|
36
|
+
gridKey = props.gridKey;
|
|
37
|
+
|
|
38
|
+
// 【新增】运行时验证 gridKey
|
|
39
|
+
if (!gridKey) {
|
|
40
|
+
console.error('[ArrayTable] gridKey 是必需的属性,用于方案管理和状态持久化');
|
|
41
|
+
throw new Error('[ArrayTable] gridKey 属性是必需的。请在 x-component-props 中提供 gridKey');
|
|
42
|
+
}
|
|
38
43
|
var _useState = useState(false),
|
|
39
44
|
_useState2 = _slicedToArray(_useState, 2),
|
|
40
45
|
isAdd = _useState2[0],
|
|
@@ -67,10 +72,12 @@ var ArrayTableInner = observer(function (props) {
|
|
|
67
72
|
var _useRowDrag = useRowDrag(field),
|
|
68
73
|
handleRowDragMove = _useRowDrag.handleRowDragMove;
|
|
69
74
|
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
// 直接使用 Context 获取方案管理状态
|
|
76
|
+
// ArrayTable 外层已经提供了完整的 GridPlusContext.Provider
|
|
77
|
+
var context = useContext(GridPlusContext);
|
|
78
|
+
var _ref = context || {},
|
|
79
|
+
currentSchemes = _ref.currentSchemes,
|
|
80
|
+
columnSchemes = _ref.columnSchemes;
|
|
74
81
|
|
|
75
82
|
// 获取当前表格的激活方案
|
|
76
83
|
var currentScheme = useMemo(function () {
|
|
@@ -290,8 +297,8 @@ var ArrayTableInner = observer(function (props) {
|
|
|
290
297
|
' <span data-ref="eSortAsc" class="ag-header-icon ag-sort-ascending-icon"></span>' + ' <span data-ref="eSortDesc" class="ag-header-icon ag-sort-descending-icon"></span>' + ' <span data-ref="eSortNone" class="ag-header-icon ag-sort-none-icon"></span>' + " </div>" + "</div>"
|
|
291
298
|
}
|
|
292
299
|
},
|
|
293
|
-
getRowId: function getRowId(
|
|
294
|
-
var data =
|
|
300
|
+
getRowId: function getRowId(_ref2) {
|
|
301
|
+
var data = _ref2.data;
|
|
295
302
|
return data._id || data.id;
|
|
296
303
|
}
|
|
297
304
|
// rowDragEntireRow={true}
|
|
@@ -325,43 +332,36 @@ var ArrayTableInner = observer(function (props) {
|
|
|
325
332
|
ArrayTableInner.displayName = "ArrayTableInner";
|
|
326
333
|
|
|
327
334
|
/**
|
|
328
|
-
* ArrayTable 组件
|
|
335
|
+
* ArrayTable 组件
|
|
336
|
+
*
|
|
337
|
+
* 注意:需要在外部使用 GridPlusContext.Provider 包裹以提供方案管理功能
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```tsx
|
|
341
|
+
* const adapter = useMemo(() => new LocalStorageSchemeAdapter({
|
|
342
|
+
* storageKey: `array-table-schemes-${gridKey}`
|
|
343
|
+
* }), [gridKey]);
|
|
344
|
+
*
|
|
345
|
+
* const schemeManager = useSchemeManager({ adapter, autoLoad: true });
|
|
346
|
+
*
|
|
347
|
+
* const contextValue = useMemo(() => ({
|
|
348
|
+
* extensibleColumns: [],
|
|
349
|
+
* columnState: undefined,
|
|
350
|
+
* onSaveColumnState: () => {},
|
|
351
|
+
* applyToGlobal: () => {},
|
|
352
|
+
* resetCurrent: () => {},
|
|
353
|
+
* resetAll: () => {},
|
|
354
|
+
* queryFormItems: [],
|
|
355
|
+
* ...schemeManager
|
|
356
|
+
* }), [schemeManager]);
|
|
329
357
|
*
|
|
330
|
-
*
|
|
358
|
+
* <GridPlusContext.Provider value={contextValue}>
|
|
359
|
+
* <ArrayTable gridKey="my-table" height={400} />
|
|
360
|
+
* </GridPlusContext.Provider>
|
|
361
|
+
* ```
|
|
331
362
|
*/
|
|
332
363
|
//@ts-ignore
|
|
333
|
-
var ArrayTable =
|
|
334
|
-
// 创建 LocalStorage 适配器实例 (使用 useMemo 避免重复创建)
|
|
335
|
-
var adapter = useMemo(function () {
|
|
336
|
-
return new LocalStorageSchemeAdapter({
|
|
337
|
-
storageKey: "array-table-schemes-".concat(props.gridKey || 'default'),
|
|
338
|
-
enableDebugLog: false
|
|
339
|
-
});
|
|
340
|
-
}, [props.gridKey]);
|
|
341
|
-
|
|
342
|
-
// 初始化方案管理器
|
|
343
|
-
var schemeManager = useSchemeManager({
|
|
344
|
-
adapter: adapter,
|
|
345
|
-
autoLoad: true,
|
|
346
|
-
showErrorMessage: true
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
// 构建 Context Value
|
|
350
|
-
var contextValue = useMemo(function () {
|
|
351
|
-
return _objectSpread({
|
|
352
|
-
extensibleColumns: [],
|
|
353
|
-
columnState: undefined,
|
|
354
|
-
onSaveColumnState: function onSaveColumnState() {},
|
|
355
|
-
applyToGlobal: function applyToGlobal() {},
|
|
356
|
-
resetCurrent: function resetCurrent() {},
|
|
357
|
-
resetAll: function resetAll() {},
|
|
358
|
-
queryFormItems: []
|
|
359
|
-
}, schemeManager);
|
|
360
|
-
}, [schemeManager]);
|
|
361
|
-
return /*#__PURE__*/React.createElement(GridPlusContext.Provider, {
|
|
362
|
-
value: contextValue
|
|
363
|
-
}, /*#__PURE__*/React.createElement(ArrayTableInner, props));
|
|
364
|
-
});
|
|
364
|
+
var ArrayTable = ArrayTableInner;
|
|
365
365
|
ArrayTable.displayName = "ArrayTable";
|
|
366
366
|
ArrayTable.Column = function () {
|
|
367
367
|
return /*#__PURE__*/React.createElement(Fragment, null);
|