@nokecy/qc-ui 1.1.8 → 1.1.9

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.
@@ -630,18 +630,17 @@ function AgGridPlus(props) {
630
630
  };
631
631
  }
632
632
 
633
- // 默认配置:启用多选和点击选择
633
+ // 默认配置:单选模式,启用点击选择
634
634
  if (enableClickSelection !== false) {
635
635
  return {
636
- mode: 'multiRow',
637
- enableClickSelection: true,
638
- enableSelectionWithoutKeys: true
636
+ mode: 'singleRow',
637
+ enableClickSelection: true
639
638
  };
640
639
  }
641
640
 
642
- // 如果禁用点击选择,返回基础多选模式(v33 对象格式)
641
+ // 如果禁用点击选择,返回基础单选模式(v33 对象格式)
643
642
  return {
644
- mode: 'multiRow',
643
+ mode: 'singleRow',
645
644
  enableClickSelection: false
646
645
  };
647
646
  }, [propsRowSelection, enableClickSelection]);
@@ -199,6 +199,7 @@ function useSchemeManager(config) {
199
199
  }(), [adapter]);
200
200
  var deleteColumnScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
201
201
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(gridId, schemeId) {
202
+ var defaultScheme;
202
203
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
203
204
  while (1) switch (_context3.prev = _context3.next) {
204
205
  case 0:
@@ -206,20 +207,40 @@ function useSchemeManager(config) {
206
207
  _context3.next = 3;
207
208
  return adapter.deleteColumnScheme(gridId, schemeId);
208
209
  case 3:
209
- // 更新本地状态
210
210
  setColumnSchemes(function (prev) {
211
211
  var schemes = (prev[gridId] || []).filter(function (s) {
212
212
  return s.id !== schemeId;
213
213
  });
214
+ // 查找默认方案(用于后续自动切换)
215
+ defaultScheme = schemes.find(function (s) {
216
+ return s.isDefault;
217
+ });
214
218
  return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, gridId, schemes));
215
219
  });
216
220
 
217
- // 如果删除的是当前方案,清除当前方案ID
221
+ // 如果删除的是当前方案,自动切换到默认方案
218
222
  setCurrentSchemes(function (prev) {
219
223
  var _prev$gridId;
220
224
  if (((_prev$gridId = prev[gridId]) === null || _prev$gridId === void 0 ? void 0 : _prev$gridId.columnSchemeId) === schemeId) {
225
+ var _defaultScheme;
226
+ var newSchemeId = ((_defaultScheme = defaultScheme) === null || _defaultScheme === void 0 ? void 0 : _defaultScheme.id) || null;
227
+ // 如果存在默认方案,同步到适配器
228
+ if (newSchemeId) {
229
+ var _prev$gridId2;
230
+ var querySchemeId = ((_prev$gridId2 = prev[gridId]) === null || _prev$gridId2 === void 0 ? void 0 : _prev$gridId2.querySchemeId) || null;
231
+ adapter.setCurrentScheme(gridId, newSchemeId, querySchemeId).catch(function (error) {
232
+ console.error('[useSchemeManager] 自动切换默认方案失败:', error);
233
+ });
234
+ } else {
235
+ var _prev$gridId3;
236
+ // 没有默认方案,同步清除到适配器
237
+ var _querySchemeId = ((_prev$gridId3 = prev[gridId]) === null || _prev$gridId3 === void 0 ? void 0 : _prev$gridId3.querySchemeId) || null;
238
+ adapter.setCurrentScheme(gridId, null, _querySchemeId).catch(function (error) {
239
+ console.error('[useSchemeManager] 清除当前方案失败:', error);
240
+ });
241
+ }
221
242
  return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, gridId, _objectSpread(_objectSpread({}, prev[gridId]), {}, {
222
- columnSchemeId: null
243
+ columnSchemeId: newSchemeId
223
244
  })));
224
245
  }
225
246
  return prev;
@@ -339,8 +360,8 @@ function useSchemeManager(config) {
339
360
 
340
361
  // 如果删除的是当前方案,清除当前方案ID
341
362
  setCurrentSchemes(function (prev) {
342
- var _prev$gridId2;
343
- if (((_prev$gridId2 = prev[gridId]) === null || _prev$gridId2 === void 0 ? void 0 : _prev$gridId2.querySchemeId) === schemeId) {
363
+ var _prev$gridId4;
364
+ if (((_prev$gridId4 = prev[gridId]) === null || _prev$gridId4 === void 0 ? void 0 : _prev$gridId4.querySchemeId) === schemeId) {
344
365
  return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, gridId, _objectSpread(_objectSpread({}, prev[gridId]), {}, {
345
366
  querySchemeId: null
346
367
  })));
@@ -66,15 +66,24 @@ interface GridProps extends AgGridReactProps {
66
66
  *
67
67
  * 默认值: true
68
68
  *
69
- * AG-Grid v33+ 特性:
70
- * 1. 点击行即可选择/取消选择
71
- * 2. **无需按键即可点击多选**(enableSelectionWithoutKeys)
72
- * 3. 复选框和行点击都支持多选
73
- * 4. 支持 Ctrl/Cmd + A 全选
69
+ * AG-Grid v33+ 默认行为:
70
+ * 1. **默认单选模式** (`mode: 'singleRow'`)
71
+ * 2. 点击行即可选择/取消选择
72
+ * 3. 用户可通过 `rowSelection` prop 覆盖为多选模式
73
+ *
74
+ * 多选模式示例:
75
+ * ```tsx
76
+ * <AgGridPlus
77
+ * rowSelection={{ mode: 'multiRow', enableSelectionWithoutKeys: true }}
78
+ * // 或使用旧 API
79
+ * rowSelection="multiple"
80
+ * />
81
+ * ```
74
82
  *
75
83
  * 内部实现:
76
84
  * - 使用 v33+ 对象化 rowSelection API
77
- * - 自动配置 enableClickSelection 和 enableSelectionWithoutKeys
85
+ * - 自动配置 enableClickSelection
86
+ * - 多选模式下自动配置 enableSelectionWithoutKeys
78
87
  * - 兼容旧的字符串 API('single' | 'multiple')
79
88
  */
80
89
  enableClickSelection?: boolean;
@@ -41,7 +41,7 @@ var TextArea = _antd.Input.TextArea;
41
41
  * 列方案管理组件 - 集成列配置和列方案管理
42
42
  */
43
43
  var ColumnSetting = function ColumnSetting(_ref) {
44
- var _currentSchemes$gridK3;
44
+ var _currentSchemes$gridK4;
45
45
  var gridKey = _ref.gridKey,
46
46
  gridApi = _ref.gridApi,
47
47
  visible = _ref.visible,
@@ -598,30 +598,43 @@ var ColumnSetting = function ColumnSetting(_ref) {
598
598
  // 删除方案
599
599
  var handleDeleteScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
600
600
  var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(schemeId, schemeName) {
601
+ var _currentSchemes$gridK2, isCurrentScheme, defaultScheme;
601
602
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
602
603
  while (1) switch (_context6.prev = _context6.next) {
603
604
  case 0:
604
605
  _context6.prev = 0;
605
- _context6.next = 3;
606
+ // 检查是否删除的是当前方案
607
+ isCurrentScheme = schemeId === (currentSchemes === null || currentSchemes === void 0 || (_currentSchemes$gridK2 = currentSchemes[gridKey]) === null || _currentSchemes$gridK2 === void 0 ? void 0 : _currentSchemes$gridK2.columnSchemeId); // 查找默认方案
608
+ defaultScheme = schemes.find(function (s) {
609
+ return s.isDefault && s.id !== schemeId;
610
+ });
611
+ _context6.next = 5;
606
612
  return deleteColumnScheme === null || deleteColumnScheme === void 0 ? void 0 : deleteColumnScheme(gridKey, schemeId);
607
- case 3:
608
- _antd.message.success("\u65B9\u6848\"".concat(schemeName, "\"\u5DF2\u5220\u9664"));
609
- _context6.next = 9;
613
+ case 5:
614
+ // 根据情况显示不同的提示消息
615
+ if (isCurrentScheme && defaultScheme) {
616
+ _antd.message.success("\u65B9\u6848\"".concat(schemeName, "\"\u5DF2\u5220\u9664\uFF0C\u5DF2\u81EA\u52A8\u5207\u6362\u5230\u9ED8\u8BA4\u65B9\u6848\"").concat(defaultScheme.name, "\""));
617
+ } else if (isCurrentScheme) {
618
+ _antd.message.success("\u65B9\u6848\"".concat(schemeName, "\"\u5DF2\u5220\u9664\uFF0C\u5DF2\u91CD\u7F6E\u4E3A\u521D\u59CB\u914D\u7F6E"));
619
+ } else {
620
+ _antd.message.success("\u65B9\u6848\"".concat(schemeName, "\"\u5DF2\u5220\u9664"));
621
+ }
622
+ _context6.next = 11;
610
623
  break;
611
- case 6:
612
- _context6.prev = 6;
624
+ case 8:
625
+ _context6.prev = 8;
613
626
  _context6.t0 = _context6["catch"](0);
614
627
  _antd.message.error(_context6.t0.message || '删除失败');
615
- case 9:
628
+ case 11:
616
629
  case "end":
617
630
  return _context6.stop();
618
631
  }
619
- }, _callee6, null, [[0, 6]]);
632
+ }, _callee6, null, [[0, 8]]);
620
633
  }));
621
634
  return function (_x3, _x4) {
622
635
  return _ref7.apply(this, arguments);
623
636
  };
624
- }(), [deleteColumnScheme, gridKey]);
637
+ }(), [deleteColumnScheme, gridKey, schemes, currentSchemes]);
625
638
 
