@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.
@@ -211,20 +211,95 @@ var ColumnSetting = function ColumnSetting(_ref) {
211
211
  onClose();
212
212
  }, [snapshotColumnDefs, gridApi, onClose]);
213
213
 
214
+ /**
215
+ * 加载方案
216
+ * 应用方案到 Grid,并更新表单数据
217
+ */
218
+ var handleLoadScheme = useCallback( /*#__PURE__*/function () {
219
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(schemeId) {
220
+ var scheme, gridColumnDefs, columnState;
221
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
222
+ while (1) switch (_context.prev = _context.next) {
223
+ case 0:
224
+ _context.prev = 0;
225
+ _context.next = 3;
226
+ return setCurrentColumnScheme === null || setCurrentColumnScheme === void 0 ? void 0 : setCurrentColumnScheme(gridKey, schemeId);
227
+ case 3:
228
+ // 应用方案到 Grid
229
+ scheme = schemes.find(function (s) {
230
+ return s.id === schemeId;
231
+ });
232
+ if (!(scheme && gridApi)) {
233
+ _context.next = 12;
234
+ break;
235
+ }
236
+ // 【关键修复】先更新 columnDefs(处理分组结构)
237
+ gridColumnDefs = flatConfigToGridState(scheme.columnConfig, originalColumnDefs);
238
+ gridApi.setGridOption('columnDefs', gridColumnDefs);
239
+
240
+ // 等待 columnDefs 更新完成
241
+ _context.next = 9;
242
+ return new Promise(function (resolve) {
243
+ return setTimeout(resolve, 100);
244
+ });
245
+ case 9:
246
+ // 【修复】然后应用列状态(宽度、隐藏、顺序等)
247
+ columnState = flatConfigToColumnState(scheme.columnConfig);
248
+ gridApi.applyColumnState({
249
+ state: columnState,
250
+ applyOrder: true // 强制应用列顺序
251
+ });
252
+
253
+ // 应用过滤器
254
+ if (scheme.filterModel) {
255
+ gridApi.setFilterModel(scheme.filterModel);
256
+ }
257
+ case 12:
258
+ message.success('方案已加载');
259
+
260
+ // 等待Grid状态更新后再刷新表单
261
+ setTimeout(function () {
262
+ if (form) {
263
+ var newData = getColumnData();
264
+ form.setValues({
265
+ items: newData
266
+ });
267
+ }
268
+ }, 100);
269
+
270
+ // 自动关闭弹窗,让用户看到Grid的变化
271
+ onClose();
272
+ _context.next = 20;
273
+ break;
274
+ case 17:
275
+ _context.prev = 17;
276
+ _context.t0 = _context["catch"](0);
277
+ message.error(_context.t0.message || '加载方案失败');
278
+ case 20:
279
+ case "end":
280
+ return _context.stop();
281
+ }
282
+ }, _callee, null, [[0, 17]]);
283
+ }));
284
+ return function (_x) {
285
+ return _ref2.apply(this, arguments);
286
+ };
287
+ }(), [setCurrentColumnScheme, gridKey, schemes, gridApi, originalColumnDefs, form, getColumnData, onClose]);
288
+
214
289
  /**
215
290
  * 保存列配置
216
- * 将扁平化配置转换回 Grid State 并应用到 AG-Grid
291
+ * 优化逻辑:先保存配置到存储,再通过 handleLoadScheme 统一加载
217
292
  */
