@nokecy/qc-ui 1.1.10 → 1.1.11

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) {