@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
|
@@ -1,125 +1,155 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { ColumnScheme, QueryScheme, CurrentSchemeDto } from "../shared/storage/schemeStorageAdapter";
|
|
3
|
-
|
|
3
|
+
import type { BackendApiAdapterConfig } from "../shared/storage/backendApiAdapter";
|
|
4
|
+
/**
|
|
5
|
+
* 方案管理 API 接口
|
|
6
|
+
*
|
|
7
|
+
* 这些 API 由 useGridSchemes Hook 自动提供,不需要在 Provider 中手动配置
|
|
8
|
+
*/
|
|
9
|
+
export interface SchemeManagementAPI {
|
|
4
10
|
/**
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
extensibleColumns: any;
|
|
8
|
-
/**
|
|
9
|
-
* 当前表格的列状态信息,包括列的显示/隐藏、顺序、宽度等
|
|
10
|
-
*/
|
|
11
|
-
columnState: any;
|
|
12
|
-
/**
|
|
13
|
-
* 原始完整的列定义,包含所有自定义属性(cellRenderer、valueFormatter、valueEnum 等)
|
|
14
|
-
* 用于列方案应用时保留这些属性
|
|
15
|
-
*/
|
|
16
|
-
allColDefs?: import('../types').ExtendedColDef[];
|
|
17
|
-
/**
|
|
18
|
-
* 保存当前表格的列状态到服务器(仅保存当前表格)
|
|
19
|
-
* @param gridKey 表格唯一标识
|
|
20
|
-
* @param columnState 当前列状态数组
|
|
21
|
-
*/
|
|
22
|
-
onSaveColumnState: (gridKey: string, columnState: any[]) => void;
|
|
23
|
-
/**
|
|
24
|
-
* 将当前列配置应用为"全局默认",影响所有表格
|
|
25
|
-
* @param columnState 要应用的列配置
|
|
26
|
-
*/
|
|
27
|
-
applyToGlobal: (gridKey: string) => void;
|
|
28
|
-
/**
|
|
29
|
-
* 恢复当前用户当前表格为"默认列配置"
|
|
30
|
-
* @param gridKey 表格唯一标识
|
|
31
|
-
*/
|
|
32
|
-
resetCurrent: (gridKey: string) => void;
|
|
33
|
-
/**
|
|
34
|
-
* 恢复所有用户当前表格为"默认列配置"
|
|
35
|
-
*/
|
|
36
|
-
resetAll: (gridKey: string) => void;
|
|
37
|
-
/**
|
|
38
|
-
* 查询表单项列表(用于查询方案管理器)
|
|
39
|
-
*/
|
|
40
|
-
queryFormItems?: any[];
|
|
41
|
-
/**
|
|
42
|
-
* 当前查询项顺序
|
|
43
|
-
*/
|
|
44
|
-
currentQueryOrder?: string[];
|
|
45
|
-
/**
|
|
46
|
-
* 更新查询项顺序
|
|
47
|
-
*/
|
|
48
|
-
updateQueryOrder?: (order: string[]) => void;
|
|
49
|
-
/**
|
|
50
|
-
* 所有列方案,按 GridId 分组
|
|
11
|
+
* 所有表格的列方案数据
|
|
12
|
+
* key: gridId, value: 该表格的列方案数组
|
|
51
13
|
*/
|
|
52
14
|
columnSchemes?: Record<string, ColumnScheme[]>;
|
|
53
15
|
/**
|
|
54
|
-
*
|
|
16
|
+
* 所有表格的查询方案数据
|
|
17
|
+
* key: gridId, value: 该表格的查询方案数组
|
|
55
18
|
*/
|
|
56
19
|
querySchemes?: Record<string, QueryScheme[]>;
|
|
57
20
|
/**
|
|
58
|
-
*
|
|
21
|
+
* 所有表格的当前方案
|
|
22
|
+
* key: gridId, value: 该表格的当前方案ID
|
|
59
23
|
*/
|
|
60
24
|
currentSchemes?: Record<string, CurrentSchemeDto>;
|
|
61
25
|
/**
|
|
62
|
-
*
|
|
26
|
+
* 方案加载状态
|
|
63
27
|
*/
|
|
64
28
|
schemesLoading?: boolean;
|
|
65
29
|
/**
|
|
66
|
-
*
|
|
30
|
+
* 最后同步时间戳
|
|
67
31
|
*/
|
|
68
32
|
lastSyncTime?: number;
|
|
69
33
|
/**
|
|
70
|
-
*
|
|
71
|
-
* @param gridId 表格ID
|
|
72
|
-
* @param scheme 方案对象
|
|
34
|
+
* 保存列方案
|
|
73
35
|
*/
|
|
74
36
|
saveColumnScheme?: (gridId: string, scheme: ColumnScheme) => Promise<void>;
|
|
75
37
|
/**
|
|
76
38
|
* 删除列方案
|
|
77
|
-
* @param gridId 表格ID
|
|
78
|
-
* @param schemeId 方案ID
|
|
79
39
|
*/
|
|
80
40
|
deleteColumnScheme?: (gridId: string, schemeId: string) => Promise<void>;
|
|
81
41
|
/**
|
|
82
42
|
* 设置当前列方案
|
|
83
|
-
* @param gridId 表格ID
|
|
84
|
-
* @param schemeId 方案ID (null 表示清除)
|
|
85
43
|
*/
|
|
86
44
|
setCurrentColumnScheme?: (gridId: string, schemeId: string | null) => Promise<void>;
|
|
87
45
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @param gridId 表格ID
|
|
90
|
-
* @param scheme 方案对象
|
|
46
|
+
* 保存查询方案
|
|
91
47
|
*/
|
|
92
48
|
saveQueryScheme?: (gridId: string, scheme: QueryScheme) => Promise<void>;
|
|
93
49
|
/**
|
|
94
50
|
* 删除查询方案
|
|
95
|
-
* @param gridId 表格ID
|
|
96
|
-
* @param schemeId 方案ID
|
|
97
51
|
*/
|
|
98
52
|
deleteQueryScheme?: (gridId: string, schemeId: string) => Promise<void>;
|
|
99
53
|
/**
|
|
100
54
|
* 设置当前查询方案
|
|
101
|
-
* @param gridId 表格ID
|
|
102
|
-
* @param schemeId 方案ID (null 表示清除)
|
|
103
55
|
*/
|
|
104
56
|
setCurrentQueryScheme?: (gridId: string, schemeId: string | null) => Promise<void>;
|
|
105
57
|
/**
|
|
106
|
-
*
|
|
58
|
+
* 刷新所有方案数据
|
|
107
59
|
*/
|
|
108
60
|
refreshSchemes?: () => Promise<void>;
|
|
109
61
|
/**
|
|
110
62
|
* 获取指定表格的列方案列表
|
|
111
|
-
* @param gridId 表格ID
|
|
112
63
|
*/
|
|
113
64
|
getColumnSchemes?: (gridId: string) => ColumnScheme[];
|
|
114
65
|
/**
|
|
115
66
|
* 获取指定表格的查询方案列表
|
|
116
|
-
* @param gridId 表格ID
|
|
117
67
|
*/
|
|
118
68
|
getQuerySchemes?: (gridId: string) => QueryScheme[];
|
|
119
69
|
/**
|
|
120
70
|
* 获取指定表格的当前方案
|
|
121
|
-
* @param gridId 表格ID
|
|
122
71
|
*/
|
|
123
72
|
getCurrentScheme?: (gridId: string) => CurrentSchemeDto | null;
|
|
124
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* GridPlus Context 值接口
|
|
76
|
+
*
|
|
77
|
+
* 注意:方案管理 API 不需要在 Provider 中配置,它们由 useGridSchemes Hook 自动提供
|
|
78
|
+
*/
|
|
79
|
+
export interface GridPlusContextValue extends SchemeManagementAPI {
|
|
80
|
+
/**
|
|
81
|
+
* 扩展列,允许运行时动态添加,用于展示用户自定义的列
|
|
82
|
+
*/
|
|
83
|
+
extensibleColumns: any;
|
|
84
|
+
/**
|
|
85
|
+
* 当前表格的列状态信息,包括列的显示/隐藏、顺序、宽度等
|
|
86
|
+
*/
|
|
87
|
+
columnState: any;
|
|
88
|
+
/**
|
|
89
|
+
* 原始完整的列定义,包含所有自定义属性(cellRenderer、valueFormatter、valueEnum 等)
|
|
90
|
+
* 用于列方案应用时保留这些属性
|
|
91
|
+
*/
|
|
92
|
+
allColDefs?: import('../types').ExtendedColDef[];
|
|
93
|
+
/**
|
|
94
|
+
* 保存当前表格的列状态到服务器(仅保存当前表格)
|
|
95
|
+
* @param gridKey 表格唯一标识
|
|
96
|
+
* @param columnState 当前列状态数组
|
|
97
|
+
*/
|
|
98
|
+
onSaveColumnState: (gridKey: string, columnState: any[]) => void;
|
|
99
|
+
/**
|
|
100
|
+
* 将当前列配置应用为"全局默认",影响所有表格
|
|
101
|
+
* @param columnState 要应用的列配置
|
|
102
|
+
*/
|
|
103
|
+
applyToGlobal: (gridKey: string) => void;
|
|
104
|
+
/**
|
|
105
|
+
* 恢复当前用户当前表格为"默认列配置"
|
|
106
|
+
* @param gridKey 表格唯一标识
|
|
107
|
+
*/
|
|
108
|
+
resetCurrent: (gridKey: string) => void;
|
|
109
|
+
/**
|
|
110
|
+
* 恢复所有用户当前表格为"默认列配置"
|
|
111
|
+
*/
|
|
112
|
+
resetAll: (gridKey: string) => void;
|
|
113
|
+
/**
|
|
114
|
+
* 查询表单项列表(用于查询方案管理器)
|
|
115
|
+
*/
|
|
116
|
+
queryFormItems?: any[];
|
|
117
|
+
/**
|
|
118
|
+
* 当前查询项顺序
|
|
119
|
+
*/
|
|
120
|
+
currentQueryOrder?: string[];
|
|
121
|
+
/**
|
|
122
|
+
* 更新查询项顺序
|
|
123
|
+
*/
|
|
124
|
+
updateQueryOrder?: (order: string[]) => void;
|
|
125
|
+
/**
|
|
126
|
+
* 后端 API 配置(可选)
|
|
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() 重新加载所有方案
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```tsx
|
|
150
|
+
* currentUserId: currentUser?.id
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
currentUserId?: string | null;
|
|
154
|
+
}
|
|
125
155
|
export declare const GridPlusContext: React.Context<GridPlusContextValue>;
|
|
@@ -6,6 +6,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.GridPlusContext = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
/**
|
|
10
|
+
* 方案管理 API 接口
|
|
11
|
+
*
|
|
12
|
+
* 这些 API 由 useGridSchemes Hook 自动提供,不需要在 Provider 中手动配置
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* GridPlus Context 值接口
|
|
17
|
+
*
|
|
18
|
+
* 注意:方案管理 API 不需要在 Provider 中配置,它们由 useGridSchemes Hook 自动提供
|
|
19
|
+
*/
|
|
20
|
+
|
|
9
21
|
var GridPlusContext = exports.GridPlusContext = /*#__PURE__*/_react.default.createContext({
|
|
10
22
|
extensibleColumns: [],
|
|
11
23
|
columnState: undefined,
|
|
@@ -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,
|
|
@@ -58,7 +58,8 @@ function useSchemeManager(config) {
|
|
|
58
58
|
_config$autoLoad = config.autoLoad,
|
|
59
59
|
autoLoad = _config$autoLoad === void 0 ? true : _config$autoLoad,
|
|
60
60
|
_config$showErrorMess = config.showErrorMessage,
|
|
61
|
-
showErrorMessage = _config$showErrorMess === void 0 ? true : _config$showErrorMess
|
|
61
|
+
showErrorMessage = _config$showErrorMess === void 0 ? true : _config$showErrorMess,
|
|
62
|
+
currentUserId = config.currentUserId;
|
|
62
63
|
|
|
63
64
|
// ========== 状态管理 ==========
|
|
64
65
|
|
|
@@ -145,6 +146,23 @@ function useSchemeManager(config) {
|
|
|
145
146
|
}
|
|
146
147
|
}, [autoLoad, loadAllSchemes]);
|
|
147
148
|
|
|
149
|
+
// 监听用户ID变化,自动重新加载方案(用于用户登录/切换场景)
|
|
150
|
+
var prevUserIdRef = (0, _react.useRef)(currentUserId);
|
|
151
|
+
(0, _react.useEffect)(function () {
|
|
152
|
+
// 只有在用户ID实际变化且已经加载过数据时才重新加载
|
|
153
|
+
if (currentUserId !== prevUserIdRef.current && loadedRef.current) {
|
|
154
|
+
console.log('[useSchemeManager] 用户切换,重新加载方案', {
|
|
155
|
+
from: prevUserIdRef.current,
|
|
156
|
+
to: currentUserId
|
|
157
|
+
});
|
|
158
|
+
prevUserIdRef.current = currentUserId;
|
|
159
|
+
loadedRef.current = false;
|
|
160
|
+
loadAllSchemes();
|
|
161
|
+
} else {
|
|
162
|
+
prevUserIdRef.current = currentUserId;
|
|
163
|
+
}
|
|
164
|
+
}, [currentUserId, loadAllSchemes]);
|
|
165
|
+
|
|
148
166
|
// ========== 列方案操作 ==========
|
|
149
167
|
|
|
150
168
|
var saveColumnScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
@@ -464,19 +482,37 @@ function useSchemeManager(config) {
|
|
|
464
482
|
}
|
|
465
483
|
|
|
466
484
|
/**
|
|
467
|
-
* Fallback
|
|
485
|
+
* Fallback 模式:根据后端 API 配置自动选择适配器
|
|
468
486
|
*/
|
|
469
|
-
function useFallbackSchemeManager() {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
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();
|
|
474
509
|
|
|
475
|
-
//
|
|
510
|
+
// 使用选定的适配器进行状态管理
|
|
476
511
|
var manager = useSchemeManager({
|
|
477
512
|
adapter: adapter,
|
|
478
513
|
autoLoad: true,
|
|
479
|
-
showErrorMessage: true
|
|
514
|
+
showErrorMessage: true,
|
|
515
|
+
currentUserId: currentUserId
|
|
480
516
|
});
|
|
481
517
|
|
|
482
518
|
// 返回与 Context 相同的接口
|
|
@@ -495,12 +531,43 @@ function useFallbackSchemeManager() {
|
|
|
495
531
|
/**
|
|
496
532
|
* 在组件中使用集中式方案管理
|
|
497
533
|
*
|
|
498
|
-
*
|
|
499
|
-
* 1.
|
|
500
|
-
* 2.
|
|
534
|
+
* 支持两种模式(根据 Context 配置自动选择):
|
|
535
|
+
* 1. Backend API 模式: Context 提供 backendApiConfig,使用后端适配器
|
|
536
|
+
* 2. LocalStorage 模式: 不提供配置,使用本地存储适配器
|
|
501
537
|
*
|
|
502
538
|
* @example
|
|
503
539
|
* ```tsx
|
|
540
|
+
* // 模式1:提供后端 API 配置
|
|
541
|
+
* <GridPlusContext.Provider value={{
|
|
542
|
+
* extensibleColumns: [],
|
|
543
|
+
* columnState: undefined,
|
|
544
|
+
* onSaveColumnState: () => {},
|
|
545
|
+
* applyToGlobal: () => {},
|
|
546
|
+
* resetCurrent: () => {},
|
|
547
|
+
* resetAll: () => {},
|
|
548
|
+
* queryFormItems: [],
|
|
549
|
+
* backendApiConfig: {
|
|
550
|
+
* apiBaseUrl: 'https://api.example.com',
|
|
551
|
+
* getToken: () => localStorage.getItem('token'),
|
|
552
|
+
* getUserId: () => localStorage.getItem('userId')
|
|
553
|
+
* }
|
|
554
|
+
* }}>
|
|
555
|
+
* <MyGrid />
|
|
556
|
+
* </GridPlusContext.Provider>
|
|
557
|
+
*
|
|
558
|
+
* // 模式2:无配置,自动使用 LocalStorage
|
|
559
|
+
* <GridPlusContext.Provider value={{
|
|
560
|
+
* extensibleColumns: [],
|
|
561
|
+
* columnState: undefined,
|
|
562
|
+
* onSaveColumnState: () => {},
|
|
563
|
+
* applyToGlobal: () => {},
|
|
564
|
+
* resetCurrent: () => {},
|
|
565
|
+
* resetAll: () => {},
|
|
566
|
+
* queryFormItems: []
|
|
567
|
+
* }}>
|
|
568
|
+
* <MyGrid />
|
|
569
|
+
* </GridPlusContext.Provider>
|
|
570
|
+
*
|
|
504
571
|
* function MyGrid() {
|
|
505
572
|
* const {
|
|
506
573
|
* columnSchemes,
|
|
@@ -520,17 +587,10 @@ function useFallbackSchemeManager() {
|
|
|
520
587
|
function useGridSchemes() {
|
|
521
588
|
var context = (0, _react.useContext)(_gridContext.GridPlusContext);
|
|
522
589
|
|
|
523
|
-
//
|
|
524
|
-
var
|
|
525
|
-
|
|
526
|
-
// 如果 Context 提供了完整 API,直接使用
|
|
527
|
-
if (hasSchemeApi) {
|
|
528
|
-
return context;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// 否则使用 fallback 模式
|
|
532
|
-
console.warn('[useGridSchemes] Context 未提供方案管理 API,使用 Fallback 模式(LocalStorage + 本地状态)');
|
|
590
|
+
// 根据后端 API 配置自动选择适配器
|
|
591
|
+
var adapterType = context !== null && context !== void 0 && context.backendApiConfig ? '后端 API' : 'LocalStorage';
|
|
592
|
+
console.log("[useGridSchemes] \u4F7F\u7528 ".concat(adapterType, " \u9002\u914D\u5668"));
|
|
533
593
|
|
|
534
594
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
535
|
-
return useFallbackSchemeManager();
|
|
595
|
+
return useFallbackSchemeManager(context === null || context === void 0 ? void 0 : context.backendApiConfig, context === null || context === void 0 ? void 0 : context.currentUserId);
|
|
536
596
|
}
|
|
@@ -1,125 +1,155 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { ColumnScheme, QueryScheme, CurrentSchemeDto } from "../shared/storage/schemeStorageAdapter";
|
|
3
|
-
|
|
3
|
+
import type { BackendApiAdapterConfig } from "../shared/storage/backendApiAdapter";
|
|
4
|
+
/**
|
|
5
|
+
* 方案管理 API 接口
|
|
6
|
+
*
|
|
7
|
+
* 这些 API 由 useGridSchemes Hook 自动提供,不需要在 Provider 中手动配置
|
|
8
|
+
*/
|
|
9
|
+
export interface SchemeManagementAPI {
|
|
4
10
|
/**
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
extensibleColumns: any;
|
|
8
|
-
/**
|
|
9
|
-
* 当前表格的列状态信息,包括列的显示/隐藏、顺序、宽度等
|
|
10
|
-
*/
|
|
11
|
-
columnState: any;
|
|
12
|
-
/**
|
|
13
|
-
* 原始完整的列定义,包含所有自定义属性(cellRenderer、valueFormatter、valueEnum 等)
|
|
14
|
-
* 用于列方案应用时保留这些属性
|
|
15
|
-
*/
|
|
16
|
-
allColDefs?: import('../types').ExtendedColDef[];
|
|
17
|
-
/**
|
|
18
|
-
* 保存当前表格的列状态到服务器(仅保存当前表格)
|
|
19
|
-
* @param gridKey 表格唯一标识
|
|
20
|
-
* @param columnState 当前列状态数组
|
|
21
|
-
*/
|
|
22
|
-
onSaveColumnState: (gridKey: string, columnState: any[]) => void;
|
|
23
|
-
/**
|
|
24
|
-
* 将当前列配置应用为"全局默认",影响所有表格
|
|
25
|
-
* @param columnState 要应用的列配置
|
|
26
|
-
*/
|
|
27
|
-
applyToGlobal: (gridKey: string) => void;
|
|
28
|
-
/**
|
|
29
|
-
* 恢复当前用户当前表格为"默认列配置"
|
|
30
|
-
* @param gridKey 表格唯一标识
|
|
31
|
-
*/
|
|
32
|
-
resetCurrent: (gridKey: string) => void;
|
|
33
|
-
/**
|
|
34
|
-
* 恢复所有用户当前表格为"默认列配置"
|
|
35
|
-
*/
|
|
36
|
-
resetAll: (gridKey: string) => void;
|
|
37
|
-
/**
|
|
38
|
-
* 查询表单项列表(用于查询方案管理器)
|
|
39
|
-
*/
|
|
40
|
-
queryFormItems?: any[];
|
|
41
|
-
/**
|
|
42
|
-
* 当前查询项顺序
|
|
43
|
-
*/
|
|
44
|
-
currentQueryOrder?: string[];
|
|
45
|
-
/**
|
|
46
|
-
* 更新查询项顺序
|
|
47
|
-
*/
|
|
48
|
-
updateQueryOrder?: (order: string[]) => void;
|
|
49
|
-
/**
|
|
50
|
-
* 所有列方案,按 GridId 分组
|
|
11
|
+
* 所有表格的列方案数据
|
|
12
|
+
* key: gridId, value: 该表格的列方案数组
|
|
51
13
|
*/
|
|
52
14
|
columnSchemes?: Record<string, ColumnScheme[]>;
|
|
53
15
|
/**
|
|
54
|
-
*
|
|
16
|
+
* 所有表格的查询方案数据
|
|
17
|
+
* key: gridId, value: 该表格的查询方案数组
|
|
55
18
|
*/
|
|
56
19
|
querySchemes?: Record<string, QueryScheme[]>;
|
|
57
20
|
/**
|
|
58
|
-
*
|
|
21
|
+
* 所有表格的当前方案
|
|
22
|
+
* key: gridId, value: 该表格的当前方案ID
|
|
59
23
|
*/
|
|
60
24
|
currentSchemes?: Record<string, CurrentSchemeDto>;
|
|
61
25
|
/**
|
|
62
|
-
*
|
|
26
|
+
* 方案加载状态
|
|
63
27
|
*/
|
|
64
28
|
schemesLoading?: boolean;
|
|
65
29
|
/**
|
|
66
|
-
*
|
|
30
|
+
* 最后同步时间戳
|
|
67
31
|
*/
|
|
68
32
|
lastSyncTime?: number;
|
|
69
33
|
/**
|
|
70
|
-
*
|
|
71
|
-
* @param gridId 表格ID
|
|
72
|
-
* @param scheme 方案对象
|
|
34
|
+
* 保存列方案
|
|
73
35
|
*/
|
|
74
36
|
saveColumnScheme?: (gridId: string, scheme: ColumnScheme) => Promise<void>;
|
|
75
37
|
/**
|
|
76
38
|
* 删除列方案
|
|
77
|
-
* @param gridId 表格ID
|
|
78
|
-
* @param schemeId 方案ID
|
|
79
39
|
*/
|
|
80
40
|
deleteColumnScheme?: (gridId: string, schemeId: string) => Promise<void>;
|
|
81
41
|
/**
|
|
82
42
|
* 设置当前列方案
|
|
83
|
-
* @param gridId 表格ID
|
|
84
|
-
* @param schemeId 方案ID (null 表示清除)
|
|
85
43
|
*/
|
|
86
44
|
setCurrentColumnScheme?: (gridId: string, schemeId: string | null) => Promise<void>;
|
|
87
45
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @param gridId 表格ID
|
|
90
|
-
* @param scheme 方案对象
|
|
46
|
+
* 保存查询方案
|
|
91
47
|
*/
|
|
92
48
|
saveQueryScheme?: (gridId: string, scheme: QueryScheme) => Promise<void>;
|
|
93
49
|
/**
|
|
94
50
|
* 删除查询方案
|
|
95
|
-
* @param gridId 表格ID
|
|
96
|
-
* @param schemeId 方案ID
|
|
97
51
|
*/
|
|
98
52
|
deleteQueryScheme?: (gridId: string, schemeId: string) => Promise<void>;
|
|
99
53
|
/**
|
|
100
54
|
* 设置当前查询方案
|
|
101
|
-
* @param gridId 表格ID
|
|
102
|
-
* @param schemeId 方案ID (null 表示清除)
|
|
103
55
|
*/
|
|
104
56
|
setCurrentQueryScheme?: (gridId: string, schemeId: string | null) => Promise<void>;
|
|
105
57
|
/**
|
|
106
|
-
*
|
|
58
|
+
* 刷新所有方案数据
|
|
107
59
|
*/
|
|
108
60
|
refreshSchemes?: () => Promise<void>;
|
|
109
61
|
/**
|
|
110
62
|
* 获取指定表格的列方案列表
|
|
111
|
-
* @param gridId 表格ID
|
|
112
63
|
*/
|
|
113
64
|
getColumnSchemes?: (gridId: string) => ColumnScheme[];
|
|
114
65
|
/**
|
|
115
66
|
* 获取指定表格的查询方案列表
|
|
116
|
-
* @param gridId 表格ID
|
|
117
67
|
*/
|
|
118
68
|
getQuerySchemes?: (gridId: string) => QueryScheme[];
|
|
119
69
|
/**
|
|
120
70
|
* 获取指定表格的当前方案
|
|
121
|
-
* @param gridId 表格ID
|
|
122
71
|
*/
|
|
123
72
|
getCurrentScheme?: (gridId: string) => CurrentSchemeDto | null;
|
|
124
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* GridPlus Context 值接口
|
|
76
|
+
*
|
|
77
|
+
* 注意:方案管理 API 不需要在 Provider 中配置,它们由 useGridSchemes Hook 自动提供
|
|
78
|
+
*/
|
|
79
|
+
export interface GridPlusContextValue extends SchemeManagementAPI {
|
|
80
|
+
/**
|
|
81
|
+
* 扩展列,允许运行时动态添加,用于展示用户自定义的列
|
|
82
|
+
*/
|
|
83
|
+
extensibleColumns: any;
|
|
84
|
+
/**
|
|
85
|
+
* 当前表格的列状态信息,包括列的显示/隐藏、顺序、宽度等
|
|
86
|
+
*/
|
|
87
|
+
columnState: any;
|
|
88
|
+
/**
|
|
89
|
+
* 原始完整的列定义,包含所有自定义属性(cellRenderer、valueFormatter、valueEnum 等)
|
|
90
|
+
* 用于列方案应用时保留这些属性
|
|
91
|
+
*/
|
|
92
|
+
allColDefs?: import('../types').ExtendedColDef[];
|
|
93
|
+
/**
|
|
94
|
+
* 保存当前表格的列状态到服务器(仅保存当前表格)
|
|
95
|
+
* @param gridKey 表格唯一标识
|
|
96
|
+
* @param columnState 当前列状态数组
|
|
97
|
+
*/
|
|
98
|
+
onSaveColumnState: (gridKey: string, columnState: any[]) => void;
|
|
99
|
+
/**
|
|
100
|
+
* 将当前列配置应用为"全局默认",影响所有表格
|
|
101
|
+
* @param columnState 要应用的列配置
|
|
102
|
+
*/
|
|
103
|
+
applyToGlobal: (gridKey: string) => void;
|
|
104
|
+
/**
|
|
105
|
+
* 恢复当前用户当前表格为"默认列配置"
|
|
106
|
+
* @param gridKey 表格唯一标识
|
|
107
|
+
*/
|
|
108
|
+
resetCurrent: (gridKey: string) => void;
|
|
109
|
+
/**
|
|
110
|
+
* 恢复所有用户当前表格为"默认列配置"
|
|
111
|
+
*/
|
|
112
|
+
resetAll: (gridKey: string) => void;
|
|
113
|
+
/**
|
|
114
|
+
* 查询表单项列表(用于查询方案管理器)
|
|
115
|
+
*/
|
|
116
|
+
queryFormItems?: any[];
|
|
117
|
+
/**
|
|
118
|
+
* 当前查询项顺序
|
|
119
|
+
*/
|
|
120
|
+
currentQueryOrder?: string[];
|
|
121
|
+
/**
|
|
122
|
+
* 更新查询项顺序
|
|
123
|
+
*/
|
|
124
|
+
updateQueryOrder?: (order: string[]) => void;
|
|
125
|
+
/**
|
|
126
|
+
* 后端 API 配置(可选)
|
|
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() 重新加载所有方案
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```tsx
|
|
150
|
+
* currentUserId: currentUser?.id
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
currentUserId?: string | null;
|
|
154
|
+
}
|
|
125
155
|
export declare const GridPlusContext: React.Context<GridPlusContextValue>;
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 方案管理 API 接口
|
|
5
|
+
*
|
|
6
|
+
* 这些 API 由 useGridSchemes Hook 自动提供,不需要在 Provider 中手动配置
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* GridPlus Context 值接口
|
|
11
|
+
*
|
|
12
|
+
* 注意:方案管理 API 不需要在 Provider 中配置,它们由 useGridSchemes Hook 自动提供
|
|
13
|
+
*/
|
|
14
|
+
|
|
2
15
|
export var GridPlusContext = /*#__PURE__*/React.createContext({
|
|
3
16
|
extensibleColumns: [],
|
|
4
17
|
columnState: undefined,
|