@nokecy/qc-ui 1.1.10 → 1.1.12

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.
@@ -220,20 +220,95 @@ var ColumnSetting = function ColumnSetting(_ref) {
220
220
  onClose();
221
221
  }, [snapshotColumnDefs, gridApi, onClose]);
222
222
 
223
+ /**
224
+ * 加载方案
225
+ * 应用方案到 Grid,并更新表单数据
226
+ */
227
+ var handleLoadScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
228
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(schemeId) {
229
+ var scheme, gridColumnDefs, columnState;
230
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
231
+ while (1) switch (_context.prev = _context.next) {
232
+ case 0:
233
+ _context.prev = 0;
234
+ _context.next = 3;
235
+ return setCurrentColumnScheme === null || setCurrentColumnScheme === void 0 ? void 0 : setCurrentColumnScheme(gridKey, schemeId);
236
+ case 3:
237
+ // 应用方案到 Grid
238
+ scheme = schemes.find(function (s) {
239
+ return s.id === schemeId;
240
+ });
241
+ if (!(scheme && gridApi)) {
242
+ _context.next = 12;
243
+ break;
244
+ }
245
+ // 【关键修复】先更新 columnDefs(处理分组结构)
246
+ gridColumnDefs = (0, _columnGroupUtils.flatConfigToGridState)(scheme.columnConfig, originalColumnDefs);
247
+ gridApi.setGridOption('columnDefs', gridColumnDefs);
248
+
249
+ // 等待 columnDefs 更新完成
250
+ _context.next = 9;
251
+ return new Promise(function (resolve) {
252
+ return setTimeout(resolve, 100);
253
+ });
254
+ case 9:
255
+ // 【修复】然后应用列状态(宽度、隐藏、顺序等)
256
+ columnState = (0, _columnGroupUtils.flatConfigToColumnState)(scheme.columnConfig);
257
+ gridApi.applyColumnState({
258
+ state: columnState,
259
+ applyOrder: true // 强制应用列顺序
260
+ });
261
+
262
+ // 应用过滤器
263
+ if (scheme.filterModel) {
264
+ gridApi.setFilterModel(scheme.filterModel);
265
+ }
266
+ case 12:
267
+ _antd.message.success('方案已加载');
268
+
269
+ // 等待Grid状态更新后再刷新表单
270
+ setTimeout(function () {
271
+ if (form) {
272
+ var newData = getColumnData();
273
+ form.setValues({
274
+ items: newData
275
+ });
276
+ }
277
+ }, 100);
278
+
279
+ // 自动关闭弹窗,让用户看到Grid的变化
280
+ onClose();
281
+ _context.next = 20;
282
+ break;
283
+ case 17:
284
+ _context.prev = 17;
285
+ _context.t0 = _context["catch"](0);
286
+ _antd.message.error(_context.t0.message || '加载方案失败');
287
+ case 20:
288
+ case "end":
289
+ return _context.stop();
290
+ }
291
+ }, _callee, null, [[0, 17]]);
292
+ }));
293
+ return function (_x) {
294
+ return _ref2.apply(this, arguments);
295
+ };
296
+ }(), [setCurrentColumnScheme, gridKey, schemes, gridApi, originalColumnDefs, form, getColumnData, onClose]);
297
+
223
298
  /**
224
299
  * 保存列配置
225
- * 将扁平化配置转换回 Grid State 并应用到 AG-Grid
300
+ * 优化逻辑:先保存配置到存储,再通过 handleLoadScheme 统一加载
226
301
  */