626
639
  // 编辑方案
627
640
  var handleEditScheme = (0, _react.useCallback)(function (scheme) {
@@ -691,7 +704,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
691
704
  flex: 1,
692
705
  minWidth: 200,
693
706
  cellRenderer: function cellRenderer(params) {
694
- var _currentSchemes$gridK2;
707
+ var _currentSchemes$gridK3;
695
708
  var record = params.data;
696
709
  if (!record) return null;
697
710
  if (editingId === record.id) {
@@ -711,7 +724,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
711
724
  size: "small"
712
725
  }, /*#__PURE__*/_react.default.createElement("span", null, record.name), record.isDefault && /*#__PURE__*/_react.default.createElement(_antd.Tag, {
713
726
  color: "blue"
714
- }, "\u9ED8\u8BA4"), record.id === (currentSchemes === null || currentSchemes === void 0 || (_currentSchemes$gridK2 = currentSchemes[gridKey]) === null || _currentSchemes$gridK2 === void 0 ? void 0 : _currentSchemes$gridK2.columnSchemeId) && /*#__PURE__*/_react.default.createElement(_antd.Tag, {
727
+ }, "\u9ED8\u8BA4"), record.id === (currentSchemes === null || currentSchemes === void 0 || (_currentSchemes$gridK3 = currentSchemes[gridKey]) === null || _currentSchemes$gridK3 === void 0 ? void 0 : _currentSchemes$gridK3.columnSchemeId) && /*#__PURE__*/_react.default.createElement(_antd.Tag, {
715
728
  color: "green"
716
729
  }, "\u5F53\u524D"));
717
730
  }
@@ -814,7 +827,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
814
827
  }))));