218
- var handleSaveColumns = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
219
- var values, flatConfig, configToSave, invalidColumns, gridColumnDefs, columnState, filterModel, defaultScheme, newScheme;
220
- return _regeneratorRuntime().wrap(function _callee$(_context) {
221
- while (1) switch (_context.prev = _context.next) {
293
+ var handleSaveColumns = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
294
+ var values, flatConfig, configToSave, invalidColumns, filterModel, schemeIdToLoad, defaultScheme, newScheme;
295
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
296
+ while (1) switch (_context2.prev = _context2.next) {
222
297
  case 0:
223
298
  if (form) {
224
- _context.next = 2;
299
+ _context2.next = 2;
225
300
  break;
226
301
  }
227
- return _context.abrupt("return");
302
+ return _context2.abrupt("return");
228
303
  case 2:
229
304
  values = form.values;
230
305
  flatConfig = values.items || []; // 检查是否是旧版本数据,如果是则先迁移
@@ -234,7 +309,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
234
309
  message.info('检测到旧版本配置,已自动迁移到新格式');
235
310
  }
236
311
 
237
- // 【修复】验证数据完整性,过滤掉无效的列配置
312
+ // 验证数据完整性,过滤掉无效的列配置
238
313
  invalidColumns = configToSave.filter(function (item) {
239
314
  return item.type === 'column' && item.field !== "" && !item.field;
240
315
  });
@@ -245,68 +320,45 @@ var ColumnSetting = function ColumnSetting(_ref) {
245
320
  return item.type === 'group' || item.type === 'column' && item.field;
246
321
  });
247
322
  }
248
-
249
- // 【修复】转换为 AG-Grid 的列定义,传入原始列定义以保留自定义属性
250
- gridColumnDefs = flatConfigToGridState(configToSave, originalColumnDefs); // 【关键修复】先更新 columnDefs(处理分组结构变化)
251
- _context.next = 11;
252
- return new Promise(function (resolve) {
253
- return setTimeout(resolve, 100);
254
- });
255
- case 11:
256
- // 【修复】然后应用列状态(宽度、隐藏、顺序等)
257
- columnState = flatConfigToColumnState(configToSave);
258
- gridApi.applyColumnState({
259
- state: columnState,
260
- applyOrder: true // 强制应用列顺序
261
- });
262
-
263
- // 【关键修复】等待 Grid 状态更新完成后再保存到方案
264
- // 使用 await 确保保存完成后再关闭弹窗,避免生产环境竞态条件
265
- _context.next = 15;
266
- return new Promise(function (resolve) {
267
- return setTimeout(resolve, 50);
268
- });
269
- case 15:
270
- _context.prev = 15;
323
+ _context2.prev = 8;
271
324
  filterModel = gridApi.getFilterModel();
272
325
  if (!currentScheme) {
273
- _context.next = 23;
326
+ _context2.next = 17;
274
327
  break;
275
328
  }
276
- _context.next = 20;
329
+ _context2.next = 13;
277
330
  return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, _objectSpread(_objectSpread({}, currentScheme), {}, {
278
331
  columnConfig: configToSave,
279
332
  filterModel: filterModel,
280
333
  updatedAt: Date.now()
281
334
  }));
282
- case 20:
335
+ case 13:
336
+ schemeIdToLoad = currentScheme.id;
283
337
  message.success('列配置已保存到方案');
284
- _context.next = 38;
338
+ _context2.next = 30;
285
339
  break;
286
- case 23:
287
- // 如果没有激活的方案,自动创建默认方案
340
+ case 17:
341
+ // 如果没有激活的方案,自动创建或更新默认方案
288
342
  defaultScheme = schemes.find(function (s) {
289
343
  return s.isDefault;
290
344
  });
291
345
  if (!defaultScheme) {
292
- _context.next = 32;
346
+ _context2.next = 25;
293
347
  break;
294
348
  }
295
- _context.next = 27;
349
+ _context2.next = 21;
296
350
  return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, _objectSpread(_objectSpread({}, defaultScheme), {}, {
297
351
  columnConfig: configToSave,
298
352
  filterModel: filterModel,
299
353
  updatedAt: Date.now()
300
354
  }));
301
- case 27:
302
- _context.next = 29;
303
- return setCurrentColumnScheme === null || setCurrentColumnScheme === void 0 ? void 0 : setCurrentColumnScheme(gridKey, defaultScheme.id);
304
- case 29:
355
+ case 21:
356
+ schemeIdToLoad = defaultScheme.id;
305
357
  message.success('列配置已保存到默认方案');
306
- _context.next = 38;
358
+ _context2.next = 30;
307
359
  break;
308
- case 32:
309
- // 创建新的默认方案并激活
360
+ case 25:
361
+ // 创建新的默认方案
310
362
  newScheme = {
311
363
  id: uuidv4(),
312
364
  name: '默认配置',
@@ -318,55 +370,45 @@ var ColumnSetting = function ColumnSetting(_ref) {
318
370
  createdAt: Date.now(),
319
371
  updatedAt: Date.now()
320
372
  };
321
- _context.next = 35;
373
+ _context2.next = 28;
322
374
  return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, newScheme);