227
- var handleSaveColumns = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
228
- var values, flatConfig, configToSave, invalidColumns, gridColumnDefs, columnState, filterModel, defaultScheme, newScheme;
229
- return _regeneratorRuntime().wrap(function _callee$(_context) {
230
- while (1) switch (_context.prev = _context.next) {
302
+ var handleSaveColumns = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
303
+ var values, flatConfig, configToSave, invalidColumns, filterModel, schemeIdToLoad, defaultScheme, newScheme;
304
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
305
+ while (1) switch (_context2.prev = _context2.next) {
231
306
  case 0:
232
307
  if (form) {
233
- _context.next = 2;
308
+ _context2.next = 2;
234
309
  break;
235
310
  }
236
- return _context.abrupt("return");
311
+ return _context2.abrupt("return");
237
312
  case 2:
238
313
  values = form.values;
239
314
  flatConfig = values.items || []; // 检查是否是旧版本数据,如果是则先迁移
@@ -243,7 +318,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
243
318
  _antd.message.info('检测到旧版本配置,已自动迁移到新格式');
244
319
  }
245
320
 
246
- // 【修复】验证数据完整性,过滤掉无效的列配置
321
+ // 验证数据完整性,过滤掉无效的列配置
247
322
  invalidColumns = configToSave.filter(function (item) {
248
323
  return item.type === 'column' && item.field !== "" && !item.field;
249
324
  });
@@ -254,68 +329,45 @@ var ColumnSetting = function ColumnSetting(_ref) {
254
329
  return item.type === 'group' || item.type === 'column' && item.field;
255
330
  });
256
331
  }
257
-
258
- // 【修复】转换为 AG-Grid 的列定义,传入原始列定义以保留自定义属性
259
- gridColumnDefs = (0, _columnGroupUtils.flatConfigToGridState)(configToSave, originalColumnDefs); // 【关键修复】先更新 columnDefs(处理分组结构变化)
260
- _context.next = 11;
261
- return new Promise(function (resolve) {
262
- return setTimeout(resolve, 100);
263
- });
264
- case 11:
265
- // 【修复】然后应用列状态(宽度、隐藏、顺序等)
266
- columnState = (0, _columnGroupUtils.flatConfigToColumnState)(configToSave);
267
- gridApi.applyColumnState({
268
- state: columnState,
269
- applyOrder: true // 强制应用列顺序
270
- });
271
-
272
- // 【关键修复】等待 Grid 状态更新完成后再保存到方案
273
- // 使用 await 确保保存完成后再关闭弹窗,避免生产环境竞态条件
274
- _context.next = 15;
275
- return new Promise(function (resolve) {
276
- return setTimeout(resolve, 50);
277
- });
278
- case 15:
279
- _context.prev = 15;
332
+ _context2.prev = 8;
280
333
  filterModel = gridApi.getFilterModel();
281
334
  if (!currentScheme) {
282
- _context.next = 23;
335
+ _context2.next = 17;
283
336
  break;
284
337
  }
285
- _context.next = 20;
338
+ _context2.next = 13;
286
339
  return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, _objectSpread(_objectSpread({}, currentScheme), {}, {
287
340
  columnConfig: configToSave,
288
341
  filterModel: filterModel,
289
342
  updatedAt: Date.now()
290
343
  }));
291
- case 20:
344
+ case 13:
345
+ schemeIdToLoad = currentScheme.id;
292
346
  _antd.message.success('列配置已保存到方案');
293
- _context.next = 38;
347
+ _context2.next = 30;
294
348
  break;
295
- case 23:
296
- // 如果没有激活的方案,自动创建默认方案
349
+ case 17:
350
+ // 如果没有激活的方案,自动创建或更新默认方案
297
351
  defaultScheme = schemes.find(function (s) {
298
352
  return s.isDefault;
299
353
  });
300
354
  if (!defaultScheme) {
301
- _context.next = 32;
355
+ _context2.next = 25;
302
356
  break;
303
357
  }
304
- _context.next = 27;
358
+ _context2.next = 21;
305
359
  return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, _objectSpread(_objectSpread({}, defaultScheme), {}, {
306
360
  columnConfig: configToSave,
307
361
  filterModel: filterModel,
308
362
  updatedAt: Date.now()
309
363
  }));
