@nokecy/qc-ui 1.1.12 → 1.1.15

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.
@@ -297,10 +297,10 @@ var ColumnSetting = function ColumnSetting(_ref) {
297
297
 
298
298
  /**
299
299
  * 保存列配置
300
- * 优化逻辑:先保存配置到存储,再通过 handleLoadScheme 统一加载
300
+ * 优化逻辑:先保存配置到存储,再直接应用到 Grid,不依赖 handleLoadScheme
301
301
  */
302
302
  var handleSaveColumns = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
303
- var values, flatConfig, configToSave, invalidColumns, filterModel, schemeIdToLoad, defaultScheme, newScheme;
303
+ var values, flatConfig, configToSave, invalidColumns, filterModel, savedScheme, defaultScheme, hasGroups, gridColumnDefs, columnState;
304
304
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
305
305
  while (1) switch (_context2.prev = _context2.next) {
306
306
  case 0:
@@ -335,16 +335,17 @@ var ColumnSetting = function ColumnSetting(_ref) {
335
335
  _context2.next = 17;
336
336
  break;
337
337
  }
338
- _context2.next = 13;
339
- return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, _objectSpread(_objectSpread({}, currentScheme), {}, {
338
+ // 如果有激活的方案,更新该方案
339
+ savedScheme = _objectSpread(_objectSpread({}, currentScheme), {}, {
340
340
  columnConfig: configToSave,
341
341
  filterModel: filterModel,
342
342
  updatedAt: Date.now()
343
- }));
344
- case 13:
345
- schemeIdToLoad = currentScheme.id;
343
+ });
344
+ _context2.next = 14;
345
+ return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, savedScheme);
346
+ case 14:
346
347
  _antd.message.success('列配置已保存到方案');
347
- _context2.next = 30;
348
+ _context2.next = 29;
348
349
  break;
349
350
  case 17:
350
351
  // 如果没有激活的方案,自动创建或更新默认方案
@@ -355,20 +356,21 @@ var ColumnSetting = function ColumnSetting(_ref) {
355
356
  _context2.next = 25;
356
357
  break;
357
358
  }
358
- _context2.next = 21;
359
- return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, _objectSpread(_objectSpread({}, defaultScheme), {}, {
359
+ // 更新默认方案
360
+ savedScheme = _objectSpread(_objectSpread({}, defaultScheme), {}, {
360
361
  columnConfig: configToSave,
361
362
  filterModel: filterModel,
362
363
  updatedAt: Date.now()
363
- }));
364
- case 21:
365
- schemeIdToLoad = defaultScheme.id;
364
+ });
365
+ _context2.next = 22;
366
+ return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, savedScheme);
367
+ case 22:
366
368
  _antd.message.success('列配置已保存到默认方案');
367
- _context2.next = 30;
369
+ _context2.next = 29;
368
370
  break;
369
371
  case 25:
370
372
  // 创建新的默认方案
371
- newScheme = {
373
+ savedScheme = {
372
374
  id: (0, _uuid.v4)(),
373
375
  name: '默认配置',
374
376
  description: '自动创建的默认列配置',
@@ -380,27 +382,71 @@ var ColumnSetting = function ColumnSetting(_ref) {
380
382
  updatedAt: Date.now()
381
383
  };
382
384
  _context2.next = 28;
383
- return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, newScheme);
385
+ return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, savedScheme);
384
386
  case 28:
385
- schemeIdToLoad = newScheme.id;
386
387
  _antd.message.success('已创建并保存到默认方案');
