@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.
@@ -83,6 +83,39 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
83
83
  }
84
84
  }
85
85
 
86
+ /**
87
+ * 【修复】将 JavaScript 时间戳转换为 ISO 字符串
88
+ *
89
+ * JavaScript Date.now() 返回毫秒时间戳(如 1699344567890)
90
+ * .NET DateTimeOffset 需要 ISO 8601 格式字符串(如 "2023-11-07T08:36:07.890Z")
91
+ *
92
+ * @param timestamp 毫秒时间戳
93
+ * @returns ISO 8601 格式字符串
94
+ */
95
+ }, {
96
+ key: "toIsoString",
97
+ value: function toIsoString(timestamp) {
98
+ if (timestamp === undefined || timestamp === null) {
99
+ return undefined;
100
+ }
101
+ return new Date(timestamp).toISOString();
102
+ }
103
+
104
+ /**
105
+ * 【修复】将 ISO 字符串转换为 JavaScript 时间戳
106
+ *
107
+ * @param isoString ISO 8601 格式字符串
108
+ * @returns 毫秒时间戳
109
+ */
110
+ }, {
111
+ key: "fromIsoString",
112
+ value: function fromIsoString(isoString) {
113
+ if (!isoString) {
114
+ return undefined;
115
+ }
116
+ return new Date(isoString).getTime();
117
+ }
118
+
86
119
  /**
87
120
  * 生成请求头
88
121
  */
@@ -257,9 +290,11 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
257
290
  _context3.prev = 0;
258
291
  this.log("\u4FDD\u5B58\u5217\u65B9\u6848: ".concat(gridId, " - ").concat(scheme.name));
259
292
 
260
- // 将 columnConfig 转换为 JSON 字符串
293
+ // 【修复】将时间戳转换为 ISO 字符串,并将 columnConfig 转换为 JSON 字符串
261
294
  schemeForBackend = _objectSpread(_objectSpread({}, scheme), {}, {
262
- columnConfig: JSON.stringify(scheme.columnConfig)
295
+ columnConfig: JSON.stringify(scheme.columnConfig),
296
+ createdAt: this.toIsoString(scheme.createdAt),
297
+ updatedAt: this.toIsoString(scheme.updatedAt)
263
298
  });
264
299
  url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/save-column-scheme");
265
300
  _context3.next = 6;
@@ -278,10 +313,20 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
278
313
  }
279
314
  throw new Error(response.message || '保存失败');
280
315
  case 9:
281
- // 将返回的 columnConfig 从字符串解析为对象数组
316
+ // 【修复】将返回的数据转换回前端格式
282
317
  savedScheme = response.scheme;