310
- case 27:
311
- _context.next = 29;
312
- return setCurrentColumnScheme === null || setCurrentColumnScheme === void 0 ? void 0 : setCurrentColumnScheme(gridKey, defaultScheme.id);
313
- case 29:
364
+ case 21:
365
+ schemeIdToLoad = defaultScheme.id;
314
366
  _antd.message.success('列配置已保存到默认方案');
315
- _context.next = 38;
367
+ _context2.next = 30;
316
368
  break;
317
- case 32:
318
- // 创建新的默认方案并激活
369
+ case 25:
370
+ // 创建新的默认方案
319
371
  newScheme = {
320
372
  id: (0, _uuid.v4)(),
321
373
  name: '默认配置',
@@ -327,55 +379,45 @@ var ColumnSetting = function ColumnSetting(_ref) {
327
379
  createdAt: Date.now(),
328
380
  updatedAt: Date.now()
329
381
  };
330
- _context.next = 35;
382
+ _context2.next = 28;
331
383
  return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, newScheme);
332
- case 35:
333
- _context.next = 37;
334
- return setCurrentColumnScheme === null || setCurrentColumnScheme === void 0 ? void 0 : setCurrentColumnScheme(gridKey, newScheme.id);
335
- case 37:
384
+ case 28:
385
+ schemeIdToLoad = newScheme.id;
336
386
  _antd.message.success('已创建并保存到默认方案');
337
- case 38:
338
- _context.next = 40;
339
- return new Promise(function (resolve) {
340
- return setTimeout(resolve, 100);
341
- });
342
- case 40:
343
- _context.next = 46;
387
+ case 30:
388
+ _context2.next = 32;
389
+ return handleLoadScheme(schemeIdToLoad);
390
+ case 32:
391
+ _context2.next = 38;
344
392
  break;
345
- case 42:
346
- _context.prev = 42;
347
- _context.t0 = _context["catch"](15);
348
- console.error('保存列配置到方案失败:', _context.t0);
393
+ case 34:
394
+ _context2.prev = 34;
395
+ _context2.t0 = _context2["catch"](8);
396
+ console.error('保存列配置到方案失败:', _context2.t0);
349
397
  _antd.message.error('保存列配置失败');
350
- case 46:
351
- // 【修复】保存成功后清除快照
352
- setSnapshotColumnDefs(null);
353
-
354
- // 【关键修复】确保在方案保存完成并传播后才关闭弹窗
355
- onClose();
356
- case 48:
398
+ case 38:
357
399
  case "end":
358
- return _context.stop();
400
+ return _context2.stop();
359
401
  }
360
- }, _callee, null, [[15, 42]]);
361
- })), [form, gridApi, onSaveColumnState, onClose, saveColumnScheme, setCurrentColumnScheme, currentScheme, schemes, gridKey, originalColumnDefs]);
402
+ }, _callee2, null, [[8, 34]]);
403
+ })), [form, gridApi, saveColumnScheme, setCurrentColumnScheme, currentScheme, schemes, gridKey, handleLoadScheme]);
362
404
 
363
405
  // 保存为新方案
364
- var handleSaveScheme = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
406
+ var handleSaveScheme = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
365
407
  var columnConfigToSave, values, gridColumnDefs, columnState, _values, filterModel, newScheme;
