@nokecy/qc-ui 1.1.11 → 1.1.13
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.
- package/dist/cjs/ag-grid-plus/shared/storage/backendApiAdapter.d.ts +17 -0
- package/dist/cjs/ag-grid-plus/shared/storage/backendApiAdapter.js +50 -5
- package/dist/cjs/array-table/index.js +65 -108
- package/dist/esm/ag-grid-plus/shared/storage/backendApiAdapter.d.ts +17 -0
- package/dist/esm/ag-grid-plus/shared/storage/backendApiAdapter.js +50 -5
- package/dist/esm/array-table/index.js +66 -109
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
11
11
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
12
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
-
import React, { Fragment, useEffect, useRef, useState, useMemo
|
|
14
|
+
import React, { Fragment, useEffect, useRef, useState, useMemo } from "react";
|
|
15
15
|
import { AgGridReact } from "ag-grid-react";
|
|
16
16
|
import { useField, observer, RecursionField } from "@formily/react";
|
|
17
17
|
import { useFieldSchema } from "@formily/react";
|
|
@@ -24,11 +24,11 @@ import ArrayAddBtn from "./arrayAddBtn";
|
|
|
24
24
|
import PreviewArrayTable from "./preview";
|
|
25
25
|
import { Space } from "antd";
|
|
26
26
|
import Setting from "../ag-grid-plus/setting";
|
|
27
|
-
import { GridPlusContext } from "../ag-grid-plus/context/gridContext";
|
|
28
27
|
import { flatConfigToColumnState, flatConfigToGridState } from "../ag-grid-plus/setting/columnGroupUtils";
|
|
29
28
|
|
|
30
29
|
// 导入 AG-Grid v33 主题
|
|
31
30
|
import { agGridTheme } from "../ag-grid-plus/theme";
|
|
31
|
+
import { useGridSchemes } from "../ag-grid-plus";
|
|
32
32
|
|
|
33
33
|
//@ts-ignore
|
|
34
34
|
var ArrayTableInner = observer(function (props) {
|
|
@@ -73,11 +73,10 @@ var ArrayTableInner = observer(function (props) {
|
|
|
73
73
|
handleRowDragMove = _useRowDrag.handleRowDragMove;
|
|
74
74
|
|
|
75
75
|
// 直接使用 Context 获取方案管理状态
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
currentSchemes =
|
|
80
|
-
columnSchemes = _ref.columnSchemes;
|
|
76
|
+
var _useGridSchemes = useGridSchemes(),
|
|
77
|
+
columnSchemes = _useGridSchemes.columnSchemes,
|
|
78
|
+
querySchemes = _useGridSchemes.querySchemes,
|
|
79
|
+
currentSchemes = _useGridSchemes.currentSchemes;
|
|
81
80
|
|
|
82
81
|
// 获取当前表格的激活方案
|
|
83
82
|
var currentScheme = useMemo(function () {
|
|
@@ -91,134 +90,94 @@ var ArrayTableInner = observer(function (props) {
|
|
|
91
90
|
});
|
|
92
91
|
}, [props.gridKey, currentSchemes, columnSchemes]);
|
|
93
92
|
|
|
94
|
-
// 使用 ref
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
// 使用 ref 记录上次应用的方案状态,避免重复应用
|
|
94
|
+
var lastAppliedSchemeRef = useRef({
|
|
95
|
+
id: null,
|
|
96
|
+
updatedAt: null
|
|
98
97
|
});
|
|
99
98
|
|
|
100
99
|
/**
|
|
101
|
-
*
|
|
100
|
+
* 方案自动加载
|
|
102
101
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
102
|
+
* 参考 ag-gridPlus 优化方案:
|
|
103
|
+
* 1. 使用 Promise 链确保顺序执行,避免竞态条件
|
|
104
|
+
* 2. 使用双重 RAF 确保渲染完成
|
|
105
|
+
* 3. 完整的错误处理和清理机制
|
|
107
106
|
*/
|
|
108
107
|
useEffect(function () {
|
|
109
108
|
// 检查必要条件
|
|
110
109
|
if (!props.gridKey || !gridApiState || !currentScheme) return;
|
|
111
110
|
if (!currentScheme.columnConfig || currentScheme.columnConfig.length === 0) return;
|
|
112
111
|
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
})
|
|
126
|
-
});
|
|
112
|
+
// 【关键修复】检查方案是否真正变化(比对 ID 和 updatedAt)
|
|
113
|
+
// 只有当方案 ID 变化,或者同一方案但 updatedAt 变化时,才重新应用
|
|
114
|
+
var isSameScheme = currentScheme.id === lastAppliedSchemeRef.current.id;
|
|
115
|
+
var isSameVersion = currentScheme.updatedAt === lastAppliedSchemeRef.current.updatedAt;
|
|
116
|
+
if (isSameScheme && isSameVersion) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (isSameScheme && !isSameVersion) {}
|
|
120
|
+
// 使用 Promise 链确保顺序执行,避免竞态条件
|
|
121
|
+
var cancelled = false;
|
|
122
|
+
Promise.resolve().then(function () {
|
|
123
|
+
if (cancelled || !gridApiState) return;
|
|
127
124
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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;
|
|
125
|
+
// 1. 检查是否包含分组配置
|
|
126
|
+
var hasGroups = currentScheme.columnConfig.some(function (item) {
|
|
127
|
+
return item.type === 'group';
|
|
128
|
+
});
|
|
140
129
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
isGridStateSameAsScheme = false;
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
130
|
+
// 如果包含分组,先更新 columnDefs
|
|
131
|
+
if (hasGroups) {
|
|
132
|
+
var gridColumnDefs = flatConfigToGridState(currentScheme.columnConfig);
|
|
133
|
+
gridApiState.setGridOption('columnDefs', gridColumnDefs);
|
|
148
134
|
}
|
|
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
|
-
};
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
135
|
|
|
162
|
-
|
|
163
|
-
var applyColumnStateAndFilter = function applyColumnStateAndFilter() {
|
|
164
|
-
if (!currentScheme || !gridApiState) return;
|
|
136
|
+
// 2. 应用列状态(列顺序、宽度、隐藏、固定等)
|
|
165
137
|
|
|
166
|
-
// 将扁平化的列配置转换为 AG-Grid 列状态
|
|
167
138
|
var columnState = flatConfigToColumnState(currentScheme.columnConfig);
|
|
168
|
-
|
|
169
|
-
// 应用列状态(包括列顺序、宽度、隐藏等)
|
|
170
139
|
gridApiState.applyColumnState({
|
|
171
140
|
state: columnState,
|
|
172
|
-
applyOrder: true
|
|
141
|
+
applyOrder: true
|
|
173
142
|
});
|
|
174
|
-
|
|
143
|
+
}).then(function () {
|
|
144
|
+
// 等待 Grid 状态稳定(使用 requestAnimationFrame 而非固定延迟)
|
|
145
|
+
return new Promise(function (resolve) {
|
|
146
|
+
if (cancelled) {
|
|
147
|
+
resolve();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
requestAnimationFrame(function () {
|
|
151
|
+
// 双重 RAF 确保渲染完成
|
|
152
|
+
requestAnimationFrame(function () {
|
|
153
|
+
return resolve();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}).then(function () {
|
|
158
|
+
if (cancelled || !gridApiState) return;
|
|
159
|
+
|
|
160
|
+
// 3. 应用过滤器(在列状态稳定后执行)
|
|
175
161
|
if (currentScheme.filterModel) {
|
|
176
162
|
gridApiState.setFilterModel(currentScheme.filterModel);
|
|
177
163
|
}
|
|
178
164
|
|
|
179
|
-
//
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
165
|
+
// 【关键修复】记录已应用的方案状态(ID + updatedAt)
|
|
166
|
+
lastAppliedSchemeRef.current = {
|
|
167
|
+
id: currentScheme.id,
|
|
168
|
+
updatedAt: currentScheme.updatedAt
|
|
183
169
|
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// 使用 requestAnimationFrame 延迟应用
|
|
187
|
-
var rafId = requestAnimationFrame(function () {
|
|
188
|
-
try {
|
|
189
|
-
// 【关键检测】检查是否包含分组配置
|
|
190
|
-
var hasGroups = currentScheme.columnConfig.some(function (item) {
|
|
191
|
-
return item.type === 'group';
|
|
192
|
-
});
|
|
193
|
-
// 【条件更新】只有在包含分组时才更新 columnDefs
|
|
194
|
-
// 原因:array-table 的列是动态生成的,无分组时不应该覆盖动态列定义
|
|
195
|
-
if (hasGroups) {
|
|
196
|
-
var gridColumnDefs = flatConfigToGridState(currentScheme.columnConfig);
|
|
197
|
-
gridApiState.setGridOption('columnDefs', gridColumnDefs);
|
|
198
|
-
|
|
199
|
-
// 等待 columnDefs 更新完成后再应用列状态
|
|
200
|
-
setTimeout(function () {
|
|
201
|
-
try {
|
|
202
|
-
applyColumnStateAndFilter();
|
|
203
|
-
} catch (error) {
|
|
204
|
-
console.error('[ArrayTable] 应用列状态失败:', error);
|
|
205
|
-
}
|
|
206
|
-
}, 100);
|
|
207
|
-
} else {
|
|
208
|
-
// 无分组时,直接应用列状态即可
|
|
209
|
-
|
|
210
|
-
applyColumnStateAndFilter();
|
|
211
|
-
}
|
|
212
|
-
} catch (error) {
|
|
170
|
+
}).catch(function (error) {
|
|
171
|
+
if (!cancelled) {
|
|
213
172
|
console.error('[ArrayTable] 应用方案失败:', error);
|
|
214
173
|
}
|
|
215
174
|
});
|
|
216
175
|
|
|
217
|
-
//
|
|
176
|
+
// 清理函数:取消进行中的操作
|
|
218
177
|
return function () {
|
|
219
|
-
|
|
178
|
+
cancelled = true;
|
|
220
179
|
};
|
|
221
|
-
}, [props.gridKey, gridApiState, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id]);
|
|
180
|
+
}, [props.gridKey, gridApiState, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id, currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.updatedAt]);
|
|
222
181
|
|
|
223
182
|
//@ts-ignore
|
|
224
183
|
if (columns.length > 0) {
|
|
@@ -284,8 +243,6 @@ var ArrayTableInner = observer(function (props) {
|
|
|
284
243
|
params.api.hidePopupMenu();
|
|
285
244
|
apiRef.current = params.api;
|
|
286
245
|
setGridApiState(params.api);
|
|
287
|
-
|
|
288
|
-
// 恢复列状态将由 useEffect 处理(使用方案系统)
|
|
289
246
|
},
|
|
290
247
|
suppressColumnVirtualisation: true,
|
|
291
248
|
gridOptions: {
|
|
@@ -333,8 +290,8 @@ var ArrayTableInner = observer(function (props) {
|
|
|
333
290
|
' <span data-ref="eSortAsc" class="ag-header-icon ag-sort-ascending-icon"></span>' + ' <span data-ref="eSortDesc" class="ag-header-icon ag-sort-descending-icon"></span>' + ' <span data-ref="eSortNone" class="ag-header-icon ag-sort-none-icon"></span>' + " </div>" + "</div>"
|
|
334
291
|
}
|
|
335
292
|
},
|
|
336
|
-
getRowId: function getRowId(
|
|
337
|
-
var data =
|
|
293
|
+
getRowId: function getRowId(_ref) {
|
|
294
|
+
var data = _ref.data;
|
|
338
295
|
return data._id || data.id;
|
|
339
296
|
}
|
|
340
297
|
// rowDragEntireRow={true}
|