@nokecy/qc-ui 1.1.26 → 1.1.27

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.
@@ -1293,9 +1293,8 @@ function AgGridPlus(props) {
1293
1293
  gridApi: apiRef.current,
1294
1294
  onSaveColumnState: onColumnStateChanged
1295
1295
  }),
1296
- /*#__PURE__*/
1297
- // 高级搜索(图标风格,位于设置右边)
1298
- _react.default.createElement(_antd.Popover, {
1296
+ // 高级搜索(图标风格,位于设置右边)- 遵循 search 属性
1297
+ search !== false ? /*#__PURE__*/_react.default.createElement(_antd.Popover, {
1299
1298
  key: "advanced-search-setting",
1300
1299
  content: /*#__PURE__*/_react.default.createElement("div", {
1301
1300
  style: {
@@ -1364,7 +1363,7 @@ function AgGridPlus(props) {
1364
1363
  fontSize: 16,
1365
1364
  cursor: "pointer"
1366
1365
  }
1367
- }, /*#__PURE__*/_react.default.createElement(_icons.FilterOutlined, null))))]
1366
+ }, /*#__PURE__*/_react.default.createElement(_icons.FilterOutlined, null)))) : null].filter(Boolean)
1368
1367
  }), /*#__PURE__*/_react.default.createElement(_agGridReact.AgGridReact, _extends({
1369
1368
  theme: _theme.agGridTheme
1370
1369
  }, rest, {
@@ -167,6 +167,130 @@ var ColumnSetting = function ColumnSetting(_ref) {
167
167
  });
168
168
  }, [originalColumnDefs]);
169
169
 
