@sun-panel/micro-app 1.0.5

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.
@@ -0,0 +1,267 @@
1
+ import { WidgetInfo } from './common.js';
2
+
3
+ /**
4
+ * 微应用 API 类型定义
5
+ */
6
+
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
+ }
18
+
19
+ /**
20
+ * 打开窗口参数
21
+ */
22
+ export interface OpenWindowOptions {
23
+ componentName: string // 必需:组件名
24
+ windowConfig?: WindowConfig // 可选:窗口配置
25
+ customParam?: any // 可选:自定义参数
26
+ title?: string // 可选:窗口标题
27
+ }
28
+
29
+ /**
30
+ * 窗口初始化参数
31
+ */
32
+ export interface PageInitializedParam {
33
+ widgetInfo?: WidgetInfo;
34
+ customParam: any;
35
+ }
36
+
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
+ }
59
+
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
+ export interface MicroAppAPI {
90
+ // 窗口管理
91
+ window: {
92
+ /**
93
+ * 打开窗口
94
+ * @param param 窗口参数
95
+ * @returns 窗口ID
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
+ };
113
+
114
+ // 缓存管理
115
+ localCache: {
116
+ // 用户级缓存
117
+ user: {
118
+ /**
119
+ * 获取缓存值
120
+ * @param key 缓存键
121
+ */
122
+ get: (key: string) => Promise<any>;
123
+
124
+ /**
125
+ * 设置缓存值
126
+ * @param key 缓存键
127
+ * @param value 缓存值
128
+ * @param expireTimestamp 过期时间戳(秒),0表示不过期
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
+
161
+ // 应用级缓存
162
+ app: {
163
+ /**
164
+ * 获取缓存值
165
+ * @param key 缓存键
166
+ */
167
+ get: (key: string) => Promise<any>;
168
+
169
+ /**
170
+ * 设置缓存值
171
+ * @param key 缓存键
172
+ * @param value 缓存值
173
+ * @param expireTimestamp 过期时间戳(秒),0表示不过期
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
+ };
206
+
207
+ // 数据节点
208
+ dataNode: {
209
+ // 用户数据节点
210
+ user: {
211
+ getByKey: <T = any>(node: string, key: string) => Promise<T>
212
+ setByKey: <T = any>(node: string, key: string, value: Record<string, any>) => Promise<T>
213
+ delByKey: <T = any>(node: string, key: string) => Promise<T>
214
+ }
215
+ // 应用级数据节点
216
+ app: {
217
+ getByKey: <T = any>(node: string, key: string) => Promise<T>
218
+ setByKey: <T = any>(node: string, key: string, value: Record<string, any>) => Promise<T>
219
+ delByKey: <T = any>(node: string, key: string) => Promise<T>
220
+ }
221
+ }
222
+
223
+
224
+ // 网络透传
225
+ network: {
226
+ /**
227
+ * 发送单个请求
228
+ * @param params 请求参数
229
+ */
230
+ request: <T = any>(params: AdvancedProxyRequest) => Promise<T>;
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
+
249
+
250
+ widget: {
251
+ save: <T = any>(data: WidgetInfo) => Promise<T>
252
+ },
253
+
254
+ // 状态(只读)
255
+ state: {
256
+ /**
257
+ * 当前窗口数量
258
+ */
259
+ windowCount: number;
260
+
261
+ /**
262
+ * 可见窗口数量
263
+ */
264
+ visibleWindows: number;
265
+ };
266
+ }
267
+
@@ -0,0 +1,67 @@
1
+ import { MicroAppAPI } from './api';
2
+ /**
3
+ * 通用类型定义
4
+ */
5
+
6
+ export interface SpContext {
7
+ api: MicroAppAPI;
8
+ isDark: boolean;
9
+ language: string;
10
+ networkMode: string;
11
+ staticPath: string;
12
+ role: number;
13
+ // size: { width: number; height: number };
14
+ [key: string]: any;
15
+ }
16
+
17
+ export interface SpContextWidget extends SpContext {
18
+ // itemInfo: ItemInfo;
19
+ background: string;
20
+ widgetInfo: WidgetInfo;
21
+ gridSizeType: GridSizeType;
22
+ }
23
+
24
+ export interface SpContextPage extends SpContext {
25
+ background: string;
26
+ widgetInfo: WidgetInfo;
27
+ customParam: any;
28
+ }
29
+
30
+
31
+ // 小部件配置
32
+ export interface WidgetInfo {
33
+ widgetId: string // 小部件ID
34
+ background?: string // 背景颜色
35
+ config: Record<string, any> // 配置
36
+ privateConfig: Record<string, any> // 私有配置
37
+ }
38
+
39
+
40
+ // export interface ItemInfo {
41
+ // id: number
42
+ // onlyName: string
43
+ // title: string
44
+ // description: string
45
+ // // microAppId: string
46
+ // // microAppCardSrc: string
47
+ // // microAppSrc: string
48
+ // cardSize: number
49
+ // background: string
50
+ // itemCardGroupId: number
51
+ // sort: number
52
+ // cardData: any
53
+ // cardDataPrivate?: any
54
+ // // blur: number
55
+ // showTitle?: boolean
56
+ // }
57
+
58
+ // LitElement 使用的属性变更类型
59
+ export type ChangedProperties = Map<string, any>;
60
+
61
+ export type GridSizeType = number;
62
+
63
+ export type BackgroundType = string;
64
+
65
+ export type NetworkMode = 'wan' | 'lan' | 'auto';
66
+
67
+ export type RoleType = 0 | 1 | 2; // 0:公开模式 1:私有模式 2:管理员模式