@nokecy/qc-ui 1.0.95 → 1.0.97
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/cjs/ag-grid-plus/shared/storage/backendApiAdapter.js +25 -16
- 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/esm/ag-grid-plus/shared/storage/backendApiAdapter.js +28 -16
- 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>;
|
|
@@ -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,
|
|
@@ -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
|
}
|
|
@@ -21,7 +21,19 @@ import { message } from 'antd';
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* 后端 API 响应格式
|
|
24
|
+
* 后端 API 响应格式 - 基础响应
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 保存方案结果
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 删除方案结果
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 设置当前方案结果
|
|
25
37
|
*/
|
|
26
38
|
|
|
27
39
|
/**
|
|
@@ -182,7 +194,7 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
|
|
|
182
194
|
case 0:
|
|
183
195
|
_context2.prev = 0;
|
|
184
196
|
this.log('加载所有方案数据');
|
|
185
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/
|
|
197
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/schemes");
|
|
186
198
|
_context2.next = 5;
|
|
187
199
|
return this.request(url);
|
|
188
200
|
case 5:
|
|
@@ -214,13 +226,13 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
|
|
|
214
226
|
key: "saveColumnScheme",
|
|
215
227
|
value: function () {
|
|
216
228
|
var _saveColumnScheme = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(gridId, scheme) {
|
|
217
|
-
var
|
|
229
|
+
var url, response;
|
|
218
230
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
219
231
|
while (1) switch (_context3.prev = _context3.next) {
|
|
220
232
|
case 0:
|
|
221
233
|
_context3.prev = 0;
|
|
222
234
|
this.log("\u4FDD\u5B58\u5217\u65B9\u6848: ".concat(gridId, " - ").concat(scheme.name));
|
|
223
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/column-scheme");
|
|
235
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/save-column-scheme");
|
|
224
236
|
_context3.next = 5;
|
|
225
237
|
return this.request(url, {
|
|
226
238
|
method: 'POST',
|
|
@@ -237,8 +249,8 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
|
|
|
237
249
|
}
|
|
238
250
|
throw new Error(response.message || '保存失败');
|
|
239
251
|
case 8:
|
|
240
|
-
this.log('保存成功',
|
|
241
|
-
return _context3.abrupt("return", response.
|
|
252
|
+
this.log('保存成功', response.scheme);
|
|
253
|
+
return _context3.abrupt("return", response.scheme);
|
|
242
254
|
case 12:
|
|
243
255
|
_context3.prev = 12;
|
|
244
256
|
_context3.t0 = _context3["catch"](0);
|
|
@@ -266,10 +278,10 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
|
|
|
266
278
|
case 0:
|
|
267
279
|
_context4.prev = 0;
|
|
268
280
|
this.log("\u5220\u9664\u5217\u65B9\u6848: ".concat(gridId, " - ").concat(schemeId));
|
|
269
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/column-scheme
|
|
281
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/delete-column-scheme?schemeId=").concat(schemeId, "&gridId=").concat(gridId);
|
|
270
282
|
_context4.next = 5;
|
|
271
283
|
return this.request(url, {
|
|
272
|
-
method: '
|
|
284
|
+
method: 'POST'
|
|
273
285
|
});
|
|
274
286
|
case 5:
|
|
275
287
|
response = _context4.sent;
|
|
@@ -303,13 +315,13 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
|
|
|
303
315
|
key: "saveQueryScheme",
|
|
304
316
|
value: function () {
|
|
305
317
|
var _saveQueryScheme = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(gridId, scheme) {
|
|
306
|
-
var
|
|
318
|
+
var url, response;
|
|
307
319
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
308
320
|
while (1) switch (_context5.prev = _context5.next) {
|
|
309
321
|
case 0:
|
|
310
322
|
_context5.prev = 0;
|
|
311
323
|
this.log("\u4FDD\u5B58\u67E5\u8BE2\u65B9\u6848: ".concat(gridId, " - ").concat(scheme.name));
|
|
312
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/query-scheme");
|
|
324
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/save-query-scheme");
|
|
313
325
|
_context5.next = 5;
|
|
314
326
|
return this.request(url, {
|
|
315
327
|
method: 'POST',
|
|
@@ -326,8 +338,8 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
|
|
|
326
338
|
}
|
|
327
339
|
throw new Error(response.message || '保存失败');
|
|
328
340
|
case 8:
|
|
329
|
-
this.log('保存成功',
|
|
330
|
-
return _context5.abrupt("return", response.
|
|
341
|
+
this.log('保存成功', response.scheme);
|
|
342
|
+
return _context5.abrupt("return", response.scheme);
|
|
331
343
|
case 12:
|
|
332
344
|
_context5.prev = 12;
|
|
333
345
|
_context5.t0 = _context5["catch"](0);
|
|
@@ -355,10 +367,10 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
|
|
|
355
367
|
case 0:
|
|
356
368
|
_context6.prev = 0;
|
|
357
369
|
this.log("\u5220\u9664\u67E5\u8BE2\u65B9\u6848: ".concat(gridId, " - ").concat(schemeId));
|
|
358
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/query-scheme
|
|
370
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/delete-query-scheme?schemeId=").concat(schemeId, "&gridId=").concat(gridId);
|
|
359
371
|
_context6.next = 5;
|
|
360
372
|
return this.request(url, {
|
|
361
|
-
method: '
|
|
373
|
+
method: 'POST'
|
|
362
374
|
});
|
|
363
375
|
case 5:
|
|
364
376
|
response = _context6.sent;
|
|
@@ -401,10 +413,10 @@ export var BackendApiSchemeAdapter = /*#__PURE__*/function () {
|
|
|
401
413
|
columnSchemeId: columnSchemeId,
|
|
402
414
|
querySchemeId: querySchemeId
|
|
403
415
|
});
|
|
404
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/current-scheme");
|
|
416
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/set-current-scheme");
|
|
405
417
|
_context7.next = 5;
|
|
406
418
|
return this.request(url, {
|
|
407
|
-
method: '
|
|
419
|
+
method: 'POST',
|
|
408
420
|
body: JSON.stringify({
|
|
409
421
|
gridId: gridId,
|
|
410
422
|
columnSchemeId: columnSchemeId,
|