323
- case 35:
324
- _context.next = 37;
325
- return setCurrentColumnScheme === null || setCurrentColumnScheme === void 0 ? void 0 : setCurrentColumnScheme(gridKey, newScheme.id);
326
- case 37:
375
+ case 28:
376
+ schemeIdToLoad = newScheme.id;
327
377
  message.success('已创建并保存到默认方案');
328
- case 38:
329
- _context.next = 40;
330
- return new Promise(function (resolve) {
331
- return setTimeout(resolve, 100);
332
- });
333
- case 40:
334
- _context.next = 46;
378
+ case 30:
379
+ _context2.next = 32;
380
+ return handleLoadScheme(schemeIdToLoad);
381
+ case 32:
382
+ _context2.next = 38;
335
383
  break;
336
- case 42:
337
- _context.prev = 42;
338
- _context.t0 = _context["catch"](15);
339
- console.error('保存列配置到方案失败:', _context.t0);
384
+ case 34:
385
+ _context2.prev = 34;
386
+ _context2.t0 = _context2["catch"](8);
387
+ console.error('保存列配置到方案失败:', _context2.t0);
340
388
  message.error('保存列配置失败');
341
- case 46:
342
- // 【修复】保存成功后清除快照
343
- setSnapshotColumnDefs(null);
344
-
345
- // 【关键修复】确保在方案保存完成并传播后才关闭弹窗
346
- onClose();
347
- case 48:
389
+ case 38:
348
390
  case "end":
349
- return _context.stop();
391
+ return _context2.stop();
350
392
  }
351
- }, _callee, null, [[15, 42]]);
352
- })), [form, gridApi, onSaveColumnState, onClose, saveColumnScheme, setCurrentColumnScheme, currentScheme, schemes, gridKey, originalColumnDefs]);
393
+ }, _callee2, null, [[8, 34]]);
394
+ })), [form, gridApi, saveColumnScheme, setCurrentColumnScheme, currentScheme, schemes, gridKey, handleLoadScheme]);
353
395
 
354
396
  // 保存为新方案
355
- var handleSaveScheme = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
397
+ var handleSaveScheme = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
356
398
  var columnConfigToSave, values, gridColumnDefs, columnState, _values, filterModel, newScheme;
357
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
358
- while (1) switch (_context2.prev = _context2.next) {
399
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
400
+ while (1) switch (_context3.prev = _context3.next) {
359
401
  case 0:
360
402
  if (schemeName.trim()) {
361
- _context2.next = 3;
403
+ _context3.next = 3;
362
404
  break;
363
405
  }
364
406
  message.warning('请输入方案名称');
365
- return _context2.abrupt("return");
407
+ return _context3.abrupt("return");
366
408
  case 3:
367
- _context2.prev = 3;
409
+ _context3.prev = 3;
368
410
  if (!(activeTab === 'columns' && form)) {
369
- _context2.next = 17;
411
+ _context3.next = 17;
370
412
  break;
371
413
  }
372
414
  values = form.values;
@@ -376,7 +418,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
376
418
  gridApi.setGridOption('columnDefs', gridColumnDefs);
377
419
 
378
420
  // 等待 columnDefs 更新完成
379
- _context2.next = 11;
421
+ _context3.next = 11;
380
422
  return new Promise(function (resolve) {
381
423
  return setTimeout(resolve, 100);
382
424
  });
@@ -389,12 +431,12 @@ var ColumnSetting = function ColumnSetting(_ref) {
389
431
  });
390
432
 
391
433
  // 等待状态更新
392
- _context2.next = 15;
434
+ _context3.next = 15;
393
435
  return new Promise(function (resolve) {
394
436
  return setTimeout(resolve, 50);
395
437
  });
396
438
  case 15:
397
- _context2.next = 19;
439
+ _context3.next = 19;
398
440
  break;
399
441
  case 17:
400
442
  // 如果在"方案管理"标签页,使用当前表单数据
@@ -414,7 +456,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
414
456
  createdAt: Date.now(),
415
457
  updatedAt: Date.now()
416
458
  };