387
- case 30:
388
- _context2.next = 32;
389
- return handleLoadScheme(schemeIdToLoad);
390
- case 32:
391
- _context2.next = 38;
388
+ case 29:
389
+ _context2.next = 31;
390
+ return new Promise(function (resolve) {
391
+ return setTimeout(resolve, 100);
392
+ });
393
+ case 31:
394
+ // 1. 检查是否包含分组配置
395
+ hasGroups = savedScheme.columnConfig.some(function (item) {
396
+ return item.type === 'group';
397
+ }); // 如果包含分组,先更新 columnDefs
398
+ if (!hasGroups) {
399
+ _context2.next = 37;
400
+ break;
401
+ }
402
+ gridColumnDefs = (0, _columnGroupUtils.flatConfigToGridState)(savedScheme.columnConfig, originalColumnDefs);
403
+ gridApi.setGridOption('columnDefs', gridColumnDefs);
404
+
405
+ // 等待 columnDefs 更新完成
406
+ _context2.next = 37;
407
+ return new Promise(function (resolve) {
408
+ return setTimeout(resolve, 100);
409
+ });
410
+ case 37:
411
+ columnState = (0, _columnGroupUtils.flatConfigToColumnState)(savedScheme.columnConfig);
412
+ gridApi.applyColumnState({
413
+ state: columnState,
414
+ applyOrder: true
415
+ });
416
+
417
+ // 3. 应用过滤器
418
+ if (savedScheme.filterModel) {
419
+ gridApi.setFilterModel(savedScheme.filterModel);
420
+ }
421
+
422
+ // 4. 设置为当前方案(如果不是当前方案)
423
+ if (!(!currentScheme || savedScheme.id !== currentScheme.id)) {
424
+ _context2.next = 43;
425
+ break;
426
+ }
427
+ _context2.next = 43;
428
+ return setCurrentColumnScheme === null || setCurrentColumnScheme === void 0 ? void 0 : setCurrentColumnScheme(gridKey, savedScheme.id);
429
+ case 43:
430
+ _context2.next = 45;
431
+ return new Promise(function (resolve) {
432
+ return setTimeout(resolve, 50);
433
+ });
434
+ case 45:
435
+ // 5. 关闭弹窗
436
+ onClose();
437
+ _context2.next = 52;
392
438
  break;
393
- case 34:
394
- _context2.prev = 34;
439
+ case 48:
440
+ _context2.prev = 48;
395
441
  _context2.t0 = _context2["catch"](8);
396
442
  console.error('保存列配置到方案失败:', _context2.t0);
397
443
  _antd.message.error('保存列配置失败');
398
- case 38:
444
+ case 52:
399
445
  case "end":
400
446
  return _context2.stop();
401
447
  }
402
- }, _callee2, null, [[8, 34]]);
403
- })), [form, gridApi, saveColumnScheme, setCurrentColumnScheme, currentScheme, schemes, gridKey, handleLoadScheme]);
448
+ }, _callee2, null, [[8, 48]]);
449
+ })), [form, gridApi, saveColumnScheme, setCurrentColumnScheme, currentScheme, schemes, gridKey, originalColumnDefs, onClose]);
404
450
 
405
451
  // 保存为新方案
406
452
  var handleSaveScheme = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
@@ -37,6 +37,23 @@ export declare class BackendApiSchemeAdapter implements SchemeStorageAdapter {
37
37
  * 日志输出
38
38
  */
39
39
  private log;
40
+ /**
41
+ * 【修复】将 JavaScript 时间戳转换为 ISO 字符串
42
+ *
43
+ * JavaScript Date.now() 返回毫秒时间戳(如 1699344567890)
44
+ * .NET DateTimeOffset 需要 ISO 8601 格式字符串(如 "2023-11-07T08:36:07.890Z")
45
+ *
46
+ * @param timestamp 毫秒时间戳
47
+ * @returns ISO 8601 格式字符串
48
+ */
49
+ private toIsoString;
50
+ /**
51
+ * 【修复】将 ISO 字符串转换为 JavaScript 时间戳
52
+ *
53
+ * @param isoString ISO 8601 格式字符串
54
+ * @returns 毫秒时间戳
55
+ */
56
+ private fromIsoString;
40
57
  /**
41
58
  * 生成请求头
42
59
  */
@@ -82,6 +82,39 @@ var BackendApiSchemeAdapter = exports.BackendApiSchemeAdapter = /*#__PURE__*/fun
82
82
  }
83
83
  }
84
84
 
