@sun-panel/micro-app 1.0.6 → 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.
@@ -5,90 +5,26 @@ import { WidgetInfo } from './common.js'
5
5
  * 微应用 API 类型定义
6
6
  */
7
7
 
8
- /**
9
- * 微应用错误类型
10
- */
11
- export class MicroAppNetworkRequestError extends Error {
12
- type: 'microApp' | 'targetUrl' | 'unknown'
13
- response?: AxiosResponse
14
-
15
- constructor(message: string, type: 'microApp' | 'targetUrl' | 'unknown' = 'unknown', response?: any) {
16
- super(message)
17
- this.name = 'MicroAppNetworkRequestError'
18
- this.type = type
19
- this.response = response
20
- }
21
- }
22
-
23
- /**
24
- * 数据节点错误类型
25
- */
26
- export class MicroDataNodeError extends Error {
27
- code: string | number
28
- response?: AxiosResponse
29
-
30
- constructor(message: string, code: string | number, response?: any) {
31
- super(message)
32
- this.name = 'MicroDataNodeError'
33
- this.code = code
34
- this.response = response
35
- }
36
- }
8
+ // ========== 请求类型 ==========
37
9
 
38
-
39
- /**
40
- * 高级代理请求参数
41
- */
42
- export interface AdvancedProxyRequest {
10
+ interface RequestOptions {
43
11
  targetUrl: string
44
- method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
12
+ method?: string
45
13
  headers?: Record<string, string>
46
- body?: any
47
- timeout?: number
48
- [key: string]: any
49
- }
50
-
51
- /**
52
- * 窗口配置
53
- */
54
- export interface WindowConfig {
55
- height?: number
56
- width?: number
57
- left?: number
58
- top?: number
59
- isFullScreen?: boolean
60
- background?: string
14
+ body?: string
15
+ templateReplacements: TemplateReplacementRule[]
61
16
  }
62
-
63
- /**
64
- * 打开窗口参数
65
- */
66
- export interface OpenWindowOptions {
67
- componentName: string // 必需:组件名
68
- windowConfig?: WindowConfig // 可选:窗口配置
69
- customParam?: any // 可选:自定义参数
70
- title?: string // 可选:窗口标题
17
+ export interface TemplateReplacementRule {
18
+ placeholder: string // 要替换的字符,用户自定义,如 "{{token}}"
19
+ fields: string[] // 替换参数,可选:targetUrl, method, headers, body
20
+ dataNode: string // 数据节点路径,如 "config.token"
71
21
  }
72
22
 
73
- /**
74
- * 窗口初始化参数
75
- */
76
- export interface PageInitializedParam {
77
- widgetInfo?: WidgetInfo
78
- customParam: any
79
- }
23
+ // ========== 微应用 API 接口 ==========
80
24
 
81
- /**
82
- * 微应用 API 接口定义
83
- */
84
25
  export interface MicroAppAPI {
85
26
  // 窗口管理
86
27
  window: {
87
- /**
88
- * 打开窗口
89
- * @param param 窗口参数
90
- * @returns 窗口ID
91
- */
92
28
  open: (options: OpenWindowOptions) => string
93
29
  // close: (windowId: string) => boolean
94
30
  // toggle: (windowId: string) => boolean
@@ -142,33 +78,62 @@ export interface MicroAppAPI {
142
78
  }
143
79
  }
144
80
 
145
-
146
81
  // 网络透传
147
82
  network: {
148
- request: <T = any>(params: AdvancedProxyRequest) => Promise<T>
149
- // batchRequest: <T = any>(params: AdvancedBatchProxyRequest) => Promise<T>
83
+ request: <T = any>(params: RequestOptions) => Promise<T>
84
+ // batchRequest: <T = any>(params: MicroApp.ApiRequest.AdvancedBatchProxyRequest) => Promise<T>
150
85
  // smartBatchRequest: <T = any>(
151
- // requests: AdvancedProxyItem[],
86
+ // requests: MicroApp.ApiRequest.AdvancedProxyItem[],
152
87
  // batchSize?: number,
153
88
  // ) => Promise<T[]>
154
89
  }
155
90
 
156
-
91
+ // 小部件
157
92
  widget: {
158
- save: <T = any>(data: WidgetInfo, closeWindowAfterSuccess?: boolean) => Promise<T>
93
+ save: <T = any>(data: WidgetInfo) => Promise<T>
159
94
  },
95
+ }
96
+
97
+ // ========== 窗口相关类型 ==========
98
+
99
+ export interface WindowConfig {
100
+ height?: number
101
+ width?: number
102
+ left?: number
103
+ top?: number
104
+ isFullScreen?: boolean
105
+ background?: string
106
+ }
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
160
120
 
161
- // // 状态(只读)
162
- // state: {
163
- // /**
164
- // * 当前窗口数量
165
- // */
166
- // windowCount: number;
167
-
168
- // /**
169
- // * 可见窗口数量
170
- // */
171
- // visibleWindows: number;
172
- // };
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
+ }
173
127
  }
174
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
+ }
@@ -14,6 +14,11 @@ export interface SpContext {
14
14
  // [key: string]: any;
15
15
  }
16
16
 
17
+ export interface PageInitializedParam {
18
+ widgetInfo?: WidgetInfo
19
+ customParam: any
20
+ }
21
+
17
22
  export interface SpContextWidget extends SpContext {
18
23
  // itemInfo: ItemInfo;
19
24
  // background: string;