vite-uni-dev-tool 0.0.13 → 0.0.14

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 (109) hide show
  1. package/dist/v2/AppInfo/index.vue +41 -0
  2. package/dist/v2/AutoSizer/index.vue +189 -0
  3. package/dist/v2/AutoSizer/index1.vue +193 -0
  4. package/dist/v2/AutoSizer/utils.ts +49 -0
  5. package/dist/v2/CaptureScreen/index.vue +78 -0
  6. package/dist/v2/CloseButton/index.vue +32 -0
  7. package/dist/v2/Connection/index.vue +94 -0
  8. package/dist/v2/ConsoleList/ConsoleItem.vue +235 -0
  9. package/dist/v2/ConsoleList/RunJSInput.vue +243 -0
  10. package/dist/v2/ConsoleList/index.vue +164 -0
  11. package/dist/v2/ConsoleList/staticTips.js +1144 -0
  12. package/dist/v2/DevTool/index.vue +162 -0
  13. package/dist/v2/DevToolButton/index.vue +228 -0
  14. package/dist/v2/DevToolTitle/index.vue +28 -0
  15. package/dist/v2/DevToolWindow/index.vue +1051 -0
  16. package/dist/v2/DeviceInfo/index.vue +48 -0
  17. package/dist/v2/Empty/empty.png +0 -0
  18. package/dist/v2/Empty/index.vue +40 -0
  19. package/dist/v2/FilterInput/index.vue +100 -0
  20. package/dist/v2/JsonPretty/components/Brackets/index.vue +30 -0
  21. package/dist/v2/JsonPretty/components/Carets/index.vue +65 -0
  22. package/dist/v2/JsonPretty/components/CheckController/index.vue +127 -0
  23. package/dist/v2/JsonPretty/components/TreeNode/index.vue +417 -0
  24. package/dist/v2/JsonPretty/hooks/useClipboard.ts +21 -0
  25. package/dist/v2/JsonPretty/hooks/useError.ts +21 -0
  26. package/dist/v2/JsonPretty/index.vue +531 -0
  27. package/dist/v2/JsonPretty/type.ts +125 -0
  28. package/dist/v2/JsonPretty/utils/index.js +211 -0
  29. package/dist/v2/NetworkList/NetworkDetail.vue +215 -0
  30. package/dist/v2/NetworkList/NetworkItem.vue +135 -0
  31. package/dist/v2/NetworkList/index.vue +148 -0
  32. package/dist/v2/PiniaList/index.vue +79 -0
  33. package/dist/v2/RouteList/index.vue +137 -0
  34. package/dist/v2/RunJS/index.vue +128 -0
  35. package/dist/v2/SettingList/index.vue +318 -0
  36. package/dist/v2/SourceCode/index.vue +237 -0
  37. package/dist/v2/StorageList/index.vue +165 -0
  38. package/dist/v2/SystemInfo/index.vue +49 -0
  39. package/dist/v2/Tabs/index.vue +127 -0
  40. package/dist/v2/Tag/index.vue +91 -0
  41. package/dist/v2/UniEvent/UniEventItem.vue +157 -0
  42. package/dist/v2/UniEvent/index.vue +127 -0
  43. package/dist/v2/UploadList/UploadDetail.vue +204 -0
  44. package/dist/v2/UploadList/UploadItem.vue +134 -0
  45. package/dist/v2/UploadList/index.vue +143 -0
  46. package/dist/v2/VirtualList/index.vue +140 -0
  47. package/dist/v2/VirtualListPro/AutoSize.vue +50 -0
  48. package/dist/v2/VirtualListPro/index.vue +255 -0
  49. package/dist/v2/VirtualListPro/readme.md +40 -0
  50. package/dist/v2/VuexList/index.vue +80 -0
  51. package/dist/v2/WebSocket/WebSocketItem.vue +129 -0
  52. package/dist/v2/WebSocket/WebSocketList.vue +183 -0
  53. package/dist/v2/WebSocket/index.vue +155 -0
  54. package/dist/v2/WindowInfo/index.vue +49 -0
  55. package/dist/v3/AppInfo/index.vue +35 -0
  56. package/dist/v3/AutoSizer/index.vue +193 -0
  57. package/dist/v3/AutoSizer/index1.vue +186 -0
  58. package/dist/v3/AutoSizer/utils.ts +49 -0
  59. package/dist/v3/CaptureScreen/index.vue +62 -0
  60. package/dist/v3/CloseButton/index.vue +29 -0
  61. package/dist/v3/Connection/index.vue +88 -0
  62. package/dist/v3/ConsoleList/ConsoleItem.vue +208 -0
  63. package/dist/v3/ConsoleList/RunJSInput.vue +240 -0
  64. package/dist/v3/ConsoleList/index.vue +139 -0
  65. package/dist/v3/ConsoleList/staticTips.ts +1145 -0
  66. package/dist/v3/DevTool/index.vue +217 -0
  67. package/dist/v3/DevToolButton/index.vue +210 -0
  68. package/dist/v3/DevToolTitle/index.vue +21 -0
  69. package/dist/v3/DevToolWindow/index.vue +1116 -0
  70. package/dist/v3/DeviceInfo/index.vue +32 -0
  71. package/dist/v3/Empty/empty.png +0 -0
  72. package/dist/v3/Empty/index.vue +28 -0
  73. package/dist/v3/FilterInput/index.vue +87 -0
  74. package/dist/v3/JsonPretty/components/Brackets/index.vue +23 -0
  75. package/dist/v3/JsonPretty/components/Carets/index.vue +59 -0
  76. package/dist/v3/JsonPretty/components/CheckController/index.vue +125 -0
  77. package/dist/v3/JsonPretty/components/TreeNode/index.vue +349 -0
  78. package/dist/v3/JsonPretty/hooks/useClipboard.ts +21 -0
  79. package/dist/v3/JsonPretty/hooks/useError.ts +21 -0
  80. package/dist/v3/JsonPretty/index.vue +476 -0
  81. package/dist/v3/JsonPretty/type.ts +125 -0
  82. package/dist/v3/JsonPretty/utils/index.ts +172 -0
  83. package/dist/v3/NetworkList/NetworkDetail.vue +194 -0
  84. package/dist/v3/NetworkList/NetworkItem.vue +120 -0
  85. package/dist/v3/NetworkList/index.vue +128 -0
  86. package/dist/v3/PiniaList/index.vue +64 -0
  87. package/dist/v3/RouteList/index.vue +121 -0
  88. package/dist/v3/RunJS/index.vue +128 -0
  89. package/dist/v3/SettingList/index.vue +313 -0
  90. package/dist/v3/SourceCode/index.vue +231 -0
  91. package/dist/v3/StorageList/index.vue +170 -0
  92. package/dist/v3/SystemInfo/index.vue +34 -0
  93. package/dist/v3/Tabs/index.vue +123 -0
  94. package/dist/v3/Tag/index.vue +89 -0
  95. package/dist/v3/UniEvent/UniEventItem.vue +126 -0
  96. package/dist/v3/UniEvent/index.vue +98 -0
  97. package/dist/v3/UploadList/UploadDetail.vue +192 -0
  98. package/dist/v3/UploadList/UploadItem.vue +117 -0
  99. package/dist/v3/UploadList/index.vue +117 -0
  100. package/dist/v3/VirtualList/index.vue +112 -0
  101. package/dist/v3/VirtualListPro/AutoSize.vue +43 -0
  102. package/dist/v3/VirtualListPro/index.vue +238 -0
  103. package/dist/v3/VirtualListPro/readme.md +40 -0
  104. package/dist/v3/VuexList/index.vue +54 -0
  105. package/dist/v3/WebSocket/WebSocketItem.vue +103 -0
  106. package/dist/v3/WebSocket/WebSocketList.vue +161 -0
  107. package/dist/v3/WebSocket/index.vue +124 -0
  108. package/dist/v3/WindowInfo/index.vue +33 -0
  109. package/package.json +1 -1