85
+ /**
86
+ * 【修复】将 JavaScript 时间戳转换为 ISO 字符串
87
+ *
88
+ * JavaScript Date.now() 返回毫秒时间戳(如 1699344567890)
89
+ * .NET DateTimeOffset 需要 ISO 8601 格式字符串(如 "2023-11-07T08:36:07.890Z")
90
+ *
91
+ * @param timestamp 毫秒时间戳
92
+ * @returns ISO 8601 格式字符串
93
+ */
94
+ }, {
95
+ key: "toIsoString",
96
+ value: function toIsoString(timestamp) {
97
+ if (timestamp === undefined || timestamp === null) {
98
+ return undefined;
99
+ }
100
+ return new Date(timestamp).toISOString();
101
+ }
102
+
103
+ /**
104
+ * 【修复】将 ISO 字符串转换为 JavaScript 时间戳
105
+ *
106
+ * @param isoString ISO 8601 格式字符串
107
+ * @returns 毫秒时间戳
108
+ */
109
+ }, {
110
+ key: "fromIsoString",
111
+ value: function fromIsoString(isoString) {
112
+ if (!isoString) {
113
+ return undefined;
114
+ }
115
+ return new Date(isoString).getTime();
116
+ }
117
+
85
118
  /**
86
119
  * 生成请求头
87
120
  */
@@ -256,9 +289,11 @@ var BackendApiSchemeAdapter = exports.BackendApiSchemeAdapter = /*#__PURE__*/fun
256
289
  _context3.prev = 0;
257
290
  this.log("\u4FDD\u5B58\u5217\u65B9\u6848: ".concat(gridId, " - ").concat(scheme.name));
258
291
 
259
- // 将 columnConfig 转换为 JSON 字符串
292
+ // 【修复】将时间戳转换为 ISO 字符串,并将 columnConfig 转换为 JSON 字符串
260
293
  schemeForBackend = _objectSpread(_objectSpread({}, scheme), {}, {
261
- columnConfig: JSON.stringify(scheme.columnConfig)
294
+ columnConfig: JSON.stringify(scheme.columnConfig),
295
+ createdAt: this.toIsoString(scheme.createdAt),
296
+ updatedAt: this.toIsoString(scheme.updatedAt)
262
297
  });
263
298
  url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/save-column-scheme");
264
299
  _context3.next = 6;
@@ -277,10 +312,20 @@ var BackendApiSchemeAdapter = exports.BackendApiSchemeAdapter = /*#__PURE__*/fun
277
312
  }
278
313
  throw new Error(response.message || '保存失败');
279
314
  case 9:
280
- // 将返回的 columnConfig 从字符串解析为对象数组
315
+ // 【修复】将返回的数据转换回前端格式
281
316
  savedScheme = response.scheme;
282
- if (savedScheme && typeof savedScheme.columnConfig === 'string') {
283
- savedScheme.columnConfig = JSON.parse(savedScheme.columnConfig);
317
+ if (savedScheme) {
318
+ // 解析 columnConfig
319
+ if (typeof savedScheme.columnConfig === 'string') {
320
+ savedScheme.columnConfig = JSON.parse(savedScheme.columnConfig);
321
+ }
322
+ // 将 ISO 字符串转换回时间戳
323
+ if (savedScheme.createdAt) {
324
+ savedScheme.createdAt = this.fromIsoString(savedScheme.createdAt);
325
+ }
326
+ if (savedScheme.updatedAt) {
327
+ savedScheme.updatedAt = this.fromIsoString(savedScheme.updatedAt);
328
+ }
284
329
  }
285
330
  this.log('保存成功', savedScheme);
286
331
  return _context3.abrupt("return", savedScheme);
@@ -56,10 +56,26 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
56
56
  gridApiState = _useState4[0],
57
57
  setGridApiState = _useState4[1];
58
58
  var dataSource = Array.isArray(field.value) ? field.value.slice() : [];
59
- var sources = (0, _utils.useArrayTableSources)();
60
- var actions = (0, _utils.useArrayTableActions)();
61
- var columns = (0, _utils.useArrayTableColumns)(dataSource, field, sources);
62
59
  var schema = (0, _react2.useFieldSchema)();
60
+
61
+ // 获取 sources(每次渲染都会重新计算,返回新的数组引用)
62
+ var rawSources = (0, _utils.useArrayTableSources)();
63
+ var actions = (0, _utils.useArrayTableActions)();
64
+
65
+ // 【关键修复】使用 useMemo 基于内容稳定 sources 引用
66
+ // 通过 JSON.stringify 比较内容,只有内容真正变化时才返回新引用
67
+ var sourcesKey = (0, _react.useMemo)(function () {
68
+ return JSON.stringify(rawSources.map(function (s) {
69
+ return {
70
+ name: s.name,
71
+ display: s.display
72
+ // 只提取稳定的标识信息
73
+ };
74
+ }));
75
+ }, [rawSources]);
76
+ var sources = (0, _react.useMemo)(function () {
77
+ return rawSources;
78
+ }, [sourcesKey]);
63
79
  //@ts-ignore
64
80
  var onAdd = props.onAdd,
65
81
  onCopy = props.onCopy,
@@ -94,8 +110,27 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
94
110
  });