815
828
  }
816
829
  }];
817
- }, [editingId, editingName, editingDescription, currentSchemes === null || currentSchemes === void 0 || (_currentSchemes$gridK3 = currentSchemes[gridKey]) === null || _currentSchemes$gridK3 === void 0 ? void 0 : _currentSchemes$gridK3.columnSchemeId, handleSaveEdit, handleLoadScheme, handleSetDefault, handleEditScheme, handleDeleteScheme]);
830
+ }, [editingId, editingName, editingDescription, currentSchemes === null || currentSchemes === void 0 || (_currentSchemes$gridK4 = currentSchemes[gridKey]) === null || _currentSchemes$gridK4 === void 0 ? void 0 : _currentSchemes$gridK4.columnSchemeId, handleSaveEdit, handleLoadScheme, handleSetDefault, handleEditScheme, handleDeleteScheme]);
818
831
 
819
832
  // 使用 useMemo 稳定传递给 ColumnConfigTable 的 items prop
820
833
  var memoizedColumnData = (0, _react.useMemo)(function () {
@@ -107,23 +107,59 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
107
107
  * 监听 currentScheme 和 gridApiState 的变化,当方案和 Grid API 都准备好时,
108
108
  * 自动应用方案中保存的列状态(列顺序、宽度、隐藏等)
109
109
  *
110
- * 关键优化:使用 ref 记录上次应用的配置哈希,避免保存配置后重复应用旧数据
110
+ * 关键优化:比较 Grid 当前状态和方案配置,只在真正不一致时才应用
111
111
  */
112
112
  (0, _react.useEffect)(function () {
113
- var _currentScheme$column;
114
113
  // 检查必要条件
115
114
  if (!props.gridKey || !gridApiState || !currentScheme) return;
116
115
  if (!currentScheme.columnConfig || currentScheme.columnConfig.length === 0) return;
117
116
 
118
- // 计算当前配置的简单哈希(用于检测配置是否真正变化)
119
- var configHash = JSON.stringify({
117
+ // 【修复】计算方案配置的哈希
118
+ var schemeConfigHash = JSON.stringify({
120
119
  id: currentScheme.id,
121
120
  columnCount: currentScheme.columnConfig.length,
122
- firstCol: (_currentScheme$column = currentScheme.columnConfig[0]) === null || _currentScheme$column === void 0 ? void 0 : _currentScheme$column.field,
123
- updatedAt: currentScheme.updatedAt
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
+ })
124
130
  });
125
- // 【关键】检查配置是否真正变化,避免重复应用
126
- if (configHash === lastAppliedRef.current.configHash) {
131
+
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;
144
+
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
+ }
152
+ }
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
+ };
127
163
  return;
128
164
  }
129
165
 
@@ -147,7 +183,7 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
147
183
  // 记录本次应用的配置哈希
148
184
  lastAppliedRef.current = {
149
185
  schemeId: currentScheme.id,
150
- configHash: configHash
186
+ configHash: schemeConfigHash
151
187
  };
152
188
  };