@@ -0,0 +1,1116 @@
1
+ <template>
2
+ <view
3
+ class="dev-tool-window"
4
+ v-if="open"
5
+ :style="{ zIndex: zIndex }"
6
+ :class="`dev-tool-window dev-tool-window-${theme}`"
7
+ >
8
+ <!-- :style="{
9
+ height: `${systemInfo?.safeArea?.height}px`
10
+ }" -->
11
+ <view class="dev-tool-window-bg"></view>
12
+ <Tabs
13
+ v-model="activeTab"
14
+ :items="items"
15
+ :scroll-left="tabScrollLeft"
16
+ @close="onCloseWindow"
17
+ @scroll="debounceScrollTabs"
18
+ @change="onChangeTabs"
19
+ >
20
+ <!-- <template #extra>
21
+ <view style="margin-left: 6px">{{ sizeFormat }}</view>
22
+ </template> -->
23
+ </Tabs>
24
+ <swiper
25
+ class="dev-tool-window-container"
26
+ :current="activeTab"
27
+ @change="onChangeSwiper"
28
+ >
29
+ <swiper-item>
30
+ <ConsoleList
31
+ v-if="swiperShow(0)"
32
+ :currentConsoleType="currentConsoleType"
33
+ :consoleList="consoleList"
34
+ :sourceFileServers="sourceFileServers"
35
+ :mode="mode"
36
+ :useDevSource="useDevSource"
37
+ :zIndex="zIndex + 1"
38
+ v-model="searchConsole"
39
+ @choose="onConsoleChoose"
40
+ @search="onSearchConsole"
41
+ @run="onRunJS"
42
+ />
43
+ </swiper-item>
44
+ <swiper-item>
45
+ <Connection v-if="swiperShow(1)" :netWorkStatus="netWorkStatus" />
46
+ </swiper-item>
47
+ <swiper-item>
48
+ <NetworkList
49
+ v-if="swiperShow(2)"
50
+ :currentNetworkType="currentNetworkType"
51
+ :networkList="networkList"
52
+ :zIndex="zIndex + 1"
53
+ v-model="searchNetwork"
54
+ @choose="onNetworkChoose"
55
+ @search="onSearchNetwork"
56
+ />
57
+ </swiper-item>
58
+ <swiper-item>
59
+ <UploadList
60
+ v-if="swiperShow(3)"
61
+ :currentUploadType="currentUploadType"
62
+ :uploadList="uploadList"
63
+ :zIndex="zIndex + 1"
64
+ v-model="searchUpload"
65
+ @choose="onUploadChoose"
66
+ @search="onSearchUpload"
67
+ />
68
+ </swiper-item>
69
+ <swiper-item>
70
+ <WebSocket
71
+ v-if="swiperShow(4)"
72
+ :wsList="wsList"
73
+ :currentWebSocketType="currentWebSocketType"
74
+ :zIndex="zIndex + 1"
75
+ v-model="searchWs"
76
+ @choose="onWebSocketChoose"
77
+ @search="onSearchWs"
78
+ />
79
+ </swiper-item>
80
+ <swiper-item>
81
+ <RouteList
82
+ v-if="swiperShow(5)"
83
+ :routeList="routeList"
84
+ v-model="searchRoute"
85
+ @goTo="onGoTo"
86
+ @search="onSearchRoute"
87
+ @routeRefresh="onRouteRefresh"
88
+ />
89
+ </swiper-item>
90
+ <swiper-item>
91
+ <UniEvent
92
+ v-if="swiperShow(6)"
93
+ :eventList="eventList"
94
+ :eventCount="eventCount"
95
+ :mode="mode"
96
+ :useDevSource="useDevSource"
97
+ :sourceFileServers="sourceFileServers"
98
+ :zIndex="zIndex + 1"
99
+ @clear="onUniEventClear"
100
+ />
101
+ </swiper-item>
102
+ <swiper-item>
103
+ <CaptureScreen
104
+ v-if="swiperShow(7)"
105
+ :captureScreenList="captureScreenList"
106
+ @clear="onCaptureScreenClear"
107
+ />
108
+ </swiper-item>
109
+ <swiper-item>
110
+ <StorageList
111
+ v-if="swiperShow(8)"
112
+ v-model:storage-list="storageList"
113
+ v-model="searchStorage"
114
+ @choose="onStorageChoose"
115
+ @remove="onStorageRemove"
116
+ @diff-value="onChangeStorage"
117
+ @search="onSearchStorage"
118
+ />
119
+ </swiper-item>
120
+ <swiper-item>
121
+ <VuexList
122
+ v-if="swiperShow(9)"
123
+ v-model:vuexList="vuexList"
124
+ @diff-value="onChangeVuex"
125
+ />
126
+ </swiper-item>
127
+ <swiper-item>
128
+ <PiniaList
129
+ v-if="swiperShow(10)"
130
+ v-model:pinia-list="piniaList"
131
+ @diff-value="onChangePinia"
132
+ />
133
+ </swiper-item>
134
+ <swiper-item>
135
+ <WindowInfo v-if="swiperShow(11)" :windowInfo="windowInfo" />
136
+ </swiper-item>
137
+ <swiper-item>
138
+ <DeviceInfo v-if="swiperShow(12)" :deviceInfo="deviceInfo" />
139
+ </swiper-item>
140
+ <swiper-item>
141
+ <SystemInfo v-if="swiperShow(13)" :systemInfo="systemInfo" />
142
+ </swiper-item>
143
+ <swiper-item>
144
+ <AppInfo v-if="swiperShow(14)" :appInfo="appInfo" />
145
+ </swiper-item>
146
+ <swiper-item>
147
+ <SettingList
148
+ v-if="swiperShow(15)"
149
+ :devToolVisible="devToolVisible"
150
+ :sizeFormat="sizeFormat"
151
+ :theme="theme"
152
+ @showDevButton="onShowDevButton"
153
+ @restartDevTool="onRestartDevTool"
154
+ @restartApp="onRestartApp"
155
+ @exportLog="onExportLog"
156
+ @screenshot="onScreenshot"
157
+ @clearCache="onClearCache"
158
+ @destroyDevTool="onDestroyDevTool"
159
+ @changeTheme="onChangeTheme"
160
+ />
161
+ </swiper-item>
162
+ </swiper>
163
+ </view>
164
+ </template>
165
+
166
+ <script setup lang="ts">
167
+ import { onLoad, onUnload, onShow, onHide } from '@dcloudio/uni-app';
168
+ import { ref, onMounted } from 'vue';
169
+ import Tabs from '../Tabs/index.vue';
170
+ import ConsoleList from '../ConsoleList/index.vue';
171
+ import NetworkList from '../NetworkList/index.vue';
172
+ import Connection from '../Connection/index.vue';
173
+ import StorageList from '../StorageList/index.vue';
174
+ import RouteList from '../RouteList/index.vue';
175
+ import SettingList from '../SettingList/index.vue';
176
+ import VuexList from '../VuexList/index.vue';
177
+ import PiniaList from '../PiniaList/index.vue';
178
+ import SystemInfo from '../SystemInfo/index.vue';
179
+ import DeviceInfo from '../DeviceInfo/index.vue';
180
+ import WindowInfo from '../WindowInfo/index.vue';
181
+ import WebSocket from '../WebSocket/index.vue';
182
+ import UploadList from '../UploadList/index.vue';
183
+ import UniEvent from '../UniEvent/index.vue';
184
+ import AppInfo from '../AppInfo/index.vue';
185
+ import CaptureScreen from '../CaptureScreen/index.vue';
186
+ import {
187
+ DEV_BUTTON_SHOW_OR_HIDE,
188
+ DEV_CONSOLE_CLEAR,
189
+ DEV_DESTROY,
190
+ DEV_EXPORT_LOG,
191
+ DEV_LOG_CACHE_CLEAR,
192
+ DEV_NETWORK_CLEAR,
193
+ DEV_PAGE_JUMP,
194
+ DEV_PINIA_CHANGE,
195
+ DEV_RESTART_APP,
196
+ DEV_RESTART_DEBUGGER,
197
+ DEV_ROUTE_REFRESH,
198
+ DEV_STORAGE_ADD,
199
+ DEV_STORAGE_CLEAR,
200
+ DEV_STORAGE_REFRESH,
201
+ DEV_STORAGE_REMOVE,
202
+ DEV_STORAGE_UPDATE,
203
+ DEV_UPLOAD_CLEAR,
204
+ DEV_VUEX_CHANGE,
205
+ DEV_WEBSOCKET_CLEAR,
206
+ DEV_APP_MESSAGE,
207
+ DEV_UNI_EVENT_CLEAR,
208
+ DEV_RUN_JS,
209
+ DEV_CAPTURE_SCREEN_CLEAR,
210
+ } from '../../const';
211
+ import { debounce, hightLight } from '../../utils/index';
212
+ import type { DevTool } from '../../type';
213
+ import { eventBus } from '../../core';
214
+ import { getDevToolInfo, setDevToolInfo } from '../../devToolInfo';
215
+
216
+ const items = [
217
+ {
218
+ key: 'Console',
219
+ label: 'Console',
220
+ value: 'Console',
221
+ index: 0,
222
+ },
223
+ {
224
+ key: 'Connection',
225
+ label: 'Connection',
226
+ value: 'Connection',
227
+ index: 1,
228
+ },
229
+ {
230
+ key: 'Network',
231
+ label: 'Network',
232
+ value: 'NetWork',
233
+ index: 2,
234
+ },
235
+ {
236
+ key: 'Upload',
237
+ label: 'Upload',
238
+ value: 'Upload',
239
+ index: 3,
240
+ },
241
+ {
242
+ key: 'WebSocket',
243
+ label: 'WebSocket',
244
+ value: 'WebSocket',
245
+ index: 4,
246
+ },
247
+ {
248
+ key: 'Route',
249
+ label: 'Route',
250
+ value: 'Route',
251
+ index: 5,
252
+ },
253
+ {
254
+ key: 'UniEvent',
255
+ label: 'UniEvent',
256
+ value: 'UniEvent',
257
+ index: 6,
258
+ },
259
+ {
260
+ key: 'CaptureScreen',
261
+ label: 'CaptureScreen',
262
+ value: 'CaptureScreen',
263
+ index: 7,
264
+ },
265
+ {
266
+ key: 'Storage',
267
+ label: 'Storage',
268
+ value: 'Storage',
269
+ index: 8,
270
+ },
271
+
272
+ {
273
+ key: 'Vuex',
274
+ label: 'Vuex',
275
+ value: 'Vuex',
276
+ index: 9,
277
+ },
278
+ {
279
+ key: 'Pinia',
280
+ label: 'Pinia',
281
+ value: 'Pinia',
282
+ index: 10,
283
+ },
284
+ {
285
+ key: 'Window',
286
+ label: 'Window',
287
+ value: 'Window',
288
+ index: 11,
289
+ },
290
+ {
291
+ key: 'Device',
292
+ label: 'Device',
293
+ value: 'Device',
294
+ index: 12,
295
+ },
296
+ {
297
+ key: 'System',
298
+ label: 'System',
299
+ value: 'System',
300
+ index: 13,
301
+ },
302
+ {
303
+ key: 'AppInfo',
304
+ label: 'AppInfo',
305
+ value: 'AppInfo',
306
+ index: 14,
307
+ },
308
+ {
309
+ key: 'Setting',
310
+ label: 'Setting',
311
+ value: 'Setting',
312
+ index: 15,
313
+ },
314
+ ];
315
+
316
+ const backup: {
317
+ consoleList: DevTool.ConsoleItem[];
318
+ networkList: DevTool.NetworkItem[];
319
+ storageList: DevTool.StorageItem[];
320
+ wsList: DevTool.WS[];
321
+ uploadList: DevTool.UploadItem[];
322
+ routeList: DevTool.Page[];
323
+ eventList: DevTool.EventItem[];
324
+ runJSList: DevTool.RunJSItem[];
325
+ } = {
326
+ consoleList: [],
327
+ networkList: [],
328
+ storageList: [],
329
+ wsList: [],
330
+ uploadList: [],
331
+ routeList: [],
332
+ eventList: [],
333
+ runJSList: [],
334
+ };
335
+ const consoleList = ref<DevTool.ConsoleItem[]>([]);
336
+ const networkList = ref<DevTool.NetworkItem[]>([]);
337
+ const uploadList = ref<DevTool.UploadItem[]>([]);
338
+ const storageList = ref<DevTool.StorageItem[]>([]);
339
+ const routeList = ref<DevTool.Page[]>([]);
340
+ const wsList = ref<DevTool.WS[]>([]);
341
+ const vuexList = ref<Record<string, any>>({});
342
+ const piniaList = ref<Record<string, any>>({});
343
+ const systemInfo = ref<Record<string, any>>({});
344
+ const deviceInfo = ref<Record<string, any>>({});
345
+ const windowInfo = ref<Record<string, any>>({});
346
+ const eventList = ref<DevTool.EventItem[]>([]);
347
+ const eventCount = ref<DevTool.EventCount>();
348
+ const appInfo = ref<Record<string, any>>({});
349
+ const captureScreenList = ref<DevTool.CaptureScreenItem[]>([]);
350
+
351
+ const netWorkStatus = ref<{
352
+ isConnected?: boolean;
353
+ networkType?: string;
354
+ }>({});
355
+ const sizeFormat = ref('');
356
+
357
+ const devToolVisible = ref(true);
358
+
359
+ const activeTab = ref(0);
360
+ const tabScrollLeft = ref(0);
361
+ const currentConsoleType = ref('all');
362
+ const currentNetworkType = ref('all');
363
+ const currentUploadType = ref('all');
364
+ const currentWebSocketType = ref('all');
365
+
366
+ const searchConsole = ref('');
367
+ const searchNetwork = ref('');
368
+ const searchUpload = ref('');
369
+ const searchWs = ref('');
370
+ const searchRoute = ref('');
371
+ const searchStorage = ref('');
372
+ const theme = ref('light');
373
+
374
+ const props = withDefaults(
375
+ defineProps<{
376
+ open?: boolean;
377
+ data?: DevTool.WindowData;
378
+ sourceFileServers?: string[];
379
+ mode?: string;
380
+ useDevSource?: boolean;
381
+ zIndex?: number;
382
+ }>(),
383
+ {
384
+ zIndex: 1000,
385
+ },
386
+ );
387
+
388
+ const emits = defineEmits<{
389
+ (e: 'close'): void;
390
+ (e: 'sendMessage', data: { type: string; data: Record<string, any> }): void;
391
+ }>();
392
+
393
+ function swiperShow(index: number) {
394
+ const show =
395
+ index == activeTab.value - 1 ||
396
+ index == activeTab.value ||
397
+ index == activeTab.value + 1;
398
+ return show;
399
+ }
400
+
401
+ const listenPostMessage = (data: DevTool.WindowData) => {
402
+ if (!props.open) return;
403
+ if (!isActive) return;
404
+ devToolVisible.value = data.devToolVisible ?? false;
405
+
406
+ if (data.consoleList) {
407
+ consoleList.value = [...(data.consoleList ?? [])]
408
+ .filter((item) => {
409
+ if (currentConsoleType.value === 'all') return item;
410
+ if (currentConsoleType.value !== 'clear') {
411
+ return item.type === currentConsoleType.value;
412
+ }
413
+ return item;
414
+ })
415
+ .filter((item) => {
416
+ return (
417
+ item.args?.some(
418
+ (arg) =>
419
+ arg.type === 'string' &&
420
+ arg.value?.includes?.(searchConsole.value),
421
+ ) ||
422
+ item.position.includes(searchConsole.value) ||
423
+ item?.stack?.includes(searchConsole.value)
424
+ );
425
+ })
426
+ ?.map((item) => {
427
+ return {
428
+ ...item,
429
+ position: hightLight(item.position, searchConsole.value),
430
+ stack: hightLight(item.stack, searchConsole.value),
431
+ args: item.args.map((arg) => {
432
+ if (arg.type === 'string') {
433
+ return {
434
+ type: 'string',
435
+ value: hightLight(arg.value, searchConsole.value),
436
+ };
437
+ }
438
+ return arg;
439
+ }),
440
+ };
441
+ });
442
+
443
+ backup.consoleList = [...data.consoleList];
444
+ }
445
+
446
+ if (data.networkList) {
447
+ networkList.value = [...(data.networkList ?? [])]
448
+ .filter((item) => {
449
+ if (currentNetworkType.value === 'all') return item;
450
+ if (currentNetworkType.value !== 'clear') {
451
+ return item.method === currentNetworkType.value;
452
+ }
453
+ return item;
454
+ })
455
+ ?.filter((item) => item?.url?.includes(searchNetwork.value))
456
+ ?.map((item) => {
457
+ return {
458
+ ...item,
459
+ url: hightLight(item.url, searchNetwork.value),
460
+ };
461
+ });
462
+
463
+ backup.networkList = [...data.networkList];
464
+ }
465
+
466
+ if (data.uploadList) {
467
+ uploadList.value = [...(data.uploadList ?? [])]
468
+ .filter((item) => {
469
+ if (currentUploadType.value === 'all') return item;
470
+ if (currentUploadType.value !== 'clear') {
471
+ return item.status === currentUploadType.value;
472
+ }
473
+ return item;
474
+ })
475
+ .filter((item) => {
476
+ return item.url?.includes(searchUpload.value);
477
+ })
478
+ ?.map((item) => {
479
+ return {
480
+ ...item,
481
+ url: hightLight(item.url, searchUpload.value),
482
+ };
483
+ });
484
+ backup.uploadList = [...data.uploadList];
485
+ }
486
+
487
+ if (data.storageList) {
488
+ storageList.value = [...(data.storageList ?? [])]
489
+ ?.filter((item) => item._oldKey.includes(searchStorage.value))
490
+ ?.map((item) => {
491
+ return {
492
+ ...item,
493
+ _oldKey: hightLight(item._oldKey, searchStorage.value),
494
+ };
495
+ });
496
+ backup.storageList = [...data.storageList];
497
+ }
498
+
499
+ if (data.wsList) {
500
+ wsList.value = [...(data.wsList ?? [])]
501
+ .filter((item) => {
502
+ if (currentWebSocketType.value === 'all') return item;
503
+ return item.readyState === currentWebSocketType.value;
504
+ })
505
+ .filter((item) => item.url.includes(searchWs.value))
506
+ ?.map((item) => {
507
+ return {
508
+ ...item,
509
+ url: hightLight(item.url, searchWs.value),
510
+ };
511
+ });
512
+ backup.wsList = [...data.wsList];
513
+ }
514
+
515
+ if (data.routeList) {
516
+ routeList.value = [...(data.routeList ?? [])]
517
+ ?.filter(
518
+ (item) =>
519
+ item.path.includes(searchRoute.value) ||
520
+ item.name?.includes(searchRoute.value),
521
+ )
522
+ ?.map((item) => {
523
+ return {
524
+ ...item,
525
+ name: hightLight(item.name, searchRoute.value),
526
+ path: hightLight(item.path, searchRoute.value),
527
+ };
528
+ });
529
+ backup.routeList = [...data.routeList];
530
+ }
531
+ if (data.eventList) {
532
+ eventList.value = [...data.eventList];
533
+ }
534
+
535
+ if (data.eventCount) {
536
+ eventCount.value = { ...data.eventCount };
537
+ }
538
+
539
+ if (data.vuexList) {
540
+ vuexList.value = data.vuexList;
541
+ }
542
+
543
+ if (data.piniaList) {
544
+ piniaList.value = data.piniaList;
545
+ }
546
+
547
+ if (data.systemInfo) {
548
+ systemInfo.value = data.systemInfo;
549
+ }
550
+
551
+ if (data.deviceInfo) {
552
+ deviceInfo.value = data.deviceInfo;
553
+ }
554
+ if (data.windowInfo) {
555
+ windowInfo.value = data.windowInfo;
556
+ }
557
+
558
+ if (data.netWorkStatus) {
559
+ netWorkStatus.value = data.netWorkStatus;
560
+ }
561
+
562
+ if (data.sizeFormat) {
563
+ sizeFormat.value = data.sizeFormat;
564
+ }
565
+
566
+ if (data.appInfo) {
567
+ appInfo.value = data.appInfo;
568
+ }
569
+
570
+ if (data.captureScreenList) {
571
+ captureScreenList.value = data.captureScreenList;
572
+ }
573
+ };
574
+
575
+ let isActive = false;
576
+ onMounted(() => {
577
+ const devToolInfo = getDevToolInfo();
578
+
579
+ if (devToolInfo) {
580
+ activeTab.value = devToolInfo?.activeTab || 0;
581
+ currentConsoleType.value = devToolInfo?.currentConsoleType || 'all';
582
+ currentNetworkType.value = devToolInfo?.currentNetworkType || 'all';
583
+ tabScrollLeft.value = devToolInfo?.tabScrollLeft || 0;
584
+ theme.value = devToolInfo?.theme || 'light';
585
+ }
586
+ if (props.data) {
587
+ listenPostMessage(props.data);
588
+ }
589
+
590
+ uni.onThemeChange((res) => {
591
+ theme.value = res.theme;
592
+ });
593
+ });
594
+
595
+ onLoad(() => {
596
+ isActive = true;
597
+ eventBus.on(DEV_APP_MESSAGE, listenPostMessage);
598
+ });
599
+ onUnload(() => {
600
+ isActive = false;
601
+ eventBus.off(DEV_APP_MESSAGE, listenPostMessage);
602
+ });
603
+
604
+ onShow(() => {
605
+ isActive = true;
606
+ });
607
+ onHide(() => {
608
+ isActive = false;
609
+
610
+ setDevToolInfo({
611
+ devToolWindowVisible: false,
612
+ });
613
+ });
614
+
615
+ /** 发送消息给 uniapp */
616
+ function basicSendMessage(message: {
617
+ type: string;
618
+ data: Record<string, any>;
619
+ }) {
620
+ emits('sendMessage', message);
621
+ }
622
+
623
+ function setWindowInfo() {
624
+ setDevToolInfo({
625
+ activeTab: activeTab.value,
626
+ currentConsoleType: currentConsoleType.value,
627
+ currentNetworkType: currentNetworkType.value,
628
+ currentWebSocketType: currentWebSocketType.value,
629
+ tabScrollLeft: tabScrollLeft.value,
630
+ });
631
+ }
632
+
633
+ const debounceSetWindowInfo = debounce(setWindowInfo, 200);
634
+
635
+ function onCloseWindow() {
636
+ emits('close');
637
+ setWindowInfo();
638
+ }
639
+ function onChangeTabs() {
640
+ setWindowInfo();
641
+ }
642
+
643
+ function onChangeSwiper({
644
+ detail,
645
+ }: {
646
+ detail: { current: number; source: any };
647
+ }) {
648
+ activeTab.value = detail.current;
649
+ setWindowInfo();
650
+ }
651
+
652
+ function onScrollTabs(e: any) {
653
+ tabScrollLeft.value = e.detail.scrollLeft;
654
+ debounceSetWindowInfo();
655
+ }
656
+
657
+ const debounceScrollTabs = debounce(onScrollTabs, 200);
658
+
659
+ function onConsoleChoose(
660
+ type: 'all' | 'log' | 'info' | 'warn' | 'error' | 'clear',
661
+ ) {
662
+ if (type === 'clear') {
663
+ consoleList.value = [];
664
+ backup.consoleList = [];
665
+ basicSendMessage({
666
+ type: DEV_CONSOLE_CLEAR,
667
+ data: {},
668
+ });
669
+ return;
670
+ } else if (type === 'all') {
671
+ currentConsoleType.value = type;
672
+ consoleList.value = backup.consoleList;
673
+ } else {
674
+ currentConsoleType.value = type;
675
+ consoleList.value = backup.consoleList.filter((item) => item.type === type);
676
+ }
677
+ setWindowInfo();
678
+ }
679
+
680
+ function onRunJS(code: string) {
681
+ basicSendMessage({
682
+ type: DEV_RUN_JS,
683
+ data: {
684
+ code,
685
+ },
686
+ });
687
+ }
688
+
689
+ function onSearchConsole(value: string) {
690
+ consoleList.value = backup.consoleList
691
+ .filter((item) => {
692
+ return (
693
+ item.args.some(
694
+ (arg) => arg.type === 'string' && arg.value.includes(value),
695
+ ) ||
696
+ item.position.includes(value) ||
697
+ item?.stack?.includes(value)
698
+ );
699
+ })
700
+ ?.map((item) => {
701
+ return {
702
+ ...item,
703
+ position: hightLight(item.position, searchConsole.value),
704
+ stack: hightLight(item.stack, searchConsole.value),
705
+ args: item.args.map((arg) => {
706
+ if (arg.type === 'string') {
707
+ return {
708
+ type: 'string',
709
+ value: hightLight(arg.value, value),
710
+ };
711
+ }
712
+ return arg;
713
+ }),
714
+ };
715
+ });
716
+ }
717
+
718
+ function onNetworkChoose(type: string) {
719
+ if (type === 'clear') {
720
+ networkList.value = [];
721
+ backup.networkList = [];
722
+ basicSendMessage({
723
+ type: DEV_NETWORK_CLEAR,
724
+ data: {},
725
+ });
726
+ return;
727
+ } else if (type === 'all') {
728
+ currentNetworkType.value = type;
729
+ networkList.value = backup.networkList;
730
+ } else if (type === 'error') {
731
+ currentNetworkType.value = type;
732
+ networkList.value = backup.networkList.filter((item) => {
733
+ return item.status === 'error' || /[4,5]\d{2,}/.test(item.status + '');
734
+ });
735
+ } else {
736
+ currentNetworkType.value = type;
737
+ networkList.value = backup.networkList.filter(
738
+ (item) => item.method === type,
739
+ );
740
+ }
741
+
742
+ setWindowInfo();
743
+ }
744
+
745
+ function onSearchNetwork(value: string) {
746
+ networkList.value = backup.networkList
747
+ .filter((item) => {
748
+ if (currentNetworkType.value === 'all') return item;
749
+ if (currentNetworkType.value !== 'clear') {
750
+ return item.method === currentNetworkType.value;
751
+ }
752
+ return item;
753
+ })
754
+ ?.filter((item) => item?.url?.includes(value))
755
+ ?.map((item) => {
756
+ return {
757
+ ...item,
758
+ url: hightLight(item.url, value),
759
+ };
760
+ });
761
+ }
762
+
763
+ function onUploadChoose(type: string) {
764
+ if (type === 'clear') {
765
+ uploadList.value = [];
766
+ backup.uploadList = [];
767
+ basicSendMessage({
768
+ type: DEV_UPLOAD_CLEAR,
769
+ data: {},
770
+ });
771
+ return;
772
+ } else if (type === 'all') {
773
+ currentUploadType.value = type;
774
+ uploadList.value = backup.uploadList;
775
+ } else {
776
+ currentUploadType.value = type;
777
+ uploadList.value = backup.uploadList.filter((item) => item.status === type);
778
+ }
779
+ }
780
+
781
+ function onSearchUpload(value: string) {
782
+ uploadList.value = backup.uploadList
783
+ .filter((item) => {
784
+ if (currentUploadType.value === 'all') return item;
785
+ if (currentUploadType.value !== 'clear') {
786
+ return item.status === currentUploadType.value;
787
+ }
788
+ return item;
789
+ })
790
+ .filter((item) => {
791
+ return item.url?.includes(value);
792
+ })
793
+ ?.map((item) => {
794
+ return {
795
+ ...item,
796
+ url: hightLight(item.url, value),
797
+ };
798
+ });
799
+ }
800
+
801
+ function onWebSocketChoose(type: string) {
802
+ if (type === 'clear') {
803
+ wsList.value = [];
804
+ backup.wsList = [];
805
+ basicSendMessage({
806
+ type: DEV_WEBSOCKET_CLEAR,
807
+ data: {},
808
+ });
809
+ return;
810
+ } else if (type === 'all') {
811
+ currentWebSocketType.value = type;
812
+ wsList.value = backup.wsList;
813
+ } else {
814
+ currentWebSocketType.value = type;
815
+ wsList.value = backup.wsList.filter((item) => item.readyState === type);
816
+ }
817
+ setWindowInfo();
818
+ }
819
+
820
+ function onSearchWs(value: string) {
821
+ wsList.value = backup.wsList
822
+ .filter((item) => {
823
+ if (currentWebSocketType.value === 'all') return item;
824
+ return item.readyState === currentWebSocketType.value;
825
+ })
826
+ .filter((item) => item.url.includes(value))
827
+ ?.map((item) => {
828
+ return {
829
+ ...item,
830
+ url: hightLight(item.url, value),
831
+ };
832
+ });
833
+ }
834
+
835
+ function onStorageChoose(type: string) {
836
+ if (type === 'clear') {
837
+ backup.storageList = [];
838
+ storageList.value = [];
839
+ basicSendMessage({
840
+ type: DEV_STORAGE_CLEAR,
841
+ data: {},
842
+ });
843
+ } else if (type === 'refresh') {
844
+ basicSendMessage({
845
+ type: DEV_STORAGE_REFRESH,
846
+ data: {},
847
+ });
848
+ } else if (type === 'add') {
849
+ const key = '_new_' + Date.now();
850
+ const newItem = {
851
+ key,
852
+ _oldKey: key,
853
+ value: JSON.stringify(''),
854
+ };
855
+ backup.storageList.unshift(newItem);
856
+ storageList.value.unshift(newItem);
857
+ basicSendMessage({
858
+ type: DEV_STORAGE_ADD,
859
+ data: {
860
+ key,
861
+ value: JSON.stringify(''),
862
+ },
863
+ });
864
+ }
865
+ }
866
+
867
+ function onStorageRemove(key: string) {
868
+ backup.storageList = backup.storageList.filter((item) => item.key !== key);
869
+ storageList.value = backup.storageList;
870
+ basicSendMessage({
871
+ type: DEV_STORAGE_REMOVE,
872
+ data: { key },
873
+ });
874
+ }
875
+
876
+ function onChangeStorage(data: DevTool.StorageItem) {
877
+ basicSendMessage({
878
+ type: DEV_STORAGE_UPDATE,
879
+ data,
880
+ });
881
+ }
882
+
883
+ function onSearchStorage(value: string) {
884
+ storageList.value = backup.storageList
885
+ .filter((item) => item._oldKey.includes(value))
886
+ ?.map((item) => {
887
+ return {
888
+ ...item,
889
+ _oldKey: hightLight(item._oldKey, value),
890
+ };
891
+ });
892
+ }
893
+
894
+ function onUniEventClear() {
895
+ eventList.value = [];
896
+ eventCount.value = {
897
+ on: 0,
898
+ once: 0,
899
+ emit: 0,
900
+ off: 0,
901
+ };
902
+ basicSendMessage({
903
+ type: DEV_UNI_EVENT_CLEAR,
904
+ data: {},
905
+ });
906
+ }
907
+
908
+ function onCaptureScreenClear() {
909
+ captureScreenList.value = [];
910
+ basicSendMessage({
911
+ type: DEV_CAPTURE_SCREEN_CLEAR,
912
+ data: {},
913
+ });
914
+ }
915
+
916
+ function onGoTo(page: DevTool.Page) {
917
+ basicSendMessage({
918
+ type: DEV_PAGE_JUMP,
919
+ data: {
920
+ path: '/' + page.path,
921
+ type: page.type,
922
+ },
923
+ });
924
+ }
925
+
926
+ function onRouteRefresh() {
927
+ basicSendMessage({
928
+ type: DEV_ROUTE_REFRESH,
929
+ data: {},
930
+ });
931
+ }
932
+
933
+ function onSearchRoute(value: string) {
934
+ routeList.value = backup.routeList
935
+ ?.filter((item) => item.path.includes(value) || item.name?.includes(value))
936
+ ?.map((item) => {
937
+ return {
938
+ ...item,
939
+ name: hightLight(item.name, searchRoute.value),
940
+ path: hightLight(item.path, searchRoute.value),
941
+ };
942
+ });
943
+ }
944
+
945
+ function onShowDevButton(show: boolean) {
946
+ basicSendMessage({
947
+ type: DEV_BUTTON_SHOW_OR_HIDE,
948
+ data: {
949
+ show,
950
+ },
951
+ });
952
+ }
953
+
954
+ function onRestartDevTool() {
955
+ basicSendMessage({
956
+ type: DEV_RESTART_DEBUGGER,
957
+ data: {},
958
+ });
959
+ }
960
+
961
+ function onRestartApp() {
962
+ basicSendMessage({
963
+ type: DEV_RESTART_APP,
964
+ data: {},
965
+ });
966
+ }
967
+
968
+ function onExportLog(exports: {
969
+ exportLog: boolean;
970
+ exportNetwork: boolean;
971
+ exportStorage: boolean;
972
+ }) {
973
+ basicSendMessage({
974
+ type: DEV_EXPORT_LOG,
975
+ data: {
976
+ ...exports,
977
+ },
978
+ });
979
+ }
980
+
981
+ function onScreenshot() {
982
+ basicSendMessage({
983
+ type: 'dev-tool-hide-screenshot',
984
+ data: {},
985
+ });
986
+ }
987
+
988
+ function onClearCache() {
989
+ basicSendMessage({
990
+ type: DEV_LOG_CACHE_CLEAR,
991
+ data: {},
992
+ });
993
+ }
994
+
995
+ function onDestroyDevTool() {
996
+ basicSendMessage({
997
+ type: DEV_DESTROY,
998
+ data: {},
999
+ });
1000
+ }
1001
+
1002
+ function onChangeTheme(t: string) {
1003
+ theme.value = t;
1004
+
1005
+ setDevToolInfo({
1006
+ theme: t,
1007
+ });
1008
+ }
1009
+
1010
+ function onChangeVuex(value: Record<string, any>) {
1011
+ basicSendMessage({
1012
+ type: DEV_VUEX_CHANGE,
1013
+ data: value,
1014
+ });
1015
+ }
1016
+
1017
+ function onChangePinia(value: Record<string, any>) {
1018
+ basicSendMessage({
1019
+ type: DEV_PINIA_CHANGE,
1020
+ data: value,
1021
+ });
1022
+ }
1023
+ </script>
1024
+
1025
+ <style scoped>
1026
+ .dev-tool-window {
1027
+ --dev-tool-main-color: #9254de;
1028
+ --dev-tool-normal-bg-color: #f9f9f9;
1029
+ --dev-tool-warn-color: #ffa940;
1030
+ --dev-tool-warn-bg-color: #fff7e6;
1031
+ --dev-tool-error-color: #ff4d4f;
1032
+ --dev-tool-error-bg-color: #fff1f0;
1033
+ --dev-tool-success-color: #bae637;
1034
+ --dev-tool-success-bg-color: #fcffe6;
1035
+
1036
+ --dev-tool-base-font-size: 12px;
1037
+ --dev-tool-tag-font-size: 10px;
1038
+ --dev-tool-tips-font-size: 10px;
1039
+ -webkit-tap-highlight-color: transparent;
1040
+
1041
+ position: fixed;
1042
+ top: 0;
1043
+ left: 0;
1044
+ z-index: 1001;
1045
+ /* #ifdef H5 */
1046
+ padding: 50px 0;
1047
+ /* #endif */
1048
+
1049
+ /* #ifdef MP-WEIXIN */
1050
+ /* padding-bottom:30px; */
1051
+ /* #endif */
1052
+
1053
+ width: 100vw;
1054
+ height: 100vh;
1055
+ font-size: 14px;
1056
+ color: var(--dev-tool-text-color);
1057
+ box-sizing: border-box;
1058
+ transition: color 0.3s;
1059
+ }
1060
+
1061
+ .dev-tool-window-light {
1062
+ --dev-tool-bg-color: rgba(255, 255, 255, 0.8);
1063
+ --dev-tool-bg2-color: rgba(255, 255, 255, 0.95);
1064
+
1065
+ --dev-tool-text-color: #000;
1066
+ --dev-tool-border-color: #f0f0f0;
1067
+ --dev-tool-info-color: #9c9c9c;
1068
+ --dev-tool-log-color: #f9f9f9;
1069
+ --dev-tool-nil-color: #020201;
1070
+ --dev-tool-string-color: #888888;
1071
+ --dev-tool-number-color: #1d8ce0;
1072
+ --dev-tool-boolean-color: #1d8ce0;
1073
+ --dev-tool-symbol-color: bisque;
1074
+ }
1075
+ .dev-tool-window-dart {
1076
+ --dev-tool-bg-color: rgba(0, 0, 0, 0.8);
1077
+ --dev-tool-bg2-color: rgba(43, 43, 43, 0.8);
1078
+
1079
+ --dev-tool-text-color: #fff;
1080
+ --dev-tool-border-color: #3d3d3d;
1081
+
1082
+ --dev-tool-log-color: #f9f9f9;
1083
+ }
1084
+
1085
+ .dev-tool-window-bg {
1086
+ position: absolute;
1087
+ z-index: -1;
1088
+ top: 0;
1089
+ left: 0;
1090
+ width: 100vw;
1091
+ height: 100vh;
1092
+ background-color: var(--dev-tool-bg-color);
1093
+ backdrop-filter: blur(6px);
1094
+ transition: background-color 0.3s;
1095
+ }
1096
+ .dev-tool-window-container {
1097
+ height: calc(100% - 32px);
1098
+ overflow: auto;
1099
+ }
1100
+ .dev-tool-window-container ::-webkit-scrollbar {
1101
+ display: none;
1102
+ width: 0;
1103
+ height: 0;
1104
+ background-color: transparent;
1105
+ }
1106
+
1107
+ .dev-tool-window-container ::-webkit-scrollbar-thumb {
1108
+ width: 0;
1109
+ height: 0;
1110
+ background-color: transparent;
1111
+ }
1112
+
1113
+ .dev-tool-window::after {
1114
+ content: '';
1115
+ }
1116
+ </style>