@nokecy/qc-ui 1.0.97 → 1.0.98
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/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/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { ColumnScheme, QueryScheme, CurrentSchemeDto } from "../shared/storage/schemeStorageAdapter";
|
|
3
|
-
import type { BackendApiAdapterConfig } from "../shared/storage/backendApiAdapter";
|
|
4
3
|
/**
|
|
5
4
|
* 方案管理 API 接口
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* ⚠️ 必须通过 useSchemeManager Hook 创建,然后传入 Provider
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const adapter = useMemo(() => new BackendApiSchemeAdapter({ ... }), []);
|
|
11
|
+
* const schemeManager = useSchemeManager({ adapter, autoLoad: true });
|
|
12
|
+
*
|
|
13
|
+
* <GridPlusContext.Provider value={{
|
|
14
|
+
* ...otherValues,
|
|
15
|
+
* ...schemeManager // 展开方案管理状态
|
|
16
|
+
* }}>
|
|
17
|
+
* ```
|
|
8
18
|
*/
|
|
9
19
|
export interface SchemeManagementAPI {
|
|
10
20
|
/**
|
|
@@ -74,7 +84,7 @@ export interface SchemeManagementAPI {
|
|
|
74
84
|
/**
|
|
75
85
|
* GridPlus Context 值接口
|
|
76
86
|
*
|
|
77
|
-
*
|
|
87
|
+
* ⚠️ 必须包含方案管理 API,通过 useSchemeManager Hook 创建后传入
|
|
78
88
|
*/
|
|
79
89
|
export interface GridPlusContextValue extends SchemeManagementAPI {
|
|
80
90
|
/**
|
|
@@ -123,32 +133,10 @@ export interface GridPlusContextValue extends SchemeManagementAPI {
|
|
|
123
133
|
*/
|
|
124
134
|
updateQueryOrder?: (order: string[]) => void;
|
|
125
135
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* 如果提供此配置,useGridSchemes Hook 将自动使用 BackendApiSchemeAdapter
|
|
129
|
-
* 否则将使用 LocalStorageSchemeAdapter
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```tsx
|
|
133
|
-
* backendApiConfig: {
|
|
134
|
-
* apiBaseUrl: 'https://api.example.com',
|
|
135
|
-
* getToken: () => localStorage.getItem('token'),
|
|
136
|
-
* getUserId: () => localStorage.getItem('userId'),
|
|
137
|
-
* timeout: 10000
|
|
138
|
-
* }
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
backendApiConfig?: Omit<BackendApiAdapterConfig, 'enableDebugLog'>;
|
|
142
|
-
/**
|
|
143
|
-
* 当前用户ID(可选)
|
|
144
|
-
*
|
|
145
|
-
* 用于监听用户切换,自动重新加载方案数据
|
|
146
|
-
* 当此值变化时,系统会自动调用 refreshSchemes() 重新加载所有方案
|
|
136
|
+
* 当前用户ID(内部使用)
|
|
147
137
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* currentUserId: currentUser?.id
|
|
151
|
-
* ```
|
|
138
|
+
* 用于 SchemeManager 监听用户切换,自动重新加载方案数据
|
|
139
|
+
* 此字段由 useSchemeManager 自动管理,无需手动设置
|
|
152
140
|
*/
|
|
153
141
|
currentUserId?: string | null;
|
|
154
142
|
}
|
|
@@ -9,13 +9,24 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
9
9
|
/**
|
|
10
10
|
* 方案管理 API 接口
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* ⚠️ 必须通过 useSchemeManager Hook 创建,然后传入 Provider
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const adapter = useMemo(() => new BackendApiSchemeAdapter({ ... }), []);
|
|
17
|
+
* const schemeManager = useSchemeManager({ adapter, autoLoad: true });
|
|
18
|
+
*
|
|
19
|
+
* <GridPlusContext.Provider value={{
|
|
20
|
+
* ...otherValues,
|
|
21
|
+
* ...schemeManager // 展开方案管理状态
|
|
22
|
+
* }}>
|
|
23
|
+
* ```
|
|
13
24
|
*/
|
|
14
25
|
|
|
15
26
|
/**
|
|
16
27
|
* GridPlus Context 值接口
|
|
17
28
|
*
|
|
18
|
-
*
|
|
29
|
+
* ⚠️ 必须包含方案管理 API,通过 useSchemeManager Hook 创建后传入
|
|
19
30
|
*/
|
|
20
31
|
|
|
21
32
|
var GridPlusContext = exports.GridPlusContext = /*#__PURE__*/_react.default.createContext({
|
|
@@ -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,
|
|
@@ -481,93 +481,49 @@ function useSchemeManager(config) {
|
|
|
481
481
|
};
|
|
482
482
|
}
|
|
483
483
|
|
|
484
|
-
/**
|
|
485
|
-
* Fallback 模式:根据后端 API 配置自动选择适配器
|
|
486
|
-
*/
|
|
487
|
-
function useFallbackSchemeManager(backendApiConfig, currentUserId) {
|
|
488
|
-
// 根据配置选择适配器
|
|
489
|
-
var adapter = (0, _react.useRef)(function () {
|
|
490
|
-
if (backendApiConfig) {
|
|
491
|
-
// 如果提供了后端 API 配置,使用后端适配器
|
|
492
|
-
var _require = require("../shared/storage/backendApiAdapter"),
|
|
493
|
-
BackendApiSchemeAdapter = _require.BackendApiSchemeAdapter;
|
|
494
|
-
console.log('[useFallbackSchemeManager] 使用后端 API 适配器');
|
|
495
|
-
return new BackendApiSchemeAdapter(_objectSpread(_objectSpread({}, backendApiConfig), {}, {
|
|
496
|
-
enableDebugLog: false
|
|
497
|
-
}));
|
|
498
|
-
} else {
|
|
499
|
-
// 否则使用本地存储适配器
|
|
500
|
-
var _require2 = require("../shared/storage/localStorageAdapter"),
|
|
501
|
-
LocalStorageSchemeAdapter = _require2.LocalStorageSchemeAdapter;
|
|
502
|
-
console.log('[useFallbackSchemeManager] 使用本地存储适配器');
|
|
503
|
-
return new LocalStorageSchemeAdapter({
|
|
504
|
-
storageKey: 'ag-grid-plus-schemes',
|
|
505
|
-
enableDebugLog: false
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
}).current();
|
|
509
|
-
|
|
510
|
-
// 使用选定的适配器进行状态管理
|
|
511
|
-
var manager = useSchemeManager({
|
|
512
|
-
adapter: adapter,
|
|
513
|
-
autoLoad: true,
|
|
514
|
-
showErrorMessage: true,
|
|
515
|
-
currentUserId: currentUserId
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
// 返回与 Context 相同的接口
|
|
519
|
-
return _objectSpread({
|
|
520
|
-
// 保留必需的默认值
|
|
521
|
-
extensibleColumns: [],
|
|
522
|
-
columnState: undefined,
|
|
523
|
-
onSaveColumnState: function onSaveColumnState() {},
|
|
524
|
-
applyToGlobal: function applyToGlobal() {},
|
|
525
|
-
resetCurrent: function resetCurrent() {},
|
|
526
|
-
resetAll: function resetAll() {},
|
|
527
|
-
queryFormItems: []
|
|
528
|
-
}, manager);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
484
|
/**
|
|
532
485
|
* 在组件中使用集中式方案管理
|
|
533
486
|
*
|
|
534
|
-
*
|
|
535
|
-
* 1. Backend API 模式: Context 提供 backendApiConfig,使用后端适配器
|
|
536
|
-
* 2. LocalStorage 模式: 不提供配置,使用本地存储适配器
|
|
487
|
+
* ⚠️ 必须在 Provider 中传入 SchemeManager 状态,否则抛出错误
|
|
537
488
|
*
|
|
538
489
|
* @example
|
|
539
490
|
* ```tsx
|
|
540
|
-
* //
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
* apiBaseUrl: 'https://api.example.com',
|
|
551
|
-
* getToken: () => localStorage.getItem('token'),
|
|
552
|
-
* getUserId: () => localStorage.getItem('userId')
|
|
553
|
-
* }
|
|
554
|
-
* }}>
|
|
555
|
-
* <MyGrid />
|
|
556
|
-
* </GridPlusContext.Provider>
|
|
491
|
+
* // 1. 创建适配器和方案管理器
|
|
492
|
+
* function App() {
|
|
493
|
+
* const adapter = useMemo(
|
|
494
|
+
* () => new BackendApiSchemeAdapter({
|
|
495
|
+
* apiBaseUrl: 'https://api.example.com',
|
|
496
|
+
* getToken: () => localStorage.getItem('token'),
|
|
497
|
+
* getUserId: () => localStorage.getItem('userId')
|
|
498
|
+
* }),
|
|
499
|
+
* []
|
|
500
|
+
* );
|
|
557
501
|
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
* resetCurrent: () => {},
|
|
565
|
-
* resetAll: () => {},
|
|
566
|
-
* queryFormItems: []
|
|
567
|
-
* }}>
|
|
568
|
-
* <MyGrid />
|
|
569
|
-
* </GridPlusContext.Provider>
|
|
502
|
+
* const schemeManager = useSchemeManager({
|
|
503
|
+
* adapter,
|
|
504
|
+
* autoLoad: true,
|
|
505
|
+
* showErrorMessage: true,
|
|
506
|
+
* currentUserId: currentUser?.id
|
|
507
|
+
* });
|
|
570
508
|
*
|
|
509
|
+
* // 2. 传入 Provider
|
|
510
|
+
* return (
|
|
511
|
+
* <GridPlusContext.Provider value={{
|
|
512
|
+
* extensibleColumns: [],
|
|
513
|
+
* columnState: undefined,
|
|
514
|
+
* onSaveColumnState: () => {},
|
|
515
|
+
* applyToGlobal: () => {},
|
|
516
|
+
* resetCurrent: () => {},
|
|
517
|
+
* resetAll: () => {},
|
|
518
|
+
* queryFormItems: [],
|
|
519
|
+
* ...schemeManager // 展开方案管理状态
|
|
520
|
+
* }}>
|
|
521
|
+
* <MyGrid />
|
|
522
|
+
* </GridPlusContext.Provider>
|
|
523
|
+
* );
|
|
524
|
+
* }
|
|
525
|
+
*
|
|
526
|
+
* // 3. 在子组件中使用
|
|
571
527
|
* function MyGrid() {
|
|
572
528
|
* const {
|
|
573
529
|
* columnSchemes,
|
|
@@ -587,10 +543,11 @@ function useFallbackSchemeManager(backendApiConfig, currentUserId) {
|
|
|
587
543
|
function useGridSchemes() {
|
|
588
544
|
var context = (0, _react.useContext)(_gridContext.GridPlusContext);
|
|
589
545
|
|
|
590
|
-
//
|
|
591
|
-
var
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
546
|
+
// 检查是否传入了方案管理状态
|
|
547
|
+
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);
|
|
548
|
+
if (!hasSchemeManagement) {
|
|
549
|
+
throw new Error('[useGridSchemes] 必须在 GridPlusContext.Provider 中传入 SchemeManager 状态。\n' + '请使用 useSchemeManager hook 创建方案管理器,然后通过 Provider 传递:\n' + ' const schemeManager = useSchemeManager({ adapter, ... });\n' + ' <GridPlusContext.Provider value={{ ...otherValues, ...schemeManager }}>');
|
|
550
|
+
}
|
|
551
|
+
console.log('[useGridSchemes] 使用 Context 中的方案管理状态');
|
|
552
|
+
return context;
|
|
596
553
|
}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { ColumnScheme, QueryScheme, CurrentSchemeDto } from "../shared/storage/schemeStorageAdapter";
|
|
3
|
-
import type { BackendApiAdapterConfig } from "../shared/storage/backendApiAdapter";
|
|
4
3
|
/**
|
|
5
4
|
* 方案管理 API 接口
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* ⚠️ 必须通过 useSchemeManager Hook 创建,然后传入 Provider
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const adapter = useMemo(() => new BackendApiSchemeAdapter({ ... }), []);
|
|
11
|
+
* const schemeManager = useSchemeManager({ adapter, autoLoad: true });
|
|
12
|
+
*
|
|
13
|
+
* <GridPlusContext.Provider value={{
|
|
14
|
+
* ...otherValues,
|
|
15
|
+
* ...schemeManager // 展开方案管理状态
|
|
16
|
+
* }}>
|
|
17
|
+
* ```
|
|
8
18
|
*/
|
|
9
19
|
export interface SchemeManagementAPI {
|
|
10
20
|
/**
|
|
@@ -74,7 +84,7 @@ export interface SchemeManagementAPI {
|
|
|
74
84
|
/**
|
|
75
85
|
* GridPlus Context 值接口
|
|
76
86
|
*
|
|
77
|
-
*
|
|
87
|
+
* ⚠️ 必须包含方案管理 API,通过 useSchemeManager Hook 创建后传入
|
|
78
88
|
*/
|
|
79
89
|
export interface GridPlusContextValue extends SchemeManagementAPI {
|
|
80
90
|
/**
|
|
@@ -123,32 +133,10 @@ export interface GridPlusContextValue extends SchemeManagementAPI {
|
|
|
123
133
|
*/
|
|
124
134
|
updateQueryOrder?: (order: string[]) => void;
|
|
125
135
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* 如果提供此配置,useGridSchemes Hook 将自动使用 BackendApiSchemeAdapter
|
|
129
|
-
* 否则将使用 LocalStorageSchemeAdapter
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```tsx
|
|
133
|
-
* backendApiConfig: {
|
|
134
|
-
* apiBaseUrl: 'https://api.example.com',
|
|
135
|
-
* getToken: () => localStorage.getItem('token'),
|
|
136
|
-
* getUserId: () => localStorage.getItem('userId'),
|
|
137
|
-
* timeout: 10000
|
|
138
|
-
* }
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
backendApiConfig?: Omit<BackendApiAdapterConfig, 'enableDebugLog'>;
|
|
142
|
-
/**
|
|
143
|
-
* 当前用户ID(可选)
|
|
144
|
-
*
|
|
145
|
-
* 用于监听用户切换,自动重新加载方案数据
|
|
146
|
-
* 当此值变化时,系统会自动调用 refreshSchemes() 重新加载所有方案
|
|
136
|
+
* 当前用户ID(内部使用)
|
|
147
137
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* currentUserId: currentUser?.id
|
|
151
|
-
* ```
|
|
138
|
+
* 用于 SchemeManager 监听用户切换,自动重新加载方案数据
|
|
139
|
+
* 此字段由 useSchemeManager 自动管理,无需手动设置
|
|
152
140
|
*/
|
|
153
141
|
currentUserId?: string | null;
|
|
154
142
|
}
|
|
@@ -3,13 +3,24 @@ import React from "react";
|
|
|
3
3
|
/**
|
|
4
4
|
* 方案管理 API 接口
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* ⚠️ 必须通过 useSchemeManager Hook 创建,然后传入 Provider
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const adapter = useMemo(() => new BackendApiSchemeAdapter({ ... }), []);
|
|
11
|
+
* const schemeManager = useSchemeManager({ adapter, autoLoad: true });
|
|
12
|
+
*
|
|
13
|
+
* <GridPlusContext.Provider value={{
|
|
14
|
+
* ...otherValues,
|
|
15
|
+
* ...schemeManager // 展开方案管理状态
|
|
16
|
+
* }}>
|
|
17
|
+
* ```
|
|
7
18
|
*/
|
|
8
19
|
|
|
9
20
|
/**
|
|
10
21
|
* GridPlus Context 值接口
|
|
11
22
|
*
|
|
12
|
-
*
|
|
23
|
+
* ⚠️ 必须包含方案管理 API,通过 useSchemeManager Hook 创建后传入
|
|
13
24
|
*/
|
|
14
25
|
|
|
15
26
|
export var GridPlusContext = /*#__PURE__*/React.createContext({
|
|
@@ -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
|
}
|