153
189
 
@@ -186,7 +222,7 @@ var ArrayTableInner = (0, _react2.observer)(function (props) {
186
222
  return function () {
187
223
  cancelAnimationFrame(rafId);
188
224
  };
189
- }, [props.gridKey, gridApiState, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.updatedAt]);
225
+ }, [props.gridKey, gridApiState, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id]);
190
226
 
191
227
  //@ts-ignore
192
228
  if (columns.length > 0) {
@@ -622,18 +622,17 @@ function AgGridPlus(props) {
622
622
  };
623
623
  }
624
624
 
625
- // 默认配置:启用多选和点击选择
625
+ // 默认配置:单选模式,启用点击选择
626
626
  if (enableClickSelection !== false) {
627
627
  return {
628
- mode: 'multiRow',
629
- enableClickSelection: true,
630
- enableSelectionWithoutKeys: true
628
+ mode: 'singleRow',
629
+ enableClickSelection: true
631
630
  };
632
631
  }
633
632
 
634
- // 如果禁用点击选择,返回基础多选模式(v33 对象格式)
633
+ // 如果禁用点击选择,返回基础单选模式(v33 对象格式)
635
634
  return {
636
- mode: 'multiRow',
635
+ mode: 'singleRow',
637
636
  enableClickSelection: false
638
637
  };
639
638
  }, [propsRowSelection, enableClickSelection]);
