vite-uni-dev-tool 0.0.1

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.
Files changed (69) hide show
  1. package/README.md +120 -0
  2. package/dev/components/Button/index.vue +34 -0
  3. package/dev/components/Checkbox/index.vue +40 -0
  4. package/dev/components/CloseButton/index.vue +25 -0
  5. package/dev/components/Connection/index.vue +98 -0
  6. package/dev/components/ConsoleList/ConsoleItem.vue +89 -0
  7. package/dev/components/ConsoleList/index.vue +98 -0
  8. package/dev/components/DevTool/index.vue +165 -0
  9. package/dev/components/DevToolButton/index.vue +213 -0
  10. package/dev/components/DevToolWindow/index.vue +847 -0
  11. package/dev/components/DeviceInfo/index.vue +32 -0
  12. package/dev/components/Empty/empty.png +0 -0
  13. package/dev/components/Empty/index.vue +28 -0
  14. package/dev/components/FilterInput/index.vue +86 -0
  15. package/dev/components/JsonPretty/components/Brackets/index.vue +23 -0
  16. package/dev/components/JsonPretty/components/Carets/index.vue +63 -0
  17. package/dev/components/JsonPretty/components/CheckController/index.vue +108 -0
  18. package/dev/components/JsonPretty/components/TreeNode/index.vue +348 -0
  19. package/dev/components/JsonPretty/hooks/useClipboard.ts +21 -0
  20. package/dev/components/JsonPretty/hooks/useError.ts +21 -0
  21. package/dev/components/JsonPretty/index.vue +463 -0
  22. package/dev/components/JsonPretty/type.ts +123 -0
  23. package/dev/components/JsonPretty/utils/index.ts +172 -0
  24. package/dev/components/NetworkList/NetworkDetail.vue +197 -0
  25. package/dev/components/NetworkList/NetworkItem.vue +106 -0
  26. package/dev/components/NetworkList/index.vue +108 -0
  27. package/dev/components/PiniaList/index.vue +64 -0
  28. package/dev/components/RouteList/index.vue +98 -0
  29. package/dev/components/SettingList/index.vue +235 -0
  30. package/dev/components/StorageList/index.vue +170 -0
  31. package/dev/components/SystemInfo/index.vue +34 -0
  32. package/dev/components/Tabs/index.vue +110 -0
  33. package/dev/components/Tag/index.vue +89 -0
  34. package/dev/components/UploadList/UploadDetail.vue +208 -0
  35. package/dev/components/UploadList/UploadItem.vue +111 -0
  36. package/dev/components/UploadList/index.vue +94 -0
  37. package/dev/components/VuexList/index.vue +54 -0
  38. package/dev/components/WebSocket/WebSocketItem.vue +98 -0
  39. package/dev/components/WebSocket/WebSocketList.vue +176 -0
  40. package/dev/components/WebSocket/index.vue +99 -0
  41. package/dev/components/WindowInfo/index.vue +33 -0
  42. package/dev/const.ts +95 -0
  43. package/dev/core.ts +103 -0
  44. package/dev/devConsole/index.ts +334 -0
  45. package/dev/devEvent/index.ts +665 -0
  46. package/dev/devIntercept/index.ts +629 -0
  47. package/dev/devStore/index.ts +581 -0
  48. package/dev/index.d.ts +6 -0
  49. package/dev/index.d.ts.map +1 -0
  50. package/dev/index.js +1 -0
  51. package/dev/plugins/uniDevTool/uniDevTool.d.ts +66 -0
  52. package/dev/plugins/uniDevTool/uniDevTool.d.ts.map +1 -0
  53. package/dev/plugins/uniDevTool/uniDevTool.js +13 -0
  54. package/dev/plugins/uniGlobalComponents/uniGlobalComponents.d.ts +28 -0
  55. package/dev/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +1 -0
  56. package/dev/plugins/uniGlobalComponents/uniGlobalComponents.js +5 -0
  57. package/dev/shims-uni.d.ts +43 -0
  58. package/dev/type.ts +188 -0
  59. package/dev/utils/date.ts +75 -0
  60. package/dev/utils/file.ts +121 -0
  61. package/dev/utils/function.ts +192 -0
  62. package/dev/utils/index.ts +25 -0
  63. package/dev/utils/ip.ts +79 -0
  64. package/dev/utils/language.ts +19 -0
  65. package/dev/utils/object.ts +235 -0
  66. package/dev/utils/page.ts +13 -0
  67. package/dev/utils/string.ts +23 -0
  68. package/dev/utils/utils.ts +198 -0
  69. package/package.json +34 -0