366
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
367
- while (1) switch (_context2.prev = _context2.next) {
408
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
409
+ while (1) switch (_context3.prev = _context3.next) {
368
410
  case 0:
369
411
  if (schemeName.trim()) {
370
- _context2.next = 3;
412
+ _context3.next = 3;
371
413
  break;
372
414
  }
373
415
  _antd.message.warning('请输入方案名称');
374
- return _context2.abrupt("return");
416
+ return _context3.abrupt("return");
375
417
  case 3:
376
- _context2.prev = 3;
418
+ _context3.prev = 3;
377
419
  if (!(activeTab === 'columns' && form)) {
378
- _context2.next = 17;
420
+ _context3.next = 17;
379
421
  break;
380
422
  }
381
423
  values = form.values;
@@ -385,7 +427,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
385
427
  gridApi.setGridOption('columnDefs', gridColumnDefs);
386
428
 
387
429
  // 等待 columnDefs 更新完成
388
- _context2.next = 11;
430
+ _context3.next = 11;
389
431
  return new Promise(function (resolve) {
390
432
  return setTimeout(resolve, 100);
391
433
  });
@@ -398,12 +440,12 @@ var ColumnSetting = function ColumnSetting(_ref) {
398
440
  });
399
441
 
400
442
  // 等待状态更新
401
- _context2.next = 15;
443
+ _context3.next = 15;
402
444
  return new Promise(function (resolve) {
403
445
  return setTimeout(resolve, 50);
404
446
  });
405
447
  case 15:
406
- _context2.next = 19;
448
+ _context3.next = 19;
407
449
  break;
408
450
  case 17:
409
451
  // 如果在"方案管理"标签页,使用当前表单数据
@@ -423,7 +465,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
423
465
  createdAt: Date.now(),
424
466
  updatedAt: Date.now()
425
467
  };
426
- _context2.next = 23;
468
+ _context3.next = 23;
427
469
  return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, newScheme);
428
470
  case 23:
429
471
  _antd.message.success('方案保存成功');
@@ -433,91 +475,19 @@ var ColumnSetting = function ColumnSetting(_ref) {
433
475
 
434
476
  // 切换到方案管理标签页,显示新创建的方案
435
477
  setActiveTab('schemes');
436
- _context2.next = 33;
478
+ _context3.next = 33;
437
479
  break;
438
480
  case 30:
439
- _context2.prev = 30;
440
- _context2.t0 = _context2["catch"](3);
441
- _antd.message.error(_context2.t0.message || '保存方案失败');
481
+ _context3.prev = 30;
482
+ _context3.t0 = _context3["catch"](3);
483
+ _antd.message.error(_context3.t0.message || '保存方案失败');
442
484
  case 33:
443
485
  case "end":
444
- return _context2.stop();
486
+ return _context3.stop();
445
487
  }
446
- }, _callee2, null, [[3, 30]]);
488
+ }, _callee3, null, [[3, 30]]);
447
489
  })), [gridApi, saveColumnScheme, gridKey, schemeName, schemeDescription, activeTab, form, originalColumnDefs]);
448
490
 
449
- // 加载方案
450
- var handleLoadScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
451
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(schemeId) {
452
- var scheme, gridColumnDefs, columnState;
453
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
454
- while (1) switch (_context3.prev = _context3.next) {
455
- case 0:
456
- _context3.prev = 0;
457
- _context3.next = 3;
458
- return setCurrentColumnScheme === null || setCurrentColumnScheme === void 0 ? void 0 : setCurrentColumnScheme(gridKey, schemeId);
459
- case 3:
460
- // 应用方案到 Grid
461
- scheme = schemes.find(function (s) {
462
- return s.id === schemeId;
463
- });
464
- if (!(scheme && gridApi)) {
465
- _context3.next = 12;
466
- break;
467
- }
468
- // 【关键修复】先更新 columnDefs(处理分组结构)
469
- gridColumnDefs = (0, _columnGroupUtils.flatConfigToGridState)(scheme.columnConfig, originalColumnDefs);
470
- gridApi.setGridOption('columnDefs', gridColumnDefs);
471
-
472
- // 等待 columnDefs 更新完成
473
- _context3.next = 9;
474
- return new Promise(function (resolve) {
475
- return setTimeout(resolve, 100);
476
- });
477
- case 9:
478
- // 【修复】然后应用列状态(宽度、隐藏、顺序等)
479
- columnState = (0, _columnGroupUtils.flatConfigToColumnState)(scheme.columnConfig);
480
- gridApi.applyColumnState({
481
- state: columnState,
482
- applyOrder: true // 强制应用列顺序
483
- });
484
-
485
- // 应用过滤器
486
- if (scheme.filterModel) {
487
- gridApi.setFilterModel(scheme.filterModel);
488
- }
489
- case 12:
490
- _antd.message.success('方案已加载');
491
-
492
- // 等待Grid状态更新后再刷新表单
493
- setTimeout(function () {
494
- if (form) {
495
- var newData = getColumnData();
496
- form.setValues({
497
- items: newData
498
- });
499
- }
500
- }, 100);
501
-
502
- // 自动关闭弹窗,让用户看到Grid的变化
503
- onClose();
504
- _context3.next = 20;
505
- break;
506
- case 17:
507
- _context3.prev = 17;
508
- _context3.t0 = _context3["catch"](0);
509
- _antd.message.error(_context3.t0.message || '加载方案失败');
510
- case 20:
511
- case "end":
512
- return _context3.stop();
513
- }
514
- }, _callee3, null, [[0, 17]]);
515
- }));
516
- return function (_x) {
517
- return _ref4.apply(this, arguments);
518
- };
519
- }(), [setCurrentColumnScheme, gridKey, schemes, gridApi, originalColumnDefs, form, getColumnData, onClose]);
520
-
521
491
  // 设置默认方案
