vite-uni-dev-tool 1.1.0 → 1.2.0

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 (135) hide show
  1. package/README.md +8 -0
  2. package/dist/const.cjs +1 -1
  3. package/dist/const.d.ts +1 -0
  4. package/dist/const.d.ts.map +1 -1
  5. package/dist/const.js +1 -1
  6. package/dist/core.d.ts.map +1 -1
  7. package/dist/core.js +2 -2
  8. package/dist/i18n/locales/en.cjs +1 -1
  9. package/dist/i18n/locales/en.d.ts +5 -0
  10. package/dist/i18n/locales/en.d.ts.map +1 -1
  11. package/dist/i18n/locales/en.js +1 -1
  12. package/dist/i18n/locales/zh-Hans.cjs +1 -1
  13. package/dist/i18n/locales/zh-Hans.d.ts +5 -0
  14. package/dist/i18n/locales/zh-Hans.d.ts.map +1 -1
  15. package/dist/i18n/locales/zh-Hans.js +1 -1
  16. package/dist/modules/devIntercept/index.cjs +9 -9
  17. package/dist/modules/devIntercept/index.d.ts +1 -1
  18. package/dist/modules/devIntercept/index.d.ts.map +1 -1
  19. package/dist/modules/devIntercept/index.js +9 -9
  20. package/dist/modules/devStore/index.cjs +1 -1
  21. package/dist/modules/devStore/index.d.ts.map +1 -1
  22. package/dist/modules/devStore/index.js +1 -1
  23. package/dist/plugins/uniDevTool/transform/transformMain.cjs +3 -3
  24. package/dist/plugins/uniDevTool/transform/transformMain.d.ts +2 -1
  25. package/dist/plugins/uniDevTool/transform/transformMain.d.ts.map +1 -1
  26. package/dist/plugins/uniDevTool/transform/transformMain.js +3 -3
  27. package/dist/plugins/uniDevTool/transform/transformVue.cjs +31 -25
  28. package/dist/plugins/uniDevTool/transform/transformVue.d.ts +2 -1
  29. package/dist/plugins/uniDevTool/transform/transformVue.d.ts.map +1 -1
  30. package/dist/plugins/uniDevTool/transform/transformVue.js +30 -24
  31. package/dist/plugins/uniDevTool/uniDevTool.cjs +3 -3
  32. package/dist/plugins/uniDevTool/uniDevTool.d.ts +3 -1
  33. package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
  34. package/dist/plugins/uniDevTool/uniDevTool.js +3 -3
  35. package/dist/type.d.ts +3 -0
  36. package/dist/type.d.ts.map +1 -1
  37. package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -199
  38. package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -730
  39. package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -167
  40. package/dist/v3/DevTool/components/CaptureScreen/index.vue +109 -109
  41. package/dist/v3/DevTool/components/ConsoleList/ConsoleItem.vue +230 -225
  42. package/dist/v3/DevTool/components/ConsoleList/RunJSInput.vue +247 -247
  43. package/dist/v3/DevTool/components/ConsoleList/index.vue +171 -171
  44. package/dist/v3/DevTool/components/ConsoleList/staticTips.ts +1145 -1145
  45. package/dist/v3/DevTool/components/DevToolTitle/index.vue +24 -24
  46. package/dist/v3/DevTool/components/DevToolWindow/DevToolOverlay.vue +197 -197
  47. package/dist/v3/DevTool/components/DevToolWindow/hooks/dataUtils.ts +48 -48
  48. package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolData.ts +387 -387
  49. package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolHandlers.ts +629 -629
  50. package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolOverlay.ts +201 -197
  51. package/dist/v3/DevTool/components/ElEvent/ElEventItem.vue +105 -105
  52. package/dist/v3/DevTool/components/ElEvent/index.vue +106 -106
  53. package/dist/v3/DevTool/components/Instance/components/InstanceTreeNode.vue +265 -265
  54. package/dist/v3/DevTool/components/Instance/flatten.ts +226 -226
  55. package/dist/v3/DevTool/components/Instance/index.vue +94 -94
  56. package/dist/v3/DevTool/components/Instance/registry.ts +49 -49
  57. package/dist/v3/DevTool/components/Instance/transformTree.ts +375 -375
  58. package/dist/v3/DevTool/components/Instance/transformTreeCtx.ts +268 -268
  59. package/dist/v3/DevTool/components/Instance/typing.d.ts +43 -43
  60. package/dist/v3/DevTool/components/InstanceDetail/index.vue +485 -485
  61. package/dist/v3/DevTool/components/JsonDetail/index.vue +70 -70
  62. package/dist/v3/DevTool/components/NFCList/NFCItem.vue +112 -112
  63. package/dist/v3/DevTool/components/NFCList/NFCTool.vue +454 -454
  64. package/dist/v3/DevTool/components/NFCList/const.ts +56 -56
  65. package/dist/v3/DevTool/components/NFCList/index.vue +94 -94
  66. package/dist/v3/DevTool/components/NetworkList/InterceptConfig.vue +624 -624
  67. package/dist/v3/DevTool/components/NetworkList/InterceptItem.vue +140 -140
  68. package/dist/v3/DevTool/components/NetworkList/NetworkDetail.vue +287 -287
  69. package/dist/v3/DevTool/components/NetworkList/NetworkIntercept.vue +88 -88
  70. package/dist/v3/DevTool/components/NetworkList/NetworkItem.vue +163 -163
  71. package/dist/v3/DevTool/components/NetworkList/NetworkSend.vue +589 -589
  72. package/dist/v3/DevTool/components/NetworkList/const.ts +4 -4
  73. package/dist/v3/DevTool/components/NetworkList/hooks/useNetworkForm.ts +86 -86
  74. package/dist/v3/DevTool/components/NetworkList/index.vue +160 -160
  75. package/dist/v3/DevTool/components/NetworkList/utils.ts +101 -101
  76. package/dist/v3/DevTool/components/Performance/index.vue +498 -498
  77. package/dist/v3/DevTool/components/Performance/modules/PerformanceMetrics.vue +153 -153
  78. package/dist/v3/DevTool/components/Performance/modules/usePerformanceChart.ts +460 -460
  79. package/dist/v3/DevTool/components/Performance/modules/usePerformanceData.ts +258 -258
  80. package/dist/v3/DevTool/components/PiniaList/index.vue +93 -93
  81. package/dist/v3/DevTool/components/RunJS/index.vue +148 -148
  82. package/dist/v3/DevTool/components/ScanCodeList/ScanCodeItem.vue +97 -97
  83. package/dist/v3/DevTool/components/ScanCodeList/index.vue +100 -100
  84. package/dist/v3/DevTool/components/SettingButton/index.vue +45 -45
  85. package/dist/v3/DevTool/components/SettingList/index.vue +218 -218
  86. package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +304 -304
  87. package/dist/v3/DevTool/components/SettingList/modules/SettingDevTool.vue +212 -212
  88. package/dist/v3/DevTool/components/SettingList/modules/SettingInfo.vue +157 -157
  89. package/dist/v3/DevTool/components/SettingList/modules/SettingLanguage.vue +74 -74
  90. package/dist/v3/DevTool/components/SettingList/modules/SettingLog.vue +230 -230
  91. package/dist/v3/DevTool/components/SettingList/typing.d.ts +2 -2
  92. package/dist/v3/DevTool/components/SourceCode/Line.vue +127 -127
  93. package/dist/v3/DevTool/components/SourceCode/parseCode.ts +609 -609
  94. package/dist/v3/DevTool/components/StorageList/index.vue +174 -174
  95. package/dist/v3/DevTool/components/TransferList/TransferDetail.vue +268 -268
  96. package/dist/v3/DevTool/components/VuexList/index.vue +84 -84
  97. package/dist/v3/DevTool/index.vue +1 -0
  98. package/dist/v3/components/AppTransition/index.vue +176 -176
  99. package/dist/v3/components/AutoSizer/index.vue +192 -192
  100. package/dist/v3/components/AutoSizer/index1.vue +184 -184
  101. package/dist/v3/components/AutoSizer/utils.ts +49 -49
  102. package/dist/v3/components/Barrage/BarrageItem.vue +137 -137
  103. package/dist/v3/components/Barrage/index.vue +202 -202
  104. package/dist/v3/components/CircularButton/index.vue +84 -84
  105. package/dist/v3/components/CustomSwiper/CustomSwiperItem.vue +49 -49
  106. package/dist/v3/components/CustomSwiper/index.vue +104 -104
  107. package/dist/v3/components/DevErrorBoundary/index.vue +380 -0
  108. package/dist/v3/components/Empty/index.vue +29 -29
  109. package/dist/v3/components/FilterSelect/index.vue +179 -179
  110. package/dist/v3/components/JsonPretty/components/Brackets/index.vue +27 -27
  111. package/dist/v3/components/JsonPretty/components/Carets/index.vue +59 -59
  112. package/dist/v3/components/JsonPretty/components/CheckController/index.vue +136 -136
  113. package/dist/v3/components/JsonPretty/components/TreeNode/index.vue +387 -387
  114. package/dist/v3/components/JsonPretty/hooks/useClipboard.ts +21 -21
  115. package/dist/v3/components/JsonPretty/hooks/useError.ts +21 -21
  116. package/dist/v3/components/JsonPretty/type.ts +127 -127
  117. package/dist/v3/components/JsonPretty/utils/index.ts +169 -169
  118. package/dist/v3/components/MovableContainer/index.vue +8 -4
  119. package/dist/v3/components/Pick/index.vue +322 -322
  120. package/dist/v3/components/Tag/index.vue +113 -113
  121. package/dist/v3/components/VirtualList/AutoSize.vue +40 -40
  122. package/dist/v3/components/VirtualList/index.vue +416 -416
  123. package/dist/v3/hooks/useBluetooth/index.ts +561 -561
  124. package/dist/v3/hooks/useContainerStyle.ts +153 -153
  125. package/dist/v3/hooks/useNFC/index.ts +107 -107
  126. package/dist/v3/hooks/useNFC/typing.d.ts +396 -396
  127. package/dist/v3/hooks/useNFC/useNFCAndroid.ts +966 -966
  128. package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +812 -812
  129. package/dist/v3/hooks/useNFC/utils.ts +754 -754
  130. package/dist/v3/hooks/useRequest/index.ts +586 -586
  131. package/dist/v3/hooks/useRequest/utils.ts +267 -267
  132. package/dist/v3/hooks/useScanCode/index.ts +206 -206
  133. package/dist/v3/hooks/useWebsocket/index.ts +253 -253
  134. package/dist/v3/styles/theme.ts +12 -12
  135. package/package.json +9 -1