@@ -0,0 +1,847 @@
1
+ <template>
2
+ <view class="dev-tool-window" v-if="open">
3
+ <!-- :style="{
4
+ height: `${systemInfo?.safeArea?.height}px`
5
+ }" -->
6
+ <view class="dev-tool-window-bg"></view>
7
+ <Tabs
8
+ v-model="activeTab"
9
+ :items="items"
10
+ :scroll-left="tabScrollLeft"
11
+ @close="onCloseWindow"
12
+ @scroll="debounceScrollTabs"
13
+ @change="onChangeTabs"
14
+ >
15
+ <!-- <template #extra>
16
+ <view style="margin-left: 6px">{{ sizeFormat }}</view>
17
+ </template> -->
18
+ </Tabs>
19
+ <view class="dev-tool-window-container">
20
+ <ConsoleList
21
+ :currentConsoleType="currentConsoleType"
22
+ :consoleList="consoleList"
23
+ v-if="activeTab === 'Console'"
24
+ v-model="searchConsole"
25
+ @choose="onConsoleChoose"
26
+ @search="onSearchConsole"
27
+ />
28
+ <NetworkList
29
+ :currentNetworkType="currentNetworkType"
30
+ :networkList="networkList"
31
+ v-model="searchNetwork"
32
+ v-if="activeTab === 'Network'"
33
+ @choose="onNetworkChoose"
34
+ @search="onSearchNetwork"
35
+ />
36
+ <UploadList
37
+ :currentUploadType="currentUploadType"
38
+ :uploadList="uploadList"
39
+ v-model="searchUpload"
40
+ v-if="activeTab === 'Upload'"
41
+ @choose="onUploadChoose"
42
+ @search="onSearchUpload"
43
+ />
44
+ <WebSocket
45
+ :wsList="wsList"
46
+ :currentWebSocketType="currentWebSocketType"
47
+ v-model="searchWs"
48
+ v-if="activeTab === 'WebSocket'"
49
+ @choose="onWebSocketChoose"
50
+ @search="onSearchWs"
51
+ />
52
+ <Connection
53
+ v-if="activeTab === 'Connection'"
54
+ :netWorkStatus="netWorkStatus"
55
+ />
56
+ <RouteList
57
+ v-if="activeTab === 'Route'"
58
+ :routeList="routeList"
59
+ v-model="searchRoute"
60
+ @goTo="onGoTo"
61
+ @search="onSearchRoute"
62
+ @routeRefresh="onRouteRefresh"
63
+ />
64
+ <SettingList
65
+ v-if="activeTab === 'Setting'"
66
+ :devToolVisible="devToolVisible"
67
+ :sizeFormat="sizeFormat"
68
+ @showDevButton="onShowDevButton"
69
+ @restartDevTool="onRestartDevTool"
70
+ @restartApp="onRestartApp"
71
+ @exportLog="onExportLog"
72
+ @screenshot="onScreenshot"
73
+ @clearCache="onClearCache"
74
+ @destroyDevTool="onDestroyDevTool"
75
+ />
76
+ <StorageList
77
+ v-if="activeTab === 'Storage'"
78
+ v-model:storage-list="storageList"
79
+ v-model="searchStorage"
80
+ @choose="onStorageChoose"
81
+ @remove="onStorageRemove"
82
+ @diff-value="onChangeStorage"
83
+ @search="onSearchStorage"
84
+ />
85
+ <VuexList
86
+ v-if="activeTab === 'Vuex'"
87
+ v-model:vuexList="vuexList"
88
+ @diff-value="onChangeVuex"
89
+ />
90
+ <PiniaList
91
+ v-if="activeTab === 'Pinia'"
92
+ v-model:pinia-list="piniaList"
93
+ @diff-value="onChangePinia"
94
+ />
95
+ <SystemInfo v-if="activeTab === 'System'" :systemInfo="systemInfo" />
96
+ <DeviceInfo v-if="activeTab === 'Device'" :deviceInfo="deviceInfo" />
97
+ <WindowInfo v-if="activeTab === 'Window'" :windowInfo="windowInfo" />
98
+ </view>
99
+ </view>
100
+ </template>
101
+
102
+ <script setup lang="ts">
103
+ import { onLoad, onUnload, onShow, onHide } from '@dcloudio/uni-app';
104
+ import { ref, onMounted } from 'vue';
105
+ import Tabs from '../Tabs/index.vue';
106
+ import ConsoleList from '../ConsoleList/index.vue';
107
+ import NetworkList from '../NetworkList/index.vue';
108
+ import Connection from '../Connection/index.vue';
109
+ import StorageList from '../StorageList/index.vue';
110
+ import RouteList from '../RouteList/index.vue';
111
+ import SettingList from '../SettingList/index.vue';
112
+ import VuexList from '../VuexList/index.vue';
113
+ import PiniaList from '../PiniaList/index.vue';
114
+ import SystemInfo from '../SystemInfo/index.vue';
115
+ import DeviceInfo from '../DeviceInfo/index.vue';
116
+ import WindowInfo from '../WindowInfo/index.vue';
117
+ import WebSocket from '../WebSocket/index.vue';
118
+ import UploadList from '../UploadList/index.vue';
119
+ import {
120
+ DEV_BUTTON_SHOW_OR_HIDE,
121
+ DEV_CONSOLE_CLEAR,
122
+ DEV_DESTROY,
123
+ DEV_EXPORT_LOG,
124
+ DEV_LOG_CACHE_CLEAR,
125
+ DEV_NETWORK_CLEAR,
126
+ DEV_PAGE_JUMP,
127
+ DEV_PINIA_CHANGE,
128
+ DEV_RESTART_APP,
129
+ DEV_RESTART_DEBUGGER,
130
+ DEV_ROUTE_REFRESH,
131
+ DEV_STORAGE_ADD,
132
+ DEV_STORAGE_CLEAR,
133
+ DEV_STORAGE_REFRESH,
134
+ DEV_STORAGE_REMOVE,
135
+ DEV_STORAGE_UPDATE,
136
+ DEV_UPLOAD_CLEAR,
137
+ DEV_VUEX_CHANGE,
138
+ DEV_WEBSOCKET_CLEAR,
139
+ DEV_WINDOW_INFO,
140
+ DEV_APP_MESSAGE,
141
+ } from '../../const';
142
+ import { debounce, hightLight } from '../../utils/index';
143
+ import type { DevTool } from '../../type';
144
+
145
+ const items = [
146
+ {
147
+ key: 'Console',
148
+ label: 'Console',
149
+ value: 'Console',
150
+ },
151
+ {
152
+ key: 'Connection',
153
+ label: 'Connection',
154
+ value: 'Connection',
155
+ },
156
+ {
157
+ key: 'Network',
158
+ label: 'Network',
159
+ value: 'NetWork',
160
+ },
161
+ {
162
+ key: 'Upload',
163
+ label: 'Upload',
164
+ value: 'Upload',
165
+ },
166
+ {
167
+ key: 'WebSocket',
168
+ label: 'WebSocket',
169
+ value: 'WebSocket',
170
+ },
171
+
172
+ {
173
+ key: 'Route',
174
+ label: 'Route',
175
+ value: 'Route',
176
+ },
177
+ {
178
+ key: 'Storage',
179
+ label: 'Storage',
180
+ value: 'Storage',
181
+ },
182
+
183
+ {
184
+ key: 'Vuex',
185
+ label: 'Vuex',
186
+ value: 'Vuex',
187
+ },
188
+ {
189
+ key: 'Pinia',
190
+ label: 'Pinia',
191
+ value: 'Pinia',
192
+ },
193
+ {
194
+ key: 'Window',
195
+ label: 'Window',
196
+ value: 'Window',
197
+ },
198
+ {
199
+ key: 'Device',
200
+ label: 'Device',
201
+ value: 'Device',
202
+ },
203
+ {
204
+ key: 'System',
205
+ label: 'System',
206
+ value: 'System',
207
+ },
208
+ {
209
+ key: 'Setting',
210
+ label: 'Setting',
211
+ value: 'Setting',
212
+ },
213
+ ];
214
+
215
+ const backup: {
216
+ consoleList: DevTool.ConsoleItem[];
217
+ networkList: DevTool.NetworkItem[];
218
+ storageList: DevTool.StorageItem[];
219
+ wsList: DevTool.WS[];
220
+ uploadList: DevTool.UploadItem[];
221
+ routeList: DevTool.Page[];
222
+ } = {
223
+ consoleList: [],
224
+ networkList: [],
225
+ storageList: [],
226
+ wsList: [],
227
+ uploadList: [],
228
+ routeList: [],
229
+ };
230
+ const consoleList = ref<DevTool.ConsoleItem[]>([]);
231
+ const networkList = ref<DevTool.NetworkItem[]>([]);
232
+ const uploadList = ref<DevTool.UploadItem[]>([]);
233
+ const storageList = ref<DevTool.StorageItem[]>([]);
234
+ const routeList = ref<DevTool.Page[]>([]);
235
+ const wsList = ref<DevTool.WS[]>([]);
236
+ const vuexList = ref<Record<string, any>>({});
237
+ const piniaList = ref<Record<string, any>>({});
238
+ const systemInfo = ref<Record<string, any>>({});
239
+ const deviceInfo = ref<Record<string, any>>({});
240
+ const windowInfo = ref<Record<string, any>>({});
241
+ const netWorkStatus = ref<{
242
+ isConnected?: boolean;
243
+ networkType?: string;
244
+ }>({});
245
+ const sizeFormat = ref('');
246
+
247
+ const devToolVisible = ref(true);
248
+
249
+ const activeTab = ref('Console');
250
+ const tabScrollLeft = ref(0);
251
+ const currentConsoleType = ref('all');
252
+ const currentNetworkType = ref('all');
253
+ const currentUploadType = ref('all');
254
+ const currentWebSocketType = ref('all');
255
+
256
+ const searchConsole = ref('');
257
+ const searchNetwork = ref('');
258
+ const searchUpload = ref('');
259
+ const searchWs = ref('');
260
+ const searchRoute = ref('');
261
+ const searchStorage = ref('');
262
+
263
+ const props = defineProps<{ open?: boolean; data?: DevTool.WindowData }>();
264
+
265
+ const emits = defineEmits<{
266
+ (e: 'close'): void;
267
+ (e: 'sendMessage', data: { type: string; data: Record<string, any> }): void;
268
+ }>();
269
+
270
+ const listenPostMessage = (data: DevTool.WindowData) => {
271
+ if (!props.open) return;
272
+ if (!isActive) return;
273
+ devToolVisible.value = data.devToolVisible ?? false;
274
+
275
+ if (data.consoleList) {
276
+ consoleList.value = [...(data.consoleList ?? [])]
277
+ .filter((item) => {
278
+ if (currentConsoleType.value === 'all') return item;
279
+ if (currentConsoleType.value !== 'clear') {
280
+ return item.type === currentConsoleType.value;
281
+ }
282
+ return item;
283
+ })
284
+ .filter((item) => {
285
+ return (
286
+ item.args.some((arg) => arg.includes(searchConsole.value)) ||
287
+ item.position.includes(searchConsole.value) ||
288
+ item?.stack?.includes(searchConsole.value)
289
+ );
290
+ })
291
+ ?.map((item) => {
292
+ return {
293
+ ...item,
294
+ position: hightLight(item.position, searchConsole.value),
295
+ stack: hightLight(item.stack, searchConsole.value),
296
+ args: item.args.map((arg) => hightLight(arg, searchConsole.value)),
297
+ };
298
+ });
299
+
300
+ backup.consoleList = [...data.consoleList];
301
+ }
302
+
303
+ if (data.networkList) {
304
+ networkList.value = [...(data.networkList ?? [])]
305
+ .filter((item) => {
306
+ if (currentNetworkType.value === 'all') return item;
307
+ if (currentNetworkType.value !== 'clear') {
308
+ return item.method === currentNetworkType.value;
309
+ }
310
+ return item;
311
+ })
312
+ ?.filter((item) => item?.url?.includes(searchNetwork.value))
313
+ ?.map((item) => {
314
+ return {
315
+ ...item,
316
+ url: hightLight(item.url, searchNetwork.value),
317
+ };
318
+ });
319
+
320
+ backup.networkList = [...data.networkList];
321
+ }
322
+
323
+ if (data.uploadList) {
324
+ uploadList.value = [...(data.uploadList ?? [])]
325
+ .filter((item) => {
326
+ if (currentUploadType.value === 'all') return item;
327
+ if (currentUploadType.value !== 'clear') {
328
+ return item.status === currentUploadType.value;
329
+ }
330
+ return item;
331
+ })
332
+ .filter((item) => {
333
+ return item.url?.includes(searchUpload.value);
334
+ })
335
+ ?.map((item) => {
336
+ return {
337
+ ...item,
338
+ url: hightLight(item.url, searchUpload.value),
339
+ };
340
+ });
341
+ backup.uploadList = [...data.uploadList];
342
+ }
343
+
344
+ if (data.storageList) {
345
+ storageList.value = [...(data.storageList ?? [])]
346
+ ?.filter((item) => item._oldKey.includes(searchStorage.value))
347
+ ?.map((item) => {
348
+ return {
349
+ ...item,
350
+ _oldKey: hightLight(item._oldKey, searchStorage.value),
351
+ };
352
+ });
353
+ backup.storageList = [...data.storageList];
354
+ }
355
+
356
+ if (data.wsList) {
357
+ wsList.value = [...(data.wsList ?? [])]
358
+ .filter((item) => {
359
+ if (currentWebSocketType.value === 'all') return item;
360
+ return item.readyState === currentWebSocketType.value;
361
+ })
362
+ .filter((item) => item.url.includes(searchWs.value))
363
+ ?.map((item) => {
364
+ return {
365
+ ...item,
366
+ url: hightLight(item.url, searchWs.value),
367
+ };
368
+ });
369
+ backup.wsList = [...data.wsList];
370
+ }
371
+
372
+ if (data.routeList) {
373
+ routeList.value = [...(data.routeList ?? [])]
374
+ ?.filter(
375
+ (item) =>
376
+ item.path.includes(searchRoute.value) ||
377
+ item.name?.includes(searchRoute.value),
378
+ )
379
+ ?.map((item) => {
380
+ return {
381
+ ...item,
382
+ name: hightLight(item.name, searchRoute.value),
383
+ path: hightLight(item.path, searchRoute.value),
384
+ };
385
+ });
386
+ backup.routeList = [...data.routeList];
387
+ }
388
+
389
+ if (data.vuexList) {
390
+ vuexList.value = data.vuexList;
391
+ }
392
+
393
+ if (data.piniaList) {
394
+ piniaList.value = data.piniaList;
395
+ }
396
+
397
+ if (data.systemInfo) {
398
+ systemInfo.value = data.systemInfo;
399
+ }
400
+
401
+ if (data.deviceInfo) {
402
+ deviceInfo.value = data.deviceInfo;
403
+ }
404
+ if (data.windowInfo) {
405
+ windowInfo.value = data.windowInfo;
406
+ }
407
+
408
+ if (data.netWorkStatus) {
409
+ netWorkStatus.value = data.netWorkStatus;
410
+ }
411
+
412
+ if (data.sizeFormat) {
413
+ sizeFormat.value = data.sizeFormat;
414
+ }
415
+ };
416
+
417
+ let isActive = false;
418
+ onMounted(() => {
419
+ const windowInfo = uni.getStorageSync(DEV_WINDOW_INFO);
420
+ if (windowInfo) {
421
+ activeTab.value = windowInfo?.activeTab || 'Console';
422
+ currentConsoleType.value = windowInfo?.currentConsoleType || 'all';
423
+ currentNetworkType.value = windowInfo?.currentNetworkType || 'all';
424
+ tabScrollLeft.value = windowInfo?.tabScrollLeft || 0;
425
+ }
426
+ if (props.data) {
427
+ listenPostMessage(props.data);
428
+ }
429
+ });
430
+
431
+ onLoad(() => {
432
+ isActive = true;
433
+ uni.$on(DEV_APP_MESSAGE, listenPostMessage);
434
+ });
435
+ onUnload(() => {
436
+ isActive = false;
437
+ uni.$off(DEV_APP_MESSAGE, listenPostMessage);
438
+ });
439
+
440
+ onShow(() => {
441
+ isActive = true;
442
+ });
443
+ onHide(() => {
444
+ isActive = false;
445
+ });
446
+
447
+ /** 发送消息给 uniapp */
448
+ function basicSendMessage(message: {
449
+ type: string;
450
+ data: Record<string, any>;
451
+ }) {
452
+ emits('sendMessage', message);
453
+ }
454
+
455
+ function setWindowInfo() {
456
+ uni.setStorageSync(DEV_WINDOW_INFO, {
457
+ activeTab: activeTab.value,
458
+ currentConsoleType: currentConsoleType.value,
459
+ currentNetworkType: currentNetworkType.value,
460
+ currentWebSocketType: currentWebSocketType.value,
461
+ tabScrollLeft: tabScrollLeft.value,
462
+ });
463
+ }
464
+
465
+ const debounceSetWindowInfo = debounce(setWindowInfo, 200);
466
+
467
+ function onCloseWindow() {
468
+ emits('close');
469
+ setWindowInfo();
470
+ }
471
+ function onChangeTabs() {
472
+ setWindowInfo();
473
+ }
474
+
475
+ function onScrollTabs(e: any) {
476
+ tabScrollLeft.value = e.detail.scrollLeft;
477
+ debounceSetWindowInfo();
478
+ }
479
+
480
+ const debounceScrollTabs = debounce(onScrollTabs, 200);
481
+
482
+ function onConsoleChoose(
483
+ type: 'all' | 'log' | 'info' | 'warn' | 'error' | 'clear',
484
+ ) {
485
+ if (type === 'clear') {
486
+ consoleList.value = [];
487
+ backup.consoleList = [];
488
+ basicSendMessage({
489
+ type: DEV_CONSOLE_CLEAR,
490
+ data: {},
491
+ });
492
+ return;
493
+ } else if (type === 'all') {
494
+ currentConsoleType.value = type;
495
+ consoleList.value = backup.consoleList;
496
+ } else {
497
+ currentConsoleType.value = type;
498
+ consoleList.value = backup.consoleList.filter((item) => item.type === type);
499
+ }
500
+ setWindowInfo();
501
+ }
502
+
503
+ function onSearchConsole(value: string) {
504
+ consoleList.value = backup.consoleList
505
+ .filter((item) => {
506
+ return (
507
+ item.args.some((arg) => arg.includes(value)) ||
508
+ item.position.includes(value) ||
509
+ item?.stack?.includes(value)
510
+ );
511
+ })
512
+ ?.map((item) => {
513
+ return {
514
+ ...item,
515
+ position: hightLight(item.position, searchConsole.value),
516
+ stack: hightLight(item.stack, searchConsole.value),
517
+ args: item.args.map((arg) => hightLight(arg, value)),
518
+ };
519
+ });
520
+ }
521
+
522
+ function onNetworkChoose(type: string) {
523
+ if (type === 'clear') {
524
+ networkList.value = [];
525
+ backup.networkList = [];
526
+ basicSendMessage({
527
+ type: DEV_NETWORK_CLEAR,
528
+ data: {},
529
+ });
530
+ return;
531
+ } else if (type === 'all') {
532
+ currentNetworkType.value = type;
533
+ networkList.value = backup.networkList;
534
+ } else if (type === 'error') {
535
+ currentNetworkType.value = type;
536
+ networkList.value = backup.networkList.filter((item) => {
537
+ return item.status === 'error' || /[4,5]\d{2,}/.test(item.status + '');
538
+ });
539
+ } else {
540
+ currentNetworkType.value = type;
541
+ networkList.value = backup.networkList.filter(
542
+ (item) => item.method === type,
543
+ );
544
+ }
545
+
546
+ setWindowInfo();
547
+ }
548
+
549
+ function onSearchNetwork(value: string) {
550
+ networkList.value = backup.networkList
551
+ .filter((item) => {
552
+ if (currentNetworkType.value === 'all') return item;
553
+ if (currentNetworkType.value !== 'clear') {
554
+ return item.method === currentNetworkType.value;
555
+ }
556
+ return item;
557
+ })
558
+ ?.filter((item) => item?.url?.includes(value))
559
+ ?.map((item) => {
560
+ return {
561
+ ...item,
562
+ url: hightLight(item.url, value),
563
+ };
564
+ });
565
+ }
566
+
567
+ function onUploadChoose(type: string) {
568
+ if (type === 'clear') {
569
+ uploadList.value = [];
570
+ backup.uploadList = [];
571
+ basicSendMessage({
572
+ type: DEV_UPLOAD_CLEAR,
573
+ data: {},
574
+ });
575
+ return;
576
+ } else if (type === 'all') {
577
+ currentUploadType.value = type;
578
+ uploadList.value = backup.uploadList;
579
+ } else {
580
+ currentUploadType.value = type;
581
+ uploadList.value = backup.uploadList.filter((item) => item.status === type);
582
+ }
583
+ }
584
+
585
+ function onSearchUpload(value: string) {
586
+ uploadList.value = backup.uploadList
587
+ .filter((item) => {
588
+ if (currentUploadType.value === 'all') return item;
589
+ if (currentUploadType.value !== 'clear') {
590
+ return item.status === currentUploadType.value;
591
+ }
592
+ return item;
593
+ })
594
+ .filter((item) => {
595
+ return item.url?.includes(value);
596
+ })
597
+ ?.map((item) => {
598
+ return {
599
+ ...item,
600
+ url: hightLight(item.url, value),
601
+ };
602
+ });
603
+ }
604
+
605
+ function onWebSocketChoose(type: string) {
606
+ if (type === 'clear') {
607
+ wsList.value = [];
608
+ backup.wsList = [];
609
+ basicSendMessage({
610
+ type: DEV_WEBSOCKET_CLEAR,
611
+ data: {},
612
+ });
613
+ return;
614
+ } else if (type === 'all') {
615
+ currentWebSocketType.value = type;
616
+ wsList.value = backup.wsList;
617
+ } else {
618
+ currentWebSocketType.value = type;
619
+ wsList.value = backup.wsList.filter((item) => item.readyState === type);
620
+ }
621
+ setWindowInfo();
622
+ }
623
+
624
+ function onSearchWs(value: string) {
625
+ wsList.value = backup.wsList
626
+ .filter((item) => {
627
+ if (currentWebSocketType.value === 'all') return item;
628
+ return item.readyState === currentWebSocketType.value;
629
+ })
630
+ .filter((item) => item.url.includes(value))
631
+ ?.map((item) => {
632
+ return {
633
+ ...item,
634
+ url: hightLight(item.url, value),
635
+ };
636
+ });
637
+ }
638
+
639
+ function onStorageChoose(type: string) {
640
+ if (type === 'clear') {
641
+ backup.storageList = [];
642
+ storageList.value = [];
643
+ basicSendMessage({
644
+ type: DEV_STORAGE_CLEAR,
645
+ data: {},
646
+ });
647
+ } else if (type === 'refresh') {
648
+ basicSendMessage({
649
+ type: DEV_STORAGE_REFRESH,
650
+ data: {},
651
+ });
652
+ } else if (type === 'add') {
653
+ const key = '_new_' + Date.now();
654
+ const newItem = {
655
+ key,
656
+ _oldKey: key,
657
+ value: JSON.stringify(''),
658
+ };
659
+ backup.storageList.unshift(newItem);
660
+ storageList.value.unshift(newItem);
661
+ basicSendMessage({
662
+ type: DEV_STORAGE_ADD,
663
+ data: {
664
+ key,
665
+ value: JSON.stringify(''),
666
+ },
667
+ });
668
+ }
669
+ }
670
+
671
+ function onStorageRemove(key: string) {
672
+ backup.storageList = backup.storageList.filter((item) => item.key !== key);
673
+ storageList.value = backup.storageList;
674
+ basicSendMessage({
675
+ type: DEV_STORAGE_REMOVE,
676
+ data: { key },
677
+ });
678
+ }
679
+
680
+ function onChangeStorage(data: DevTool.StorageItem) {
681
+ basicSendMessage({
682
+ type: DEV_STORAGE_UPDATE,
683
+ data,
684
+ });
685
+ }
686
+
687
+ function onSearchStorage(value: string) {
688
+ storageList.value = backup.storageList
689
+ .filter((item) => item._oldKey.includes(value))
690
+ ?.map((item) => {
691
+ return {
692
+ ...item,
693
+ _oldKey: hightLight(item._oldKey, value),
694
+ };
695
+ });
696
+ }
697
+
698
+ function onGoTo(page: DevTool.Page) {
699
+ basicSendMessage({
700
+ type: DEV_PAGE_JUMP,
701
+ data: {
702
+ path: '/' + page.path,
703
+ isNav: page.isNav,
704
+ },
705
+ });
706
+ }
707
+
708
+ function onRouteRefresh() {
709
+ basicSendMessage({
710
+ type: DEV_ROUTE_REFRESH,
711
+ data: {},
712
+ });
713
+ }
714
+
715
+ function onSearchRoute(value: string) {
716
+ routeList.value = backup.routeList
717
+ ?.filter((item) => item.path.includes(value) || item.name?.includes(value))
718
+ ?.map((item) => {
719
+ return {
720
+ ...item,
721
+ name: hightLight(item.name, searchRoute.value),
722
+ path: hightLight(item.path, searchRoute.value),
723
+ };
724
+ });
725
+ }
726
+
727
+ function onShowDevButton(show: boolean) {
728
+ basicSendMessage({
729
+ type: DEV_BUTTON_SHOW_OR_HIDE,
730
+ data: {
731
+ show,
732
+ },
733
+ });
734
+ }
735
+
736
+ function onRestartDevTool() {
737
+ basicSendMessage({
738
+ type: DEV_RESTART_DEBUGGER,
739
+ data: {},
740
+ });
741
+ }
742
+
743
+ function onRestartApp() {
744
+ basicSendMessage({
745
+ type: DEV_RESTART_APP,
746
+ data: {},
747
+ });
748
+ }
749
+
750
+ function onExportLog(exports: {
751
+ exportLog: boolean;
752
+ exportNetwork: boolean;
753
+ exportStorage: boolean;
754
+ }) {
755
+ basicSendMessage({
756
+ type: DEV_EXPORT_LOG,
757
+ data: {
758
+ ...exports,
759
+ },
760
+ });
761
+ }
762
+
763
+ function onScreenshot() {
764
+ basicSendMessage({
765
+ type: 'dev-tool-hide-screenshot',
766
+ data: {},
767
+ });
768
+ }
769
+
770
+ function onClearCache() {
771
+ basicSendMessage({
772
+ type: DEV_LOG_CACHE_CLEAR,
773
+ data: {},
774
+ });
775
+ }
776
+
777
+ function onDestroyDevTool() {
778
+ basicSendMessage({
779
+ type: DEV_DESTROY,
780
+ data: {},
781
+ });
782
+ }
783
+
784
+ function onChangeVuex(value: Record<string, any>) {
785
+ basicSendMessage({
786
+ type: DEV_VUEX_CHANGE,
787
+ data: value,
788
+ });
789
+ }
790
+
791
+ function onChangePinia(value: Record<string, any>) {
792
+ basicSendMessage({
793
+ type: DEV_PINIA_CHANGE,
794
+ data: value,
795
+ });
796
+ }
797
+ </script>
798
+
799
+ <style scoped>
800
+ .dev-tool-window {
801
+ position: fixed;
802
+ top: 0;
803
+ left: 0;
804
+ z-index: 10000;
805
+ /* #ifdef H5 */
806
+ padding: 50px 0;
807
+ /* #endif */
808
+
809
+ /* #ifdef MP-WEIXIN */
810
+ /* padding-bottom:30px; */
811
+ /* #endif */
812
+
813
+ width: 100vw;
814
+ height: 100vh;
815
+ font-size: 14px;
816
+ box-sizing: border-box;
817
+ }
818
+ .dev-tool-window .dev-tool-window-bg {
819
+ position: absolute;
820
+ z-index: -1;
821
+ top: 0;
822
+ left: 0;
823
+ width: 100vw;
824
+ height: 100vh;
825
+ background: rgba(255, 255, 255, 0.8);
826
+ backdrop-filter: blur(6px);
827
+ }
828
+ .dev-tool-window .dev-tool-window-container {
829
+ height: calc(100% - 32px);
830
+ overflow: auto;
831
+ }
832
+ .dev-tool-window-container ::-webkit-scrollbar {
833
+ display: none;
834
+ width: 0;
835
+ height: 0;
836
+ background-color: transparent;
837
+ }
838
+
839
+ .dev-tool-window-container ::-webkit-scrollbar-thumb {
840
+ width: 0;
841
+ height: 0;
842
+ background-color: transparent;
843
+ }
844
+ .dev-tool-window::after {
845
+ content: '';
846
+ }
847
+ </style>