522
492
  var handleSetDefault = (0, _react.useCallback)( /*#__PURE__*/function () {
523
493
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schemeId) {
@@ -16,9 +16,9 @@ var _arrayAddBtn = _interopRequireDefault(require("./arrayAddBtn"));
16
16
  var _preview = _interopRequireDefault(require("./preview"));
17
17
  var _antd = require("antd");
18
18
  var _setting = _interopRequireDefault(require("../ag-grid-plus/setting"));
19
- var _gridContext = require("../ag-grid-plus/context/gridContext");
20
19
  var _columnGroupUtils = require("../ag-grid-plus/setting/columnGroupUtils");
21
20
  var _theme = require("../ag-grid-plus/theme");
21
+ var _agGridPlus = require("../ag-grid-plus");
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
24
24
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -77,11 +77,10 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
77
77
  handleRowDragMove = _useRowDrag.handleRowDragMove;
78
78
 
79
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;
80
+ var _useGridSchemes = (0, _agGridPlus.useGridSchemes)(),
81
+ columnSchemes = _useGridSchemes.columnSchemes,
82
+ querySchemes = _useGridSchemes.querySchemes,
83
+ currentSchemes = _useGridSchemes.currentSchemes;
85
84
 
86
85
  // 获取当前表格的激活方案
87
86
  var currentScheme = (0, _react.useMemo)(function () {
@@ -95,132 +94,82 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
95
94
  });
96
95
  }, [props.gridKey, currentSchemes, columnSchemes]);
97
96
 
98
- // 使用 ref 记录上次应用的方案 ID 和配置哈希,避免重复应用
99
- var lastAppliedRef = (0, _react.useRef)({
100
- schemeId: null,
101
- configHash: null
102
- });
97
+ // 使用 ref 记录上次应用的方案 ID,避免重复应用
98
+ var lastAppliedSchemeIdRef = (0, _react.useRef)(null);
103
99
 
104
100
  /**
105
- * 【关键修复】在页面刷新或切换方案时自动恢复列方案
101
+ * 方案自动加载
106
102
  *
107
- * 监听 currentScheme 和 gridApiState 的变化,当方案和 Grid API 都准备好时,
108
- * 自动应用方案中保存的列状态(列顺序、宽度、隐藏等)
109
- *
110
- * 关键优化:比较 Grid 当前状态和方案配置,只在真正不一致时才应用
103
+ * 参考 ag-gridPlus 优化方案:
104
+ * 1. 使用 Promise 链确保顺序执行,避免竞态条件
105
+ * 2. 使用双重 RAF 确保渲染完成
106
+ * 3. 完整的错误处理和清理机制
111
107
  */
