@nokecy/qc-ui 1.0.97 → 1.0.99
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/context/gridContext.d.ts +16 -28
- package/dist/cjs/ag-grid-plus/context/gridContext.js +13 -2
- package/dist/cjs/ag-grid-plus/context/useSchemeManager.d.ts +35 -32
- package/dist/cjs/ag-grid-plus/context/useSchemeManager.js +42 -85
- package/dist/cjs/ag-grid-plus/shared/storage/backendApiAdapter.js +90 -28
- package/dist/esm/ag-grid-plus/context/gridContext.d.ts +16 -28
- package/dist/esm/ag-grid-plus/context/gridContext.js +13 -2
- package/dist/esm/ag-grid-plus/context/useSchemeManager.d.ts +35 -32
- package/dist/esm/ag-grid-plus/context/useSchemeManager.js +42 -85
- package/dist/esm/ag-grid-plus/shared/storage/backendApiAdapter.js +90 -28
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
|
@@ -55,43 +55,46 @@ export declare function useSchemeManager(config: UseSchemeManagerConfig): {
|
|
|
55
55
|
/**
|
|
56
56
|
* 在组件中使用集中式方案管理
|
|
57
57
|
*
|
|
58
|
-
*
|
|
59
|
-
* 1. Backend API 模式: Context 提供 backendApiConfig,使用后端适配器
|
|
60
|
-
* 2. LocalStorage 模式: 不提供配置,使用本地存储适配器
|
|
58
|
+
* ⚠️ 必须在 Provider 中传入 SchemeManager 状态,否则抛出错误
|
|
61
59
|
*
|
|
62
60
|
* @example
|
|
63
61
|
* ```tsx
|
|
64
|
-
* //
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
62
|
+
* // 1. 创建适配器和方案管理器
|
|
63
|
+
* function App() {
|
|
64
|
+
* const adapter = useMemo(
|
|
65
|
+
* () => new BackendApiSchemeAdapter({
|
|
66
|
+
* apiBaseUrl: 'https://api.example.com',
|
|
67
|
+
* getToken: () => localStorage.getItem('token'),
|
|
68
|
+
* getUserId: () => localStorage.getItem('userId')
|
|
69
|
+
* }),
|
|
70
|
+
* []
|
|
71
|
+
* );
|
|
72
|
+
*
|
|
73
|
+
* const schemeManager = useSchemeManager({
|
|
74
|
+
* adapter,
|
|
75
|
+
* autoLoad: true,
|
|
76
|
+
* showErrorMessage: true,
|
|
77
|
+
* currentUserId: currentUser?.id
|
|
78
|
+
* });
|
|
81
79
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
80
|
+
* // 2. 传入 Provider
|
|
81
|
+
* return (
|
|
82
|
+
* <GridPlusContext.Provider value={{
|
|
83
|
+
* extensibleColumns: [],
|
|
84
|
+
* columnState: undefined,
|
|
85
|
+
* onSaveColumnState: () => {},
|
|
86
|
+
* applyToGlobal: () => {},
|
|
87
|
+
* resetCurrent: () => {},
|
|
88
|
+
* resetAll: () => {},
|
|
89
|
+
* queryFormItems: [],
|
|
90
|
+
* ...schemeManager // 展开方案管理状态
|
|
91
|
+
* }}>
|
|
92
|
+
* <MyGrid />
|
|
93
|
+
* </GridPlusContext.Provider>
|
|
94
|
+
* );
|
|
95
|
+
* }
|
|
94
96
|
*
|
|
97
|
+
* // 3. 在子组件中使用
|
|
95
98
|
* function MyGrid() {
|
|
96
99
|
* const {
|
|
97
100
|
* columnSchemes,
|
|
@@ -475,93 +475,49 @@ export function useSchemeManager(config) {
|
|
|
475
475
|
};
|
|
476
476
|
}
|
|
477
477
|
|
|
478
|
-
/**
|
|
479
|
-
* Fallback 模式:根据后端 API 配置自动选择适配器
|
|
480
|
-
*/
|
|
481
|
-
function useFallbackSchemeManager(backendApiConfig, currentUserId) {
|
|
482
|
-
// 根据配置选择适配器
|
|
483
|
-
var adapter = useRef(function () {
|
|
484
|
-
if (backendApiConfig) {
|
|
485
|
-
// 如果提供了后端 API 配置,使用后端适配器
|
|
486
|
-
var _require = require("../shared/storage/backendApiAdapter"),
|
|
487
|
-
BackendApiSchemeAdapter = _require.BackendApiSchemeAdapter;
|
|
488
|
-
console.log('[useFallbackSchemeManager] 使用后端 API 适配器');
|
|
489
|
-
return new BackendApiSchemeAdapter(_objectSpread(_objectSpread({}, backendApiConfig), {}, {
|
|
490
|
-
enableDebugLog: false
|
|
491
|
-
}));
|
|
492
|
-
} else {
|
|
493
|
-
// 否则使用本地存储适配器
|
|
494
|
-
var _require2 = require("../shared/storage/localStorageAdapter"),
|
|
495
|
-
LocalStorageSchemeAdapter = _require2.LocalStorageSchemeAdapter;
|
|
496
|
-
console.log('[useFallbackSchemeManager] 使用本地存储适配器');
|
|
497
|
-
return new LocalStorageSchemeAdapter({
|
|
498
|
-
storageKey: 'ag-grid-plus-schemes',
|
|
499
|
-
enableDebugLog: false
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
}).current();
|
|
503
|
-
|
|
504
|
-
// 使用选定的适配器进行状态管理
|
|
505
|
-
var manager = useSchemeManager({
|
|
506
|
-
adapter: adapter,
|
|
507
|
-
autoLoad: true,
|
|
508
|
-
showErrorMessage: true,
|
|
509
|
-
currentUserId: currentUserId
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
// 返回与 Context 相同的接口
|
|
513
|
-
return _objectSpread({
|
|
514
|
-
// 保留必需的默认值
|
|
515
|
-
extensibleColumns: [],
|
|
516
|
-
columnState: undefined,
|
|
517
|
-
onSaveColumnState: function onSaveColumnState() {},
|
|
518
|
-
applyToGlobal: function applyToGlobal() {},
|
|
519
|
-
resetCurrent: function resetCurrent() {},
|
|
520
|
-
resetAll: function resetAll() {},
|
|
521
|
-
queryFormItems: []
|
|
522
|
-
}, manager);
|
|
523
|
-
}
|
|
524
|
-
|
|
525
478
|
/**
|
|
526
479
|
* 在组件中使用集中式方案管理
|
|
527
480
|
*
|
|
528
|
-
*
|
|
529
|
-
* 1. Backend API 模式: Context 提供 backendApiConfig,使用后端适配器
|
|
530
|
-
* 2. LocalStorage 模式: 不提供配置,使用本地存储适配器
|
|
481
|
+
* ⚠️ 必须在 Provider 中传入 SchemeManager 状态,否则抛出错误
|
|
531
482
|
*
|
|
532
483
|
* @example
|
|
533
484
|
* ```tsx
|
|
534
|
-
* //
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
* apiBaseUrl: 'https://api.example.com',
|
|
545
|
-
* getToken: () => localStorage.getItem('token'),
|
|
546
|
-
* getUserId: () => localStorage.getItem('userId')
|
|
547
|
-
* }
|
|
548
|
-
* }}>
|
|
549
|
-
* <MyGrid />
|
|
550
|
-
* </GridPlusContext.Provider>
|
|
485
|
+
* // 1. 创建适配器和方案管理器
|
|
486
|
+
* function App() {
|
|
487
|
+
* const adapter = useMemo(
|
|
488
|
+
* () => new BackendApiSchemeAdapter({
|
|
489
|
+
* apiBaseUrl: 'https://api.example.com',
|
|
490
|
+
* getToken: () => localStorage.getItem('token'),
|
|
491
|
+
* getUserId: () => localStorage.getItem('userId')
|
|
492
|
+
* }),
|
|
493
|
+
* []
|
|
494
|
+
* );
|
|
551
495
|
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
* resetCurrent: () => {},
|
|
559
|
-
* resetAll: () => {},
|
|
560
|
-
* queryFormItems: []
|
|
561
|
-
* }}>
|
|
562
|
-
* <MyGrid />
|
|
563
|
-
* </GridPlusContext.Provider>
|
|
496
|
+
* const schemeManager = useSchemeManager({
|
|
497
|
+
* adapter,
|
|
498
|
+
* autoLoad: true,
|
|
499
|
+
* showErrorMessage: true,
|
|
500
|
+
* currentUserId: currentUser?.id
|
|
501
|
+
* });
|
|
564
502
|
*
|
|
503
|
+
* // 2. 传入 Provider
|
|
504
|
+
* return (
|
|
505
|
+
* <GridPlusContext.Provider value={{
|
|
506
|
+
* extensibleColumns: [],
|
|
507
|
+
* columnState: undefined,
|
|
508
|
+
* onSaveColumnState: () => {},
|
|
509
|
+
* applyToGlobal: () => {},
|
|
510
|
+
* resetCurrent: () => {},
|
|
511
|
+
* resetAll: () => {},
|
|
512
|
+
* queryFormItems: [],
|
|
513
|
+
* ...schemeManager // 展开方案管理状态
|
|
514
|
+
* }}>
|
|
515
|
+
* <MyGrid />
|
|
516
|
+
* </GridPlusContext.Provider>
|
|
517
|
+
* );
|
|
518
|
+
* }
|
|
519
|
+
*
|
|
520
|
+
* // 3. 在子组件中使用
|
|
565
521
|
* function MyGrid() {
|
|
566
522
|
* const {
|
|
567
523
|
* columnSchemes,
|
|
@@ -581,10 +537,11 @@ function useFallbackSchemeManager(backendApiConfig, currentUserId) {
|
|
|
581
537
|
export function useGridSchemes() {
|
|
582
538
|
var context = useContext(GridPlusContext);
|
|
583
539
|
|
|
584
|
-
//
|
|
585
|
-
var
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
540
|
+
// 检查是否传入了方案管理状态
|
|
541
|
+
var hasSchemeManagement = !!((context === null || context === void 0 ? void 0 : context.columnSchemes) !== undefined || context !== null && context !== void 0 && context.saveColumnScheme || context !== null && context !== void 0 && context.deleteColumnScheme);
|
|
542
|
+
if (!hasSchemeManagement) {
|
|
543
|
+
throw new Error('[useGridSchemes] 必须在 GridPlusContext.Provider 中传入 SchemeManager 状态。\n' + '请使用 useSchemeManager hook 创建方案管理器,然后通过 Provider 传递:\n' + ' const schemeManager = useSchemeManager({ adapter, ... });\n' + ' <GridPlusContext.Provider value={{ ...otherValues, ...schemeManager }}>');
|
|
544
|
+
}
|
|
545
|
+
console.log('[useGridSchemes] 使用 Context 中的方案管理状态');
|
|
546
|
+
return context;
|
|
590
547
|
}
|
|
@@ -199,23 +199,55 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
|
|
|
199
199
|
return this.request(url);
|
|
200
200
|
case 5:
|
|
201
201
|
response = _context2.sent;
|
|
202
|
+
// 将所有列方案的 columnConfig 从字符串解析为对象数组
|
|
203
|
+
if (response.columnSchemes) {
|
|
204
|
+
Object.keys(response.columnSchemes).forEach(function (gridId) {
|
|
205
|
+
response.columnSchemes[gridId] = response.columnSchemes[gridId].map(function (scheme) {
|
|
206
|
+
if (typeof scheme.columnConfig === 'string') {
|
|
207
|
+
return _objectSpread(_objectSpread({}, scheme), {}, {
|
|
208
|
+
columnConfig: JSON.parse(scheme.columnConfig)
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return scheme;
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// 将所有查询方案的字段从字符串解析为数组和对象
|
|
217
|
+
if (response.querySchemes) {
|
|
218
|
+
Object.keys(response.querySchemes).forEach(function (gridId) {
|
|
219
|
+
response.querySchemes[gridId] = response.querySchemes[gridId].map(function (scheme) {
|
|
220
|
+
var parsedScheme = _objectSpread({}, scheme);
|
|
221
|
+
if (typeof parsedScheme.itemsOrder === 'string') {
|
|
222
|
+
parsedScheme.itemsOrder = JSON.parse(parsedScheme.itemsOrder);
|
|
223
|
+
}
|
|
224
|
+
if (typeof parsedScheme.hiddenFields === 'string') {
|
|
225
|
+
parsedScheme.hiddenFields = JSON.parse(parsedScheme.hiddenFields);
|
|
226
|
+
}
|
|
227
|
+
if (typeof parsedScheme.formValues === 'string') {
|
|
228
|
+
parsedScheme.formValues = JSON.parse(parsedScheme.formValues);
|
|
229
|
+
}
|
|
230
|
+
return parsedScheme;
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}
|
|
202
234
|
this.log('加载完成', {
|
|
203
235
|
columnSchemes: Object.keys(response.columnSchemes || {}).length,
|
|
204
236
|
querySchemes: Object.keys(response.querySchemes || {}).length,
|
|
205
237
|
version: response.version
|
|
206
238
|
});
|
|
207
239
|
return _context2.abrupt("return", response);
|
|
208
|
-
case
|
|
209
|
-
_context2.prev =
|
|
240
|
+
case 12:
|
|
241
|
+
_context2.prev = 12;
|
|
210
242
|
_context2.t0 = _context2["catch"](0);
|
|
211
243
|
console.error('[BackendApiAdapter] 加载方案失败:', _context2.t0);
|
|
212
244
|
message.error('加载方案失败');
|
|
213
245
|
throw _context2.t0;
|
|
214
|
-
case
|
|
246
|
+
case 17:
|
|
215
247
|
case "end":
|
|
216
248
|
return _context2.stop();
|
|
217
249
|
}
|
|
218
|
-
}, _callee2, this, [[0,
|
|
250
|
+
}, _callee2, this, [[0, 12]]);
|
|
219
251
|
}));
|
|
220
252
|
function loadAllSchemes() {
|
|
221
253
|
return _loadAllSchemes.apply(this, arguments);
|
|
@@ -226,42 +258,52 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
|
|
|
226
258
|
key: "saveColumnScheme",
|
|
227
259
|
value: function () {
|
|
228
260
|
var _saveColumnScheme = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(gridId, scheme) {
|
|
229
|
-
var url, response;
|
|
261
|
+
var schemeForBackend, url, response, savedScheme;
|
|
230
262
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
231
263
|
while (1) switch (_context3.prev = _context3.next) {
|
|
232
264
|
case 0:
|
|
233
265
|
_context3.prev = 0;
|
|
234
266
|
this.log("\u4FDD\u5B58\u5217\u65B9\u6848: ".concat(gridId, " - ").concat(scheme.name));
|
|
267
|
+
|
|
268
|
+
// 将 columnConfig 转换为 JSON 字符串
|
|
269
|
+
schemeForBackend = _objectSpread(_objectSpread({}, scheme), {}, {
|
|
270
|
+
columnConfig: JSON.stringify(scheme.columnConfig)
|
|
271
|
+
});
|
|
235
272
|
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/save-column-scheme");
|
|
236
|
-
_context3.next =
|
|
273
|
+
_context3.next = 6;
|
|
237
274
|
return this.request(url, {
|
|
238
275
|
method: 'POST',
|
|
239
276
|
body: JSON.stringify({
|
|
240
277
|
gridId: gridId,
|
|
241
|
-
scheme:
|
|
278
|
+
scheme: schemeForBackend
|
|
242
279
|
})
|
|
243
280
|
});
|
|
244
|
-
case
|
|
281
|
+
case 6:
|
|
245
282
|
response = _context3.sent;
|
|
246
283
|
if (response.success) {
|
|
247
|
-
_context3.next =
|
|
284
|
+
_context3.next = 9;
|
|
248
285
|
break;
|
|
249
286
|
}
|
|
250
287
|
throw new Error(response.message || '保存失败');
|
|
251
|
-
case
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
288
|
+
case 9:
|
|
289
|
+
// 将返回的 columnConfig 从字符串解析为对象数组
|
|
290
|
+
savedScheme = response.scheme;
|
|
291
|
+
if (savedScheme && typeof savedScheme.columnConfig === 'string') {
|
|
292
|
+
savedScheme.columnConfig = JSON.parse(savedScheme.columnConfig);
|
|
293
|
+
}
|
|
294
|
+
this.log('保存成功', savedScheme);
|
|
295
|
+
return _context3.abrupt("return", savedScheme);
|
|
296
|
+
case 15:
|
|
297
|
+
_context3.prev = 15;
|
|
256
298
|
_context3.t0 = _context3["catch"](0);
|
|
257
299
|
console.error('[BackendApiAdapter] 保存列方案失败:', _context3.t0);
|
|
258
300
|
message.error('保存列方案失败');
|
|
259
301
|
throw _context3.t0;
|
|
260
|
-
case
|
|
302
|
+
case 20:
|
|
261
303
|
case "end":
|
|
262
304
|
return _context3.stop();
|
|
263
305
|
}
|
|
264
|
-
}, _callee3, this, [[0,
|
|
306
|
+
}, _callee3, this, [[0, 15]]);
|
|
265
307
|
}));
|
|
266
308
|
function saveColumnScheme(_x2, _x3) {
|
|
267
309
|
return _saveColumnScheme.apply(this, arguments);
|
|
@@ -315,42 +357,62 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
|
|
|
315
357
|
key: "saveQueryScheme",
|
|
316
358
|
value: function () {
|
|
317
359
|
var _saveQueryScheme = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(gridId, scheme) {
|
|
318
|
-
var url, response;
|
|
360
|
+
var schemeForBackend, url, response, savedScheme;
|
|
319
361
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
320
362
|
while (1) switch (_context5.prev = _context5.next) {
|
|
321
363
|
case 0:
|
|
322
364
|
_context5.prev = 0;
|
|
323
365
|
this.log("\u4FDD\u5B58\u67E5\u8BE2\u65B9\u6848: ".concat(gridId, " - ").concat(scheme.name));
|
|
366
|
+
|
|
367
|
+
// 将数组和对象字段转换为 JSON 字符串
|
|
368
|
+
schemeForBackend = _objectSpread(_objectSpread({}, scheme), {}, {
|
|
369
|
+
itemsOrder: scheme.itemsOrder ? JSON.stringify(scheme.itemsOrder) : undefined,
|
|
370
|
+
hiddenFields: scheme.hiddenFields ? JSON.stringify(scheme.hiddenFields) : undefined,
|
|
371
|
+
formValues: scheme.formValues ? JSON.stringify(scheme.formValues) : undefined
|
|
372
|
+
});
|
|
324
373
|
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/save-query-scheme");
|
|
325
|
-
_context5.next =
|
|
374
|
+
_context5.next = 6;
|
|
326
375
|
return this.request(url, {
|
|
327
376
|
method: 'POST',
|
|
328
377
|
body: JSON.stringify({
|
|
329
378
|
gridId: gridId,
|
|
330
|
-
scheme:
|
|
379
|
+
scheme: schemeForBackend
|
|
331
380
|
})
|
|
332
381
|
});
|
|
333
|
-
case
|
|
382
|
+
case 6:
|
|
334
383
|
response = _context5.sent;
|
|
335
384
|
if (response.success) {
|
|
336
|
-
_context5.next =
|
|
385
|
+
_context5.next = 9;
|
|
337
386
|
break;
|
|
338
387
|
}
|
|
339
388
|
throw new Error(response.message || '保存失败');
|
|
340
|
-
case
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
389
|
+
case 9:
|
|
390
|
+
// 将返回的字符串字段解析为数组和对象
|
|
391
|
+
savedScheme = response.scheme;
|
|
392
|
+
if (savedScheme) {
|
|
393
|
+
if (typeof savedScheme.itemsOrder === 'string') {
|
|
394
|
+
savedScheme.itemsOrder = JSON.parse(savedScheme.itemsOrder);
|
|
395
|
+
}
|
|
396
|
+
if (typeof savedScheme.hiddenFields === 'string') {
|
|
397
|
+
savedScheme.hiddenFields = JSON.parse(savedScheme.hiddenFields);
|
|
398
|
+
}
|
|
399
|
+
if (typeof savedScheme.formValues === 'string') {
|
|
400
|
+
savedScheme.formValues = JSON.parse(savedScheme.formValues);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
this.log('保存成功', savedScheme);
|
|
404
|
+
return _context5.abrupt("return", savedScheme);
|
|
405
|
+
case 15:
|
|
406
|
+
_context5.prev = 15;
|
|
345
407
|
_context5.t0 = _context5["catch"](0);
|
|
346
408
|
console.error('[BackendApiAdapter] 保存查询方案失败:', _context5.t0);
|
|
347
409
|
message.error('保存查询方案失败');
|
|
348
410
|
throw _context5.t0;
|
|
349
|
-
case
|
|
411
|
+
case 20:
|
|
350
412
|
case "end":
|
|
351
413
|
return _context5.stop();
|
|
352
414
|
}
|
|
353
|
-
}, _callee5, this, [[0,
|
|
415
|
+
}, _callee5, this, [[0, 15]]);
|
|
354
416
|
}));
|
|
355
417
|
function saveQueryScheme(_x6, _x7) {
|
|
356
418
|
return _saveQueryScheme.apply(this, arguments);
|