vite-uni-dev-tool 0.0.11 → 0.0.13
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 +55 -1
- package/dist/const.d.ts +133 -0
- package/dist/const.d.ts.map +1 -0
- package/dist/const.js +36 -0
- package/dist/core.d.ts +52 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +80 -0
- package/dist/devConsole/index.d.ts +169 -0
- package/dist/devConsole/index.d.ts.map +1 -0
- package/dist/devConsole/index.js +270 -0
- package/dist/devEvent/index.d.ts +286 -0
- package/dist/devEvent/index.d.ts.map +1 -0
- package/dist/devEvent/index.js +435 -0
- package/dist/devEventBus/index.d.ts +42 -0
- package/dist/devEventBus/index.d.ts.map +1 -0
- package/dist/devEventBus/index.js +70 -0
- package/dist/devIntercept/index.d.ts +119 -0
- package/dist/devIntercept/index.d.ts.map +1 -0
- package/dist/devIntercept/index.js +582 -0
- package/dist/devRunJS/index.d.ts +67 -0
- package/dist/devRunJS/index.d.ts.map +1 -0
- package/dist/devStore/index.d.ts +178 -0
- package/dist/devStore/index.d.ts.map +1 -0
- package/dist/devStore/index.js +395 -0
- package/dist/devToolInfo/index.d.ts +17 -0
- package/dist/devToolInfo/index.d.ts.map +1 -0
- package/dist/devToolInfo/index.js +15 -0
- package/{dev → dist}/plugins/uniDevTool/uniDevTool.d.ts +15 -1
- package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -0
- package/dist/plugins/uniDevTool/uniDevTool.js +35 -0
- package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.js +7 -7
- package/{dev → dist}/plugins/utils/index.d.ts +3 -0
- package/{dev → dist}/plugins/utils/index.d.ts.map +1 -1
- package/dist/plugins/utils/index.js +1 -0
- package/dist/type.d.ts +264 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/utils/array.d.ts +2 -0
- package/dist/utils/array.d.ts.map +1 -0
- package/dist/utils/array.js +12 -0
- package/dist/utils/date.d.ts +19 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +40 -0
- package/dist/utils/file.d.ts +11 -0
- package/dist/utils/file.d.ts.map +1 -0
- package/dist/utils/file.js +87 -0
- package/dist/utils/function.d.ts +28 -0
- package/dist/utils/function.d.ts.map +1 -0
- package/dist/utils/function.js +46 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +55 -0
- package/dist/utils/ip.d.ts +5 -0
- package/dist/utils/ip.d.ts.map +1 -0
- package/dist/utils/ip.js +21 -0
- package/dist/utils/language.d.ts +29 -0
- package/dist/utils/language.d.ts.map +1 -0
- package/dist/utils/language.js +50 -0
- package/dist/utils/object.d.ts +49 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/object.js +118 -0
- package/dist/utils/page.d.ts +7 -0
- package/dist/utils/page.d.ts.map +1 -0
- package/dist/utils/page.js +7 -0
- package/dist/utils/platform.d.ts +4 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +14 -0
- package/dist/utils/string.d.ts +45 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/string.js +88 -0
- package/dist/utils/utils.d.ts +16 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/v2/AutoSizer/utils.d.ts +5 -0
- package/dist/v2/AutoSizer/utils.d.ts.map +1 -0
- package/dist/v2/JsonPretty/hooks/useClipboard.d.ts +4 -0
- package/dist/v2/JsonPretty/hooks/useClipboard.d.ts.map +1 -0
- package/dist/v2/JsonPretty/hooks/useError.d.ts +8 -0
- package/dist/v2/JsonPretty/hooks/useError.d.ts.map +1 -0
- package/dist/v2/JsonPretty/type.d.ts +93 -0
- package/dist/v2/JsonPretty/type.d.ts.map +1 -0
- package/dist/v3/AutoSizer/utils.d.ts +5 -0
- package/dist/v3/AutoSizer/utils.d.ts.map +1 -0
- package/dist/v3/ConsoleList/staticTips.d.ts +13 -0
- package/dist/v3/ConsoleList/staticTips.d.ts.map +1 -0
- package/dist/v3/JsonPretty/hooks/useClipboard.d.ts +4 -0
- package/dist/v3/JsonPretty/hooks/useClipboard.d.ts.map +1 -0
- package/dist/v3/JsonPretty/hooks/useError.d.ts +8 -0
- package/dist/v3/JsonPretty/hooks/useError.d.ts.map +1 -0
- package/dist/v3/JsonPretty/type.d.ts +93 -0
- package/dist/v3/JsonPretty/type.d.ts.map +1 -0
- package/dist/v3/JsonPretty/utils/index.d.ts +10 -0
- package/dist/v3/JsonPretty/utils/index.d.ts.map +1 -0
- package/package.json +5 -5
- package/dev/components/AppInfo/index.vue +0 -36
- package/dev/components/AutoSizer/index.vue +0 -193
- package/dev/components/AutoSizer/index1.vue +0 -186
- package/dev/components/AutoSizer/utils.ts +0 -49
- package/dev/components/Button/index.vue +0 -34
- package/dev/components/CaptureScreen/index.vue +0 -62
- package/dev/components/Checkbox/index.vue +0 -40
- package/dev/components/CloseButton/index.vue +0 -26
- package/dev/components/Code/index.vue +0 -230
- package/dev/components/Connection/index.vue +0 -88
- package/dev/components/ConsoleList/Code.vue +0 -227
- package/dev/components/ConsoleList/ConsoleItem.vue +0 -186
- package/dev/components/ConsoleList/RunJSInput.vue +0 -235
- package/dev/components/ConsoleList/index.vue +0 -130
- package/dev/components/ConsoleList/staticTips.ts +0 -1145
- package/dev/components/DevTool/index.vue +0 -182
- package/dev/components/DevToolButton/index.vue +0 -213
- package/dev/components/DevToolTitle/index.vue +0 -21
- package/dev/components/DevToolWindow/index.vue +0 -1037
- package/dev/components/DeviceInfo/index.vue +0 -32
- package/dev/components/Empty/empty.png +0 -0
- package/dev/components/Empty/index.vue +0 -28
- package/dev/components/FilterInput/index.vue +0 -86
- package/dev/components/JsonPretty/components/Brackets/index.vue +0 -23
- package/dev/components/JsonPretty/components/Carets/index.vue +0 -59
- package/dev/components/JsonPretty/components/CheckController/index.vue +0 -125
- package/dev/components/JsonPretty/components/TreeNode/index.vue +0 -349
- package/dev/components/JsonPretty/hooks/useClipboard.ts +0 -21
- package/dev/components/JsonPretty/hooks/useError.ts +0 -21
- package/dev/components/JsonPretty/index.vue +0 -474
- package/dev/components/JsonPretty/type.ts +0 -125
- package/dev/components/JsonPretty/utils/index.ts +0 -172
- package/dev/components/NetworkList/NetworkDetail.vue +0 -197
- package/dev/components/NetworkList/NetworkItem.vue +0 -106
- package/dev/components/NetworkList/index.vue +0 -115
- package/dev/components/PiniaList/index.vue +0 -64
- package/dev/components/RouteList/index.vue +0 -110
- package/dev/components/RunJS/index.vue +0 -128
- package/dev/components/SettingList/index.vue +0 -225
- package/dev/components/StorageList/index.vue +0 -170
- package/dev/components/SystemInfo/index.vue +0 -34
- package/dev/components/Tabs/index.vue +0 -123
- package/dev/components/Tag/index.vue +0 -89
- package/dev/components/UniEvent/UniEventItem.vue +0 -124
- package/dev/components/UniEvent/index.vue +0 -94
- package/dev/components/UploadList/UploadDetail.vue +0 -208
- package/dev/components/UploadList/UploadItem.vue +0 -111
- package/dev/components/UploadList/index.vue +0 -104
- package/dev/components/VirtualList/index.vue +0 -112
- package/dev/components/VirtualListPro/AutoSize.vue +0 -43
- package/dev/components/VirtualListPro/index.vue +0 -175
- package/dev/components/VirtualListPro/readme.md +0 -40
- package/dev/components/VuexList/index.vue +0 -54
- package/dev/components/WebSocket/WebSocketItem.vue +0 -98
- package/dev/components/WebSocket/WebSocketList.vue +0 -176
- package/dev/components/WebSocket/index.vue +0 -111
- package/dev/components/WindowInfo/index.vue +0 -33
- package/dev/const.ts +0 -166
- package/dev/core.ts +0 -118
- package/dev/devConsole/index.ts +0 -350
- package/dev/devEvent/index.ts +0 -806
- package/dev/devEventBus/index.ts +0 -94
- package/dev/devIntercept/index.ts +0 -745
- package/dev/devRunJS/index.ts +0 -170
- package/dev/devStore/index.ts +0 -718
- package/dev/plugins/uniDevTool/uniDevTool.d.ts.map +0 -1
- package/dev/plugins/uniDevTool/uniDevTool.js +0 -36
- package/dev/plugins/utils/index.js +0 -1
- package/dev/shims-uni.d.ts +0 -43
- package/dev/type.ts +0 -264
- package/dev/utils/array.ts +0 -15
- package/dev/utils/date.ts +0 -75
- package/dev/utils/file.ts +0 -121
- package/dev/utils/function.ts +0 -192
- package/dev/utils/index.d.ts +0 -6
- package/dev/utils/index.ts +0 -46
- package/dev/utils/ip.ts +0 -79
- package/dev/utils/language.ts +0 -72
- package/dev/utils/object.ts +0 -298
- package/dev/utils/page.ts +0 -13
- package/dev/utils/platform.ts +0 -14
- package/dev/utils/string.ts +0 -133
- package/dev/utils/utils.ts +0 -198
- /package/{dev → dist}/index.d.ts +0 -0
- /package/{dev → dist}/index.d.ts.map +0 -0
- /package/{dev → dist}/index.js +0 -0
- /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.d.ts +0 -0
- /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +0 -0
|
@@ -1,745 +0,0 @@
|
|
|
1
|
-
import { backup } from '../core';
|
|
2
|
-
import { DevEvent } from '../devEvent';
|
|
3
|
-
import type { DevTool } from '../type';
|
|
4
|
-
import {
|
|
5
|
-
escapeHTML,
|
|
6
|
-
getCurrentDate,
|
|
7
|
-
getCurrentPagePath,
|
|
8
|
-
parseValue,
|
|
9
|
-
} from '../utils/index';
|
|
10
|
-
import { transformValueToView } from '../utils/language';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 拦截器
|
|
14
|
-
*
|
|
15
|
-
* @export
|
|
16
|
-
* @class DevIntercept
|
|
17
|
-
*/
|
|
18
|
-
export class DevIntercept {
|
|
19
|
-
private event: DevEvent;
|
|
20
|
-
|
|
21
|
-
initPinia = false;
|
|
22
|
-
|
|
23
|
-
cache$on = new Map();
|
|
24
|
-
cache$once = new Map();
|
|
25
|
-
cache$emit = new Map();
|
|
26
|
-
cache$off = new Map();
|
|
27
|
-
|
|
28
|
-
constructor(options: DevTool.DevInterceptOptions) {
|
|
29
|
-
this.event = options.event;
|
|
30
|
-
this.init(options);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
init(options: DevTool.DevInterceptOptions) {
|
|
34
|
-
this.interceptAppError();
|
|
35
|
-
|
|
36
|
-
this.interceptAppConsole();
|
|
37
|
-
|
|
38
|
-
this.interceptSetStorage();
|
|
39
|
-
this.interceptRemoveStorage();
|
|
40
|
-
this.interceptClearStorage();
|
|
41
|
-
|
|
42
|
-
this.interceptUploadFile();
|
|
43
|
-
this.interceptRequest();
|
|
44
|
-
this.interceptSocket();
|
|
45
|
-
|
|
46
|
-
this.interceptSwitchTab();
|
|
47
|
-
this.interceptNavigateTo();
|
|
48
|
-
|
|
49
|
-
this.interceptUniEvent();
|
|
50
|
-
|
|
51
|
-
options.enableInterceptPromiseReject && this.interceptPromiseReject();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* app 中拦截 console
|
|
56
|
-
* app
|
|
57
|
-
* @memberof DevIntercept
|
|
58
|
-
*/
|
|
59
|
-
interceptAppConsole() {
|
|
60
|
-
if (!(uni as any).__log__) return;
|
|
61
|
-
const that = this;
|
|
62
|
-
(uni as any).__log__ = function (
|
|
63
|
-
type: DevTool.ConsoleType,
|
|
64
|
-
line: string,
|
|
65
|
-
...args: any
|
|
66
|
-
) {
|
|
67
|
-
const path = getCurrentPagePath();
|
|
68
|
-
|
|
69
|
-
backup['__log__'](type, line, ...args);
|
|
70
|
-
|
|
71
|
-
that.event.updateConsoleList([
|
|
72
|
-
{
|
|
73
|
-
type,
|
|
74
|
-
position: path,
|
|
75
|
-
time: getCurrentDate(),
|
|
76
|
-
args: args.map((item: any) => {
|
|
77
|
-
// 处理 item 循环引用的问题
|
|
78
|
-
return {
|
|
79
|
-
type: transformValueToView(item),
|
|
80
|
-
value: parseValue(item),
|
|
81
|
-
};
|
|
82
|
-
}),
|
|
83
|
-
stack: line,
|
|
84
|
-
},
|
|
85
|
-
]);
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* 拦截 vue3 信息
|
|
91
|
-
*
|
|
92
|
-
* @memberof DevIntercept
|
|
93
|
-
*/
|
|
94
|
-
interceptVue3(vue3instance: any) {
|
|
95
|
-
if (vue3instance) {
|
|
96
|
-
// 微信小程序触发了该事件
|
|
97
|
-
vue3instance.appContext.config.errorHandler = (
|
|
98
|
-
error: Error,
|
|
99
|
-
vm: any,
|
|
100
|
-
info: string,
|
|
101
|
-
) => {
|
|
102
|
-
if (this.event.getDevToolDestroy()) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
this.interceptErrorVue3(error);
|
|
106
|
-
};
|
|
107
|
-
vue3instance.appContext.config.warnHandler = (
|
|
108
|
-
msg: string,
|
|
109
|
-
vm: any,
|
|
110
|
-
trace: string,
|
|
111
|
-
) => {
|
|
112
|
-
if (this.event.getDevToolDestroy()) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
this.interceptWarnVue3(msg + '\n' + trace);
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* app 中捕获全局错误
|
|
123
|
-
*
|
|
124
|
-
* @memberof DevIntercept
|
|
125
|
-
*/
|
|
126
|
-
interceptAppError() {
|
|
127
|
-
uni.onError((error) => {
|
|
128
|
-
if (this.event.getDevToolDestroy()) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const info = error.toString();
|
|
133
|
-
const stack = (error as unknown as Error)?.stack?.split('\n')?.[1] ?? '';
|
|
134
|
-
|
|
135
|
-
this.event.updateConsoleList([
|
|
136
|
-
{
|
|
137
|
-
type: 'error',
|
|
138
|
-
args: [
|
|
139
|
-
{
|
|
140
|
-
type: 'string',
|
|
141
|
-
value: info,
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
position: getCurrentPagePath(),
|
|
145
|
-
time: getCurrentDate(),
|
|
146
|
-
stack,
|
|
147
|
-
},
|
|
148
|
-
]);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* 拦截 app 错误
|
|
154
|
-
*
|
|
155
|
-
* @param {*} error
|
|
156
|
-
* @memberof DevIntercept
|
|
157
|
-
*/
|
|
158
|
-
interceptErrorVue3(error: Error) {
|
|
159
|
-
const stackList = error?.stack?.split('\n');
|
|
160
|
-
|
|
161
|
-
const stack = stackList?.[1];
|
|
162
|
-
|
|
163
|
-
console.error(error);
|
|
164
|
-
|
|
165
|
-
this.event.updateConsoleList([
|
|
166
|
-
{
|
|
167
|
-
type: 'error',
|
|
168
|
-
args: [
|
|
169
|
-
{
|
|
170
|
-
type: 'string',
|
|
171
|
-
value: error.toString(),
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
position: getCurrentPagePath(),
|
|
175
|
-
time: getCurrentDate(),
|
|
176
|
-
stack,
|
|
177
|
-
},
|
|
178
|
-
]);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
preWarn: any;
|
|
182
|
-
/**
|
|
183
|
-
* 拦截 app 警告
|
|
184
|
-
*
|
|
185
|
-
* @param {*} warn
|
|
186
|
-
* @return {*}
|
|
187
|
-
* @memberof DevIntercept
|
|
188
|
-
*/
|
|
189
|
-
interceptWarnVue3(warn: string) {
|
|
190
|
-
if (this.preWarn === warn) return;
|
|
191
|
-
this.preWarn = warn;
|
|
192
|
-
const path = getCurrentPagePath();
|
|
193
|
-
|
|
194
|
-
const stackList = new Error()?.stack?.split('\n');
|
|
195
|
-
|
|
196
|
-
const stack = stackList?.slice(2)?.[0];
|
|
197
|
-
|
|
198
|
-
console.warn(warn);
|
|
199
|
-
|
|
200
|
-
const args = warn
|
|
201
|
-
.split('\n')
|
|
202
|
-
?.map((item) => escapeHTML(item))
|
|
203
|
-
.join('\n');
|
|
204
|
-
|
|
205
|
-
this.event.updateConsoleList([
|
|
206
|
-
{
|
|
207
|
-
type: 'warn',
|
|
208
|
-
args: [
|
|
209
|
-
{
|
|
210
|
-
type: 'string',
|
|
211
|
-
value: args,
|
|
212
|
-
},
|
|
213
|
-
],
|
|
214
|
-
position: path,
|
|
215
|
-
time: getCurrentDate(),
|
|
216
|
-
stack,
|
|
217
|
-
},
|
|
218
|
-
]);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* 拦截 promise reject
|
|
223
|
-
*
|
|
224
|
-
* @memberof DevIntercept
|
|
225
|
-
*/
|
|
226
|
-
interceptPromiseReject() {
|
|
227
|
-
Object.defineProperty(Promise, 'reject', {
|
|
228
|
-
value: function (reason: any) {
|
|
229
|
-
this.interceptErrorApp(reason);
|
|
230
|
-
return backup.reject.call(Promise, reason);
|
|
231
|
-
},
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* 拦截 nav 跳转
|
|
237
|
-
*
|
|
238
|
-
* @memberof DevIntercept
|
|
239
|
-
*/
|
|
240
|
-
interceptSwitchTab() {
|
|
241
|
-
const that = this;
|
|
242
|
-
uni.addInterceptor('switchTab', {
|
|
243
|
-
invoke(args: UniNamespace.NavigateToOptions) {
|
|
244
|
-
const complete = args.complete;
|
|
245
|
-
args.complete = function (e: any) {
|
|
246
|
-
complete && complete(e);
|
|
247
|
-
|
|
248
|
-
const url = args.url?.slice(1)?.split('?')?.[0] || '/';
|
|
249
|
-
that.event.updateCurrentPagePath(url);
|
|
250
|
-
};
|
|
251
|
-
},
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* 拦截页面跳转
|
|
257
|
-
*
|
|
258
|
-
* @memberof DevIntercept
|
|
259
|
-
*/
|
|
260
|
-
interceptNavigateTo() {
|
|
261
|
-
const that = this;
|
|
262
|
-
uni.addInterceptor('navigateTo', {
|
|
263
|
-
invoke(args: UniNamespace.NavigateToOptions) {
|
|
264
|
-
const complete = args.complete;
|
|
265
|
-
args.complete = function (e: any) {
|
|
266
|
-
complete && complete(e);
|
|
267
|
-
const url = args.url?.slice(1)?.split('?')?.[0] || '/';
|
|
268
|
-
that.event.updateCurrentPagePath(url);
|
|
269
|
-
};
|
|
270
|
-
},
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* 拦截网络请求
|
|
276
|
-
*
|
|
277
|
-
* @memberof DevIntercept
|
|
278
|
-
*/
|
|
279
|
-
interceptRequest() {
|
|
280
|
-
const that = this;
|
|
281
|
-
uni.addInterceptor('request', {
|
|
282
|
-
invoke(args: UniNamespace.RequestOptions) {
|
|
283
|
-
const preIndex = that.event.getRequestIndex();
|
|
284
|
-
const index = that.event.setRequestIndex(preIndex + 1);
|
|
285
|
-
const url = args.url;
|
|
286
|
-
const noParams = url?.split('?')?.[0];
|
|
287
|
-
const lastG = noParams?.lastIndexOf('/');
|
|
288
|
-
const name = noParams?.slice(lastG + 1) ?? '';
|
|
289
|
-
const addInterceptorRequestData: DevTool.NetworkItem = {
|
|
290
|
-
index,
|
|
291
|
-
url: args.url,
|
|
292
|
-
name,
|
|
293
|
-
startTime: Date.now(),
|
|
294
|
-
endTime: 0,
|
|
295
|
-
time: '-',
|
|
296
|
-
headers: {
|
|
297
|
-
requestHeader: Object.entries(args.header ?? {}).map(
|
|
298
|
-
([key, value]) => ({
|
|
299
|
-
key,
|
|
300
|
-
value,
|
|
301
|
-
}),
|
|
302
|
-
),
|
|
303
|
-
responseHeader: [],
|
|
304
|
-
},
|
|
305
|
-
method: args.method || 'GET',
|
|
306
|
-
status: 'pending',
|
|
307
|
-
payload: args?.data ? JSON.stringify(args.data) : '',
|
|
308
|
-
response: '',
|
|
309
|
-
size: '',
|
|
310
|
-
};
|
|
311
|
-
that.event.updateNetworkList([addInterceptorRequestData]);
|
|
312
|
-
|
|
313
|
-
let _complete = args.complete;
|
|
314
|
-
args.complete = function (e: any) {
|
|
315
|
-
_complete && _complete(e);
|
|
316
|
-
|
|
317
|
-
addInterceptorRequestData.status = e.statusCode ?? 'error';
|
|
318
|
-
addInterceptorRequestData.endTime = Date.now();
|
|
319
|
-
|
|
320
|
-
const diff = Date.now() - addInterceptorRequestData.startTime;
|
|
321
|
-
|
|
322
|
-
addInterceptorRequestData.time =
|
|
323
|
-
diff < 1000 ? diff + 'ms' : diff / 1000 + 's';
|
|
324
|
-
|
|
325
|
-
const len =
|
|
326
|
-
e?.header?.['Content-Length'] || e?.header?.['content-length'] || 0;
|
|
327
|
-
addInterceptorRequestData.size =
|
|
328
|
-
len > 1024 ? (len / 1024).toFixed(2) + 'k' : len + 'b';
|
|
329
|
-
addInterceptorRequestData.response = e;
|
|
330
|
-
addInterceptorRequestData.headers.responseHeader = Object.entries(
|
|
331
|
-
e.header ?? {},
|
|
332
|
-
).map(([key, value]) => ({
|
|
333
|
-
key,
|
|
334
|
-
value,
|
|
335
|
-
}));
|
|
336
|
-
that.event.updateNetworkList([addInterceptorRequestData], index);
|
|
337
|
-
};
|
|
338
|
-
},
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* 拦截 websocket
|
|
344
|
-
*
|
|
345
|
-
* @memberof DevIntercept
|
|
346
|
-
*/
|
|
347
|
-
interceptSocket() {
|
|
348
|
-
const that = this;
|
|
349
|
-
|
|
350
|
-
const connectSocket = function (
|
|
351
|
-
connectOption: UniNamespace.ConnectSocketOption,
|
|
352
|
-
) {
|
|
353
|
-
const url = connectOption.url;
|
|
354
|
-
const headers = Object.entries(connectOption.header ?? {}).map(
|
|
355
|
-
([key, value]) => {
|
|
356
|
-
return { key, value } as { key: string; value: string };
|
|
357
|
-
},
|
|
358
|
-
);
|
|
359
|
-
const method = (connectOption.method ?? 'GET').toLowerCase();
|
|
360
|
-
const protocols = connectOption.protocols ?? [];
|
|
361
|
-
that.event.updateWsList({
|
|
362
|
-
url,
|
|
363
|
-
headers,
|
|
364
|
-
method,
|
|
365
|
-
protocols,
|
|
366
|
-
readyState: 'connection',
|
|
367
|
-
message: [],
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
const socketTask = backup.connectSocket({
|
|
371
|
-
...connectOption,
|
|
372
|
-
success: (res) => {
|
|
373
|
-
connectOption.success?.(res);
|
|
374
|
-
that.event.updateWsList({
|
|
375
|
-
url,
|
|
376
|
-
readyState: 'open',
|
|
377
|
-
headers,
|
|
378
|
-
protocols,
|
|
379
|
-
message: [
|
|
380
|
-
{
|
|
381
|
-
data: '连接成功',
|
|
382
|
-
type: 'success',
|
|
383
|
-
time: Date.now(),
|
|
384
|
-
},
|
|
385
|
-
],
|
|
386
|
-
});
|
|
387
|
-
},
|
|
388
|
-
fail: (error) => {
|
|
389
|
-
connectOption.fail?.(error);
|
|
390
|
-
that.event.updateWsList({
|
|
391
|
-
url,
|
|
392
|
-
readyState: 'error',
|
|
393
|
-
headers,
|
|
394
|
-
protocols,
|
|
395
|
-
message: [
|
|
396
|
-
{
|
|
397
|
-
data: '连接失败',
|
|
398
|
-
type: 'error',
|
|
399
|
-
time: Date.now(),
|
|
400
|
-
},
|
|
401
|
-
],
|
|
402
|
-
});
|
|
403
|
-
},
|
|
404
|
-
complete: (res) => {
|
|
405
|
-
connectOption?.complete?.(res);
|
|
406
|
-
},
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
const send = socketTask.send;
|
|
410
|
-
socketTask.send = (options: UniApp.SendSocketMessageOptions) => {
|
|
411
|
-
send.call(socketTask, {
|
|
412
|
-
data: options.data,
|
|
413
|
-
fail: (error) => {
|
|
414
|
-
options?.fail?.(error);
|
|
415
|
-
that.event.updateWsList({
|
|
416
|
-
url,
|
|
417
|
-
readyState: 'error',
|
|
418
|
-
headers,
|
|
419
|
-
protocols,
|
|
420
|
-
message: [
|
|
421
|
-
{
|
|
422
|
-
data: JSON.stringify(error),
|
|
423
|
-
type: 'error',
|
|
424
|
-
time: Date.now(),
|
|
425
|
-
},
|
|
426
|
-
],
|
|
427
|
-
});
|
|
428
|
-
},
|
|
429
|
-
success: (res) => {
|
|
430
|
-
options?.success?.(res);
|
|
431
|
-
that.event.updateWsList({
|
|
432
|
-
readyState: 'open',
|
|
433
|
-
url,
|
|
434
|
-
headers,
|
|
435
|
-
protocols,
|
|
436
|
-
message: [
|
|
437
|
-
{
|
|
438
|
-
type: 'success',
|
|
439
|
-
time: Date.now(),
|
|
440
|
-
data: options.data?.toString(),
|
|
441
|
-
},
|
|
442
|
-
],
|
|
443
|
-
});
|
|
444
|
-
},
|
|
445
|
-
complete: (res) => {
|
|
446
|
-
options?.complete?.(res);
|
|
447
|
-
},
|
|
448
|
-
});
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
const close = socketTask.close;
|
|
452
|
-
socketTask.close = (options: UniApp.CloseSocketOptions) => {
|
|
453
|
-
that.event.updateWsList({
|
|
454
|
-
url,
|
|
455
|
-
readyState: 'closing',
|
|
456
|
-
headers,
|
|
457
|
-
protocols,
|
|
458
|
-
message: [],
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
close.call(socketTask, {
|
|
462
|
-
...options,
|
|
463
|
-
fail: (error) => {
|
|
464
|
-
options?.fail?.(error);
|
|
465
|
-
that.event.updateWsList({
|
|
466
|
-
url,
|
|
467
|
-
headers,
|
|
468
|
-
readyState: 'open',
|
|
469
|
-
protocols,
|
|
470
|
-
message: [],
|
|
471
|
-
});
|
|
472
|
-
},
|
|
473
|
-
success: (res) => {
|
|
474
|
-
options?.success?.(res);
|
|
475
|
-
that.event.updateWsList({
|
|
476
|
-
url,
|
|
477
|
-
headers,
|
|
478
|
-
readyState: 'closed',
|
|
479
|
-
protocols,
|
|
480
|
-
message: [],
|
|
481
|
-
});
|
|
482
|
-
},
|
|
483
|
-
complete: (res) => {
|
|
484
|
-
options?.complete?.(res);
|
|
485
|
-
},
|
|
486
|
-
});
|
|
487
|
-
};
|
|
488
|
-
|
|
489
|
-
socketTask.onMessage((res) => {
|
|
490
|
-
that.event.updateWsList({
|
|
491
|
-
url,
|
|
492
|
-
headers,
|
|
493
|
-
protocols,
|
|
494
|
-
message: [
|
|
495
|
-
{
|
|
496
|
-
type: 'success',
|
|
497
|
-
time: Date.now(),
|
|
498
|
-
data: JSON.parse(res.data),
|
|
499
|
-
},
|
|
500
|
-
],
|
|
501
|
-
});
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
return socketTask;
|
|
505
|
-
};
|
|
506
|
-
|
|
507
|
-
uni.connectSocket = connectSocket;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* 拦截 uni.setStorageSync 和 uni.setStorage
|
|
512
|
-
*
|
|
513
|
-
* @memberof DevIntercept
|
|
514
|
-
*/
|
|
515
|
-
interceptSetStorage() {
|
|
516
|
-
uni.setStorageSync = (key, value) => {
|
|
517
|
-
backup.setStorageSync(key.toString(), value);
|
|
518
|
-
|
|
519
|
-
this.event.updateStoreList([
|
|
520
|
-
{
|
|
521
|
-
key: key.toString(),
|
|
522
|
-
_oldKey: key.toString(),
|
|
523
|
-
value: value,
|
|
524
|
-
},
|
|
525
|
-
]);
|
|
526
|
-
};
|
|
527
|
-
uni.setStorage = (options: UniNamespace.SetStorageOptions) => {
|
|
528
|
-
backup
|
|
529
|
-
.setStorage({
|
|
530
|
-
...options,
|
|
531
|
-
key: options.key?.toString(),
|
|
532
|
-
})
|
|
533
|
-
.then(() => {
|
|
534
|
-
this.event.updateStoreList([
|
|
535
|
-
{
|
|
536
|
-
key: options.key?.toString(),
|
|
537
|
-
_oldKey: options.key?.toString(),
|
|
538
|
-
value: options.data,
|
|
539
|
-
},
|
|
540
|
-
]);
|
|
541
|
-
});
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
/**
|
|
546
|
-
* 拦截 uni.clearStorageSync 和 uni.clearStorage
|
|
547
|
-
*
|
|
548
|
-
* @memberof DevIntercept
|
|
549
|
-
*/
|
|
550
|
-
interceptClearStorage() {
|
|
551
|
-
uni.clearStorageSync = () => {
|
|
552
|
-
backup.clearStorageSync();
|
|
553
|
-
this.event.clearStorage();
|
|
554
|
-
};
|
|
555
|
-
uni.clearStorage = () => {
|
|
556
|
-
backup.clearStorage();
|
|
557
|
-
this.event.clearStorage();
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
/**
|
|
562
|
-
* 拦截 uni.removeStorageSync 和 uni.removeStorage
|
|
563
|
-
*
|
|
564
|
-
* @memberof DevIntercept
|
|
565
|
-
*/
|
|
566
|
-
interceptRemoveStorage() {
|
|
567
|
-
uni.removeStorageSync = (key) => {
|
|
568
|
-
backup.removeStorageSync(key);
|
|
569
|
-
// remove(key);
|
|
570
|
-
this.event.removeStorage(key);
|
|
571
|
-
};
|
|
572
|
-
uni.removeStorage = (options: UniNamespace.RemoveStorageOptions) => {
|
|
573
|
-
backup.removeStorage(options).then(() => {
|
|
574
|
-
this.event.removeStorage(options.key);
|
|
575
|
-
});
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
/** 拦截vuex */
|
|
580
|
-
interceptVuexStorage(store: any) {
|
|
581
|
-
this.event.setVuexList(store.state);
|
|
582
|
-
|
|
583
|
-
store?.subscribe?.((_: any, state: any) => {
|
|
584
|
-
this.event.setVuexList(state);
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
/** 拦截pinia */
|
|
589
|
-
interceptPiniaStore(context: any) {
|
|
590
|
-
if (!this.initPinia) {
|
|
591
|
-
this.initPinia = true;
|
|
592
|
-
this.event.setPiniaStore(context.pinia);
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
this.event.setPiniaList(context.pinia.state.value);
|
|
596
|
-
|
|
597
|
-
context?.store?.$subscribe(() => {
|
|
598
|
-
this.event.setPiniaList({
|
|
599
|
-
[context.store.$id]: context.store.$state,
|
|
600
|
-
});
|
|
601
|
-
});
|
|
602
|
-
return context.pinia;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* 拦截 uni.uploadFile
|
|
607
|
-
*
|
|
608
|
-
* @memberof DevIntercept
|
|
609
|
-
*/
|
|
610
|
-
interceptUploadFile() {
|
|
611
|
-
const that = this;
|
|
612
|
-
const uploadFile = (uploadOption: UniNamespace.UploadFileOption) => {
|
|
613
|
-
const preIndex = that.event.getUploadIndex();
|
|
614
|
-
|
|
615
|
-
const index = that.event.setUploadIndex(preIndex + 1);
|
|
616
|
-
|
|
617
|
-
that.event.updateUploadList(
|
|
618
|
-
[
|
|
619
|
-
{
|
|
620
|
-
index,
|
|
621
|
-
name: uploadOption.name,
|
|
622
|
-
url: uploadOption.url,
|
|
623
|
-
filePath: uploadOption.filePath,
|
|
624
|
-
fileType: uploadOption.fileType,
|
|
625
|
-
headers: {
|
|
626
|
-
requestHeader: Object.entries(uploadOption.header || {}).map(
|
|
627
|
-
([key, value]) => ({ key, value }),
|
|
628
|
-
),
|
|
629
|
-
responseHeader: [],
|
|
630
|
-
},
|
|
631
|
-
formData: uploadOption.formData,
|
|
632
|
-
status: 'pending',
|
|
633
|
-
progress: 0,
|
|
634
|
-
totalBytesSent: 0,
|
|
635
|
-
totalBytesExpectedToSend: 0,
|
|
636
|
-
startTime: Date.now(),
|
|
637
|
-
},
|
|
638
|
-
],
|
|
639
|
-
index,
|
|
640
|
-
);
|
|
641
|
-
const uploadTask = backup.uploadFile({
|
|
642
|
-
...uploadOption,
|
|
643
|
-
success: (res) => {
|
|
644
|
-
uploadOption?.success?.(res);
|
|
645
|
-
that.event.updateUploadList(
|
|
646
|
-
[
|
|
647
|
-
{
|
|
648
|
-
index,
|
|
649
|
-
status: 'success',
|
|
650
|
-
endTime: Date.now(),
|
|
651
|
-
response: {
|
|
652
|
-
...res,
|
|
653
|
-
data: JSON.parse(res.data),
|
|
654
|
-
},
|
|
655
|
-
},
|
|
656
|
-
],
|
|
657
|
-
index,
|
|
658
|
-
);
|
|
659
|
-
that.event.removeUploadTask(index);
|
|
660
|
-
},
|
|
661
|
-
fail: (error) => {
|
|
662
|
-
uploadOption?.fail?.(error);
|
|
663
|
-
that.event.updateUploadList(
|
|
664
|
-
[
|
|
665
|
-
{
|
|
666
|
-
index,
|
|
667
|
-
status: 'error',
|
|
668
|
-
response: error,
|
|
669
|
-
endTime: Date.now(),
|
|
670
|
-
},
|
|
671
|
-
],
|
|
672
|
-
index,
|
|
673
|
-
);
|
|
674
|
-
that.event.removeUploadTask(index);
|
|
675
|
-
},
|
|
676
|
-
});
|
|
677
|
-
uploadTask.onProgressUpdate((res) => {
|
|
678
|
-
that.event.updateUploadList(
|
|
679
|
-
[
|
|
680
|
-
{
|
|
681
|
-
index,
|
|
682
|
-
progress: res.progress,
|
|
683
|
-
totalBytesSent: res.totalBytesSent,
|
|
684
|
-
totalBytesExpectedToSend: res.totalBytesExpectedToSend,
|
|
685
|
-
status: 'uploading',
|
|
686
|
-
},
|
|
687
|
-
],
|
|
688
|
-
index,
|
|
689
|
-
);
|
|
690
|
-
});
|
|
691
|
-
|
|
692
|
-
that.event.addUploadTask(index, uploadTask);
|
|
693
|
-
|
|
694
|
-
return uploadTask;
|
|
695
|
-
};
|
|
696
|
-
uni.uploadFile = uploadFile.bind(uni);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
interceptUniEventFactory(type: DevTool.EventCountKey) {
|
|
700
|
-
const key = `$${type}` as '$on' | '$emit' | '$once' | '$off';
|
|
701
|
-
|
|
702
|
-
uni[`$${type}`] = (eventName: string, callback: (result: any) => void) => {
|
|
703
|
-
const stockList = new Error()?.stack?.split('\n');
|
|
704
|
-
const stack = stockList?.[2];
|
|
705
|
-
backup?.[key]?.(eventName, callback);
|
|
706
|
-
|
|
707
|
-
this.event.updateUniEventList([
|
|
708
|
-
{
|
|
709
|
-
eventName,
|
|
710
|
-
timer: getCurrentDate(),
|
|
711
|
-
stack,
|
|
712
|
-
type,
|
|
713
|
-
},
|
|
714
|
-
]);
|
|
715
|
-
|
|
716
|
-
this.event.updateUniEventCount(type);
|
|
717
|
-
};
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
interceptUniEvent() {
|
|
721
|
-
// 判断是否是相同的位置注册,相同的位置注册只算一次
|
|
722
|
-
this.interceptUniEventFactory('on');
|
|
723
|
-
this.interceptUniEventFactory('once');
|
|
724
|
-
this.interceptUniEventFactory('emit');
|
|
725
|
-
this.interceptUniEventFactory('off');
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
/**
|
|
729
|
-
* 监听截屏
|
|
730
|
-
*
|
|
731
|
-
* @memberof DevIntercept
|
|
732
|
-
*/
|
|
733
|
-
interceptCaptureScreen() {
|
|
734
|
-
uni.onUserCaptureScreen(() => {
|
|
735
|
-
if (!this.event.getDevToolDestroy()) {
|
|
736
|
-
this.event.updateCaptureScreenList([
|
|
737
|
-
{
|
|
738
|
-
position: getCurrentPagePath(),
|
|
739
|
-
timer: getCurrentDate(),
|
|
740
|
-
},
|
|
741
|
-
]);
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
}
|