112
108
  (0, _react.useEffect)(function () {
113
109
  // 检查必要条件
114
110
  if (!props.gridKey || !gridApiState || !currentScheme) return;
115
111
  if (!currentScheme.columnConfig || currentScheme.columnConfig.length === 0) return;
116
112
 
117
- // 【修复】计算方案配置的哈希
118
- var schemeConfigHash = JSON.stringify({
119
- id: currentScheme.id,
120
- columnCount: currentScheme.columnConfig.length,
121
- // 使用前3列的完整配置作为哈希的一部分(包含顺序、宽度、隐藏等)
122
- firstCols: currentScheme.columnConfig.slice(0, 3).map(function (col) {
123
- return {
124
- field: col.field,
125
- width: col.width,
126
- hide: col.hide,
127
- pinned: col.pinned
128
- };
129
- })
130
- });
113
+ // 如果是同一个方案,跳过应用(避免重复应用)
114
+ if (currentScheme.id === lastAppliedSchemeIdRef.current) {
115
+ return;
116
+ }
117
+ // 使用 Promise 链确保顺序执行,避免竞态条件
118
+ var cancelled = false;
119
+ Promise.resolve().then(function () {
120
+ if (cancelled || !gridApiState) return;
131
121
 
132
- // 【关键修复】比较方案配置和 Grid 当前状态
133
- // 检查前3列的关键属性是否一致(跳过字段名差异)
134
- var currentGridState = gridApiState.getColumnState();
135
- var isGridStateSameAsScheme = true;
136
- if (currentGridState.length !== currentScheme.columnConfig.length) {
137
- isGridStateSameAsScheme = false;
138
- } else {
139
- // 比较前3列的关键属性
140
- for (var i = 0; i < Math.min(3, currentGridState.length); i++) {
141
- var gridCol = currentGridState[i];
142
- var schemeCol = currentScheme.columnConfig[i];
143
- if (schemeCol.type !== 'column') continue;
122
+ // 1. 检查是否包含分组配置
123
+ var hasGroups = currentScheme.columnConfig.some(function (item) {
124
+ return item.type === 'group';
125
+ });
144
126
 
145
- // 比较关键属性(field/colId, width, hide, pinned)
146
- if (gridCol.colId !== schemeCol.field || Math.abs((gridCol.width || 0) - (schemeCol.width || 0)) > 5 ||
147
- // 允许5px误差
148
- gridCol.hide !== schemeCol.hide || gridCol.pinned !== schemeCol.pinned) {
149
- isGridStateSameAsScheme = false;
150
- break;
151
- }
127
+ // 如果包含分组,先更新 columnDefs
128
+ if (hasGroups) {
129
+ var gridColumnDefs = (0, _columnGroupUtils.flatConfigToGridState)(currentScheme.columnConfig);
130
+ gridApiState.setGridOption('columnDefs', gridColumnDefs);
152
131
  }
153
- }
154
- // 【关键】跳过应用的条件:
155
- // 1. Grid 当前状态与方案配置一致(说明已经应用过或刚保存)
156
- // 2. 方案配置与上次应用的相同(避免重复应用)
157
- if (isGridStateSameAsScheme || schemeConfigHash === lastAppliedRef.current.configHash) {
158
- // 更新记录,避免后续误判
159
- lastAppliedRef.current = {
160
- schemeId: currentScheme.id,
161
- configHash: schemeConfigHash
162
- };
163
- return;
164
- }
165
132
 
166
- // 【提取函数】应用列状态和过滤器
167
- var applyColumnStateAndFilter = function applyColumnStateAndFilter() {
168
- if (!currentScheme || !gridApiState) return;
133
+ // 2. 应用列状态(列顺序、宽度、隐藏、固定等)
169
134
 
170
- // 将扁平化的列配置转换为 AG-Grid 列状态
171
135
  var columnState = (0, _columnGroupUtils.flatConfigToColumnState)(currentScheme.columnConfig);
172
-
173
- // 应用列状态(包括列顺序、宽度、隐藏等)
174
136
  gridApiState.applyColumnState({
175
137
  state: columnState,
176
- applyOrder: true // 强制应用列顺序
138
+ applyOrder: true
177
139
  });
178
- // 如果方案中包含过滤器配置,也一并应用
140
+ }).then(function () {
141
+ // 等待 Grid 状态稳定(使用 requestAnimationFrame 而非固定延迟)
142
+ return new Promise(function (resolve) {
143
+ if (cancelled) {
144
+ resolve();
145
+ return;
146
+ }
147
+ requestAnimationFrame(function () {
148
+ // 双重 RAF 确保渲染完成
149
+ requestAnimationFrame(function () {
150
+ return resolve();
151
+ });
152
+ });
153
+ });
154
+ }).then(function () {
155
+ if (cancelled || !gridApiState) return;
156
+
157
+ // 3. 应用过滤器(在列状态稳定后执行)
179
158
  if (currentScheme.filterModel) {
180
159
  gridApiState.setFilterModel(currentScheme.filterModel);
181
160
  }
182
161
 
183
- // 记录本次应用的配置哈希
184
- lastAppliedRef.current = {
185
- schemeId: currentScheme.id,
186
- configHash: schemeConfigHash
187
- };
188
- };
189
-
190
- // 使用 requestAnimationFrame 延迟应用
191
- var rafId = requestAnimationFrame(function () {
192
- try {
193
- // 【关键检测】检查是否包含分组配置
194
- var hasGroups = currentScheme.columnConfig.some(function (item) {
195
- return item.type === 'group';
196
- });
197
- // 【条件更新】只有在包含分组时才更新 columnDefs
198
- // 原因:array-table 的列是动态生成的,无分组时不应该覆盖动态列定义
199
- if (hasGroups) {
200
- var gridColumnDefs = (0, _columnGroupUtils.flatConfigToGridState)(currentScheme.columnConfig);
201
- gridApiState.setGridOption('columnDefs', gridColumnDefs);
202
-
203
- // 等待 columnDefs 更新完成后再应用列状态
204
- setTimeout(function () {
205
- try {
206
- applyColumnStateAndFilter();
207
- } catch (error) {
208
- console.error('[ArrayTable] 应用列状态失败:', error);
209
- }
210
- }, 100);
211
- } else {
212
- // 无分组时,直接应用列状态即可
213
-
214
- applyColumnStateAndFilter();
215
- }
216
- } catch (error) {
162
+ // 记录已应用的方案 ID
163
+ lastAppliedSchemeIdRef.current = currentScheme.id;
164
+ }).catch(function (error) {
165
+ if (!cancelled) {
217
166
  console.error('[ArrayTable] 应用方案失败:', error);
218
167
  }
219
168
  });
220
169
 
221
- // 清理函数:取消待执行的 RAF
170
+ // 清理函数:取消进行中的操作
222
171
  return function () {
223
- cancelAnimationFrame(rafId);
172
+ cancelled = true;
224
173
  };
225
174
  }, [props.gridKey, gridApiState, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id]);
226
175
 
@@ -288,8 +237,6 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
288
237
  params.api.hidePopupMenu();
289
238
  apiRef.current = params.api;
290
239
  setGridApiState(params.api);
291
-
292
- // 恢复列状态将由 useEffect 处理(使用方案系统)
293
240
  },
294
241
  suppressColumnVirtualisation: true,
295
242
  gridOptions: {
@@ -337,8 +284,8 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
337
284
  ' <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>"
338
285
  }
339
286
  },
340
- getRowId: function getRowId(_ref2) {
341
- var data = _ref2.data;
287
+ getRowId: function getRowId(_ref) {
288
+ var data = _ref.data;
342
289
  return data._id || data.id;
343
290
  }
344
291
  // rowDragEntireRow={true}