170
+ /**
171
+ * 合并代码中新增的列到配置中
172
+ * 场景:用户保存列配置后,开发者在代码中新增了列,这些列应该显示在配置表格中
173
+ * 【增强】按照原始定义的顺序插入新增列,保留原始位置
174
+ */
175
+ var mergeNewColumns = (0, _react.useCallback)(function (config, originalDefs) {
176
+ if (!originalDefs || originalDefs.length === 0) {
177
+ return config;
178
+ }
179
+
180
+ // 创建 field -> config item 的映射(用于快速查找已保存的列配置)
181
+ var configByField = new Map();
182
+ config.filter(function (item) {
183
+ return item.type === 'column' && item.field;
184
+ }).forEach(function (item) {
185
+ configByField.set(item.field, item);
186
+ });
187
+
188
+ // 创建 groupId -> config item 的映射(用于快速查找已保存的分组配置)
189
+ var configByGroupId = new Map();
190
+ config.filter(function (item) {
191
+ return item.type === 'group' && item.groupId;
192
+ }).forEach(function (item) {
193
+ configByGroupId.set(item.groupId, item);
194
+ });
195
+ var result = [];
196
+ var order = 0;
197
+ var hasNewColumns = false;
198
+
199
+ /**
200
+ * 递归处理列定义,按原始顺序构建结果
201
+ * @param defs 列定义数组
202
+ * @param level 当前层级
203
+ * @param parentId 父节点 ID(如果有)
204
+ */
205
+ var processDefsInOrder = function processDefsInOrder(defs, level, parentId) {
206
+ var _iterator2 = _createForOfIteratorHelper(defs),
207
+ _step2;
208
+ try {
209
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
210
+ var def = _step2.value;
211
+ // 检查是否是分组
212
+ if ('children' in def && def.children && def.children.length > 0) {
213
+ var groupDef = def;
214
+ var groupIdValue = groupDef.groupId || groupDef.field || (0, _columnGroupUtils.generateId)();
215
+
216
+ // 查找已保存的分组配置
217
+ var existingGroup = configByGroupId.get(groupIdValue);
218
+ var groupItem = void 0;
219
+ if (existingGroup) {
220
+ // 使用已保存的分组配置,但更新 order 和 parentId
221
+ groupItem = _objectSpread(_objectSpread({}, existingGroup), {}, {
222
+ order: order++,
223
+ parentId: parentId,
224
+ level: level
225
+ });
226
+ } else {
227
+ // 新分组
228
+ hasNewColumns = true;
229
+ groupItem = {
230
+ id: (0, _columnGroupUtils.generateId)(),
231
+ type: 'group',
232
+ parentId: parentId,
233
+ level: level,
234
+ order: order++,
235
+ headerName: groupDef.headerName || '未命名分组',
236
+ originalHeaderName: groupDef.headerName || '未命名分组',
237
+ groupId: groupIdValue,
238
+ marryChildren: groupDef.marryChildren
239
+ };
240
+ }
241
+ result.push(groupItem);
242
+
243
+ // 递归处理子节点
244
+ processDefsInOrder(groupDef.children, level + 1, groupItem.id);
245
+ } else {
246
+ // 普通列
247
+ var colDef = def;
248
+ if (!colDef.field) continue;
249
+
250
+ // 查找已保存的列配置
251
+ var existingCol = configByField.get(colDef.field);
252
+ if (existingCol) {
253
+ // 使用已保存的列配置,但更新 order 和 parentId
254
+ result.push(_objectSpread(_objectSpread({}, existingCol), {}, {
255
+ order: order++,
256
+ parentId: parentId,
257
+ level: level
258
+ }));
259
+ } else {
260
+ // 新列
261
+ hasNewColumns = true;
262
+ result.push({
263
+ id: (0, _columnGroupUtils.generateId)(),
264
+ type: 'column',
265
+ parentId: parentId,
266
+ level: level,
267
+ order: order++,
268
+ field: colDef.field,
269
+ headerName: colDef.headerName || colDef.field || '未命名列',
270
+ originalHeaderName: colDef.headerName || colDef.field || '未命名列',
271
+ width: colDef.width,
272
+ hide: colDef.hide,
273
+ pinned: colDef.pinned === null || colDef.pinned === true || colDef.pinned === false ? 'notPinned' : colDef.pinned,
274
+ cellClass: colDef.cellClass,
275
+ flex: colDef.flex,
276
+ suppressHeaderFilterButton: colDef.suppressHeaderFilterButton
277
+ });
278
+ }
279
+ }
280
+ }
281
+ } catch (err) {
282
+ _iterator2.e(err);
283
+ } finally {
284
+ _iterator2.f();
285
+ }
286
+ };
287
+
288
+ // 从根级别开始处理
289
+ processDefsInOrder(originalDefs, 0);
290
+ if (hasNewColumns) {}
291
+ return result;
292
+ }, []);
293
+
170
294
  /**
171
295
  * 获取列数据 - 将 Grid 的列定义转换为扁平化配置
172
296
  * 新版本使用树形结构,兼容旧版本的 groupName 结构
@@ -175,7 +299,10 @@ var ColumnSetting = function ColumnSetting(_ref) {
175
299
  // 优先使用当前方案中保存的完整列配置(包含分组结构)
176
300
  if (currentScheme !== null && currentScheme !== void 0 && currentScheme.columnConfig) {
177
301
  // 【修复】修正 originalHeaderName,确保使用 initialColumnDefs 中的原始值
178
- return fixOriginalHeaderName(currentScheme.columnConfig);
302
+ var config = fixOriginalHeaderName(currentScheme.columnConfig);
303
+ // 【修复】检测并追加代码中新增的列到配置末尾
304
+ config = mergeNewColumns(config, originalColumnDefs);
305
+ return config;
179
306
  }
180
307
 
181
308
  // 如果方案中没有 columnConfig,则从 Grid 读取
@@ -215,7 +342,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
215
342
  return item;
216
343
  });
217
344
  return flatConfig;
218
- }, [gridApi, currentScheme, fixOriginalHeaderName, originalColumnDefs]);
345
+ }, [gridApi, currentScheme, fixOriginalHeaderName, originalColumnDefs, mergeNewColumns]);
219
346
 
220
347
  // 创建 Formily Form 实例
221
348
  var form = (0, _react.useMemo)(function () {
@@ -589,7 +716,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
589
716
  // 设置默认方案
590
717
  var handleSetDefault = (0, _react.useCallback)( /*#__PURE__*/function () {
591
718
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schemeId) {
592
- var scheme, _iterator2, _step2, s;
719
+ var scheme, _iterator3, _step3, s;
593
720
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
594
721
  while (1) switch (_context4.prev = _context4.next) {
595
722
  case 0:
@@ -602,15 +729,15 @@ var ColumnSetting = function ColumnSetting(_ref) {
602
729
  break;
603
730
  }
604
731
  // 将其他方案设为非默认
605
- _iterator2 = _createForOfIteratorHelper(schemes);
732
+ _iterator3 = _createForOfIteratorHelper(schemes);
606
733
  _context4.prev = 4;
607
- _iterator2.s();
734
+ _iterator3.s();
608
735
  case 6:
609
- if ((_step2 = _iterator2.n()).done) {
736
+ if ((_step3 = _iterator3.n()).done) {
610
737
  _context4.next = 13;
611
738
  break;
612
739
  }
613
- s = _step2.value;
740
+ s = _step3.value;
614
741
  if (!(s.isDefault && s.id !== schemeId)) {
615
742
  _context4.next = 11;
616
743
  break;
@@ -628,10 +755,10 @@ var ColumnSetting = function ColumnSetting(_ref) {
628
755
  case 15:
629
756
  _context4.prev = 15;
630
757
  _context4.t0 = _context4["catch"](4);
631
- _iterator2.e(_context4.t0);
758
+ _iterator3.e(_context4.t0);
632
759
  case 18:
633
760
  _context4.prev = 18;
634
- _iterator2.f();
761
+ _iterator3.f();
635
762
  return _context4.finish(18);
636
763
  case 21:
637
764
  _context4.next = 23;
@@ -1285,9 +1285,8 @@ function AgGridPlus(props) {
1285
1285
  gridApi: apiRef.current,
1286
1286
  onSaveColumnState: onColumnStateChanged
1287
1287
  }),
1288
- /*#__PURE__*/
1289
- // 高级搜索(图标风格,位于设置右边)
1290
- React.createElement(Popover, {
1288
+ // 高级搜索(图标风格,位于设置右边)- 遵循 search 属性
1289
+ search !== false ? /*#__PURE__*/React.createElement(Popover, {
1291
1290
  key: "advanced-search-setting",
1292
1291
  content: /*#__PURE__*/React.createElement("div", {
1293
1292
  style: {
@@ -1356,7 +1355,7 @@ function AgGridPlus(props) {
1356
1355
  fontSize: 16,
1357
1356
  cursor: "pointer"
1358
1357
  }
1359
- }, /*#__PURE__*/React.createElement(FilterOutlined, null))))]
1358
+ }, /*#__PURE__*/React.createElement(FilterOutlined, null)))) : null].filter(Boolean)
1360
1359
  }), /*#__PURE__*/React.createElement(AgGridReact, _extends({
1361
1360
  theme: agGridTheme
1362
1361
  }, rest, {
@@ -26,7 +26,7 @@ import { AgGridReact } from 'ag-grid-react';
26
26
  import { agGridTheme } from "../theme";
27
27
  import { localeText } from "../locale";
28
28
  import { createForm, onFormInit } from '@formily/core';
29
- import { gridStateToFlatConfig, flatConfigToGridState, flatConfigToColumnState, isOldSchemeData, migrateOldScheme } from "./columnGroupUtils";
29
+ import { gridStateToFlatConfig, flatConfigToGridState, flatConfigToColumnState, isOldSchemeData, migrateOldScheme, generateId } from "./columnGroupUtils";
30
30
  import ColumnConfigTable from "./ColumnConfigTable";
31
31
  import DraggableModal from "../../draggableModal";
32
32
  import { useGridSchemes } from "../context/useSchemeManager";
@@ -158,6 +158,130 @@ var ColumnSetting = function ColumnSetting(_ref) {
158
158
  });
159
159
  }, [originalColumnDefs]);