@@ -193,6 +193,7 @@ export function useSchemeManager(config) {
193
193
  }(), [adapter]);
194
194
  var deleteColumnScheme = useCallback( /*#__PURE__*/function () {
195
195
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(gridId, schemeId) {
196
+ var defaultScheme;
196
197
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
197
198
  while (1) switch (_context3.prev = _context3.next) {
198
199
  case 0:
@@ -200,20 +201,40 @@ export function useSchemeManager(config) {
200
201
  _context3.next = 3;
201
202
  return adapter.deleteColumnScheme(gridId, schemeId);
202
203
  case 3:
203
- // 更新本地状态
204
204
  setColumnSchemes(function (prev) {
205
205
  var schemes = (prev[gridId] || []).filter(function (s) {
206
206
  return s.id !== schemeId;
207
207
  });
208
+ // 查找默认方案(用于后续自动切换)
209
+ defaultScheme = schemes.find(function (s) {
210
+ return s.isDefault;
211
+ });
208
212
  return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, gridId, schemes));
209
213
  });
210
214
 
211
- // 如果删除的是当前方案,清除当前方案ID
215
+ // 如果删除的是当前方案,自动切换到默认方案
212
216
  setCurrentSchemes(function (prev) {
213
217
  var _prev$gridId;
214
218
  if (((_prev$gridId = prev[gridId]) === null || _prev$gridId === void 0 ? void 0 : _prev$gridId.columnSchemeId) === schemeId) {
219
+ var _defaultScheme;
220
+ var newSchemeId = ((_defaultScheme = defaultScheme) === null || _defaultScheme === void 0 ? void 0 : _defaultScheme.id) || null;
221
+ // 如果存在默认方案,同步到适配器
222
+ if (newSchemeId) {
223
+ var _prev$gridId2;
224
+ var querySchemeId = ((_prev$gridId2 = prev[gridId]) === null || _prev$gridId2 === void 0 ? void 0 : _prev$gridId2.querySchemeId) || null;
225
+ adapter.setCurrentScheme(gridId, newSchemeId, querySchemeId).catch(function (error) {
226
+ console.error('[useSchemeManager] 自动切换默认方案失败:', error);
227
+ });
228
+ } else {
229
+ var _prev$gridId3;
230
+ // 没有默认方案,同步清除到适配器
231
+ var _querySchemeId = ((_prev$gridId3 = prev[gridId]) === null || _prev$gridId3 === void 0 ? void 0 : _prev$gridId3.querySchemeId) || null;
232
+ adapter.setCurrentScheme(gridId, null, _querySchemeId).catch(function (error) {
233
+ console.error('[useSchemeManager] 清除当前方案失败:', error);
234
+ });
235
+ }
215
236
  return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, gridId, _objectSpread(_objectSpread({}, prev[gridId]), {}, {
216
- columnSchemeId: null
237
+ columnSchemeId: newSchemeId
217
238
  })));
218
239
  }
219
240
  return prev;
@@ -333,8 +354,8 @@ export function useSchemeManager(config) {
333
354
 
334
355
  // 如果删除的是当前方案,清除当前方案ID
335
356
  setCurrentSchemes(function (prev) {
336
- var _prev$gridId2;
337
- if (((_prev$gridId2 = prev[gridId]) === null || _prev$gridId2 === void 0 ? void 0 : _prev$gridId2.querySchemeId) === schemeId) {
357
+ var _prev$gridId4;
358
+ if (((_prev$gridId4 = prev[gridId]) === null || _prev$gridId4 === void 0 ? void 0 : _prev$gridId4.querySchemeId) === schemeId) {
338
359
  return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, gridId, _objectSpread(_objectSpread({}, prev[gridId]), {}, {
339
360
  querySchemeId: null
340
361
  })));
@@ -66,15 +66,24 @@ interface GridProps extends AgGridReactProps {
66
66
  *
67
67
  * 默认值: true
68
68
  *
69
- * AG-Grid v33+ 特性:
70
- * 1. 点击行即可选择/取消选择
71
- * 2. **无需按键即可点击多选**(enableSelectionWithoutKeys)
72
- * 3. 复选框和行点击都支持多选
73
- * 4. 支持 Ctrl/Cmd + A 全选
69
+ * AG-Grid v33+ 默认行为:
70
+ * 1. **默认单选模式** (`mode: 'singleRow'`)
71
+ * 2. 点击行即可选择/取消选择
72
+ * 3. 用户可通过 `rowSelection` prop 覆盖为多选模式
73
+ *
74
+ * 多选模式示例:
75
+ * ```tsx
76
+ * <AgGridPlus
77
+ * rowSelection={{ mode: 'multiRow', enableSelectionWithoutKeys: true }}
78
+ * // 或使用旧 API
79
+ * rowSelection="multiple"
80
+ * />
81
+ * ```
74
82
  *
75
83
  * 内部实现:
76
84
  * - 使用 v33+ 对象化 rowSelection API
77
- * - 自动配置 enableClickSelection 和 enableSelectionWithoutKeys
85
+ * - 自动配置 enableClickSelection
86
+ * - 多选模式下自动配置 enableSelectionWithoutKeys
78
87
  * - 兼容旧的字符串 API('single' | 'multiple')
79
88
  */
80
89
  enableClickSelection?: boolean;
@@ -32,7 +32,7 @@ var TextArea = Input.TextArea;
32
32
  * 列方案管理组件 - 集成列配置和列方案管理
33
33
  */
34
34
  var ColumnSetting = function ColumnSetting(_ref) {
35
- var _currentSchemes$gridK3;
35
+ var _currentSchemes$gridK4;
36
36
  var gridKey = _ref.gridKey,
37
37
  gridApi = _ref.gridApi,
38
38
  visible = _ref.visible,
@@ -589,30 +589,43 @@ var ColumnSetting = function ColumnSetting(_ref) {
589
589
  // 删除方案
590
590
  var handleDeleteScheme = useCallback( /*#__PURE__*/function () {
591
591
  var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(schemeId, schemeName) {
592
+ var _currentSchemes$gridK2, isCurrentScheme, defaultScheme;
592
593
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
593
594
  while (1) switch (_context6.prev = _context6.next) {
594
595
  case 0:
595
596
  _context6.prev = 0;
596
- _context6.next = 3;
597
+ // 检查是否删除的是当前方案
598
+ isCurrentScheme = schemeId === (currentSchemes === null || currentSchemes === void 0 || (_currentSchemes$gridK2 = currentSchemes[gridKey]) === null || _currentSchemes$gridK2 === void 0 ? void 0 : _currentSchemes$gridK2.columnSchemeId); // 查找默认方案
599
+ defaultScheme = schemes.find(function (s) {
600
+ return s.isDefault && s.id !== schemeId;
601
+ });
602
+ _context6.next = 5;
597
603
  return deleteColumnScheme === null || deleteColumnScheme === void 0 ? void 0 : deleteColumnScheme(gridKey, schemeId);
598
- case 3:
599
- message.success("\u65B9\u6848\"".concat(schemeName, "\"\u5DF2\u5220\u9664"));
600
- _context6.next = 9;
604
+ case 5:
605
+ // 根据情况显示不同的提示消息
606
+ if (isCurrentScheme && defaultScheme) {
607
+ message.success("\u65B9\u6848\"".concat(schemeName, "\"\u5DF2\u5220\u9664\uFF0C\u5DF2\u81EA\u52A8\u5207\u6362\u5230\u9ED8\u8BA4\u65B9\u6848\"").concat(defaultScheme.name, "\""));
608
+ } else if (isCurrentScheme) {
609
+ message.success("\u65B9\u6848\"".concat(schemeName, "\"\u5DF2\u5220\u9664\uFF0C\u5DF2\u91CD\u7F6E\u4E3A\u521D\u59CB\u914D\u7F6E"));
610
+ } else {
611
+ message.success("\u65B9\u6848\"".concat(schemeName, "\"\u5DF2\u5220\u9664"));
612
+ }
613
+ _context6.next = 11;
601
614
  break;
602
- case 6:
603
- _context6.prev = 6;
615
+ case 8:
616
+ _context6.prev = 8;
604
617
  _context6.t0 = _context6["catch"](0);
605
618
  message.error(_context6.t0.message || '删除失败');
606
- case 9:
619
+ case 11:
607
620
  case "end":
608
621
  return _context6.stop();
609
622
  }
610
- }, _callee6, null, [[0, 6]]);
623
+ }, _callee6, null, [[0, 8]]);
611
624
  }));
612
625
  return function (_x3, _x4) {
613
626
  return _ref7.apply(this, arguments);
614
627
  };
615
- }(), [deleteColumnScheme, gridKey]);
628
+ }(), [deleteColumnScheme, gridKey, schemes, currentSchemes]);
616
629
 
617
630
  // 编辑方案
618
631
  var handleEditScheme = useCallback(function (scheme) {
@@ -682,7 +695,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
682
695
  flex: 1,
683
696
  minWidth: 200,
684
697
  cellRenderer: function cellRenderer(params) {
685
- var _currentSchemes$gridK2;
698
+ var _currentSchemes$gridK3;
686
699
  var record = params.data;
687
700
  if (!record) return null;
688
701
  if (editingId === record.id) {
@@ -702,7 +715,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
702
715
  size: "small"
703
716
  }, /*#__PURE__*/React.createElement("span", null, record.name), record.isDefault && /*#__PURE__*/React.createElement(Tag, {
704
717
  color: "blue"
705
- }, "\u9ED8\u8BA4"), record.id === (currentSchemes === null || currentSchemes === void 0 || (_currentSchemes$gridK2 = currentSchemes[gridKey]) === null || _currentSchemes$gridK2 === void 0 ? void 0 : _currentSchemes$gridK2.columnSchemeId) && /*#__PURE__*/React.createElement(Tag, {
718
+ }, "\u9ED8\u8BA4"), record.id === (currentSchemes === null || currentSchemes === void 0 || (_currentSchemes$gridK3 = currentSchemes[gridKey]) === null || _currentSchemes$gridK3 === void 0 ? void 0 : _currentSchemes$gridK3.columnSchemeId) && /*#__PURE__*/React.createElement(Tag, {
706
719
  color: "green"
707
720
  }, "\u5F53\u524D"));
708
721
  }
@@ -805,7 +818,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
805
818
  }))));