417
- _context2.next = 23;
459
+ _context3.next = 23;
418
460
  return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, newScheme);
419
461
  case 23:
420
462
  message.success('方案保存成功');
@@ -424,91 +466,19 @@ var ColumnSetting = function ColumnSetting(_ref) {
424
466
 
425
467
  // 切换到方案管理标签页,显示新创建的方案
426
468
  setActiveTab('schemes');
427
- _context2.next = 33;
469
+ _context3.next = 33;
428
470
  break;
429
471
  case 30:
430
- _context2.prev = 30;
431
- _context2.t0 = _context2["catch"](3);
432
- message.error(_context2.t0.message || '保存方案失败');
472
+ _context3.prev = 30;
473
+ _context3.t0 = _context3["catch"](3);
474
+ message.error(_context3.t0.message || '保存方案失败');
433
475
  case 33:
434
476
  case "end":
435
- return _context2.stop();
477
+ return _context3.stop();
436
478
  }
437
- }, _callee2, null, [[3, 30]]);
479
+ }, _callee3, null, [[3, 30]]);
438
480
  })), [gridApi, saveColumnScheme, gridKey, schemeName, schemeDescription, activeTab, form, originalColumnDefs]);
439
481
 
440
- // 加载方案
441
- var handleLoadScheme = useCallback( /*#__PURE__*/function () {
442
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(schemeId) {
443
- var scheme, gridColumnDefs, columnState;
444
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
445
- while (1) switch (_context3.prev = _context3.next) {
446
- case 0:
447
- _context3.prev = 0;
448
- _context3.next = 3;
449
- return setCurrentColumnScheme === null || setCurrentColumnScheme === void 0 ? void 0 : setCurrentColumnScheme(gridKey, schemeId);
450
- case 3:
451
- // 应用方案到 Grid
452
- scheme = schemes.find(function (s) {
453
- return s.id === schemeId;
454
- });
455
- if (!(scheme && gridApi)) {
456
- _context3.next = 12;
457
- break;
458
- }
459
- // 【关键修复】先更新 columnDefs(处理分组结构)
460
- gridColumnDefs = flatConfigToGridState(scheme.columnConfig, originalColumnDefs);
461
- gridApi.setGridOption('columnDefs', gridColumnDefs);
462
-
463
- // 等待 columnDefs 更新完成
464
- _context3.next = 9;
465
- return new Promise(function (resolve) {
466
- return setTimeout(resolve, 100);
467
- });
468
- case 9:
469
- // 【修复】然后应用列状态(宽度、隐藏、顺序等)
470
- columnState = flatConfigToColumnState(scheme.columnConfig);
471
- gridApi.applyColumnState({
472
- state: columnState,
473
- applyOrder: true // 强制应用列顺序
474
- });
475
-
476
- // 应用过滤器
477
- if (scheme.filterModel) {
478
- gridApi.setFilterModel(scheme.filterModel);
479
- }
480
- case 12:
481
- message.success('方案已加载');
482
-
483
- // 等待Grid状态更新后再刷新表单
484
- setTimeout(function () {
485
- if (form) {
486
- var newData = getColumnData();
487
- form.setValues({
488
- items: newData
489
- });
490
- }
491
- }, 100);
492
-
493
- // 自动关闭弹窗,让用户看到Grid的变化
494
- onClose();
495
- _context3.next = 20;
496
- break;
497
- case 17:
498
- _context3.prev = 17;
499
- _context3.t0 = _context3["catch"](0);
500
- message.error(_context3.t0.message || '加载方案失败');
501
- case 20:
502
- case "end":
503
- return _context3.stop();
504
- }
505
- }, _callee3, null, [[0, 17]]);
506
- }));
507
- return function (_x) {
508
- return _ref4.apply(this, arguments);
509
- };
510
- }(), [setCurrentColumnScheme, gridKey, schemes, gridApi, originalColumnDefs, form, getColumnData, onClose]);
511
-
512
482
  // 设置默认方案
513
483
  var handleSetDefault = useCallback( /*#__PURE__*/function () {
514
484
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schemeId) {