95
111
  }, [props.gridKey, currentSchemes, columnSchemes]);
96
112
 
97
- // 使用 ref 记录上次应用的方案 ID,避免重复应用
98
- var lastAppliedSchemeIdRef = (0, _react.useRef)(null);
113
+ // 使用 ref 记录上次应用的方案状态,避免重复应用
114
+ var lastAppliedSchemeRef = (0, _react.useRef)({
115
+ id: null,
116
+ updatedAt: null
117
+ });
118
+
119
+ /**
120
+ * 【关键优化】使用 useMemo 稳定 columnDefs 引用
121
+ * 只在基础列定义(sources)变化时更新,避免数据变化导致列重置
122
+ * 列的状态(宽度、顺序、隐藏等)由方案通过 applyColumnState 控制,不需要通过 columnDefs 传递
123
+ */
124
+ var stableColumnDefs = (0, _react.useMemo)(function () {
125
+ // 只依赖 sources,不依赖 dataSource 和 field.value
126
+ var cols = (0, _utils.useArrayTableColumns)([], field, sources);
127
+ //@ts-ignore
128
+ if (cols.length > 0 && props.onRowDrag) {
129
+ //@ts-ignore
130
+ cols[0].rowDrag = true;
131
+ }
132
+ return cols;
133
+ }, [sources, props.onRowDrag]); // 移除 field 依赖,避免数据变化时重新计算
99
134
 
100
135
  /**
101
136
  * 方案自动加载
@@ -110,10 +145,14 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
110
145
  if (!props.gridKey || !gridApiState || !currentScheme) return;
111
146
  if (!currentScheme.columnConfig || currentScheme.columnConfig.length === 0) return;
112
147
 
113
- // 如果是同一个方案,跳过应用(避免重复应用)
114
- if (currentScheme.id === lastAppliedSchemeIdRef.current) {
148
+ // 【关键修复】检查方案是否真正变化(比对 ID 和 updatedAt)
149
+ // 只有当方案 ID 变化,或者同一方案但 updatedAt 变化时,才重新应用
150
+ var isSameScheme = currentScheme.id === lastAppliedSchemeRef.current.id;
151
+ var isSameVersion = currentScheme.updatedAt === lastAppliedSchemeRef.current.updatedAt;
152
+ if (isSameScheme && isSameVersion) {
115
153
  return;
116
154
  }
155
+ if (isSameScheme && !isSameVersion) {}
117
156
  // 使用 Promise 链确保顺序执行,避免竞态条件
118
157
  var cancelled = false;
119
158
  Promise.resolve().then(function () {
@@ -159,8 +198,11 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
159
198
  gridApiState.setFilterModel(currentScheme.filterModel);
160
199
  }
161
200
 
162
- // 记录已应用的方案 ID
163
- lastAppliedSchemeIdRef.current = currentScheme.id;
201
+ // 【关键修复】记录已应用的方案状态(ID + updatedAt)
202
+ lastAppliedSchemeRef.current = {
203
+ id: currentScheme.id,
204
+ updatedAt: currentScheme.updatedAt
205
+ };
164
206
  }).catch(function (error) {
165
207
  if (!cancelled) {
166
208
  console.error('[ArrayTable] 应用方案失败:', error);
@@ -171,13 +213,7 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
171
213
  return function () {
172
214
  cancelled = true;
173
215
  };
174
- }, [props.gridKey, gridApiState, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id]);
175
-
176
- //@ts-ignore
177
- if (columns.length > 0) {
178
- //@ts-ignore
179
- columns[0].rowDrag = props.onRowDrag ? true : false;
180
- }
216
+ }, [props.gridKey, gridApiState, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.updatedAt]);
181
217
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
182
218
  ref: ref,
183
219
  style: {
@@ -224,7 +260,7 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
224
260
  gridKey: props.gridKey,
225
261
  gridApi: apiRef.current,
226
262
  gridApiState: gridApiState,
227
- allColDefs: columns,
263
+ allColDefs: stableColumnDefs,
228
264
  showQueryScheme: false
229
265
  })), /*#__PURE__*/_react.default.createElement("div", {
230
266
  style: {
@@ -246,7 +282,9 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
246
282
  suppressCopySingleCellRanges: true,
247
283
  enterNavigatesVertically: true,
248
284
  enterNavigatesVerticallyAfterEdit: true,
249
- columnHoverHighlight: true
285
+ columnHoverHighlight: true,
286
+ // 【关键修复】保持用户设置的列顺序
287
+ maintainColumnOrder: true
250
288
  },
251
289
  onCellKeyDown: handleCellKeyDown,
252
290
  onCellClicked: function onCellClicked(event) {
@@ -303,7 +341,7 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
303
341
  ,
304
342
  rowHeight: 38,
305
343
  pagination: false,
306
- columnDefs: columns,
344
+ columnDefs: stableColumnDefs,
307
345
  rowData: dataSource
308
346
  })), sources.map(function (column, key) {
309
347
  //专门用来承接对Column的状态管理
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
@@ -8,13 +9,15 @@ var _react = _interopRequireDefault(require("react"));
8
9
  var _react2 = require("@formily/react");
9
10
  var _shared = require("@formily/shared");
10
11
  var _arrayBase = _interopRequireDefault(require("./arrayBase"));
12
+ var _excluded = ["pinned", "width", "hide", "sort", "sortIndex"];
11
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
13
14
  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; }
14
15
  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; }
