@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>;
|
|
@@ -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
|
}
|
|
@@ -24,7 +24,16 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
24
24
|
* 内部配置类型(所有字段必填)
|
|
25
25
|
*/
|
|
26
26
|
/**
|
|
27
|
-
* 后端 API 响应格式
|
|
27
|
+
* 后端 API 响应格式 - 基础响应
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* 保存方案结果
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* 删除方案结果
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* 设置当前方案结果
|
|
28
37
|
*/
|
|
29
38
|
/**
|
|
30
39
|
* 后端 API 方案存储适配器
|
|
@@ -184,7 +193,7 @@ var BackendApiSchemeAdapter = exports.BackendApiSchemeAdapter = /*#__PURE__*/fun
|
|
|
184
193
|
case 0:
|
|
185
194
|
_context2.prev = 0;
|
|
186
195
|
this.log('加载所有方案数据');
|
|
187
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/
|
|
196
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/schemes");
|
|
188
197
|
_context2.next = 5;
|
|
189
198
|
return this.request(url);
|
|
190
199
|
case 5:
|
|
@@ -216,13 +225,13 @@ var BackendApiSchemeAdapter = exports.BackendApiSchemeAdapter = /*#__PURE__*/fun
|
|
|
216
225
|
key: "saveColumnScheme",
|
|
217
226
|
value: function () {
|
|
218
227
|
var _saveColumnScheme = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(gridId, scheme) {
|
|
219
|
-
var
|
|
228
|
+
var url, response;
|
|
220
229
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
221
230
|
while (1) switch (_context3.prev = _context3.next) {
|
|
222
231
|
case 0:
|
|
223
232
|
_context3.prev = 0;
|
|
224
233
|
this.log("\u4FDD\u5B58\u5217\u65B9\u6848: ".concat(gridId, " - ").concat(scheme.name));
|
|
225
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/column-scheme");
|
|
234
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/save-column-scheme");
|
|
226
235
|
_context3.next = 5;
|
|
227
236
|
return this.request(url, {
|
|
228
237
|
method: 'POST',
|
|
@@ -239,8 +248,8 @@ var BackendApiSchemeAdapter = exports.BackendApiSchemeAdapter = /*#__PURE__*/fun
|
|
|
239
248
|
}
|
|
240
249
|
throw new Error(response.message || '保存失败');
|
|
241
250
|
case 8:
|
|
242
|
-
this.log('保存成功',
|
|
243
|
-
return _context3.abrupt("return", response.
|
|
251
|
+
this.log('保存成功', response.scheme);
|
|
252
|
+
return _context3.abrupt("return", response.scheme);
|
|
244
253
|
case 12:
|
|
245
254
|
_context3.prev = 12;
|
|
246
255
|
_context3.t0 = _context3["catch"](0);
|
|
@@ -268,10 +277,10 @@ var BackendApiSchemeAdapter = exports.BackendApiSchemeAdapter = /*#__PURE__*/fun
|
|
|
268
277
|
case 0:
|
|
269
278
|
_context4.prev = 0;
|
|
270
279
|
this.log("\u5220\u9664\u5217\u65B9\u6848: ".concat(gridId, " - ").concat(schemeId));
|
|
271
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/column-scheme
|
|
280
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/delete-column-scheme?schemeId=").concat(schemeId, "&gridId=").concat(gridId);
|
|
272
281
|
_context4.next = 5;
|
|
273
282
|
return this.request(url, {
|
|
274
|
-
method: '
|
|
283
|
+
method: 'POST'
|
|
275
284
|
});
|
|
276
285
|
case 5:
|
|
277
286
|
response = _context4.sent;
|
|
@@ -305,13 +314,13 @@ var BackendApiSchemeAdapter = exports.BackendApiSchemeAdapter = /*#__PURE__*/fun
|
|
|
305
314
|
key: "saveQueryScheme",
|
|
306
315
|
value: function () {
|
|
307
316
|
var _saveQueryScheme = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(gridId, scheme) {
|
|
308
|
-
var
|
|
317
|
+
var url, response;
|
|
309
318
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
310
319
|
while (1) switch (_context5.prev = _context5.next) {
|
|
311
320
|
case 0:
|
|
312
321
|
_context5.prev = 0;
|
|
313
322
|
this.log("\u4FDD\u5B58\u67E5\u8BE2\u65B9\u6848: ".concat(gridId, " - ").concat(scheme.name));
|
|
314
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/query-scheme");
|
|
323
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/save-query-scheme");
|
|
315
324
|
_context5.next = 5;
|
|
316
325
|
return this.request(url, {
|
|
317
326
|
method: 'POST',
|
|
@@ -328,8 +337,8 @@ var BackendApiSchemeAdapter = exports.BackendApiSchemeAdapter = /*#__PURE__*/fun
|
|
|
328
337
|
}
|
|
329
338
|
throw new Error(response.message || '保存失败');
|
|
330
339
|
case 8:
|
|
331
|
-
this.log('保存成功',
|
|
332
|
-
return _context5.abrupt("return", response.
|
|
340
|
+
this.log('保存成功', response.scheme);
|
|
341
|
+
return _context5.abrupt("return", response.scheme);
|
|
333
342
|
case 12:
|
|
334
343
|
_context5.prev = 12;
|
|
335
344
|
_context5.t0 = _context5["catch"](0);
|
|
@@ -357,10 +366,10 @@ var BackendApiSchemeAdapter = exports.BackendApiSchemeAdapter = /*#__PURE__*/fun
|
|
|
357
366
|
case 0:
|
|
358
367
|
_context6.prev = 0;
|
|
359
368
|
this.log("\u5220\u9664\u67E5\u8BE2\u65B9\u6848: ".concat(gridId, " - ").concat(schemeId));
|
|
360
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/query-scheme
|
|
369
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/delete-query-scheme?schemeId=").concat(schemeId, "&gridId=").concat(gridId);
|
|
361
370
|
_context6.next = 5;
|
|
362
371
|
return this.request(url, {
|
|
363
|
-
method: '
|
|
372
|
+
method: 'POST'
|
|
364
373
|
});
|
|
365
374
|
case 5:
|
|
366
375
|
response = _context6.sent;
|
|
@@ -403,10 +412,10 @@ var BackendApiSchemeAdapter = exports.BackendApiSchemeAdapter = /*#__PURE__*/fun
|
|
|
403
412
|
columnSchemeId: columnSchemeId,
|
|
404
413
|
querySchemeId: querySchemeId
|
|
405
414
|
});
|
|
406
|
-
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/current-scheme");
|
|
415
|
+
url = "".concat(this.config.apiBaseUrl, "/api/extra-object/table-scheme/set-current-scheme");
|
|
407
416
|
_context7.next = 5;
|
|
408
417
|
return this.request(url, {
|
|
409
|
-
method: '
|
|
418
|
+
method: 'POST',
|
|
410
419
|
body: JSON.stringify({
|
|
411
420
|
gridId: gridId,
|
|
412
421
|
columnSchemeId: columnSchemeId,
|