@@ -1,387 +1,387 @@
1
- import { shallowRef, reactive, ref } from 'vue';
2
- import type { DevTool } from '../../../../../type';
3
-
4
- import { hightLight } from '../../../../../utils/index';
5
- import { calcLineStartAndEnd, calcNetworkTimeline } from './dataUtils';
6
-
7
- export function useDevToolData(props: any) {
8
- const consoleList = shallowRef<DevTool.ConsoleItem[]>([]);
9
- const networkList = shallowRef<DevTool.NetworkItem[]>([]);
10
- const transferList = shallowRef<DevTool.TransferItem[]>([]);
11
- const storageList = shallowRef<DevTool.StorageItem[]>([]);
12
- const routeList = shallowRef<DevTool.Page[]>([]);
13
- const wsList = shallowRef<DevTool.WS[]>([]);
14
- const vuexList = shallowRef<Record<string, any>>({});
15
- const piniaList = shallowRef<Record<string, any>>({});
16
-
17
- const elEventList = shallowRef<DevTool.ElEventItem[]>([]);
18
- const uniEventList = shallowRef<DevTool.UniEventItem[]>([]);
19
- const eventCount = shallowRef<DevTool.EventCount>();
20
- const screenList = shallowRef<DevTool.ScreenItem[]>([]);
21
- const interceptNetworkList = shallowRef<DevTool.NetworkItem[]>([]);
22
- const scanCodeList = shallowRef<DevTool.ScanCodeItem[]>([]);
23
- const nfcList = shallowRef<DevTool.NFCItem[]>([]);
24
-
25
- const netWorkStatus = ref<{ isConnected?: boolean; networkType?: string }>(
26
- {},
27
- );
28
- const sizeFormat = shallowRef('');
29
- const devToolVisible = shallowRef(true);
30
- const cacheInterceptConfig = shallowRef(true);
31
- const cacheNetworkLog = shallowRef(false);
32
- const cacheConsoleLog = shallowRef(false);
33
- const useTransition = shallowRef(true);
34
- const baseFontSize = shallowRef(12);
35
- const tagFontSize = shallowRef(10);
36
- const tipsFontSize = shallowRef(10);
37
- const fontFamily = shallowRef('');
38
- const fontWeight = shallowRef('normal');
39
- const performanceVisible = shallowRef(false);
40
- const performanceShowFps = shallowRef(true);
41
- const performanceShowCpu = shallowRef(true);
42
- const barrageVisible = shallowRef(true);
43
- const barrageShowWhenOpen = shallowRef(false);
44
- const barrageMaxTracks = shallowRef(10);
45
- const barrageTrackHeight = shallowRef(36);
46
- const barrageStartTop = shallowRef(40);
47
- const barrageDuration = shallowRef(6);
48
- const barrageMaxLength = shallowRef(100);
49
- const barrageTypes = shallowRef([
50
- 'log',
51
- 'info',
52
- 'warn',
53
- 'error',
54
- 'network',
55
- 'transfer',
56
- 'websocket',
57
- ]);
58
-
59
- // 窗口管理状态
60
- const isFullScreen = ref(true);
61
- const windowX = ref(10);
62
- const windowY = ref(100);
63
- const windowWidth = ref(375);
64
- const windowHeight = ref(450);
65
-
66
- const backup = {
67
- consoleList: [] as DevTool.ConsoleItem[],
68
- networkList: [] as DevTool.NetworkItem[],
69
- storageList: [] as DevTool.StorageItem[],
70
- wsList: [] as DevTool.WS[],
71
- transferList: [] as DevTool.TransferItem[],
72
- routeList: [] as DevTool.Page[],
73
- uniEventList: [] as DevTool.UniEventItem[],
74
- };
75
-
76
- const buildInfo = reactive({
77
- devToolVersion: '0.0.0',
78
- devToolBuildTime: '',
79
- devToolGit: '',
80
- });
81
-
82
- // 搜索和过滤相关的状态(部分可能需要放在这里以便在 listenPostMessage 中使用)
83
- const currentConsoleType = shallowRef('all');
84
- const currentNetworkType = shallowRef('all');
85
- const currentNetworkSort = shallowRef<1 | -1>(1);
86
- const currentTransferCategory = shallowRef('all');
87
- const currentTransferType = shallowRef('all');
88
- const currentWebSocketType = shallowRef('all');
89
- const searchConsole = shallowRef('');
90
- const searchNetwork = shallowRef('');
91
- const searchTransfer = shallowRef('');
92
- const searchWs = shallowRef('');
93
- const searchRoute = shallowRef('');
94
- const searchStorage = shallowRef('');
95
-
96
- const activeTab = shallowRef(1);
97
- const tabScrollLeft = shallowRef(0);
98
- const theme = shallowRef('light');
99
- let isActive = false;
100
-
101
- const setIsActive = (value: boolean) => {
102
- isActive = value;
103
- };
104
-
105
- const listenPostMessage = (data: DevTool.WindowData) => {
106
- if (!props.open) return;
107
- if (!isActive) return;
108
-
109
- if (data.devToolVisible !== undefined)
110
- devToolVisible.value = data.devToolVisible;
111
- if (data.cacheInterceptConfig !== undefined)
112
- cacheInterceptConfig.value = data.cacheInterceptConfig;
113
- if (data.cacheNetworkLog !== undefined)
114
- cacheNetworkLog.value = data.cacheNetworkLog;
115
- if (data.cacheConsoleLog !== undefined)
116
- cacheConsoleLog.value = data.cacheConsoleLog;
117
- if (data.useTransition !== undefined)
118
- useTransition.value = data.useTransition;
119
- if (data.baseFontSize !== undefined) baseFontSize.value = data.baseFontSize;
120
- if (data.tagFontSize !== undefined) tagFontSize.value = data.tagFontSize;
121
- if (data.tipsFontSize !== undefined) tipsFontSize.value = data.tipsFontSize;
122
- if (data.fontFamily !== undefined) fontFamily.value = data.fontFamily;
123
- if (data.fontWeight !== undefined) fontWeight.value = data.fontWeight;
124
- if (data.performanceVisible !== undefined)
125
- performanceVisible.value = data.performanceVisible;
126
- if (data.performanceShowFps !== undefined)
127
- performanceShowFps.value = data.performanceShowFps;
128
- if (data.performanceShowCpu !== undefined)
129
- performanceShowCpu.value = data.performanceShowCpu;
130
- if (data.barrageVisible !== undefined)
131
- barrageVisible.value = data.barrageVisible;
132
- if (data.barrageShowWhenOpen !== undefined)
133
- barrageShowWhenOpen.value = data.barrageShowWhenOpen;
134
- if (data.barrageMaxTracks !== undefined)
135
- barrageMaxTracks.value = data.barrageMaxTracks;
136
- if (data.barrageTrackHeight !== undefined)
137
- barrageTrackHeight.value = data.barrageTrackHeight;
138
- if (data.barrageStartTop !== undefined)
139
- barrageStartTop.value = data.barrageStartTop;
140
- if (data.barrageDuration !== undefined)
141
- barrageDuration.value = data.barrageDuration;
142
- if (data.barrageMaxLength !== undefined)
143
- barrageMaxLength.value = data.barrageMaxLength;
144
- if (data.barrageTypes !== undefined) {
145
- if (Array.isArray(data.barrageTypes)) {
146
- barrageTypes.value = data.barrageTypes;
147
- } else {
148
- // 如果收到了非数组(如诡异的循环引用字符串),打印个警告并忽略
149
- console.warn(
150
- '[DevTool] Received invalid barrageTypes:',
151
- data.barrageTypes,
152
- );
153
- }
154
- }
155
-
156
- if (data.consoleList) {
157
- consoleList.value = [...(data.consoleList ?? [])]
158
- .filter((item) => {
159
- if (currentConsoleType.value === 'all') return item;
160
- if (currentConsoleType.value !== 'clear') {
161
- return item.type === currentConsoleType.value;
162
- }
163
- return item;
164
- })
165
- .filter((item) => {
166
- return (
167
- item.args?.some(
168
- (arg) =>
169
- arg.type === 'string' &&
170
- arg.value?.includes?.(searchConsole.value),
171
- ) ||
172
- item.position.includes(searchConsole.value) ||
173
- item?.stack?.includes(searchConsole.value)
174
- );
175
- })
176
- ?.map((item) => {
177
- return {
178
- ...item,
179
- position: hightLight(item.position, searchConsole.value),
180
- stack: hightLight(item.stack, searchConsole.value),
181
- args: item.args.map((arg) => {
182
- if (arg.type === 'string') {
183
- return {
184
- type: 'string',
185
- value: hightLight(arg.value, searchConsole.value),
186
- };
187
- }
188
- return arg;
189
- }),
190
- };
191
- });
192
-
193
- backup.consoleList = [...data.consoleList];
194
- }
195
-
196
- if (data.networkList) {
197
- const { startTime, endTime } = calcLineStartAndEnd(data.networkList);
198
- const list = calcNetworkTimeline(data.networkList, startTime, endTime);
199
-
200
- networkList.value = list
201
- .filter((item) => {
202
- if (currentNetworkType.value === 'all') return item;
203
- if (currentNetworkType.value !== 'clear') {
204
- return item.method === currentNetworkType.value;
205
- }
206
- return item;
207
- })
208
- ?.filter((item) => item?.url?.includes(searchNetwork.value))
209
- ?.map((item) => {
210
- return {
211
- ...item,
212
- url: hightLight(item.url, searchNetwork.value),
213
- };
214
- })
215
- ?.sort((a, b) => {
216
- if (currentNetworkSort.value === 1) {
217
- return b.startTime - a.startTime;
218
- } else {
219
- return a.startTime - b.startTime;
220
- }
221
- });
222
-
223
- backup.networkList = [...data.networkList];
224
- }
225
-
226
- if (data.transferList) {
227
- transferList.value = [...(data.transferList ?? [])]
228
- .filter((item) => {
229
- const typeMatch =
230
- currentTransferCategory.value === 'all' ||
231
- item.type === currentTransferCategory.value;
232
- const statusMatch =
233
- currentTransferType.value === 'all' ||
234
- item.status === currentTransferType.value;
235
-
236
- if (currentTransferType.value === 'clear') return true;
237
-
238
- return typeMatch && statusMatch;
239
- })
240
- .filter((item) => {
241
- return item.url?.includes(searchTransfer.value);
242
- })
243
- ?.map((item) => {
244
- return {
245
- ...item,
246
- url: hightLight(item.url, searchTransfer.value),
247
- };
248
- }) as any;
249
- backup.transferList = [...data.transferList];
250
- }
251
-
252
- if (data.storageList) {
253
- storageList.value = [...(data.storageList ?? [])]
254
- ?.filter((item) => item._oldKey.includes(searchStorage.value))
255
- ?.map((item) => {
256
- return {
257
- ...item,
258
- _oldKey: hightLight(item._oldKey, searchStorage.value),
259
- };
260
- });
261
- backup.storageList = [...data.storageList];
262
- }
263
-
264
- if (data.wsList) {
265
- wsList.value = [...(data.wsList ?? [])]
266
- .filter((item) => {
267
- if (currentWebSocketType.value === 'all') return item;
268
- return item.readyState === currentWebSocketType.value;
269
- })
270
- .filter((item) => item.url.includes(searchWs.value))
271
- ?.map((item) => {
272
- return {
273
- ...item,
274
- _highlightUrl: hightLight(item.url, searchWs.value),
275
- };
276
- });
277
- backup.wsList = [...data.wsList];
278
- }
279
-
280
- if (data.routeList) {
281
- routeList.value = [...(data.routeList ?? [])]
282
- ?.filter(
283
- (item) =>
284
- item.path.includes(searchRoute.value) ||
285
- item.name?.includes(searchRoute.value),
286
- )
287
- ?.map((item) => {
288
- return {
289
- ...item,
290
- name: hightLight(item.name, searchRoute.value),
291
- path: hightLight(item.path, searchRoute.value),
292
- };
293
- });
294
- backup.routeList = [...data.routeList];
295
- }
296
-
297
- if (data.elEventList) elEventList.value = [...data.elEventList];
298
- if (data.uniEventList) uniEventList.value = [...data.uniEventList];
299
- if (data.eventCount) eventCount.value = { ...data.eventCount };
300
- if (data.vuexList) vuexList.value = data.vuexList;
301
- if (data.piniaList) piniaList.value = data.piniaList;
302
- if (data.netWorkStatus) netWorkStatus.value = data.netWorkStatus;
303
- if (data.sizeFormat) sizeFormat.value = data.sizeFormat;
304
- if (data.screenList) screenList.value = [...data.screenList];
305
- if (data.interceptNetworkMap) {
306
- interceptNetworkList.value = Array.from(
307
- data.interceptNetworkMap.values(),
308
- );
309
- }
310
-
311
- if (data.devToolVersion || data.devToolBuildTime || data.devToolGit) {
312
- Object.assign(buildInfo, {
313
- devToolVersion: data.devToolVersion,
314
- devToolBuildTime: data.devToolBuildTime,
315
- devToolGit: data.devToolGit,
316
- });
317
- }
318
-
319
- if (data.scanCodeList) scanCodeList.value = [...data.scanCodeList];
320
- if (data.nfcList) nfcList.value = [...data.nfcList];
321
- };
322
-
323
- return {
324
- consoleList,
325
- networkList,
326
- transferList,
327
- storageList,
328
- routeList,
329
- wsList,
330
- vuexList,
331
- piniaList,
332
- elEventList,
333
- uniEventList,
334
- eventCount,
335
- screenList,
336
- interceptNetworkList,
337
- scanCodeList,
338
- nfcList,
339
- netWorkStatus,
340
- sizeFormat,
341
- devToolVisible,
342
- cacheInterceptConfig,
343
- cacheNetworkLog,
344
- cacheConsoleLog,
345
- useTransition,
346
- baseFontSize,
347
- tagFontSize,
348
- tipsFontSize,
349
- fontFamily,
350
- fontWeight,
351
- performanceVisible,
352
- performanceShowFps,
353
- performanceShowCpu,
354
- barrageVisible,
355
- barrageShowWhenOpen,
356
- barrageMaxTracks,
357
- barrageTrackHeight,
358
- barrageStartTop,
359
- barrageDuration,
360
- barrageMaxLength,
361
- barrageTypes,
362
- backup,
363
- buildInfo,
364
- currentConsoleType,
365
- currentNetworkType,
366
- currentNetworkSort,
367
- currentTransferType,
368
- currentTransferCategory,
369
- currentWebSocketType,
370
- searchConsole,
371
- searchNetwork,
372
- searchTransfer,
373
- searchWs,
374
- searchRoute,
375
- searchStorage,
376
- activeTab,
377
- tabScrollLeft,
378
- theme,
379
- isFullScreen,
380
- windowX,
381
- windowY,
382
- windowWidth,
383
- windowHeight,
384
- setIsActive,
385
- listenPostMessage,
386
- };
387
- }
1
+ import { shallowRef, reactive, ref } from 'vue';
2
+ import type { DevTool } from '../../../../../type';
3
+
4
+ import { hightLight } from '../../../../../utils/index';
5
+ import { calcLineStartAndEnd, calcNetworkTimeline } from './dataUtils';
6
+
7
+ export function useDevToolData(props: any) {
8
+ const consoleList = shallowRef<DevTool.ConsoleItem[]>([]);
9
+ const networkList = shallowRef<DevTool.NetworkItem[]>([]);
10
+ const transferList = shallowRef<DevTool.TransferItem[]>([]);
11
+ const storageList = shallowRef<DevTool.StorageItem[]>([]);
12
+ const routeList = shallowRef<DevTool.Page[]>([]);
13
+ const wsList = shallowRef<DevTool.WS[]>([]);
14
+ const vuexList = shallowRef<Record<string, any>>({});
15
+ const piniaList = shallowRef<Record<string, any>>({});
16
+
17
+ const elEventList = shallowRef<DevTool.ElEventItem[]>([]);
18
+ const uniEventList = shallowRef<DevTool.UniEventItem[]>([]);
19
+ const eventCount = shallowRef<DevTool.EventCount>();
20
+ const screenList = shallowRef<DevTool.ScreenItem[]>([]);
21
+ const interceptNetworkList = shallowRef<DevTool.NetworkItem[]>([]);
22
+ const scanCodeList = shallowRef<DevTool.ScanCodeItem[]>([]);
23
+ const nfcList = shallowRef<DevTool.NFCItem[]>([]);
24
+
25
+ const netWorkStatus = ref<{ isConnected?: boolean; networkType?: string }>(
26
+ {},
27
+ );
28
+ const sizeFormat = shallowRef('');
29
+ const devToolVisible = shallowRef(true);
30
+ const cacheInterceptConfig = shallowRef(true);
31
+ const cacheNetworkLog = shallowRef(false);
32
+ const cacheConsoleLog = shallowRef(false);
33
+ const useTransition = shallowRef(true);
34
+ const baseFontSize = shallowRef(12);
35
+ const tagFontSize = shallowRef(10);
36
+ const tipsFontSize = shallowRef(10);
37
+ const fontFamily = shallowRef('');
38
+ const fontWeight = shallowRef('normal');
39
+ const performanceVisible = shallowRef(false);
40
+ const performanceShowFps = shallowRef(true);
41
+ const performanceShowCpu = shallowRef(true);
42
+ const barrageVisible = shallowRef(true);
43
+ const barrageShowWhenOpen = shallowRef(false);
44
+ const barrageMaxTracks = shallowRef(10);
45
+ const barrageTrackHeight = shallowRef(36);
46
+ const barrageStartTop = shallowRef(40);
47
+ const barrageDuration = shallowRef(6);
48
+ const barrageMaxLength = shallowRef(100);
49
+ const barrageTypes = shallowRef([
50
+ 'log',
51
+ 'info',
52
+ 'warn',
53
+ 'error',
54
+ 'network',
55
+ 'transfer',
56
+ 'websocket',
57
+ ]);
58
+
59
+ // 窗口管理状态
60
+ const isFullScreen = ref(true);
61
+ const windowX = ref(10);
62
+ const windowY = ref(100);
63
+ const windowWidth = ref(375);
64
+ const windowHeight = ref(450);
65
+
66
+ const backup = {
67
+ consoleList: [] as DevTool.ConsoleItem[],
68
+ networkList: [] as DevTool.NetworkItem[],
69
+ storageList: [] as DevTool.StorageItem[],
70
+ wsList: [] as DevTool.WS[],
71
+ transferList: [] as DevTool.TransferItem[],
72
+ routeList: [] as DevTool.Page[],
73
+ uniEventList: [] as DevTool.UniEventItem[],
74
+ };
75
+
76
+ const buildInfo = reactive({
77
+ devToolVersion: '0.0.0',
78
+ devToolBuildTime: '',
79
+ devToolGit: '',
80
+ });
81
+
82
+ // 搜索和过滤相关的状态(部分可能需要放在这里以便在 listenPostMessage 中使用)
83
+ const currentConsoleType = shallowRef('all');
84
+ const currentNetworkType = shallowRef('all');
85
+ const currentNetworkSort = shallowRef<1 | -1>(1);
86
+ const currentTransferCategory = shallowRef('all');
87
+ const currentTransferType = shallowRef('all');
88
+ const currentWebSocketType = shallowRef('all');
89
+ const searchConsole = shallowRef('');
90
+ const searchNetwork = shallowRef('');
91
+ const searchTransfer = shallowRef('');
92
+ const searchWs = shallowRef('');
93
+ const searchRoute = shallowRef('');
94
+ const searchStorage = shallowRef('');
95
+
96
+ const activeTab = shallowRef(1);
97
+ const tabScrollLeft = shallowRef(0);
98
+ const theme = shallowRef('light');
99
+ let isActive = false;
100
+
101
+ const setIsActive = (value: boolean) => {
102
+ isActive = value;
103
+ };
104
+
105
+ const listenPostMessage = (data: DevTool.WindowData) => {
106
+ if (!props.open) return;
107
+ if (!isActive) return;
108
+
109
+ if (data.devToolVisible !== undefined)
110
+ devToolVisible.value = data.devToolVisible;
111
+ if (data.cacheInterceptConfig !== undefined)
112
+ cacheInterceptConfig.value = data.cacheInterceptConfig;
113
+ if (data.cacheNetworkLog !== undefined)
114
+ cacheNetworkLog.value = data.cacheNetworkLog;
115
+ if (data.cacheConsoleLog !== undefined)
116
+ cacheConsoleLog.value = data.cacheConsoleLog;
117
+ if (data.useTransition !== undefined)
118
+ useTransition.value = data.useTransition;
119
+ if (data.baseFontSize !== undefined) baseFontSize.value = data.baseFontSize;
120
+ if (data.tagFontSize !== undefined) tagFontSize.value = data.tagFontSize;
121
+ if (data.tipsFontSize !== undefined) tipsFontSize.value = data.tipsFontSize;
122
+ if (data.fontFamily !== undefined) fontFamily.value = data.fontFamily;
123
+ if (data.fontWeight !== undefined) fontWeight.value = data.fontWeight;
124
+ if (data.performanceVisible !== undefined)
125
+ performanceVisible.value = data.performanceVisible;
126
+ if (data.performanceShowFps !== undefined)
127
+ performanceShowFps.value = data.performanceShowFps;
128
+ if (data.performanceShowCpu !== undefined)
129
+ performanceShowCpu.value = data.performanceShowCpu;
130
+ if (data.barrageVisible !== undefined)
131
+ barrageVisible.value = data.barrageVisible;
132
+ if (data.barrageShowWhenOpen !== undefined)
133
+ barrageShowWhenOpen.value = data.barrageShowWhenOpen;
134
+ if (data.barrageMaxTracks !== undefined)
135
+ barrageMaxTracks.value = data.barrageMaxTracks;
136
+ if (data.barrageTrackHeight !== undefined)
137
+ barrageTrackHeight.value = data.barrageTrackHeight;
138
+ if (data.barrageStartTop !== undefined)
139
+ barrageStartTop.value = data.barrageStartTop;
140
+ if (data.barrageDuration !== undefined)
141
+ barrageDuration.value = data.barrageDuration;
142
+ if (data.barrageMaxLength !== undefined)
143
+ barrageMaxLength.value = data.barrageMaxLength;
144
+ if (data.barrageTypes !== undefined) {
145
+ if (Array.isArray(data.barrageTypes)) {
146
+ barrageTypes.value = data.barrageTypes;
147
+ } else {
148
+ // 如果收到了非数组(如诡异的循环引用字符串),打印个警告并忽略
149
+ console.warn(
150
+ '[DevTool] Received invalid barrageTypes:',
151
+ data.barrageTypes,
152
+ );
153
+ }
154
+ }
155
+
156
+ if (data.consoleList) {
157
+ consoleList.value = [...(data.consoleList ?? [])]
158
+ .filter((item) => {
159
+ if (currentConsoleType.value === 'all') return item;
160
+ if (currentConsoleType.value !== 'clear') {
161
+ return item.type === currentConsoleType.value;
162
+ }
163
+ return item;
164
+ })
165
+ .filter((item) => {
166
+ return (
167
+ item.args?.some(
168
+ (arg) =>
169
+ arg.type === 'string' &&
170
+ arg.value?.includes?.(searchConsole.value),
171
+ ) ||
172
+ item.position.includes(searchConsole.value) ||
173
+ item?.stack?.includes(searchConsole.value)
174
+ );
175
+ })
176
+ ?.map((item) => {
177
+ return {
178
+ ...item,
179
+ _positionHtml: hightLight(item.position, searchConsole.value),
180
+ _stackHtml: hightLight(item.stack, searchConsole.value),
181
+ args: item.args.map((arg) => {
182
+ if (arg.type === 'string') {
183
+ return {
184
+ ...arg,
185
+ _valueHtml: hightLight(arg.value, searchConsole.value),
186
+ };
187
+ }
188
+ return arg;
189
+ }),
190
+ };
191
+ });
192
+
193
+ backup.consoleList = [...data.consoleList];
194
+ }
195
+
196
+ if (data.networkList) {
197
+ const { startTime, endTime } = calcLineStartAndEnd(data.networkList);
198
+ const list = calcNetworkTimeline(data.networkList, startTime, endTime);
199
+
200
+ networkList.value = list
201
+ .filter((item) => {
202
+ if (currentNetworkType.value === 'all') return item;
203
+ if (currentNetworkType.value !== 'clear') {
204
+ return item.method === currentNetworkType.value;
205
+ }
206
+ return item;
207
+ })
208
+ ?.filter((item) => item?.url?.includes(searchNetwork.value))
209
+ ?.map((item) => {
210
+ return {
211
+ ...item,
212
+ url: hightLight(item.url, searchNetwork.value),
213
+ };
214
+ })
215
+ ?.sort((a, b) => {
216
+ if (currentNetworkSort.value === 1) {
217
+ return b.startTime - a.startTime;
218
+ } else {
219
+ return a.startTime - b.startTime;
220
+ }
221
+ });
222
+
223
+ backup.networkList = [...data.networkList];
224
+ }
225
+
226
+ if (data.transferList) {
227
+ transferList.value = [...(data.transferList ?? [])]
228
+ .filter((item) => {
229
+ const typeMatch =
230
+ currentTransferCategory.value === 'all' ||
231
+ item.type === currentTransferCategory.value;
232
+ const statusMatch =
233
+ currentTransferType.value === 'all' ||
234
+ item.status === currentTransferType.value;
235
+
236
+ if (currentTransferType.value === 'clear') return true;
237
+
238
+ return typeMatch && statusMatch;
239
+ })
240
+ .filter((item) => {
241
+ return item.url?.includes(searchTransfer.value);
242
+ })
243
+ ?.map((item) => {
244
+ return {
245
+ ...item,
246
+ url: hightLight(item.url, searchTransfer.value),
247
+ };
248
+ }) as any;
249
+ backup.transferList = [...data.transferList];
250
+ }
251
+
252
+ if (data.storageList) {
253
+ storageList.value = [...(data.storageList ?? [])]
254
+ ?.filter((item) => item._oldKey.includes(searchStorage.value))
255
+ ?.map((item) => {
256
+ return {
257
+ ...item,
258
+ _oldKey: hightLight(item._oldKey, searchStorage.value),
259
+ };
260
+ });
261
+ backup.storageList = [...data.storageList];
262
+ }
263
+
264
+ if (data.wsList) {
265
+ wsList.value = [...(data.wsList ?? [])]
266
+ .filter((item) => {
267
+ if (currentWebSocketType.value === 'all') return item;
268
+ return item.readyState === currentWebSocketType.value;
269
+ })
270
+ .filter((item) => item.url.includes(searchWs.value))
271
+ ?.map((item) => {
272
+ return {
273
+ ...item,
274
+ _highlightUrl: hightLight(item.url, searchWs.value),
275
+ };
276
+ });
277
+ backup.wsList = [...data.wsList];
278
+ }
279
+
280
+ if (data.routeList) {
281
+ routeList.value = [...(data.routeList ?? [])]
282
+ ?.filter(
283
+ (item) =>
284
+ item.path.includes(searchRoute.value) ||
285
+ item.name?.includes(searchRoute.value),
286
+ )
287
+ ?.map((item) => {
288
+ return {
289
+ ...item,
290
+ name: hightLight(item.name, searchRoute.value),
291
+ path: hightLight(item.path, searchRoute.value),
292
+ };
293
+ });
294
+ backup.routeList = [...data.routeList];
295
+ }
296
+
297
+ if (data.elEventList) elEventList.value = [...data.elEventList];
298
+ if (data.uniEventList) uniEventList.value = [...data.uniEventList];
299
+ if (data.eventCount) eventCount.value = { ...data.eventCount };
300
+ if (data.vuexList) vuexList.value = data.vuexList;
301
+ if (data.piniaList) piniaList.value = data.piniaList;
302
+ if (data.netWorkStatus) netWorkStatus.value = data.netWorkStatus;
303
+ if (data.sizeFormat) sizeFormat.value = data.sizeFormat;
304
+ if (data.screenList) screenList.value = [...data.screenList];
305
+ if (data.interceptNetworkMap) {
306
+ interceptNetworkList.value = Array.from(
307
+ data.interceptNetworkMap.values(),
308
+ );
309
+ }
310
+
311
+ if (data.devToolVersion || data.devToolBuildTime || data.devToolGit) {
312
+ Object.assign(buildInfo, {
313
+ devToolVersion: data.devToolVersion,
314
+ devToolBuildTime: data.devToolBuildTime,
315
+ devToolGit: data.devToolGit,
316
+ });
317
+ }
318
+
319
+ if (data.scanCodeList) scanCodeList.value = [...data.scanCodeList];
320
+ if (data.nfcList) nfcList.value = [...data.nfcList];
321
+ };
322
+
323
+ return {
324
+ consoleList,
325
+ networkList,
326
+ transferList,
327
+ storageList,
328
+ routeList,
329
+ wsList,
330
+ vuexList,
331
+ piniaList,
332
+ elEventList,
333
+ uniEventList,
334
+ eventCount,
335
+ screenList,
336
+ interceptNetworkList,
337
+ scanCodeList,
338
+ nfcList,
339
+ netWorkStatus,
340
+ sizeFormat,
341
+ devToolVisible,
342
+ cacheInterceptConfig,
343
+ cacheNetworkLog,
344
+ cacheConsoleLog,
345
+ useTransition,
346
+ baseFontSize,
347
+ tagFontSize,
348
+ tipsFontSize,
349
+ fontFamily,
350
+ fontWeight,
351
+ performanceVisible,
352
+ performanceShowFps,
353
+ performanceShowCpu,
354
+ barrageVisible,
355
+ barrageShowWhenOpen,
356
+ barrageMaxTracks,
357
+ barrageTrackHeight,
358
+ barrageStartTop,
359
+ barrageDuration,
360
+ barrageMaxLength,
361
+ barrageTypes,
362
+ backup,
363
+ buildInfo,
364
+ currentConsoleType,
365
+ currentNetworkType,
366
+ currentNetworkSort,
367
+ currentTransferType,
368
+ currentTransferCategory,
369
+ currentWebSocketType,
370
+ searchConsole,
371
+ searchNetwork,
372
+ searchTransfer,
373
+ searchWs,
374
+ searchRoute,
375
+ searchStorage,
376
+ activeTab,
377
+ tabScrollLeft,
378
+ theme,
379
+ isFullScreen,
380
+ windowX,
381
+ windowY,
382
+ windowWidth,
383
+ windowHeight,
384
+ setIsActive,
385
+ listenPostMessage,
386
+ };
387
+ }