283
- if (savedScheme && typeof savedScheme.columnConfig === 'string') {
284
- savedScheme.columnConfig = JSON.parse(savedScheme.columnConfig);
318
+ if (savedScheme) {
319
+ // 解析 columnConfig
320
+ if (typeof savedScheme.columnConfig === 'string') {
321
+ savedScheme.columnConfig = JSON.parse(savedScheme.columnConfig);
322
+ }
323
+ // 将 ISO 字符串转换回时间戳
324
+ if (savedScheme.createdAt) {
325
+ savedScheme.createdAt = this.fromIsoString(savedScheme.createdAt);
326
+ }
327
+ if (savedScheme.updatedAt) {
328
+ savedScheme.updatedAt = this.fromIsoString(savedScheme.updatedAt);
329
+ }
285
330
  }
286
331
  this.log('保存成功', savedScheme);
287
332
  return _context3.abrupt("return", savedScheme);
@@ -52,10 +52,26 @@ var ArrayTableInner = observer(function (props) {
52
52
  gridApiState = _useState4[0],
53
53
  setGridApiState = _useState4[1];
54
54
  var dataSource = Array.isArray(field.value) ? field.value.slice() : [];
55
- var sources = useArrayTableSources();
56
- var actions = useArrayTableActions();
57
- var columns = useArrayTableColumns(dataSource, field, sources);
58
55
  var schema = useFieldSchema();
56
+
57
+ // 获取 sources(每次渲染都会重新计算,返回新的数组引用)
58
+ var rawSources = useArrayTableSources();
59
+ var actions = useArrayTableActions();
60
+
61
+ // 【关键修复】使用 useMemo 基于内容稳定 sources 引用
62
+ // 通过 JSON.stringify 比较内容,只有内容真正变化时才返回新引用
63
+ var sourcesKey = useMemo(function () {
64
+ return JSON.stringify(rawSources.map(function (s) {
65
+ return {
66
+ name: s.name,
67
+ display: s.display
68
+ // 只提取稳定的标识信息
69
+ };
70
+ }));
71
+ }, [rawSources]);
72
+ var sources = useMemo(function () {
73
+ return rawSources;
74
+ }, [sourcesKey]);
59
75
  //@ts-ignore
60
76
  var onAdd = props.onAdd,
61
77
  onCopy = props.onCopy,
@@ -90,8 +106,27 @@ var ArrayTableInner = observer(function (props) {
90
106
  });
91
107
  }, [props.gridKey, currentSchemes, columnSchemes]);
92
108
 
93
- // 使用 ref 记录上次应用的方案 ID,避免重复应用
94
- var lastAppliedSchemeIdRef = useRef(null);
109
+ // 使用 ref 记录上次应用的方案状态,避免重复应用
110
+ var lastAppliedSchemeRef = useRef({
111
+ id: null,
112
+ updatedAt: null
113
+ });
114
+
115
+ /**
116
+ * 【关键优化】使用 useMemo 稳定 columnDefs 引用
117
+ * 只在基础列定义(sources)变化时更新,避免数据变化导致列重置
118
+ * 列的状态(宽度、顺序、隐藏等)由方案通过 applyColumnState 控制,不需要通过 columnDefs 传递
119
+ */
120
+ var stableColumnDefs = useMemo(function () {
121
+ // 只依赖 sources,不依赖 dataSource 和 field.value
122
+ var cols = useArrayTableColumns([], field, sources);
123
+ //@ts-ignore
124
+ if (cols.length > 0 && props.onRowDrag) {
125
+ //@ts-ignore
126
+ cols[0].rowDrag = true;
127
+ }
128
+ return cols;
129
+ }, [sources, props.onRowDrag]); // 移除 field 依赖,避免数据变化时重新计算
95
130
 
96
131
  /**
97
132
  * 方案自动加载
@@ -106,10 +141,14 @@ var ArrayTableInner = observer(function (props) {
106
141
  if (!props.gridKey || !gridApiState || !currentScheme) return;
107
142
  if (!currentScheme.columnConfig || currentScheme.columnConfig.length === 0) return;
108
143
 
109
- // 如果是同一个方案,跳过应用(避免重复应用)
110
- if (currentScheme.id === lastAppliedSchemeIdRef.current) {
144
+ // 【关键修复】检查方案是否真正变化(比对 ID 和 updatedAt)
145
+ // 只有当方案 ID 变化,或者同一方案但 updatedAt 变化时,才重新应用
146
+ var isSameScheme = currentScheme.id === lastAppliedSchemeRef.current.id;
147
+ var isSameVersion = currentScheme.updatedAt === lastAppliedSchemeRef.current.updatedAt;
148
+ if (isSameScheme && isSameVersion) {
111
149
  return;
112
150
  }
151
+ if (isSameScheme && !isSameVersion) {}
113
152
  // 使用 Promise 链确保顺序执行,避免竞态条件
114
153
  var cancelled = false;
115
154
  Promise.resolve().then(function () {
@@ -155,8 +194,11 @@ var ArrayTableInner = observer(function (props) {
155
194
  gridApiState.setFilterModel(currentScheme.filterModel);
156
195
  }
157
196
 
158
- // 记录已应用的方案 ID
159
- lastAppliedSchemeIdRef.current = currentScheme.id;
197
+ // 【关键修复】记录已应用的方案状态(ID + updatedAt)
198
+ lastAppliedSchemeRef.current = {
199
+ id: currentScheme.id,
200
+ updatedAt: currentScheme.updatedAt
201
+ };
160
202
  }).catch(function (error) {
161
203
  if (!cancelled) {
162
204
  console.error('[ArrayTable] 应用方案失败:', error);
@@ -167,13 +209,7 @@ var ArrayTableInner = observer(function (props) {
167
209
  return function () {
168
210
  cancelled = true;
169
211
  };
170
- }, [props.gridKey, gridApiState, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id]);
171
-
172
- //@ts-ignore
173
- if (columns.length > 0) {
174
- //@ts-ignore
175
- columns[0].rowDrag = props.onRowDrag ? true : false;
176
- }
212
+ }, [props.gridKey, gridApiState, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.updatedAt]);
177
213
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
178
214
  ref: ref,
179
215
  style: {
@@ -220,7 +256,7 @@ var ArrayTableInner = observer(function (props) {
220
256
  gridKey: props.gridKey,
221
257
  gridApi: apiRef.current,
222
258
  gridApiState: gridApiState,
223
- allColDefs: columns,
259
+ allColDefs: stableColumnDefs,
224
260
  showQueryScheme: false
225
261
  })), /*#__PURE__*/React.createElement("div", {
226
262
  style: {
@@ -242,7 +278,9 @@ var ArrayTableInner = observer(function (props) {
242
278
  suppressCopySingleCellRanges: true,
243
279
  enterNavigatesVertically: true,
244
280
  enterNavigatesVerticallyAfterEdit: true,
245
- columnHoverHighlight: true
281
+ columnHoverHighlight: true,
282
+ // 【关键修复】保持用户设置的列顺序
283
+ maintainColumnOrder: true
246
284
  },
247
285
  onCellKeyDown: handleCellKeyDown,
248
286
  onCellClicked: function onCellClicked(event) {
@@ -299,7 +337,7 @@ var ArrayTableInner = observer(function (props) {
299
337
  ,
300
338
  rowHeight: 38,
301
339
  pagination: false,
302
- columnDefs: columns,
340
+ columnDefs: stableColumnDefs,
303
341
  rowData: dataSource
304
342
  })), sources.map(function (column, key) {
305
343
  //专门用来承接对Column的状态管理
@@ -1,9 +1,12 @@
1
1
  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); }
2
+ var _excluded = ["pinned", "width", "hide", "sort", "sortIndex"];
2
3
  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; }
3
4
  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; }
4
5
  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; }
5
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
7
  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); }