806
819
  }
807
820
  }];
808
- }, [editingId, editingName, editingDescription, currentSchemes === null || currentSchemes === void 0 || (_currentSchemes$gridK3 = currentSchemes[gridKey]) === null || _currentSchemes$gridK3 === void 0 ? void 0 : _currentSchemes$gridK3.columnSchemeId, handleSaveEdit, handleLoadScheme, handleSetDefault, handleEditScheme, handleDeleteScheme]);
821
+ }, [editingId, editingName, editingDescription, currentSchemes === null || currentSchemes === void 0 || (_currentSchemes$gridK4 = currentSchemes[gridKey]) === null || _currentSchemes$gridK4 === void 0 ? void 0 : _currentSchemes$gridK4.columnSchemeId, handleSaveEdit, handleLoadScheme, handleSetDefault, handleEditScheme, handleDeleteScheme]);
809
822
 
810
823
  // 使用 useMemo 稳定传递给 ColumnConfigTable 的 items prop
811
824
  var memoizedColumnData = useMemo(function () {
@@ -103,23 +103,59 @@ var ArrayTableInner = observer(function (props) {
103
103
  * 监听 currentScheme 和 gridApiState 的变化,当方案和 Grid API 都准备好时,
104
104
  * 自动应用方案中保存的列状态(列顺序、宽度、隐藏等)
105
105
  *
106
- * 关键优化:使用 ref 记录上次应用的配置哈希,避免保存配置后重复应用旧数据
106
+ * 关键优化:比较 Grid 当前状态和方案配置,只在真正不一致时才应用
107
107
  */
108
108
  useEffect(function () {
109
- var _currentScheme$column;
110
109
  // 检查必要条件
111
110
  if (!props.gridKey || !gridApiState || !currentScheme) return;
112
111
  if (!currentScheme.columnConfig || currentScheme.columnConfig.length === 0) return;
113
112
 
114
- // 计算当前配置的简单哈希(用于检测配置是否真正变化)
115
- var configHash = JSON.stringify({
113
+ // 【修复】计算方案配置的哈希
114
+ var schemeConfigHash = JSON.stringify({
116
115
  id: currentScheme.id,
117
116
  columnCount: currentScheme.columnConfig.length,
118
- firstCol: (_currentScheme$column = currentScheme.columnConfig[0]) === null || _currentScheme$column === void 0 ? void 0 : _currentScheme$column.field,
119
- updatedAt: currentScheme.updatedAt
117
+ // 使用前3列的完整配置作为哈希的一部分(包含顺序、宽度、隐藏等)
118
+ firstCols: currentScheme.columnConfig.slice(0, 3).map(function (col) {
119
+ return {
120
+ field: col.field,
121
+ width: col.width,
122
+ hide: col.hide,
123
+ pinned: col.pinned
124
+ };
125
+ })
120
126
  });
121
- // 【关键】检查配置是否真正变化,避免重复应用
122
- if (configHash === lastAppliedRef.current.configHash) {
127
+
128
+ // 【关键修复】比较方案配置和 Grid 当前状态
129
+ // 检查前3列的关键属性是否一致(跳过字段名差异)
130
+ var currentGridState = gridApiState.getColumnState();
131
+ var isGridStateSameAsScheme = true;
132
+ if (currentGridState.length !== currentScheme.columnConfig.length) {
133
+ isGridStateSameAsScheme = false;
134
+ } else {
135
+ // 比较前3列的关键属性
136
+ for (var i = 0; i < Math.min(3, currentGridState.length); i++) {
137
+ var gridCol = currentGridState[i];
138
+ var schemeCol = currentScheme.columnConfig[i];
139
+ if (schemeCol.type !== 'column') continue;
140
+
141
+ // 比较关键属性(field/colId, width, hide, pinned)
142
+ if (gridCol.colId !== schemeCol.field || Math.abs((gridCol.width || 0) - (schemeCol.width || 0)) > 5 ||
143
+ // 允许5px误差
144
+ gridCol.hide !== schemeCol.hide || gridCol.pinned !== schemeCol.pinned) {
145
+ isGridStateSameAsScheme = false;
146
+ break;
147
+ }
148
+ }
149
+ }
150
+ // 【关键】跳过应用的条件:
151
+ // 1. Grid 当前状态与方案配置一致(说明已经应用过或刚保存)
152
+ // 2. 方案配置与上次应用的相同(避免重复应用)
153
+ if (isGridStateSameAsScheme || schemeConfigHash === lastAppliedRef.current.configHash) {
154
+ // 更新记录,避免后续误判
155
+ lastAppliedRef.current = {
156
+ schemeId: currentScheme.id,
157
+ configHash: schemeConfigHash
158
+ };
123
159
  return;
124
160
  }
125
161
 
@@ -143,7 +179,7 @@ var ArrayTableInner = observer(function (props) {
143
179
  // 记录本次应用的配置哈希
144
180
  lastAppliedRef.current = {
145
181
  schemeId: currentScheme.id,
146
- configHash: configHash
182
+ configHash: schemeConfigHash
147
183
  };
148
184
  };
149
185
 
@@ -182,7 +218,7 @@ var ArrayTableInner = observer(function (props) {
182
218
  return function () {
183
219
  cancelAnimationFrame(rafId);
184
220
  };
185
- }, [props.gridKey, gridApiState, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.updatedAt]);
221
+ }, [props.gridKey, gridApiState, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id]);
186
222
 
187
223
  //@ts-ignore
188
224
  if (columns.length > 0) {