15
16
  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; }
16
17
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
18
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
19
+ 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; }
20
+ 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; }
18
21
  var isColumnComponent = exports.isColumnComponent = function isColumnComponent(schema) {
19
22
  var _schema$xComponent;
20
23
  return ((_schema$xComponent = schema['x-component']) === null || _schema$xComponent === void 0 ? void 0 : _schema$xComponent.indexOf('Column')) > -1;
@@ -106,12 +109,16 @@ var useArrayTableActions = exports.useArrayTableActions = function useArrayTable
106
109
  return schema.properties ? parseSources(schema.properties['actions'] || {}) : [];
107
110
  };
108
111
  var AgField = function AgField(_ref) {
112
+ var _ref2, _node$rowIndex;
109
113
  var value = _ref.value,
110
114
  record = _ref.data,
111
115
  dataSource = _ref.dataSource,
112
116
  schema = _ref.schema,
113
- field = _ref.field;
114
- var index = dataSource === null || dataSource === void 0 ? void 0 : dataSource.indexOf(record);
117
+ field = _ref.field,
118
+ node = _ref.node;
119
+ // 【修复】优先使用 AG-Grid 的 node.rowIndex,避免依赖 dataSource
120
+ // 这样即使 columnDefs 中的 dataSource 是空数组,也能正确获取索引
121
+ var index = (_ref2 = (_node$rowIndex = node === null || node === void 0 ? void 0 : node.rowIndex) !== null && _node$rowIndex !== void 0 ? _node$rowIndex : dataSource === null || dataSource === void 0 ? void 0 : dataSource.indexOf(record)) !== null && _ref2 !== void 0 ? _ref2 : -1;
115
122
  var children =
116
123
  /*#__PURE__*/
117
124
  //@ts-ignore
@@ -131,14 +138,23 @@ var AgField = function AgField(_ref) {
131
138
  return children;
132
139
  };
133
140
  var useArrayTableColumns = exports.useArrayTableColumns = function useArrayTableColumns(dataSource, field, sources) {
134
- return sources.reduce(function (buf, _ref2, key) {
135
- var name = _ref2.name,
136
- columnProps = _ref2.columnProps,
137
- schema = _ref2.schema,
138
- display = _ref2.display;
141
+ return sources.reduce(function (buf, _ref3, key) {
142
+ var name = _ref3.name,
143
+ columnProps = _ref3.columnProps,
144
+ schema = _ref3.schema,
145
+ display = _ref3.display;
139
146
  if (display && display !== 'visible') return buf;
140
147
  if (!isColumnComponent(schema)) return buf;
141
- return buf.concat(_objectSpread(_objectSpread({}, columnProps), {}, {
148
+
149
+ // 【关键修复】移除可能干扰用户列状态的属性
150
+ // 这些属性应该由用户通过列配置(applyColumnState)控制,而不是从 columnDefs 继承
151
+ var pinned = columnProps.pinned,
152
+ width = columnProps.width,
153
+ hide = columnProps.hide,
154
+ sort = columnProps.sort,
155
+ sortIndex = columnProps.sortIndex,
156
+ safeColumnProps = _objectWithoutProperties(columnProps, _excluded);
157
+ return buf.concat(_objectSpread(_objectSpread({}, safeColumnProps), {}, {
142
158
  //@ts-ignore
143
159
  headerName: columnProps.headerName || columnProps.title,
144
160
  field: name,
@@ -288,10 +288,10 @@ var ColumnSetting = function ColumnSetting(_ref) {
288
288
 
289
289
  /**
290
290
  * 保存列配置
291
- * 优化逻辑:先保存配置到存储,再通过 handleLoadScheme 统一加载
291
+ * 优化逻辑:先保存配置到存储,再直接应用到 Grid,不依赖 handleLoadScheme
292
292
  */
293
293
  var handleSaveColumns = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
294
- var values, flatConfig, configToSave, invalidColumns, filterModel, schemeIdToLoad, defaultScheme, newScheme;
294
+ var values, flatConfig, configToSave, invalidColumns, filterModel, savedScheme, defaultScheme, hasGroups, gridColumnDefs, columnState;
295
295
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
296
296
  while (1) switch (_context2.prev = _context2.next) {
297
297
  case 0:
@@ -326,16 +326,17 @@ var ColumnSetting = function ColumnSetting(_ref) {
326
326
  _context2.next = 17;
327
327
  break;
328
328
  }
329
- _context2.next = 13;
330
- return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, _objectSpread(_objectSpread({}, currentScheme), {}, {
329
+ // 如果有激活的方案,更新该方案
330
+ savedScheme = _objectSpread(_objectSpread({}, currentScheme), {}, {
331
331
  columnConfig: configToSave,
332
332
  filterModel: filterModel,
333
333
  updatedAt: Date.now()
334
- }));
335
- case 13:
336
- schemeIdToLoad = currentScheme.id;
334
+ });
335
+ _context2.next = 14;
336
+ return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, savedScheme);
337
+ case 14:
337
338
  message.success('列配置已保存到方案');
338
- _context2.next = 30;
339
+ _context2.next = 29;
339
340
  break;
340
341
  case 17:
341
342
  // 如果没有激活的方案,自动创建或更新默认方案
@@ -346,20 +347,21 @@ var ColumnSetting = function ColumnSetting(_ref) {
346
347
  _context2.next = 25;
347
348
  break;
348
349
  }
349
- _context2.next = 21;
350
- return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, _objectSpread(_objectSpread({}, defaultScheme), {}, {
350
+ // 更新默认方案
351
+ savedScheme = _objectSpread(_objectSpread({}, defaultScheme), {}, {
351
352
  columnConfig: configToSave,
352
353
  filterModel: filterModel,
353
354
  updatedAt: Date.now()
354
- }));
355
- case 21:
356
- schemeIdToLoad = defaultScheme.id;
355
+ });
356
+ _context2.next = 22;
357
+ return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, savedScheme);
358
+ case 22:
357
359
  message.success('列配置已保存到默认方案');
358
- _context2.next = 30;
360
+ _context2.next = 29;
359
361
  break;
360
362
  case 25:
361
363
  // 创建新的默认方案
362
- newScheme = {
364
+ savedScheme = {
363
365
  id: uuidv4(),
364
366
  name: '默认配置',
365
367
  description: '自动创建的默认列配置',
@@ -371,27 +373,71 @@ var ColumnSetting = function ColumnSetting(_ref) {
371
373
  updatedAt: Date.now()
372
374
  };
373
375
  _context2.next = 28;
374
- return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, newScheme);
376
+ return saveColumnScheme === null || saveColumnScheme === void 0 ? void 0 : saveColumnScheme(gridKey, savedScheme);
375
377
  case 28:
376
- schemeIdToLoad = newScheme.id;
377
378
  message.success('已创建并保存到默认方案');
378
- case 30:
379
- _context2.next = 32;
380
- return handleLoadScheme(schemeIdToLoad);
381
- case 32:
382
- _context2.next = 38;
379
+ case 29:
380
+ _context2.next = 31;
381
+ return new Promise(function (resolve) {
382
+ return setTimeout(resolve, 100);
383
+ });
384
+ case 31:
385
+ // 1. 检查是否包含分组配置
386
+ hasGroups = savedScheme.columnConfig.some(function (item) {
387
+ return item.type === 'group';
388
+ }); // 如果包含分组,先更新 columnDefs
389
+ if (!hasGroups) {
390
+ _context2.next = 37;
391
+ break;
392
+ }
393
+ gridColumnDefs = flatConfigToGridState(savedScheme.columnConfig, originalColumnDefs);
394
+ gridApi.setGridOption('columnDefs', gridColumnDefs);
395
+
396
+ // 等待 columnDefs 更新完成
397
+ _context2.next = 37;
398
+ return new Promise(function (resolve) {
399
+ return setTimeout(resolve, 100);
400
+ });
401
+ case 37:
402
+ columnState = flatConfigToColumnState(savedScheme.columnConfig);
403
+ gridApi.applyColumnState({
404
+ state: columnState,
405
+ applyOrder: true
406
+ });
407
+
408
+ // 3. 应用过滤器
409
+ if (savedScheme.filterModel) {
410
+ gridApi.setFilterModel(savedScheme.filterModel);
411
+ }
412
+
413
+ // 4. 设置为当前方案(如果不是当前方案)
414
+ if (!(!currentScheme || savedScheme.id !== currentScheme.id)) {
415
+ _context2.next = 43;
416
+ break;
417
+ }
418
+ _context2.next = 43;
419
+ return setCurrentColumnScheme === null || setCurrentColumnScheme === void 0 ? void 0 : setCurrentColumnScheme(gridKey, savedScheme.id);
420
+ case 43:
421
+ _context2.next = 45;
422
+ return new Promise(function (resolve) {
423
+ return setTimeout(resolve, 50);
424
+ });
425
+ case 45:
426
+ // 5. 关闭弹窗
427
+ onClose();
428
+ _context2.next = 52;
383
429
  break;
384
- case 34:
385
- _context2.prev = 34;
430
+ case 48:
431
+ _context2.prev = 48;
386
432
  _context2.t0 = _context2["catch"](8);
387
433
  console.error('保存列配置到方案失败:', _context2.t0);
388
434
  message.error('保存列配置失败');
389
- case 38:
435
+ case 52:
390
436
  case "end":
391
437
  return _context2.stop();
392
438
  }
393
- }, _callee2, null, [[8, 34]]);
394
- })), [form, gridApi, saveColumnScheme, setCurrentColumnScheme, currentScheme, schemes, gridKey, handleLoadScheme]);
439
+ }, _callee2, null, [[8, 48]]);
440
+ })), [form, gridApi, saveColumnScheme, setCurrentColumnScheme, currentScheme, schemes, gridKey, originalColumnDefs, onClose]);
395
441
 
396
442
  // 保存为新方案
397
443
  var handleSaveScheme = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
@@ -37,6 +37,23 @@ export declare class BackendApiSchemeAdapter implements SchemeStorageAdapter {
37
37
  * 日志输出
38
38
  */
39
39
  private log;
40
+ /**
41
+ * 【修复】将 JavaScript 时间戳转换为 ISO 字符串
42
+ *
43
+ * JavaScript Date.now() 返回毫秒时间戳(如 1699344567890)
44
+ * .NET DateTimeOffset 需要 ISO 8601 格式字符串(如 "2023-11-07T08:36:07.890Z")
45
+ *
46
+ * @param timestamp 毫秒时间戳
47
+ * @returns ISO 8601 格式字符串
48
+ */
49
+ private toIsoString;
50
+ /**
51
+ * 【修复】将 ISO 字符串转换为 JavaScript 时间戳
52
+ *
53
+ * @param isoString ISO 8601 格式字符串
54
+ * @returns 毫秒时间戳
55
+ */
56
+ private fromIsoString;
40
57
  /**
41
58
  * 生成请求头
42
59
  */