@nokecy/qc-ui 1.1.8 → 1.1.10

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.
@@ -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;