@nokecy/qc-ui 1.0.87 → 1.0.89
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.
- package/dist/cjs/ag-grid-plus/_utils/processColumnGroups.js +3 -1
- package/dist/cjs/ag-grid-plus/ag-gridPlus.js +36 -80
- package/dist/cjs/ag-grid-plus/schemes/hooks/useColumnSchemes.js +43 -14
- package/dist/cjs/ag-grid-plus/schemes/types.d.ts +3 -1
- package/dist/cjs/ag-grid-plus/setting/ColumnSetting.js +12 -16
- package/dist/esm/ag-grid-plus/_utils/processColumnGroups.js +3 -1
- package/dist/esm/ag-grid-plus/ag-gridPlus.js +36 -80
- package/dist/esm/ag-grid-plus/schemes/hooks/useColumnSchemes.js +43 -14
- package/dist/esm/ag-grid-plus/schemes/types.d.ts +3 -1
- package/dist/esm/ag-grid-plus/setting/ColumnSetting.js +12 -16
- package/dist/esm/standardFormDialog/withStandardForm.d.ts +2 -2
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
|
@@ -43,8 +43,10 @@ var processColumnGroups = function processColumnGroups(columns) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// 检查是否是新格式(FlatColumnItem)
|
|
46
|
+
// 注意:不能用 col.type 判断,因为 AG-Grid 列定义也有 type 字段(如 type: 'dateTimeColumn')
|
|
47
|
+
// FlatColumnItem 的特征是:有 id, parentId, level, order 等字段,且 type 的值是 'group' 或 'column'
|
|
46
48
|
var isNewFormat = columns.some(function (col) {
|
|
47
|
-
return col.
|
|
49
|
+
return col.id !== undefined && col.level !== undefined && col.order !== undefined && (col.type === 'group' || col.type === 'column');
|
|
48
50
|
});
|
|
49
51
|
if (isNewFormat) {
|
|
50
52
|
// 新格式:使用 flatConfigToGridState 转换
|
|
@@ -284,83 +284,36 @@ function AgGridPlus(props) {
|
|
|
284
284
|
}
|
|
285
285
|
}, [gridKey, columnSchemeManager === null || columnSchemeManager === void 0 || (_columnSchemeManager$2 = columnSchemeManager.currentScheme) === null || _columnSchemeManager$2 === void 0 ? void 0 : _columnSchemeManager$2.columnConfig]);
|
|
286
286
|
|
|
287
|
-
//
|
|
287
|
+
// 【修复】使用 applyColumnState 来应用列的顺序、宽度、隐藏等状态
|
|
288
|
+
// applyColumnState 是 AG-Grid 推荐的方式,专门用于控制列状态
|
|
288
289
|
(0, _react.useEffect)(function () {
|
|
289
|
-
var _currentScheme$column;
|
|
290
290
|
var currentScheme = columnSchemeManager === null || columnSchemeManager === void 0 ? void 0 : columnSchemeManager.currentScheme;
|
|
291
|
-
|
|
292
|
-
// 两个依赖都不存在时,直接返回
|
|
293
291
|
if (!apiRef.current || !currentScheme) {
|
|
294
|
-
console.log('[AgGridPlus] useEffect: 等待依赖准备', {
|
|
295
|
-
hasApiRef: !!apiRef.current,
|
|
296
|
-
hasCurrentScheme: !!currentScheme
|
|
297
|
-
});
|
|
298
292
|
return;
|
|
299
293
|
}
|
|
300
|
-
console.log('[AgGridPlus] useEffect: 两个依赖都准备好,应用方案', {
|
|
301
|
-
schemeId: currentScheme.id,
|
|
302
|
-
schemeName: currentScheme.name,
|
|
303
|
-
hasColumnConfig: !!currentScheme.columnConfig,
|
|
304
|
-
columnConfigCount: ((_currentScheme$column = currentScheme.columnConfig) === null || _currentScheme$column === void 0 ? void 0 : _currentScheme$column.length) || 0
|
|
305
|
-
});
|
|
306
|
-
var timer = setTimeout(function () {
|
|
307
|
-
// 优先使用 columnConfig(包含完整的分组结构)
|
|
308
|
-
if (currentScheme.columnConfig) {
|
|
309
|
-
var _require2 = require("./setting/columnGroupUtils"),
|
|
310
|
-
flatConfigToGridState = _require2.flatConfigToGridState;
|
|
311
|
-
var gridColumnDefs = flatConfigToGridState(currentScheme.columnConfig);
|
|
312
|
-
console.log('[AgGridPlus] useEffect: 应用方案的 columnConfig:', {
|
|
313
|
-
columnConfig: currentScheme.columnConfig,
|
|
314
|
-
columnConfigLength: currentScheme.columnConfig.length,
|
|
315
|
-
gridColumnDefs: gridColumnDefs,
|
|
316
|
-
gridColumnDefsLength: gridColumnDefs.length,
|
|
317
|
-
columnConfigDetail: currentScheme.columnConfig.map(function (item) {
|
|
318
|
-
return {
|
|
319
|
-
type: item.type,
|
|
320
|
-
field: item.field,
|
|
321
|
-
headerName: item.headerName,
|
|
322
|
-
order: item.order,
|
|
323
|
-
parentId: item.parentId
|
|
324
|
-
};
|
|
325
|
-
}),
|
|
326
|
-
gridColumnDefsDetail: gridColumnDefs.map(function (def, idx) {
|
|
327
|
-
var _def$children;
|
|
328
|
-
return {
|
|
329
|
-
index: idx,
|
|
330
|
-
field: def.field,
|
|
331
|
-
headerName: def.headerName,
|
|
332
|
-
groupId: def.groupId,
|
|
333
|
-
children: (_def$children = def.children) === null || _def$children === void 0 ? void 0 : _def$children.length
|
|
334
|
-
};
|
|
335
|
-
})
|
|
336
|
-
});
|
|
337
294
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
295
|
+
// 如果有 columnConfig,使用 applyColumnState 应用列状态
|
|
296
|
+
if (currentScheme.columnConfig && currentScheme.columnConfig.length > 0) {
|
|
297
|
+
var _require2 = require("./setting/columnGroupUtils"),
|
|
298
|
+
flatConfigToColumnState = _require2.flatConfigToColumnState;
|
|
299
|
+
var _columnState2 = flatConfigToColumnState(currentScheme.columnConfig);
|
|
341
300
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
apiRef.current.setFilterModel(currentScheme.filterModel);
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
}
|
|
301
|
+
// 使用 applyColumnState 应用列状态
|
|
302
|
+
// applyOrder: true 表示按照 state 数组的顺序重新排列列
|
|
303
|
+
apiRef.current.applyColumnState({
|
|
304
|
+
state: _columnState2,
|
|
305
|
+
applyOrder: true
|
|
306
|
+
});
|
|
307
|
+
}
|
|
354
308
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
};
|
|
309
|
+
// 应用过滤器状态
|
|
310
|
+
if (currentScheme.filterModel) {
|
|
311
|
+
setTimeout(function () {
|
|
312
|
+
if (apiRef.current) {
|
|
313
|
+
apiRef.current.setFilterModel(currentScheme.filterModel);
|
|
314
|
+
}
|
|
315
|
+
}, 50); // 延迟稍长一点,等待 columnState 应用完成
|
|
316
|
+
}
|
|
364
317
|
}, [apiRef.current, columnSchemeManager === null || columnSchemeManager === void 0 ? void 0 : columnSchemeManager.currentScheme]);
|
|
365
318
|
(0, _react.useEffect)(function () {
|
|
366
319
|
setRowData(dataSource || propRowData || []);
|
|
@@ -943,6 +896,17 @@ function AgGridPlus(props) {
|
|
|
943
896
|
calculateSum();
|
|
944
897
|
};
|
|
945
898
|
var colDefs = (0, _react.useMemo)(function () {
|
|
899
|
+
var currentScheme = columnSchemeManager === null || columnSchemeManager === void 0 ? void 0 : columnSchemeManager.currentScheme;
|
|
900
|
+
|
|
901
|
+
// 【修复】优先使用方案的 columnConfig,避免被默认逻辑覆盖
|
|
902
|
+
if (currentScheme !== null && currentScheme !== void 0 && currentScheme.columnConfig && currentScheme.columnConfig.length > 0) {
|
|
903
|
+
var _require3 = require("./setting/columnGroupUtils"),
|
|
904
|
+
flatConfigToGridState = _require3.flatConfigToGridState;
|
|
905
|
+
var gridColumnDefs = flatConfigToGridState(currentScheme.columnConfig);
|
|
906
|
+
return gridColumnDefs;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// 【默认逻辑】没有方案配置时,使用原有的列定义生成逻辑
|
|
946
910
|
// 使用缓存的首行数据进行类型推断,而不是当前的 rowData
|
|
947
911
|
// 这样 rowData 更新时不会触发 colDefs 重新计算
|
|
948
912
|
var dataForTypeInference = firstRowDataRef.current || (rowData.length > 0 ? rowData[0] : {});
|
|
@@ -978,16 +942,8 @@ function AgGridPlus(props) {
|
|
|
978
942
|
return !x.hideInTable;
|
|
979
943
|
});
|
|
980
944
|
var processedColumns = (0, _processColumnGroups.default)(columnDefs);
|
|
981
|
-
console.log('[AgGridPlus] colDefs 重新计算:', {
|
|
982
|
-
childrenCount: _react.default.Children.count(children),
|
|
983
|
-
hasPropsColumnDefs: !!props.columnDefs,
|
|
984
|
-
extensibleColumnsCount: Object.keys(extensibleColumns || {}).length,
|
|
985
|
-
columnCellClassCount: Object.keys(columnCellClass).length,
|
|
986
|
-
processedColumnsCount: processedColumns.length,
|
|
987
|
-
usingCachedData: !!firstRowDataRef.current
|
|
988
|
-
});
|
|
989
945
|
return processedColumns;
|
|
990
|
-
}, [_react.default.Children.count(children), props.columnDefs, extensibleColumns, columnCellClass]);
|
|
946
|
+
}, [columnSchemeManager === null || columnSchemeManager === void 0 ? void 0 : columnSchemeManager.currentScheme, _react.default.Children.count(children), props.columnDefs, extensibleColumns, columnCellClass]);
|
|
991
947
|
|
|
992
948
|
// 构建查询表单项(带 order 属性)
|
|
993
949
|
var queryFormItems = (0, _react.useMemo)(function () {
|
|
@@ -1145,8 +1101,8 @@ function AgGridPlus(props) {
|
|
|
1145
1101
|
onDragStopped: function onDragStopped(e) {
|
|
1146
1102
|
if (apiRef.current) {
|
|
1147
1103
|
var _apiRef$current5;
|
|
1148
|
-
var
|
|
1149
|
-
setColumnState(
|
|
1104
|
+
var _columnState3 = (_apiRef$current5 = apiRef.current) === null || _apiRef$current5 === void 0 ? void 0 : _apiRef$current5.getColumnState();
|
|
1105
|
+
setColumnState(_columnState3);
|
|
1150
1106
|
|
|
1151
1107
|
// onColumnStateChanged && onColumnStateChanged(columnState)
|
|
1152
1108
|
}
|
|
@@ -10,10 +10,13 @@ var _uuid = require("uuid");
|
|
|
10
10
|
var _localStorageAdapter = require("../storage/localStorageAdapter");
|
|
11
11
|
var _validator = require("../utils/validator");
|
|
12
12
|
var _constants = require("../constants");
|
|
13
|
+
var _excluded = ["activate"];
|
|
13
14
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
14
15
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
16
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
16
17
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
18
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
19
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
17
20
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
21
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
22
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -336,7 +339,7 @@ function useColumnSchemes(config) {
|
|
|
336
339
|
*/
|
|
337
340
|
var createScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
338
341
|
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(name, columnConfig, options) {
|
|
339
|
-
var nameValidation, uniqueName, newScheme, updatedSchemes;
|
|
342
|
+
var nameValidation, uniqueName, _ref6, activate, schemeOptions, newScheme, updatedSchemes;
|
|
340
343
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
341
344
|
while (1) switch (_context5.prev = _context5.next) {
|
|
342
345
|
case 0:
|
|
@@ -355,14 +358,15 @@ function useColumnSchemes(config) {
|
|
|
355
358
|
throw new Error("\u65B9\u6848\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF08".concat(_constants.MAX_SCHEMES_PER_GRID, "\u4E2A\uFF09\uFF0C\u8BF7\u5220\u9664\u4E00\u4E9B\u65B9\u6848\u540E\u518D\u8BD5"));
|
|
356
359
|
case 5:
|
|
357
360
|
// 处理重名情况
|
|
358
|
-
uniqueName = (0, _validator.checkDuplicateName)(name, schemes) ? (0, _validator.generateUniqueName)(name, schemes) : name;
|
|
361
|
+
uniqueName = (0, _validator.checkDuplicateName)(name, schemes) ? (0, _validator.generateUniqueName)(name, schemes) : name; // 提取 activate 选项
|
|
362
|
+
_ref6 = options || {}, activate = _ref6.activate, schemeOptions = _objectWithoutProperties(_ref6, _excluded);
|
|
359
363
|
newScheme = _objectSpread({
|
|
360
364
|
id: (0, _uuid.v4)(),
|
|
361
365
|
name: uniqueName,
|
|
362
366
|
createdAt: Date.now(),
|
|
363
367
|
updatedAt: Date.now(),
|
|
364
368
|
columnConfig: columnConfig
|
|
365
|
-
},
|
|
369
|
+
}, schemeOptions); // 如果设置为默认方案,取消其他方案的默认标记
|
|
366
370
|
updatedSchemes = schemes;
|
|
367
371
|
if (newScheme.isDefault) {
|
|
368
372
|
updatedSchemes = schemes.map(function (s) {
|
|
@@ -372,27 +376,52 @@ function useColumnSchemes(config) {
|
|
|
372
376
|
});
|
|
373
377
|
}
|
|
374
378
|
updatedSchemes = [].concat(_toConsumableArray(updatedSchemes), [newScheme]);
|
|
375
|
-
_context5.next =
|
|
379
|
+
_context5.next = 13;
|
|
376
380
|
return saveSchemesToStorage(updatedSchemes);
|
|
377
|
-
case
|
|
381
|
+
case 13:
|
|
382
|
+
if (!activate) {
|
|
383
|
+
_context5.next = 26;
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
setCurrentScheme(newScheme);
|
|
387
|
+
setIsDirty(false);
|
|
388
|
+
|
|
389
|
+
// 保存当前方案ID
|
|
390
|
+
if (!storageAdapter.saveCurrentSchemeId) {
|
|
391
|
+
_context5.next = 25;
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
_context5.prev = 17;
|
|
395
|
+
_context5.next = 20;
|
|
396
|
+
return storageAdapter.saveCurrentSchemeId(gridId, newScheme.id);
|
|
397
|
+
case 20:
|
|
398
|
+
_context5.next = 25;
|
|
399
|
+
break;
|
|
400
|
+
case 22:
|
|
401
|
+
_context5.prev = 22;
|
|
402
|
+
_context5.t0 = _context5["catch"](17);
|
|
403
|
+
console.error('[useColumnSchemes] 保存当前方案ID失败:', _context5.t0);
|
|
404
|
+
case 25:
|
|
405
|
+
onSchemeChange === null || onSchemeChange === void 0 || onSchemeChange(newScheme);
|
|
406
|
+
case 26:
|
|
378
407
|
onSchemeSave === null || onSchemeSave === void 0 || onSchemeSave(newScheme);
|
|
379
408
|
return _context5.abrupt("return", newScheme);
|
|
380
|
-
case
|
|
409
|
+
case 28:
|
|
381
410
|
case "end":
|
|
382
411
|
return _context5.stop();
|
|
383
412
|
}
|
|
384
|
-
}, _callee5);
|
|
413
|
+
}, _callee5, null, [[17, 22]]);
|
|
385
414
|
}));
|
|
386
415
|
return function (_x4, _x5, _x6) {
|
|
387
416
|
return _ref5.apply(this, arguments);
|
|
388
417
|
};
|
|
389
|
-
}(), [schemes, saveSchemesToStorage, onSchemeSave]);
|
|
418
|
+
}(), [schemes, gridId, storageAdapter, saveSchemesToStorage, onSchemeChange, onSchemeSave]);
|
|
390
419
|
|
|
391
420
|
/**
|
|
392
421
|
* 更新方案信息(不影响 columnState)
|
|
393
422
|
*/
|
|
394
423
|
var updateScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
395
|
-
var
|
|
424
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(schemeId, updates) {
|
|
396
425
|
var scheme, nameValidation, updatedScheme, updatedSchemes;
|
|
397
426
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
398
427
|
while (1) switch (_context6.prev = _context6.next) {
|
|
@@ -456,7 +485,7 @@ function useColumnSchemes(config) {
|
|
|
456
485
|
}, _callee6);
|
|
457
486
|
}));
|
|
458
487
|
return function (_x7, _x8) {
|
|
459
|
-
return
|
|
488
|
+
return _ref7.apply(this, arguments);
|
|
460
489
|
};
|
|
461
490
|
}(), [schemes, currentScheme, saveSchemesToStorage]);
|
|
462
491
|
|
|
@@ -464,7 +493,7 @@ function useColumnSchemes(config) {
|
|
|
464
493
|
* 删除方案
|
|
465
494
|
*/
|
|
466
495
|
var deleteScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
467
|
-
var
|
|
496
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(schemeId) {
|
|
468
497
|
var scheme, updatedSchemes;
|
|
469
498
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
470
499
|
while (1) switch (_context7.prev = _context7.next) {
|
|
@@ -523,7 +552,7 @@ function useColumnSchemes(config) {
|
|
|
523
552
|
}, _callee7, null, [[12, 17]]);
|
|
524
553
|
}));
|
|
525
554
|
return function (_x9) {
|
|
526
|
-
return
|
|
555
|
+
return _ref8.apply(this, arguments);
|
|
527
556
|
};
|
|
528
557
|
}(), [schemes, currentScheme, gridId, storageAdapter, saveSchemesToStorage, onSchemeChange, onSchemeDelete]);
|
|
529
558
|
|
|
@@ -542,7 +571,7 @@ function useColumnSchemes(config) {
|
|
|
542
571
|
* 设置默认方案
|
|
543
572
|
*/
|
|
544
573
|
var setDefaultScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
545
|
-
var
|
|
574
|
+
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(schemeId) {
|
|
546
575
|
var updatedSchemes;
|
|
547
576
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
548
577
|
while (1) switch (_context8.prev = _context8.next) {
|
|
@@ -561,7 +590,7 @@ function useColumnSchemes(config) {
|
|
|
561
590
|
}, _callee8);
|
|
562
591
|
}));
|
|
563
592
|
return function (_x10) {
|
|
564
|
-
return
|
|
593
|
+
return _ref9.apply(this, arguments);
|
|
565
594
|
};
|
|
566
595
|
}(), [schemes, saveSchemesToStorage]);
|
|
567
596
|
|
|
@@ -109,7 +109,9 @@ export interface UseColumnSchemesReturn {
|
|
|
109
109
|
/** 保存当前方案(更新现有方案) */
|
|
110
110
|
saveScheme: (updates?: Partial<ColumnScheme>) => Promise<void>;
|
|
111
111
|
/** 创建新方案 */
|
|
112
|
-
createScheme: (name: string, columnConfig: FlatColumnItem[], options?: Partial<ColumnScheme>
|
|
112
|
+
createScheme: (name: string, columnConfig: FlatColumnItem[], options?: Partial<ColumnScheme> & {
|
|
113
|
+
activate?: boolean;
|
|
114
|
+
}) => Promise<ColumnScheme>;
|
|
113
115
|
/** 更新方案信息(不影响 columnConfig) */
|
|
114
116
|
updateScheme: (schemeId: string, updates: Partial<Omit<ColumnScheme, 'id' | 'columnConfig'>>) => Promise<void>;
|
|
115
117
|
/** 删除方案 */
|
|
@@ -254,7 +254,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
|
|
|
254
254
|
while (1) switch (_context.prev = _context.next) {
|
|
255
255
|
case 0:
|
|
256
256
|
if (!(schemeManager && gridKey)) {
|
|
257
|
-
_context.next =
|
|
257
|
+
_context.next = 27;
|
|
258
258
|
break;
|
|
259
259
|
}
|
|
260
260
|
_context.prev = 1;
|
|
@@ -287,7 +287,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
|
|
|
287
287
|
filterModel: filterModel
|
|
288
288
|
});
|
|
289
289
|
case 8:
|
|
290
|
-
_context.next =
|
|
290
|
+
_context.next = 22;
|
|
291
291
|
break;
|
|
292
292
|
case 10:
|
|
293
293
|
// 如果没有激活的方案,查找或创建"默认配置"方案
|
|
@@ -308,7 +308,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
|
|
|
308
308
|
filterModel: filterModel
|
|
309
309
|
});
|
|
310
310
|
case 16:
|
|
311
|
-
_context.next =
|
|
311
|
+
_context.next = 22;
|
|
312
312
|
break;
|
|
313
313
|
case 18:
|
|
314
314
|
_context.next = 20;
|
|
@@ -317,33 +317,29 @@ var ColumnSetting = function ColumnSetting(_ref) {
|
|
|
317
317
|
{
|
|
318
318
|
isDefault: true,
|
|
319
319
|
description: '自动保存的默认列配置',
|
|
320
|
-
filterModel: filterModel
|
|
320
|
+
filterModel: filterModel,
|
|
321
|
+
activate: true // 立即激活该方案
|
|
321
322
|
});
|
|
322
323
|
case 20:
|
|
323
324
|
newScheme = _context.sent;
|
|
324
|
-
console.log('[ColumnSetting]
|
|
325
|
+
console.log('[ColumnSetting] 创建默认方案成功并已激活:', {
|
|
325
326
|
schemeId: newScheme.id,
|
|
326
327
|
schemeName: newScheme.name,
|
|
327
328
|
hasColumnConfig: !!newScheme.columnConfig,
|
|
328
329
|
columnConfigLength: ((_newScheme$columnConf = newScheme.columnConfig) === null || _newScheme$columnConf === void 0 ? void 0 : _newScheme$columnConf.length) || 0
|
|
329
330
|
});
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
// loadScheme 会设置 currentScheme 并触发 onSchemeChange
|
|
333
|
-
_context.next = 24;
|
|
334
|
-
return schemeManager.loadScheme(newScheme.id);
|
|
335
|
-
case 24:
|
|
336
|
-
_context.next = 29;
|
|
331
|
+
case 22:
|
|
332
|
+
_context.next = 27;
|
|
337
333
|
break;
|
|
338
|
-
case
|
|
339
|
-
_context.prev =
|
|
334
|
+
case 24:
|
|
335
|
+
_context.prev = 24;
|
|
340
336
|
_context.t0 = _context["catch"](1);
|
|
341
337
|
console.error('[ColumnSetting] 保存列配置到方案失败:', _context.t0);
|
|
342
|
-
case
|
|
338
|
+
case 27:
|
|
343
339
|
case "end":
|
|
344
340
|
return _context.stop();
|
|
345
341
|
}
|
|
346
|
-
}, _callee, null, [[1,
|
|
342
|
+
}, _callee, null, [[1, 24]]);
|
|
347
343
|
})), 50);
|
|
348
344
|
|
|
349
345
|
// 保存成功后清除备份
|
|
@@ -38,8 +38,10 @@ var processColumnGroups = function processColumnGroups(columns) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// 检查是否是新格式(FlatColumnItem)
|
|
41
|
+
// 注意:不能用 col.type 判断,因为 AG-Grid 列定义也有 type 字段(如 type: 'dateTimeColumn')
|
|
42
|
+
// FlatColumnItem 的特征是:有 id, parentId, level, order 等字段,且 type 的值是 'group' 或 'column'
|
|
41
43
|
var isNewFormat = columns.some(function (col) {
|
|
42
|
-
return col.
|
|
44
|
+
return col.id !== undefined && col.level !== undefined && col.order !== undefined && (col.type === 'group' || col.type === 'column');
|
|
43
45
|
});
|
|
44
46
|
if (isNewFormat) {
|
|
45
47
|
// 新格式:使用 flatConfigToGridState 转换
|
|
@@ -277,83 +277,36 @@ function AgGridPlus(props) {
|
|
|
277
277
|
}
|
|
278
278
|
}, [gridKey, columnSchemeManager === null || columnSchemeManager === void 0 || (_columnSchemeManager$2 = columnSchemeManager.currentScheme) === null || _columnSchemeManager$2 === void 0 ? void 0 : _columnSchemeManager$2.columnConfig]);
|
|
279
279
|
|
|
280
|
-
//
|
|
280
|
+
// 【修复】使用 applyColumnState 来应用列的顺序、宽度、隐藏等状态
|
|
281
|
+
// applyColumnState 是 AG-Grid 推荐的方式,专门用于控制列状态
|
|
281
282
|
useEffect(function () {
|
|
282
|
-
var _currentScheme$column;
|
|
283
283
|
var currentScheme = columnSchemeManager === null || columnSchemeManager === void 0 ? void 0 : columnSchemeManager.currentScheme;
|
|
284
|
-
|
|
285
|
-
// 两个依赖都不存在时,直接返回
|
|
286
284
|
if (!apiRef.current || !currentScheme) {
|
|
287
|
-
console.log('[AgGridPlus] useEffect: 等待依赖准备', {
|
|
288
|
-
hasApiRef: !!apiRef.current,
|
|
289
|
-
hasCurrentScheme: !!currentScheme
|
|
290
|
-
});
|
|
291
285
|
return;
|
|
292
286
|
}
|
|
293
|
-
console.log('[AgGridPlus] useEffect: 两个依赖都准备好,应用方案', {
|
|
294
|
-
schemeId: currentScheme.id,
|
|
295
|
-
schemeName: currentScheme.name,
|
|
296
|
-
hasColumnConfig: !!currentScheme.columnConfig,
|
|
297
|
-
columnConfigCount: ((_currentScheme$column = currentScheme.columnConfig) === null || _currentScheme$column === void 0 ? void 0 : _currentScheme$column.length) || 0
|
|
298
|
-
});
|
|
299
|
-
var timer = setTimeout(function () {
|
|
300
|
-
// 优先使用 columnConfig(包含完整的分组结构)
|
|
301
|
-
if (currentScheme.columnConfig) {
|
|
302
|
-
var _require2 = require("./setting/columnGroupUtils"),
|
|
303
|
-
flatConfigToGridState = _require2.flatConfigToGridState;
|
|
304
|
-
var gridColumnDefs = flatConfigToGridState(currentScheme.columnConfig);
|
|
305
|
-
console.log('[AgGridPlus] useEffect: 应用方案的 columnConfig:', {
|
|
306
|
-
columnConfig: currentScheme.columnConfig,
|
|
307
|
-
columnConfigLength: currentScheme.columnConfig.length,
|
|
308
|
-
gridColumnDefs: gridColumnDefs,
|
|
309
|
-
gridColumnDefsLength: gridColumnDefs.length,
|
|
310
|
-
columnConfigDetail: currentScheme.columnConfig.map(function (item) {
|
|
311
|
-
return {
|
|
312
|
-
type: item.type,
|
|
313
|
-
field: item.field,
|
|
314
|
-
headerName: item.headerName,
|
|
315
|
-
order: item.order,
|
|
316
|
-
parentId: item.parentId
|
|
317
|
-
};
|
|
318
|
-
}),
|
|
319
|
-
gridColumnDefsDetail: gridColumnDefs.map(function (def, idx) {
|
|
320
|
-
var _def$children;
|
|
321
|
-
return {
|
|
322
|
-
index: idx,
|
|
323
|
-
field: def.field,
|
|
324
|
-
headerName: def.headerName,
|
|
325
|
-
groupId: def.groupId,
|
|
326
|
-
children: (_def$children = def.children) === null || _def$children === void 0 ? void 0 : _def$children.length
|
|
327
|
-
};
|
|
328
|
-
})
|
|
329
|
-
});
|
|
330
287
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
288
|
+
// 如果有 columnConfig,使用 applyColumnState 应用列状态
|
|
289
|
+
if (currentScheme.columnConfig && currentScheme.columnConfig.length > 0) {
|
|
290
|
+
var _require2 = require("./setting/columnGroupUtils"),
|
|
291
|
+
flatConfigToColumnState = _require2.flatConfigToColumnState;
|
|
292
|
+
var _columnState2 = flatConfigToColumnState(currentScheme.columnConfig);
|
|
334
293
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
apiRef.current.setFilterModel(currentScheme.filterModel);
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
}
|
|
294
|
+
// 使用 applyColumnState 应用列状态
|
|
295
|
+
// applyOrder: true 表示按照 state 数组的顺序重新排列列
|
|
296
|
+
apiRef.current.applyColumnState({
|
|
297
|
+
state: _columnState2,
|
|
298
|
+
applyOrder: true
|
|
299
|
+
});
|
|
300
|
+
}
|
|
347
301
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
};
|
|
302
|
+
// 应用过滤器状态
|
|
303
|
+
if (currentScheme.filterModel) {
|
|
304
|
+
setTimeout(function () {
|
|
305
|
+
if (apiRef.current) {
|
|
306
|
+
apiRef.current.setFilterModel(currentScheme.filterModel);
|
|
307
|
+
}
|
|
308
|
+
}, 50); // 延迟稍长一点,等待 columnState 应用完成
|
|
309
|
+
}
|
|
357
310
|
}, [apiRef.current, columnSchemeManager === null || columnSchemeManager === void 0 ? void 0 : columnSchemeManager.currentScheme]);
|
|
358
311
|
useEffect(function () {
|
|
359
312
|
setRowData(dataSource || propRowData || []);
|
|
@@ -936,6 +889,17 @@ function AgGridPlus(props) {
|
|
|
936
889
|
calculateSum();
|
|
937
890
|
};
|
|
938
891
|
var colDefs = useMemo(function () {
|
|
892
|
+
var currentScheme = columnSchemeManager === null || columnSchemeManager === void 0 ? void 0 : columnSchemeManager.currentScheme;
|
|
893
|
+
|
|
894
|
+
// 【修复】优先使用方案的 columnConfig,避免被默认逻辑覆盖
|
|
895
|
+
if (currentScheme !== null && currentScheme !== void 0 && currentScheme.columnConfig && currentScheme.columnConfig.length > 0) {
|
|
896
|
+
var _require3 = require("./setting/columnGroupUtils"),
|
|
897
|
+
flatConfigToGridState = _require3.flatConfigToGridState;
|
|
898
|
+
var gridColumnDefs = flatConfigToGridState(currentScheme.columnConfig);
|
|
899
|
+
return gridColumnDefs;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
// 【默认逻辑】没有方案配置时,使用原有的列定义生成逻辑
|
|
939
903
|
// 使用缓存的首行数据进行类型推断,而不是当前的 rowData
|
|
940
904
|
// 这样 rowData 更新时不会触发 colDefs 重新计算
|
|
941
905
|
var dataForTypeInference = firstRowDataRef.current || (rowData.length > 0 ? rowData[0] : {});
|
|
@@ -971,16 +935,8 @@ function AgGridPlus(props) {
|
|
|
971
935
|
return !x.hideInTable;
|
|
972
936
|
});
|
|
973
937
|
var processedColumns = processColumnGroups(columnDefs);
|
|
974
|
-
console.log('[AgGridPlus] colDefs 重新计算:', {
|
|
975
|
-
childrenCount: React.Children.count(children),
|
|
976
|
-
hasPropsColumnDefs: !!props.columnDefs,
|
|
977
|
-
extensibleColumnsCount: Object.keys(extensibleColumns || {}).length,
|
|
978
|
-
columnCellClassCount: Object.keys(columnCellClass).length,
|
|
979
|
-
processedColumnsCount: processedColumns.length,
|
|
980
|
-
usingCachedData: !!firstRowDataRef.current
|
|
981
|
-
});
|
|
982
938
|
return processedColumns;
|
|
983
|
-
}, [React.Children.count(children), props.columnDefs, extensibleColumns, columnCellClass]);
|
|
939
|
+
}, [columnSchemeManager === null || columnSchemeManager === void 0 ? void 0 : columnSchemeManager.currentScheme, React.Children.count(children), props.columnDefs, extensibleColumns, columnCellClass]);
|
|
984
940
|
|
|
985
941
|
// 构建查询表单项(带 order 属性)
|
|
986
942
|
var queryFormItems = useMemo(function () {
|
|
@@ -1138,8 +1094,8 @@ function AgGridPlus(props) {
|
|
|
1138
1094
|
onDragStopped: function onDragStopped(e) {
|
|
1139
1095
|
if (apiRef.current) {
|
|
1140
1096
|
var _apiRef$current5;
|
|
1141
|
-
var
|
|
1142
|
-
setColumnState(
|
|
1097
|
+
var _columnState3 = (_apiRef$current5 = apiRef.current) === null || _apiRef$current5 === void 0 ? void 0 : _apiRef$current5.getColumnState();
|
|
1098
|
+
setColumnState(_columnState3);
|
|
1143
1099
|
|
|
1144
1100
|
// onColumnStateChanged && onColumnStateChanged(columnState)
|
|
1145
1101
|
}
|