8
+ 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; }
9
+ 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; }
7
10
  import React from 'react';
8
11
  import { useField, useFieldSchema, RecursionField } from '@formily/react';
9
12
  import { isArr } from '@formily/shared';
@@ -99,12 +102,16 @@ var useArrayTableActions = function useArrayTableActions() {
99
102
  return schema.properties ? parseSources(schema.properties['actions'] || {}) : [];
100
103
  };
101
104
  var AgField = function AgField(_ref) {
105
+ var _ref2, _node$rowIndex;
102
106
  var value = _ref.value,
103
107
  record = _ref.data,
104
108
  dataSource = _ref.dataSource,
105
109
  schema = _ref.schema,
106
- field = _ref.field;
107
- var index = dataSource === null || dataSource === void 0 ? void 0 : dataSource.indexOf(record);
110
+ field = _ref.field,
111
+ node = _ref.node;
112
+ // 【修复】优先使用 AG-Grid 的 node.rowIndex,避免依赖 dataSource
113
+ // 这样即使 columnDefs 中的 dataSource 是空数组,也能正确获取索引
114
+ 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;
108
115
  var children =
109
116
  /*#__PURE__*/
110
117
  //@ts-ignore
@@ -124,14 +131,23 @@ var AgField = function AgField(_ref) {
124
131
  return children;
125
132
  };
126
133
  var useArrayTableColumns = function useArrayTableColumns(dataSource, field, sources) {
127
- return sources.reduce(function (buf, _ref2, key) {
128
- var name = _ref2.name,
129
- columnProps = _ref2.columnProps,
130
- schema = _ref2.schema,
131
- display = _ref2.display;
134
+ return sources.reduce(function (buf, _ref3, key) {
135
+ var name = _ref3.name,
136
+ columnProps = _ref3.columnProps,
137
+ schema = _ref3.schema,
138
+ display = _ref3.display;
132
139
  if (display && display !== 'visible') return buf;
133
140
  if (!isColumnComponent(schema)) return buf;
134
- return buf.concat(_objectSpread(_objectSpread({}, columnProps), {}, {
141
+
142
+ // 【关键修复】移除可能干扰用户列状态的属性
143
+ // 这些属性应该由用户通过列配置(applyColumnState)控制,而不是从 columnDefs 继承
144
+ var pinned = columnProps.pinned,
145
+ width = columnProps.width,
146
+ hide = columnProps.hide,
147
+ sort = columnProps.sort,
148
+ sortIndex = columnProps.sortIndex,
149
+ safeColumnProps = _objectWithoutProperties(columnProps, _excluded);
150
+ return buf.concat(_objectSpread(_objectSpread({}, safeColumnProps), {}, {
135
151
  //@ts-ignore
136
152
  headerName: columnProps.headerName || columnProps.title,
137
153
  field: name,
@@ -173,7 +173,7 @@ export declare const createSelectField: (title: string, options: {
173
173
  export declare const createCascaderField: (title: string, options: any[], config?: {
174
174
  required?: boolean | undefined;
175
175
  changeOnSelect?: boolean | undefined;
176
- expandTrigger?: "click" | "hover" | undefined;
176
+ expandTrigger?: "hover" | "click" | undefined;
177
177
  placeholder?: string | undefined;
178
178
  }) => {
179
179
  type: string;
@@ -187,7 +187,7 @@ export declare const createCascaderField: (title: string, options: any[], config
187
187
  };
188
188
  options: any[];
189
189
  changeOnSelect: boolean;
190
- expandTrigger: "click" | "hover";
190
+ expandTrigger: "hover" | "click";
191
191
  };
192
192
  };
193
193
  export default withStandardForm;