@sun-panel/micro-app 1.0.5 → 1.0.7
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/README.md +1 -277
- package/dist/SunPanelPageElement.d.ts +4 -5
- package/dist/SunPanelPageElement.d.ts.map +1 -1
- package/dist/SunPanelWidgetElement.d.ts +6 -15
- package/dist/SunPanelWidgetElement.d.ts.map +1 -1
- package/dist/index.bundle.js +2 -2
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +4 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/types/api.d.ts +93 -221
- package/dist/types/common.d.ts +11 -5
- package/package.json +1 -1
- package/src/types/api.d.ts +93 -221
- package/src/types/common.d.ts +11 -5
package/src/types/api.d.ts
CHANGED
|
@@ -1,267 +1,139 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AxiosResponse } from 'axios'
|
|
2
|
+
import { WidgetInfo } from './common.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 微应用 API 类型定义
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
* 窗口配置
|
|
9
|
-
*/
|
|
10
|
-
export interface WindowConfig {
|
|
11
|
-
height?: number
|
|
12
|
-
width?: number
|
|
13
|
-
left?: number
|
|
14
|
-
top?: number
|
|
15
|
-
isFullScreen?: boolean
|
|
16
|
-
background?: string
|
|
17
|
-
}
|
|
8
|
+
// ========== 请求类型 ==========
|
|
18
9
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
customParam?: any // 可选:自定义参数
|
|
26
|
-
title?: string // 可选:窗口标题
|
|
10
|
+
interface RequestOptions {
|
|
11
|
+
targetUrl: string
|
|
12
|
+
method?: string
|
|
13
|
+
headers?: Record<string, string>
|
|
14
|
+
body?: string
|
|
15
|
+
templateReplacements: TemplateReplacementRule[]
|
|
27
16
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export interface PageInitializedParam {
|
|
33
|
-
widgetInfo?: WidgetInfo;
|
|
34
|
-
customParam: any;
|
|
17
|
+
export interface TemplateReplacementRule {
|
|
18
|
+
placeholder: string // 要替换的字符,用户自定义,如 "{{token}}"
|
|
19
|
+
fields: string[] // 替换参数,可选:targetUrl, method, headers, body
|
|
20
|
+
dataNode: string // 数据节点路径,如 "config.token"
|
|
35
21
|
}
|
|
36
22
|
|
|
37
|
-
|
|
38
|
-
* 高级代理请求参数
|
|
39
|
-
*/
|
|
40
|
-
export interface AdvancedProxyRequest {
|
|
41
|
-
url: string;
|
|
42
|
-
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
43
|
-
headers?: Record<string, string>;
|
|
44
|
-
body?: any;
|
|
45
|
-
timeout?: number;
|
|
46
|
-
[key: string]: any;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 高级代理请求项
|
|
51
|
-
*/
|
|
52
|
-
export interface AdvancedProxyItem {
|
|
53
|
-
url: string;
|
|
54
|
-
method?: string;
|
|
55
|
-
headers?: Record<string, string>;
|
|
56
|
-
body?: any;
|
|
57
|
-
[key: string]: any;
|
|
58
|
-
}
|
|
23
|
+
// ========== 微应用 API 接口 ==========
|
|
59
24
|
|
|
60
|
-
/**
|
|
61
|
-
* 批量代理请求参数
|
|
62
|
-
*/
|
|
63
|
-
export interface AdvancedBatchProxyRequest {
|
|
64
|
-
requests: AdvancedProxyItem[];
|
|
65
|
-
parallel?: boolean;
|
|
66
|
-
[key: string]: any;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* 保存数据节点请求
|
|
71
|
-
*/
|
|
72
|
-
export interface SaveDataNodeRequest {
|
|
73
|
-
node: string;
|
|
74
|
-
data: any;
|
|
75
|
-
[key: string]: any;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 获取数据节点请求
|
|
80
|
-
*/
|
|
81
|
-
export interface GetDataNodeRequest {
|
|
82
|
-
node: string;
|
|
83
|
-
[key: string]: any;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 微应用 API 接口定义
|
|
88
|
-
*/
|
|
89
25
|
export interface MicroAppAPI {
|
|
90
26
|
// 窗口管理
|
|
91
27
|
window: {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
*/
|
|
97
|
-
open: (options: OpenWindowOptions) => string;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* 关闭窗口
|
|
101
|
-
* @param windowId 窗口ID
|
|
102
|
-
* @returns 是否成功
|
|
103
|
-
*/
|
|
104
|
-
close: (windowId: string) => boolean;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* 切换窗口显示/隐藏
|
|
108
|
-
* @param windowId 窗口ID
|
|
109
|
-
* @returns 是否成功
|
|
110
|
-
*/
|
|
111
|
-
toggle: (windowId: string) => boolean;
|
|
112
|
-
};
|
|
28
|
+
open: (options: OpenWindowOptions) => string
|
|
29
|
+
// close: (windowId: string) => boolean
|
|
30
|
+
// toggle: (windowId: string) => boolean
|
|
31
|
+
}
|
|
113
32
|
|
|
114
33
|
// 缓存管理
|
|
115
34
|
localCache: {
|
|
116
|
-
//
|
|
35
|
+
// 用户缓存
|
|
117
36
|
user: {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*/
|
|
130
|
-
set: (key: string, value: any, expireTimestamp?: number) => Promise<void>;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* 删除缓存
|
|
134
|
-
* @param key 缓存键
|
|
135
|
-
*/
|
|
136
|
-
del: (key: string) => Promise<void>;
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* 清空所有用户缓存
|
|
140
|
-
*/
|
|
141
|
-
clear: () => Promise<void>;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 获取所有缓存键
|
|
145
|
-
*/
|
|
146
|
-
getKeys: () => Promise<string[]>;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* 获取数据并缓存(如果缓存不存在则调用API)
|
|
150
|
-
* @param key 缓存键
|
|
151
|
-
* @param apiCall API调用函数
|
|
152
|
-
* @param expireTimestamp 过期时间(秒)
|
|
153
|
-
*/
|
|
154
|
-
getWithCache: <T>(
|
|
155
|
-
key: string,
|
|
156
|
-
apiCall: () => Promise<T>,
|
|
157
|
-
expireTimestamp?: number,
|
|
158
|
-
) => Promise<T>;
|
|
159
|
-
};
|
|
160
|
-
|
|
37
|
+
get: (key: string) => Promise<any>
|
|
38
|
+
set: (key: string, value: any, expireTimestamp?: number) => Promise<void>
|
|
39
|
+
del: (key: string) => Promise<void>
|
|
40
|
+
clear: () => Promise<void>
|
|
41
|
+
getKeys: () => Promise<string[]>
|
|
42
|
+
// getWithCache: <T>(
|
|
43
|
+
// key: string,
|
|
44
|
+
// apiCall: () => Promise<T>,
|
|
45
|
+
// expireTimestamp?: number,
|
|
46
|
+
// ) => Promise<T>
|
|
47
|
+
}
|
|
161
48
|
// 应用级缓存
|
|
162
49
|
app: {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
set: (key: string, value: any, expireTimestamp?: number) => Promise<void>;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* 删除缓存
|
|
179
|
-
* @param key 缓存键
|
|
180
|
-
*/
|
|
181
|
-
del: (key: string) => Promise<void>;
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* 清空所有应用缓存
|
|
185
|
-
*/
|
|
186
|
-
clear: () => Promise<void>;
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* 获取所有缓存键
|
|
190
|
-
*/
|
|
191
|
-
getKeys: () => Promise<string[]>;
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* 获取数据并缓存(如果缓存不存在则调用API)
|
|
195
|
-
* @param key 缓存键
|
|
196
|
-
* @param apiCall API调用函数
|
|
197
|
-
* @param expireTimestamp 过期时间(秒)
|
|
198
|
-
*/
|
|
199
|
-
getWithCache: <T>(
|
|
200
|
-
key: string,
|
|
201
|
-
apiCall: () => Promise<T>,
|
|
202
|
-
expireTimestamp?: number,
|
|
203
|
-
) => Promise<T>;
|
|
204
|
-
};
|
|
205
|
-
};
|
|
50
|
+
get: (key: string) => Promise<any>
|
|
51
|
+
set: (key: string, value: any, expireTimestamp?: number) => Promise<void>
|
|
52
|
+
del: (key: string) => Promise<void>
|
|
53
|
+
clear: () => Promise<void>
|
|
54
|
+
getKeys: () => Promise<string[]>
|
|
55
|
+
// getWithCache: <T>(
|
|
56
|
+
// key: string,
|
|
57
|
+
// apiCall: () => Promise<T>,
|
|
58
|
+
// expireTimestamp?: number,
|
|
59
|
+
// ) => Promise<T>
|
|
60
|
+
}
|
|
61
|
+
}
|
|
206
62
|
|
|
207
63
|
// 数据节点
|
|
208
64
|
dataNode: {
|
|
209
65
|
// 用户数据节点
|
|
210
66
|
user: {
|
|
211
67
|
getByKey: <T = any>(node: string, key: string) => Promise<T>
|
|
68
|
+
getByKeys: <T = any>(node: string, keys: string[]) => Promise<T>
|
|
212
69
|
setByKey: <T = any>(node: string, key: string, value: Record<string, any>) => Promise<T>
|
|
213
70
|
delByKey: <T = any>(node: string, key: string) => Promise<T>
|
|
214
71
|
}
|
|
215
72
|
// 应用级数据节点
|
|
216
73
|
app: {
|
|
217
74
|
getByKey: <T = any>(node: string, key: string) => Promise<T>
|
|
75
|
+
getByKeys: <T = any>(node: string, keys: string[]) => Promise<T>
|
|
218
76
|
setByKey: <T = any>(node: string, key: string, value: Record<string, any>) => Promise<T>
|
|
219
77
|
delByKey: <T = any>(node: string, key: string) => Promise<T>
|
|
220
78
|
}
|
|
221
79
|
}
|
|
222
80
|
|
|
223
|
-
|
|
224
81
|
// 网络透传
|
|
225
82
|
network: {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
* 批量发送请求
|
|
234
|
-
* @param params 批量请求参数
|
|
235
|
-
*/
|
|
236
|
-
batchRequest: <T = any>(params: AdvancedBatchProxyRequest) => Promise<T>;
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* 智能批量请求(自动分批)
|
|
240
|
-
* @param requests 请求列表
|
|
241
|
-
* @param batchSize 每批数量
|
|
242
|
-
*/
|
|
243
|
-
smartBatchRequest: <T = any>(
|
|
244
|
-
requests: AdvancedProxyItem[],
|
|
245
|
-
batchSize?: number,
|
|
246
|
-
) => Promise<T[]>;
|
|
247
|
-
};
|
|
248
|
-
|
|
83
|
+
request: <T = any>(params: RequestOptions) => Promise<T>
|
|
84
|
+
// batchRequest: <T = any>(params: MicroApp.ApiRequest.AdvancedBatchProxyRequest) => Promise<T>
|
|
85
|
+
// smartBatchRequest: <T = any>(
|
|
86
|
+
// requests: MicroApp.ApiRequest.AdvancedProxyItem[],
|
|
87
|
+
// batchSize?: number,
|
|
88
|
+
// ) => Promise<T[]>
|
|
89
|
+
}
|
|
249
90
|
|
|
91
|
+
// 小部件
|
|
250
92
|
widget: {
|
|
251
93
|
save: <T = any>(data: WidgetInfo) => Promise<T>
|
|
252
94
|
},
|
|
95
|
+
}
|
|
253
96
|
|
|
254
|
-
|
|
255
|
-
state: {
|
|
256
|
-
/**
|
|
257
|
-
* 当前窗口数量
|
|
258
|
-
*/
|
|
259
|
-
windowCount: number;
|
|
97
|
+
// ========== 窗口相关类型 ==========
|
|
260
98
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
99
|
+
export interface WindowConfig {
|
|
100
|
+
height?: number
|
|
101
|
+
width?: number
|
|
102
|
+
left?: number
|
|
103
|
+
top?: number
|
|
104
|
+
isFullScreen?: boolean
|
|
105
|
+
background?: string
|
|
266
106
|
}
|
|
267
107
|
|
|
108
|
+
export interface OpenWindowOptions {
|
|
109
|
+
componentName: string // 必需:组件名
|
|
110
|
+
windowConfig?: WindowConfig // 可选:窗口配置
|
|
111
|
+
customParam?: any // 可选:自定义参数
|
|
112
|
+
title?: string // 可选:窗口标题
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ========== 错误类型 ==========
|
|
116
|
+
|
|
117
|
+
export class MicroAppNetworkRequestError extends Error {
|
|
118
|
+
type: 'microApp' | 'targetUrl' | 'unknown'
|
|
119
|
+
response?: AxiosResponse
|
|
120
|
+
|
|
121
|
+
constructor(message: string, type: 'microApp' | 'targetUrl' | 'unknown' = 'unknown', response?: any) {
|
|
122
|
+
super(message)
|
|
123
|
+
this.name = 'MicroAppNetworkRequestError'
|
|
124
|
+
this.type = type
|
|
125
|
+
this.response = response
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export class MicroDataNodeError extends Error {
|
|
130
|
+
code: string | number
|
|
131
|
+
response?: AxiosResponse
|
|
132
|
+
|
|
133
|
+
constructor(message: string, code: string | number, response?: any) {
|
|
134
|
+
super(message)
|
|
135
|
+
this.name = 'MicroDataNodeError'
|
|
136
|
+
this.code = code
|
|
137
|
+
this.response = response
|
|
138
|
+
}
|
|
139
|
+
}
|
package/src/types/common.d.ts
CHANGED
|
@@ -5,20 +5,25 @@ import { MicroAppAPI } from './api';
|
|
|
5
5
|
|
|
6
6
|
export interface SpContext {
|
|
7
7
|
api: MicroAppAPI;
|
|
8
|
-
|
|
8
|
+
darkMode: boolean;
|
|
9
9
|
language: string;
|
|
10
10
|
networkMode: string;
|
|
11
11
|
staticPath: string;
|
|
12
12
|
role: number;
|
|
13
13
|
// size: { width: number; height: number };
|
|
14
|
-
[key: string]: any;
|
|
14
|
+
// [key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface PageInitializedParam {
|
|
18
|
+
widgetInfo?: WidgetInfo
|
|
19
|
+
customParam: any
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export interface SpContextWidget extends SpContext {
|
|
18
23
|
// itemInfo: ItemInfo;
|
|
19
|
-
background: string;
|
|
24
|
+
// background: string;
|
|
20
25
|
widgetInfo: WidgetInfo;
|
|
21
|
-
gridSizeType: GridSizeType;
|
|
26
|
+
// gridSizeType: GridSizeType;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
export interface SpContextPage extends SpContext {
|
|
@@ -33,7 +38,8 @@ export interface WidgetInfo {
|
|
|
33
38
|
widgetId: string // 小部件ID
|
|
34
39
|
background?: string // 背景颜色
|
|
35
40
|
config: Record<string, any> // 配置
|
|
36
|
-
|
|
41
|
+
gridSize: string
|
|
42
|
+
title: string
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
|