160
160
 
161
+ /**
162
+ * 合并代码中新增的列到配置中
163
+ * 场景:用户保存列配置后,开发者在代码中新增了列,这些列应该显示在配置表格中
164
+ * 【增强】按照原始定义的顺序插入新增列,保留原始位置
165
+ */
166
+ var mergeNewColumns = useCallback(function (config, originalDefs) {
167
+ if (!originalDefs || originalDefs.length === 0) {
168
+ return config;
169
+ }
170
+
171
+ // 创建 field -> config item 的映射(用于快速查找已保存的列配置)
172
+ var configByField = new Map();
173
+ config.filter(function (item) {
174
+ return item.type === 'column' && item.field;
175
+ }).forEach(function (item) {
176
+ configByField.set(item.field, item);
177
+ });
178
+
179
+ // 创建 groupId -> config item 的映射(用于快速查找已保存的分组配置)
180
+ var configByGroupId = new Map();
181
+ config.filter(function (item) {
182
+ return item.type === 'group' && item.groupId;
183
+ }).forEach(function (item) {
184
+ configByGroupId.set(item.groupId, item);
185
+ });
186
+ var result = [];
187
+ var order = 0;
188
+ var hasNewColumns = false;
189
+
190
+ /**
191
+ * 递归处理列定义,按原始顺序构建结果
192
+ * @param defs 列定义数组
193
+ * @param level 当前层级
194
+ * @param parentId 父节点 ID(如果有)
195
+ */
196
+ var processDefsInOrder = function processDefsInOrder(defs, level, parentId) {
197
+ var _iterator2 = _createForOfIteratorHelper(defs),
198
+ _step2;
199
+ try {
200
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
201
+ var def = _step2.value;
202
+ // 检查是否是分组
203
+ if ('children' in def && def.children && def.children.length > 0) {
204
+ var groupDef = def;
205
+ var groupIdValue = groupDef.groupId || groupDef.field || generateId();
206
+
207
+ // 查找已保存的分组配置
208
+ var existingGroup = configByGroupId.get(groupIdValue);
209
+ var groupItem = void 0;
210
+ if (existingGroup) {
211
+ // 使用已保存的分组配置,但更新 order 和 parentId
212
+ groupItem = _objectSpread(_objectSpread({}, existingGroup), {}, {
213
+ order: order++,
214
+ parentId: parentId,
215
+ level: level
216
+ });
217
+ } else {
218
+ // 新分组
219
+ hasNewColumns = true;
220
+ groupItem = {
221
+ id: generateId(),
222
+ type: 'group',
223
+ parentId: parentId,
224
+ level: level,
225
+ order: order++,
226
+ headerName: groupDef.headerName || '未命名分组',
227
+ originalHeaderName: groupDef.headerName || '未命名分组',
228
+ groupId: groupIdValue,
229
+ marryChildren: groupDef.marryChildren
230
+ };
231
+ }
232
+ result.push(groupItem);
233
+
234
+ // 递归处理子节点
235
+ processDefsInOrder(groupDef.children, level + 1, groupItem.id);
236
+ } else {
237
+ // 普通列
238
+ var colDef = def;
239
+ if (!colDef.field) continue;
240
+
241
+ // 查找已保存的列配置
242
+ var existingCol = configByField.get(colDef.field);
243
+ if (existingCol) {
244
+ // 使用已保存的列配置,但更新 order 和 parentId
245
+ result.push(_objectSpread(_objectSpread({}, existingCol), {}, {
246
+ order: order++,
247
+ parentId: parentId,
248
+ level: level
249
+ }));
250
+ } else {
251
+ // 新列
252
+ hasNewColumns = true;
253
+ result.push({
254
+ id: generateId(),
255
+ type: 'column',
256
+ parentId: parentId,
257
+ level: level,
258
+ order: order++,
259
+ field: colDef.field,
260
+ headerName: colDef.headerName || colDef.field || '未命名列',
261
+ originalHeaderName: colDef.headerName || colDef.field || '未命名列',
262
+ width: colDef.width,
263
+ hide: colDef.hide,
264
+ pinned: colDef.pinned === null || colDef.pinned === true || colDef.pinned === false ? 'notPinned' : colDef.pinned,
265
+ cellClass: colDef.cellClass,
266
+ flex: colDef.flex,
267
+ suppressHeaderFilterButton: colDef.suppressHeaderFilterButton
268
+ });
269
+ }
270
+ }
271
+ }
272
+ } catch (err) {
273
+ _iterator2.e(err);
274
+ } finally {
275
+ _iterator2.f();
276
+ }
277
+ };
278
+
279
+ // 从根级别开始处理
280
+ processDefsInOrder(originalDefs, 0);
281
+ if (hasNewColumns) {}
282
+ return result;
283
+ }, []);
284
+
161
285
  /**
162
286
  * 获取列数据 - 将 Grid 的列定义转换为扁平化配置
163
287
  * 新版本使用树形结构,兼容旧版本的 groupName 结构
@@ -166,7 +290,10 @@ var ColumnSetting = function ColumnSetting(_ref) {
166
290
  // 优先使用当前方案中保存的完整列配置(包含分组结构)
167
291
  if (currentScheme !== null && currentScheme !== void 0 && currentScheme.columnConfig) {
168
292
  // 【修复】修正 originalHeaderName,确保使用 initialColumnDefs 中的原始值
169
- return fixOriginalHeaderName(currentScheme.columnConfig);
293
+ var config = fixOriginalHeaderName(currentScheme.columnConfig);
294
+ // 【修复】检测并追加代码中新增的列到配置末尾
295
+ config = mergeNewColumns(config, originalColumnDefs);
296
+ return config;
170
297
  }
171
298
 
172
299
  // 如果方案中没有 columnConfig,则从 Grid 读取
@@ -206,7 +333,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
206
333
  return item;
207
334
  });
208
335
  return flatConfig;
209
- }, [gridApi, currentScheme, fixOriginalHeaderName, originalColumnDefs]);
336
+ }, [gridApi, currentScheme, fixOriginalHeaderName, originalColumnDefs, mergeNewColumns]);
210
337
 
211
338
  // 创建 Formily Form 实例
212
339
  var form = useMemo(function () {
@@ -580,7 +707,7 @@ var ColumnSetting = function ColumnSetting(_ref) {
580
707
  // 设置默认方案
581
708
  var handleSetDefault = useCallback( /*#__PURE__*/function () {
582
709
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schemeId) {
583
- var scheme, _iterator2, _step2, s;
710
+ var scheme, _iterator3, _step3, s;
584
711
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
585
712
  while (1) switch (_context4.prev = _context4.next) {
586
713
  case 0:
@@ -593,15 +720,15 @@ var ColumnSetting = function ColumnSetting(_ref) {
593
720
  break;
594
721
  }
595
722
  // 将其他方案设为非默认
596
- _iterator2 = _createForOfIteratorHelper(schemes);
723
+ _iterator3 = _createForOfIteratorHelper(schemes);
597
724
  _context4.prev = 4;
598
- _iterator2.s();
725
+ _iterator3.s();
599
726
  case 6:
600
- if ((_step2 = _iterator2.n()).done) {
727
+ if ((_step3 = _iterator3.n()).done) {
601
728
  _context4.next = 13;
602
729
  break;
603
730
  }
604
- s = _step2.value;
731
+ s = _step3.value;
605
732
  if (!(s.isDefault && s.id !== schemeId)) {
606
733
  _context4.next = 11;
607
734
  break;
@@ -619,10 +746,10 @@ var ColumnSetting = function ColumnSetting(_ref) {
619
746
  case 15:
620
747
  _context4.prev = 15;
621
748
  _context4.t0 = _context4["catch"](4);
622
- _iterator2.e(_context4.t0);
749
+ _iterator3.e(_context4.t0);
623
750
  case 18:
624
751
  _context4.prev = 18;
625
- _iterator2.f();
752
+ _iterator3.f();
626
753
  return _context4.finish(18);
627
754
  case 21:
628
755
  _context4.next = 23;