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