@nokecy/qc-ui 1.0.95 → 1.0.96
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 +99 -69
- package/dist/cjs/ag-grid-plus/context/gridContext.js +12 -0
- package/dist/cjs/ag-grid-plus/context/useSchemeManager.d.ts +36 -3
- package/dist/cjs/ag-grid-plus/context/useSchemeManager.js +83 -23
- package/dist/esm/ag-grid-plus/context/gridContext.d.ts +99 -69
- package/dist/esm/ag-grid-plus/context/gridContext.js +13 -0
- package/dist/esm/ag-grid-plus/context/useSchemeManager.d.ts +36 -3
- package/dist/esm/ag-grid-plus/context/useSchemeManager.js +83 -23
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
|
@@ -10,6 +10,8 @@ export interface UseSchemeManagerConfig {
|
|
|
10
10
|
autoLoad?: boolean;
|
|
11
11
|
/** 加载失败时是否显示错误提示,默认 true */
|
|
12
12
|
showErrorMessage?: boolean;
|
|
13
|
+
/** 当前用户ID,用于监听用户切换 */
|
|
14
|
+
currentUserId?: string | null;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* 集中式方案管理 Hook
|
|
@@ -53,12 +55,43 @@ export declare function useSchemeManager(config: UseSchemeManagerConfig): {
|
|
|
53
55
|
/**
|
|
54
56
|
* 在组件中使用集中式方案管理
|
|
55
57
|
*
|
|
56
|
-
*
|
|
57
|
-
* 1.
|
|
58
|
-
* 2.
|
|
58
|
+
* 支持两种模式(根据 Context 配置自动选择):
|
|
59
|
+
* 1. Backend API 模式: Context 提供 backendApiConfig,使用后端适配器
|
|
60
|
+
* 2. LocalStorage 模式: 不提供配置,使用本地存储适配器
|
|
59
61
|
*
|
|
60
62
|
* @example
|
|
61
63
|
* ```tsx
|
|
64
|
+
* // 模式1:提供后端 API 配置
|
|
65
|
+
* <GridPlusContext.Provider value={{
|
|
66
|
+
* extensibleColumns: [],
|
|
67
|
+
* columnState: undefined,
|
|
68
|
+
* onSaveColumnState: () => {},
|
|
69
|
+
* applyToGlobal: () => {},
|
|
70
|
+
* resetCurrent: () => {},
|
|
71
|
+
* resetAll: () => {},
|
|
72
|
+
* queryFormItems: [],
|
|
73
|
+
* backendApiConfig: {
|
|
74
|
+
* apiBaseUrl: 'https://api.example.com',
|
|
75
|
+
* getToken: () => localStorage.getItem('token'),
|
|
76
|
+
* getUserId: () => localStorage.getItem('userId')
|
|
77
|
+
* }
|
|
78
|
+
* }}>
|
|
79
|
+
* <MyGrid />
|
|
80
|
+
* </GridPlusContext.Provider>
|
|
81
|
+
*
|
|
82
|
+
* // 模式2:无配置,自动使用 LocalStorage
|
|
83
|
+
* <GridPlusContext.Provider value={{
|
|
84
|
+
* extensibleColumns: [],
|
|
85
|
+
* columnState: undefined,
|
|
86
|
+
* onSaveColumnState: () => {},
|
|
87
|
+
* applyToGlobal: () => {},
|
|
88
|
+
* resetCurrent: () => {},
|
|
89
|
+
* resetAll: () => {},
|
|
90
|
+
* queryFormItems: []
|
|
91
|
+
* }}>
|
|
92
|
+
* <MyGrid />
|
|
93
|
+
* </GridPlusContext.Provider>
|
|
94
|
+
*
|
|
62
95
|
* function MyGrid() {
|
|
63
96
|
* const {
|
|
64
97
|
* columnSchemes,
|
|
@@ -52,7 +52,8 @@ export function useSchemeManager(config) {
|
|
|
52
52
|
_config$autoLoad = config.autoLoad,
|
|
53
53
|
autoLoad = _config$autoLoad === void 0 ? true : _config$autoLoad,
|
|
54
54
|
_config$showErrorMess = config.showErrorMessage,
|
|
55
|
-
showErrorMessage = _config$showErrorMess === void 0 ? true : _config$showErrorMess
|
|
55
|
+
showErrorMessage = _config$showErrorMess === void 0 ? true : _config$showErrorMess,
|
|
56
|
+
currentUserId = config.currentUserId;
|
|
56
57
|
|
|
57
58
|
// ========== 状态管理 ==========
|
|
58
59
|
|
|
@@ -139,6 +140,23 @@ export function useSchemeManager(config) {
|
|
|
139
140
|
}
|
|
140
141
|
}, [autoLoad, loadAllSchemes]);
|
|
141
142
|
|
|
143
|
+
// 监听用户ID变化,自动重新加载方案(用于用户登录/切换场景)
|
|
144
|
+
var prevUserIdRef = useRef(currentUserId);
|
|
145
|
+
useEffect(function () {
|
|
146
|
+
// 只有在用户ID实际变化且已经加载过数据时才重新加载
|
|
147
|
+
if (currentUserId !== prevUserIdRef.current && loadedRef.current) {
|
|
148
|
+
console.log('[useSchemeManager] 用户切换,重新加载方案', {
|
|
149
|
+
from: prevUserIdRef.current,
|
|
150
|
+
to: currentUserId
|
|
151
|
+
});
|
|
152
|
+
prevUserIdRef.current = currentUserId;
|
|
153
|
+
loadedRef.current = false;
|
|
154
|
+
loadAllSchemes();
|
|
155
|
+
} else {
|
|
156
|
+
prevUserIdRef.current = currentUserId;
|
|
157
|
+
}
|
|
158
|
+
}, [currentUserId, loadAllSchemes]);
|
|
159
|
+
|
|
142
160
|
// ========== 列方案操作 ==========
|
|
143
161
|
|
|
144
162
|
var saveColumnScheme = useCallback( /*#__PURE__*/function () {
|
|
@@ -458,19 +476,37 @@ export function useSchemeManager(config) {
|
|
|
458
476
|
}
|
|
459
477
|
|
|
460
478
|
/**
|
|
461
|
-
* Fallback
|
|
479
|
+
* Fallback 模式:根据后端 API 配置自动选择适配器
|
|
462
480
|
*/
|
|
463
|
-
function useFallbackSchemeManager() {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
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();
|
|
468
503
|
|
|
469
|
-
//
|
|
504
|
+
// 使用选定的适配器进行状态管理
|
|
470
505
|
var manager = useSchemeManager({
|
|
471
506
|
adapter: adapter,
|
|
472
507
|
autoLoad: true,
|
|
473
|
-
showErrorMessage: true
|
|
508
|
+
showErrorMessage: true,
|
|
509
|
+
currentUserId: currentUserId
|
|
474
510
|
});
|
|
475
511
|
|
|
476
512
|
// 返回与 Context 相同的接口
|
|
@@ -489,12 +525,43 @@ function useFallbackSchemeManager() {
|
|
|
489
525
|
/**
|
|
490
526
|
* 在组件中使用集中式方案管理
|
|
491
527
|
*
|
|
492
|
-
*
|
|
493
|
-
* 1.
|
|
494
|
-
* 2.
|
|
528
|
+
* 支持两种模式(根据 Context 配置自动选择):
|
|
529
|
+
* 1. Backend API 模式: Context 提供 backendApiConfig,使用后端适配器
|
|
530
|
+
* 2. LocalStorage 模式: 不提供配置,使用本地存储适配器
|
|
495
531
|
*
|
|
496
532
|
* @example
|
|
497
533
|
* ```tsx
|
|
534
|
+
* // 模式1:提供后端 API 配置
|
|
535
|
+
* <GridPlusContext.Provider value={{
|
|
536
|
+
* extensibleColumns: [],
|
|
537
|
+
* columnState: undefined,
|
|
538
|
+
* onSaveColumnState: () => {},
|
|
539
|
+
* applyToGlobal: () => {},
|
|
540
|
+
* resetCurrent: () => {},
|
|
541
|
+
* resetAll: () => {},
|
|
542
|
+
* queryFormItems: [],
|
|
543
|
+
* backendApiConfig: {
|
|
544
|
+
* apiBaseUrl: 'https://api.example.com',
|
|
545
|
+
* getToken: () => localStorage.getItem('token'),
|
|
546
|
+
* getUserId: () => localStorage.getItem('userId')
|
|
547
|
+
* }
|
|
548
|
+
* }}>
|
|
549
|
+
* <MyGrid />
|
|
550
|
+
* </GridPlusContext.Provider>
|
|
551
|
+
*
|
|
552
|
+
* // 模式2:无配置,自动使用 LocalStorage
|
|
553
|
+
* <GridPlusContext.Provider value={{
|
|
554
|
+
* extensibleColumns: [],
|
|
555
|
+
* columnState: undefined,
|
|
556
|
+
* onSaveColumnState: () => {},
|
|
557
|
+
* applyToGlobal: () => {},
|
|
558
|
+
* resetCurrent: () => {},
|
|
559
|
+
* resetAll: () => {},
|
|
560
|
+
* queryFormItems: []
|
|
561
|
+
* }}>
|
|
562
|
+
* <MyGrid />
|
|
563
|
+
* </GridPlusContext.Provider>
|
|
564
|
+
*
|
|
498
565
|
* function MyGrid() {
|
|
499
566
|
* const {
|
|
500
567
|
* columnSchemes,
|
|
@@ -514,17 +581,10 @@ function useFallbackSchemeManager() {
|
|
|
514
581
|
export function useGridSchemes() {
|
|
515
582
|
var context = useContext(GridPlusContext);
|
|
516
583
|
|
|
517
|
-
//
|
|
518
|
-
var
|
|
519
|
-
|
|
520
|
-
// 如果 Context 提供了完整 API,直接使用
|
|
521
|
-
if (hasSchemeApi) {
|
|
522
|
-
return context;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
// 否则使用 fallback 模式
|
|
526
|
-
console.warn('[useGridSchemes] Context 未提供方案管理 API,使用 Fallback 模式(LocalStorage + 本地状态)');
|
|
584
|
+
// 根据后端 API 配置自动选择适配器
|
|
585
|
+
var adapterType = context !== null && context !== void 0 && context.backendApiConfig ? '后端 API' : 'LocalStorage';
|
|
586
|
+
console.log("[useGridSchemes] \u4F7F\u7528 ".concat(adapterType, " \u9002\u914D\u5668"));
|
|
527
587
|
|
|
528
588
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
529
|
-
return useFallbackSchemeManager();
|
|
589
|
+
return useFallbackSchemeManager(context === null || context === void 0 ? void 0 : context.backendApiConfig, context === null || context === void 0 ? void 0 : context.currentUserId);
|
|
530
590
|
}
|