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,629 +1,629 @@
1
- import { debounce } from '../../../../../utils/index';
2
- import { setDevToolInfo } from '../../../../../modules/devToolInfo';
3
- import type { DevTool } from '../../../../../type';
4
- import { CMD_TYPE, MSG_TYPE, DEV_CORE_MESSAGE } from '../../../../../const';
5
- import { hightLight } from '../../../../../utils/index';
6
-
7
- export function useDevToolHandlers(props: any, emits: any, state: any) {
8
- const {
9
- activeTab,
10
- currentConsoleType,
11
- currentNetworkType,
12
- currentWebSocketType,
13
- currentTransferType,
14
- currentTransferCategory,
15
- tabScrollLeft,
16
- cacheInterceptConfig,
17
- useTransition,
18
- baseFontSize,
19
- tagFontSize,
20
- tipsFontSize,
21
- fontFamily,
22
- fontWeight,
23
- cacheNetworkLog,
24
- cacheConsoleLog,
25
- interceptNetworkList,
26
- consoleList,
27
- networkList,
28
- transferList,
29
- wsList,
30
- storageList,
31
- elEventList,
32
- uniEventList,
33
- eventCount,
34
- screenList,
35
- scanCodeList,
36
- nfcList,
37
- routeList,
38
- backup,
39
- searchConsole,
40
- theme,
41
- currentNetworkSort,
42
- barrageVisible,
43
- barrageShowWhenOpen,
44
- } = state;
45
-
46
- /** 发送消息给核心模块 */
47
- function basicSendMessage(message: {
48
- type: string;
49
- data: Record<string, any>;
50
- }) {
51
- emits('sendMessage', message);
52
- }
53
-
54
- function setWindowInfo() {
55
- setDevToolInfo({
56
- activeTab: activeTab.value,
57
- currentConsoleType: currentConsoleType.value,
58
- currentNetworkType: currentNetworkType.value,
59
- currentWebSocketType: currentWebSocketType.value,
60
- theme: theme.value,
61
- tabScrollLeft: tabScrollLeft.value,
62
- cacheInterceptConfig: cacheInterceptConfig.value,
63
- cacheNetworkLog: cacheNetworkLog.value,
64
- cacheConsoleLog: cacheConsoleLog.value,
65
- useTransition: useTransition.value,
66
- baseFontSize: baseFontSize.value,
67
- tagFontSize: tagFontSize.value,
68
- tipsFontSize: tipsFontSize.value,
69
- fontFamily: fontFamily.value,
70
- fontWeight: fontWeight.value,
71
- interceptNetworkList: interceptNetworkList.value,
72
- performanceShowFps: state.performanceShowFps.value,
73
- performanceShowCpu: state.performanceShowCpu.value,
74
- barrageVisible: barrageVisible.value,
75
- barrageShowWhenOpen: barrageShowWhenOpen.value,
76
- });
77
- }
78
-
79
- const debounceSetWindowInfo = debounce(setWindowInfo, 200);
80
-
81
- function onCloseWindow() {
82
- emits('close');
83
- setWindowInfo();
84
- }
85
-
86
- function onChangeTabs(index: number) {
87
- activeTab.value = index;
88
- setWindowInfo();
89
- }
90
-
91
- function onScrollTabs(e: any) {
92
- tabScrollLeft.value = e.detail.scrollLeft;
93
- debounceSetWindowInfo();
94
- }
95
-
96
- const debounceScrollTabs = debounce(onScrollTabs, 200);
97
-
98
- function onConsoleChoose(type: string) {
99
- if (type === 'clear') {
100
- consoleList.value = [];
101
- backup.consoleList = [];
102
- basicSendMessage({ type: CMD_TYPE.CONSOLE_CLEAR, data: {} });
103
- } else if (type === 'all') {
104
- currentConsoleType.value = type;
105
- consoleList.value = backup.consoleList;
106
- } else {
107
- currentConsoleType.value = type;
108
- consoleList.value = backup.consoleList.filter(
109
- (item: any) => item.type === type,
110
- );
111
- }
112
- setWindowInfo();
113
- }
114
-
115
- function onRunJS(code: string) {
116
- basicSendMessage({ type: CMD_TYPE.RUN_JS, data: { code } });
117
- }
118
-
119
- function onSearchConsole(value: string) {
120
- consoleList.value = backup.consoleList
121
- .filter((item: any) => {
122
- return (
123
- item.args.some(
124
- (arg: any) => arg.type === 'string' && arg.value.includes(value),
125
- ) ||
126
- item.position.includes(value) ||
127
- item?.stack?.includes(value)
128
- );
129
- })
130
- ?.map((item: any) => {
131
- return {
132
- ...item,
133
- position: hightLight(item.position, searchConsole.value),
134
- stack: hightLight(item.stack, searchConsole.value),
135
- args: item.args.map((arg: any) => {
136
- if (arg.type === 'string') {
137
- return { type: 'string', value: hightLight(arg.value, value) };
138
- }
139
- return arg;
140
- }),
141
- };
142
- });
143
- }
144
-
145
- function onNetworkChoose(type: string) {
146
- if (type === 'clear') {
147
- networkList.value = [];
148
- backup.networkList = [];
149
- basicSendMessage({ type: CMD_TYPE.NETWORK_CLEAR, data: {} });
150
- } else if (type === 'all') {
151
- currentNetworkType.value = type;
152
- networkList.value = backup.networkList;
153
- } else if (type === 'error') {
154
- currentNetworkType.value = type;
155
- networkList.value = backup.networkList.filter((item: any) => {
156
- return item.status === 'error' || /[4,5]\d{2,}/.test(item.status + '');
157
- });
158
- } else {
159
- currentNetworkType.value = type;
160
- networkList.value = backup.networkList.filter(
161
- (item: any) => item.method === type,
162
- );
163
- }
164
- setWindowInfo();
165
- }
166
-
167
- function onSearchNetwork(value: string) {
168
- networkList.value = backup.networkList
169
- .filter((item: any) => {
170
- if (currentNetworkType.value === 'all') return item;
171
- return item.method === currentNetworkType.value;
172
- })
173
- ?.filter((item: any) => item?.url?.includes(value))
174
- ?.map((item: any) => {
175
- return { ...item, url: hightLight(item.url, value) };
176
- });
177
- }
178
-
179
- function onSortNetwork(sort: -1 | 1) {
180
- currentNetworkSort.value = sort;
181
- const list = networkList.value.sort((a: any, b: any) => {
182
- return sort === 1 ? b.startTime - a.startTime : a.startTime - b.startTime;
183
- });
184
- networkList.value = [...list];
185
- }
186
-
187
- function filterTransferList() {
188
- transferList.value = backup.transferList.filter((item: any) => {
189
- const typeMatch =
190
- currentTransferCategory.value === 'all' ||
191
- item.type === currentTransferCategory.value;
192
- let statusMatch =
193
- currentTransferType.value === 'all' ||
194
- item.status === currentTransferType.value;
195
-
196
- if (currentTransferType.value === 'pending') {
197
- statusMatch = ['pending', 'uploading', 'downloading'].includes(
198
- item.status,
199
- );
200
- }
201
-
202
- return typeMatch && statusMatch;
203
- });
204
- }
205
-
206
- function onTransferChoose(type: string) {
207
- if (type === 'clear') {
208
- transferList.value = [];
209
- backup.transferList = [];
210
- basicSendMessage({ type: CMD_TYPE.TRANSFER_CLEAR, data: {} });
211
- } else {
212
- currentTransferType.value = type;
213
- filterTransferList();
214
- }
215
- }
216
-
217
- function onTransferCategoryChoose(category: string) {
218
- currentTransferCategory.value = category;
219
- filterTransferList();
220
- }
221
-
222
- function onSearchTransfer(value: string) {
223
- filterTransferList(); // Reset list based on filters first
224
- transferList.value = transferList.value
225
- .filter((item: any) => item.url?.includes(value))
226
- ?.map((item: any) => {
227
- return { ...item, url: hightLight(item.url, value) };
228
- });
229
- }
230
-
231
- function onWebSocketChoose(type: string) {
232
- if (type === 'clear') {
233
- wsList.value = [];
234
- backup.wsList = [];
235
- basicSendMessage({ type: CMD_TYPE.WS_CLEAR, data: {} });
236
- } else if (type === 'all') {
237
- currentWebSocketType.value = type;
238
- wsList.value = backup.wsList;
239
- } else {
240
- currentWebSocketType.value = type;
241
- wsList.value = backup.wsList.filter(
242
- (item: any) => item.readyState === type,
243
- );
244
- }
245
- setWindowInfo();
246
- }
247
-
248
- function onSearchWs(value: string) {
249
- wsList.value = backup.wsList
250
- .filter((item: any) => {
251
- if (currentWebSocketType.value === 'all') return item;
252
- return item.readyState === currentWebSocketType.value;
253
- })
254
- .filter((item: any) => item.url.includes(value))
255
- ?.map((item: any) => {
256
- return { ...item, url: hightLight(item.url, value) };
257
- });
258
- }
259
-
260
- function onStorageChoose(type: string) {
261
- if (type === 'clear') {
262
- backup.storageList = [];
263
- storageList.value = [];
264
- basicSendMessage({ type: CMD_TYPE.STORAGE_CLEAR, data: {} });
265
- } else if (type === 'refresh') {
266
- basicSendMessage({ type: CMD_TYPE.STORAGE_REFRESH, data: {} });
267
- } else if (type === 'add') {
268
- const key = '_new_' + Date.now();
269
- const newItem = { key, _oldKey: key, value: JSON.stringify('') };
270
- backup.storageList.unshift(newItem);
271
- storageList.value.unshift(newItem);
272
- basicSendMessage({
273
- type: CMD_TYPE.STORAGE_ADD,
274
- data: { key, value: newItem.value },
275
- });
276
- }
277
- }
278
-
279
- function onStorageRemove(key: string) {
280
- backup.storageList = backup.storageList.filter(
281
- (item: any) => item.key !== key,
282
- );
283
- storageList.value = backup.storageList;
284
- basicSendMessage({ type: CMD_TYPE.STORAGE_REMOVE, data: { key } });
285
- }
286
-
287
- function onChangeStorage(data: DevTool.StorageItem) {
288
- basicSendMessage({ type: CMD_TYPE.STORAGE_UPDATE, data });
289
- }
290
-
291
- function onSearchStorage(value: string) {
292
- storageList.value = backup.storageList
293
- .filter((item: any) => item._oldKey.includes(value))
294
- ?.map((item: any) => {
295
- return { ...item, _oldKey: hightLight(item._oldKey, value) };
296
- });
297
- }
298
-
299
- function onElEventClear() {
300
- elEventList.value = [];
301
- basicSendMessage({ type: CMD_TYPE.EL_EVENT_CLEAR, data: {} });
302
- }
303
-
304
- function onUniEventClear() {
305
- uniEventList.value = [];
306
- eventCount.value = { on: 0, once: 0, emit: 0, off: 0 };
307
- basicSendMessage({ type: CMD_TYPE.UNI_EVENT_CLEAR, data: {} });
308
- }
309
-
310
- function onCaptureScreenClear() {
311
- screenList.value = [];
312
- basicSendMessage({ type: CMD_TYPE.SCREEN_CLEAR, data: {} });
313
- }
314
-
315
- function onScanCodeListClear() {
316
- scanCodeList.value = [];
317
- basicSendMessage({ type: CMD_TYPE.SCAN_CODE_CLEAR, data: {} });
318
- }
319
-
320
- function onNfcClear() {
321
- nfcList.value = [];
322
- basicSendMessage({ type: CMD_TYPE.NFC_CLEAR, data: {} });
323
- }
324
-
325
- function onRouteRefresh() {
326
- basicSendMessage({ type: CMD_TYPE.ROUTE_REFRESH, data: {} });
327
- }
328
-
329
- function onSearchRoute(value: string) {
330
- routeList.value = backup.routeList
331
- ?.filter(
332
- (item: any) => item.path.includes(value) || item.name?.includes(value),
333
- )
334
- ?.map((item: any) => {
335
- return {
336
- ...item,
337
- name: hightLight(item.name, value),
338
- path: hightLight(item.path, value),
339
- };
340
- });
341
- }
342
-
343
- function onShowDevButton(show: boolean) {
344
- basicSendMessage({ type: CMD_TYPE.BUTTON_TOGGLE, data: { show } });
345
- }
346
-
347
- function onRestartDevTool() {
348
- basicSendMessage({ type: CMD_TYPE.RESTART_DEBUGGER, data: {} });
349
- }
350
-
351
- function onRestartApp() {
352
- basicSendMessage({ type: CMD_TYPE.RESTART_APP, data: {} });
353
- }
354
-
355
- function onExportLog(exports: any) {
356
- basicSendMessage({ type: CMD_TYPE.EXPORT_LOG, data: { ...exports } });
357
- }
358
-
359
- function onScreenshot() {
360
- basicSendMessage({ type: 'dev-tool-hide-screenshot', data: {} });
361
- }
362
-
363
- function onClearCache() {
364
- basicSendMessage({ type: CMD_TYPE.CACHE_CLEAR, data: {} });
365
- }
366
-
367
- function onDestroyDevTool() {
368
- basicSendMessage({ type: CMD_TYPE.DESTROY, data: {} });
369
- }
370
-
371
- function onChangeTheme(t: string) {
372
- theme.value = t;
373
- setDevToolInfo({ theme: t });
374
- emits('changeTheme', t);
375
- }
376
-
377
- function onChangeCacheInterceptConfig(value: boolean) {
378
- setDevToolInfo({
379
- cacheInterceptConfig: value,
380
- interceptNetworkList: value ? interceptNetworkList.value : [],
381
- });
382
- basicSendMessage({
383
- type: CMD_TYPE.SET_CACHE_INTERCEPT,
384
- data: { cacheInterceptConfig: value },
385
- });
386
- }
387
-
388
- function onChangeCacheNetworkLog(value: boolean) {
389
- setDevToolInfo({
390
- cacheNetworkLog: value,
391
- });
392
- cacheNetworkLog.value = value;
393
- basicSendMessage({
394
- type: CMD_TYPE.SET_CACHE_NETWORK_LOG,
395
- data: { cacheNetworkLog: value },
396
- });
397
- }
398
-
399
- function onChangeCacheConsoleLog(value: boolean) {
400
- setDevToolInfo({
401
- cacheConsoleLog: value,
402
- });
403
- cacheConsoleLog.value = value;
404
- basicSendMessage({
405
- type: CMD_TYPE.SET_CACHE_CONSOLE_LOG,
406
- data: { cacheConsoleLog: value },
407
- });
408
- }
409
-
410
- function onChangeUseTransition(value: boolean) {
411
- useTransition.value = value;
412
- setDevToolInfo({
413
- useTransition: value,
414
- });
415
- basicSendMessage({
416
- type: CMD_TYPE.SET_TRANSITION,
417
- data: { useTransition: value },
418
- });
419
- }
420
-
421
- function onChangeFontSize(data: {
422
- baseFontSize: number;
423
- tagFontSize: number;
424
- tipsFontSize: number;
425
- fontFamily: string;
426
- fontWeight: string;
427
- }) {
428
- baseFontSize.value = data.baseFontSize;
429
- tagFontSize.value = data.tagFontSize;
430
- tipsFontSize.value = data.tipsFontSize;
431
- fontFamily.value = data.fontFamily;
432
- fontWeight.value = data.fontWeight;
433
- setDevToolInfo(data);
434
- basicSendMessage({
435
- type: CMD_TYPE.SET_FONT,
436
- data,
437
- });
438
- }
439
-
440
- function onChangePerformance(show: boolean) {
441
- state.performanceVisible.value = show;
442
- setDevToolInfo({
443
- performanceVisible: show,
444
- });
445
- uni.$emit(DEV_CORE_MESSAGE, { type: MSG_TYPE.PERF_VISIBLE, data: show });
446
- }
447
-
448
- function onChangePerformanceShowFps(show: boolean) {
449
- state.performanceShowFps.value = show;
450
- setDevToolInfo({
451
- performanceShowFps: show,
452
- });
453
- uni.$emit('DEV_CHANGE_PERFORMANCE_SHOW_FPS', show);
454
- }
455
-
456
- function onChangePerformanceShowCpu(show: boolean) {
457
- state.performanceShowCpu.value = show;
458
- setDevToolInfo({
459
- performanceShowCpu: show,
460
- });
461
- uni.$emit('DEV_CHANGE_PERFORMANCE_SHOW_CPU', show);
462
- }
463
-
464
- function onChangeBarrage(show: boolean) {
465
- state.barrageVisible.value = show;
466
- setDevToolInfo({
467
- barrageVisible: show,
468
- });
469
- basicSendMessage({ type: CMD_TYPE.BARRAGE_TOGGLE, data: { show } });
470
- uni.$emit(DEV_CORE_MESSAGE, { type: MSG_TYPE.BARRAGE_VISIBLE, data: show });
471
- }
472
-
473
- function onChangeVuex(value: any) {
474
- basicSendMessage({ type: CMD_TYPE.VUEX_CHANGE, data: value });
475
- }
476
-
477
- function onChangePinia(value: any) {
478
- basicSendMessage({ type: CMD_TYPE.PINIA_CHANGE, data: value });
479
- }
480
-
481
- function onClearWebSocketMessage(ws: DevTool.WS) {
482
- basicSendMessage({ type: CMD_TYPE.WS_CLEAR_MESSAGE, data: ws });
483
- }
484
-
485
- function onSendWebSocket(data: { url: string; message: any }) {
486
- basicSendMessage({ type: CMD_TYPE.WS_SEND, data });
487
- }
488
-
489
- function onConfirmInterceptConfig(ni: DevTool.NetworkItem) {
490
- const index = interceptNetworkList.value.findIndex((item: any) => {
491
- const key = `${item.method?.toUpperCase()}|${item.url?.split('?')[0]}`;
492
- const niKey = `${ni.method?.toUpperCase()}|${ni.url?.split('?')[0]}`;
493
- return key === niKey;
494
- });
495
- const list = [...interceptNetworkList.value];
496
- if (index > -1) {
497
- list[index] = ni;
498
- } else {
499
- list.unshift(ni);
500
- }
501
- setDevToolInfo({
502
- cacheInterceptConfig: cacheInterceptConfig.value,
503
- interceptNetworkList: cacheInterceptConfig.value ? list : [],
504
- });
505
- basicSendMessage({ type: CMD_TYPE.INTERCEPT_UPDATE, data: [ni] });
506
- }
507
-
508
- function onRemoveInterceptConfig(ni: DevTool.NetworkItem) {
509
- basicSendMessage({ type: CMD_TYPE.INTERCEPT_UPDATE, data: ni });
510
- }
511
-
512
- function onChangeBarrageMaxTracks(val: number) {
513
- state.barrageMaxTracks.value = val;
514
- basicSendMessage({
515
- type: CMD_TYPE.BARRAGE_MAX_TRACKS,
516
- data: { value: val },
517
- });
518
- }
519
-
520
- function onChangeBarrageTrackHeight(val: number) {
521
- state.barrageTrackHeight.value = val;
522
- basicSendMessage({
523
- type: CMD_TYPE.BARRAGE_TRACK_HEIGHT,
524
- data: { value: val },
525
- });
526
- }
527
-
528
- function onChangeBarrageStartTop(val: number) {
529
- state.barrageStartTop.value = val;
530
- basicSendMessage({
531
- type: CMD_TYPE.BARRAGE_START_TOP,
532
- data: { value: val },
533
- });
534
- }
535
-
536
- function onChangeBarrageDuration(val: number) {
537
- state.barrageDuration.value = val;
538
- basicSendMessage({
539
- type: CMD_TYPE.BARRAGE_DURATION,
540
- data: { value: val },
541
- });
542
- }
543
-
544
- function onChangeBarrageMaxLength(val: number) {
545
- state.barrageMaxLength.value = val;
546
- basicSendMessage({
547
- type: CMD_TYPE.BARRAGE_MAX_LENGTH,
548
- data: { value: val },
549
- });
550
- }
551
-
552
- function onChangeBarrageTypes(val: string[]) {
553
- state.barrageTypes.value = val;
554
- basicSendMessage({
555
- type: CMD_TYPE.BARRAGE_TYPES,
556
- data: { value: val },
557
- });
558
- }
559
-
560
- function onChangeBarrageShowWhenOpen(val: boolean) {
561
- state.barrageShowWhenOpen.value = val;
562
- setDevToolInfo({
563
- barrageShowWhenOpen: val,
564
- });
565
- basicSendMessage({
566
- type: CMD_TYPE.SET_BARRAGE_SHOW_WHEN_OPEN,
567
- data: { value: val },
568
- });
569
- }
570
-
571
- return {
572
- onCloseWindow,
573
- onChangeTabs,
574
- debounceScrollTabs,
575
- onConsoleChoose,
576
- onRunJS,
577
- onSearchConsole,
578
- onNetworkChoose,
579
- onSearchNetwork,
580
- onSortNetwork,
581
- onTransferChoose,
582
- onTransferCategoryChoose,
583
- onSearchTransfer,
584
- onWebSocketChoose,
585
- onSearchWs,
586
- onStorageChoose,
587
- onStorageRemove,
588
- onChangeStorage,
589
- onSearchStorage,
590
- onElEventClear,
591
- onUniEventClear,
592
- onCaptureScreenClear,
593
- onScanCodeListClear,
594
- onNfcClear,
595
- onRouteRefresh,
596
- onSearchRoute,
597
- onShowDevButton,
598
- onRestartDevTool,
599
- onRestartApp,
600
- onExportLog,
601
- onScreenshot,
602
- onClearCache,
603
- onDestroyDevTool,
604
- onChangeTheme,
605
- onChangeCacheInterceptConfig,
606
- onChangeCacheNetworkLog,
607
- onChangeCacheConsoleLog,
608
- onChangeUseTransition,
609
- onChangeFontSize,
610
- onChangeVuex,
611
- onChangePinia,
612
- onClearWebSocketMessage,
613
- onSendWebSocket,
614
- onConfirmInterceptConfig,
615
- onRemoveInterceptConfig,
616
- onChangePerformance,
617
- onChangePerformanceShowFps,
618
- onChangePerformanceShowCpu,
619
- onChangeBarrage,
620
- onChangeBarrageMaxTracks,
621
- onChangeBarrageTrackHeight,
622
- onChangeBarrageStartTop,
623
- onChangeBarrageDuration,
624
- onChangeBarrageMaxLength,
625
- onChangeBarrageTypes,
626
- onChangeBarrageShowWhenOpen,
627
- basicSendMessage,
628
- };
629
- }
1
+ import { debounce } from '../../../../../utils/index';
2
+ import { setDevToolInfo } from '../../../../../modules/devToolInfo';
3
+ import type { DevTool } from '../../../../../type';
4
+ import { CMD_TYPE, MSG_TYPE, DEV_CORE_MESSAGE } from '../../../../../const';
5
+ import { hightLight } from '../../../../../utils/index';
6
+
7
+ export function useDevToolHandlers(props: any, emits: any, state: any) {
8
+ const {
9
+ activeTab,
10
+ currentConsoleType,
11
+ currentNetworkType,
12
+ currentWebSocketType,
13
+ currentTransferType,
14
+ currentTransferCategory,
15
+ tabScrollLeft,
16
+ cacheInterceptConfig,
17
+ useTransition,
18
+ baseFontSize,
19
+ tagFontSize,
20
+ tipsFontSize,
21
+ fontFamily,
22
+ fontWeight,
23
+ cacheNetworkLog,
24
+ cacheConsoleLog,
25
+ interceptNetworkList,
26
+ consoleList,
27
+ networkList,
28
+ transferList,
29
+ wsList,
30
+ storageList,
31
+ elEventList,
32
+ uniEventList,
33
+ eventCount,
34
+ screenList,
35
+ scanCodeList,
36
+ nfcList,
37
+ routeList,
38
+ backup,
39
+ searchConsole,
40
+ theme,
41
+ currentNetworkSort,
42
+ barrageVisible,
43
+ barrageShowWhenOpen,
44
+ } = state;
45
+
46
+ /** 发送消息给核心模块 */
47
+ function basicSendMessage(message: {
48
+ type: string;
49
+ data: Record<string, any>;
50
+ }) {
51
+ emits('sendMessage', message);
52
+ }
53
+
54
+ function setWindowInfo() {
55
+ setDevToolInfo({
56
+ activeTab: activeTab.value,
57
+ currentConsoleType: currentConsoleType.value,
58
+ currentNetworkType: currentNetworkType.value,
59
+ currentWebSocketType: currentWebSocketType.value,
60
+ theme: theme.value,
61
+ tabScrollLeft: tabScrollLeft.value,
62
+ cacheInterceptConfig: cacheInterceptConfig.value,
63
+ cacheNetworkLog: cacheNetworkLog.value,
64
+ cacheConsoleLog: cacheConsoleLog.value,
65
+ useTransition: useTransition.value,
66
+ baseFontSize: baseFontSize.value,
67
+ tagFontSize: tagFontSize.value,
68
+ tipsFontSize: tipsFontSize.value,
69
+ fontFamily: fontFamily.value,
70
+ fontWeight: fontWeight.value,
71
+ interceptNetworkList: interceptNetworkList.value,
72
+ performanceShowFps: state.performanceShowFps.value,
73
+ performanceShowCpu: state.performanceShowCpu.value,
74
+ barrageVisible: barrageVisible.value,
75
+ barrageShowWhenOpen: barrageShowWhenOpen.value,
76
+ });
77
+ }
78
+
79
+ const debounceSetWindowInfo = debounce(setWindowInfo, 200);
80
+
81
+ function onCloseWindow() {
82
+ emits('close');
83
+ setWindowInfo();
84
+ }
85
+
86
+ function onChangeTabs(index: number) {
87
+ activeTab.value = index;
88
+ setWindowInfo();
89
+ }
90
+
91
+ function onScrollTabs(e: any) {
92
+ tabScrollLeft.value = e.detail.scrollLeft;
93
+ debounceSetWindowInfo();
94
+ }
95
+
96
+ const debounceScrollTabs = debounce(onScrollTabs, 200);
97
+
98
+ function onConsoleChoose(type: string) {
99
+ if (type === 'clear') {
100
+ consoleList.value = [];
101
+ backup.consoleList = [];
102
+ basicSendMessage({ type: CMD_TYPE.CONSOLE_CLEAR, data: {} });
103
+ } else if (type === 'all') {
104
+ currentConsoleType.value = type;
105
+ consoleList.value = backup.consoleList;
106
+ } else {
107
+ currentConsoleType.value = type;
108
+ consoleList.value = backup.consoleList.filter(
109
+ (item: any) => item.type === type,
110
+ );
111
+ }
112
+ setWindowInfo();
113
+ }
114
+
115
+ function onRunJS(code: string) {
116
+ basicSendMessage({ type: CMD_TYPE.RUN_JS, data: { code } });
117
+ }
118
+
119
+ function onSearchConsole(value: string) {
120
+ consoleList.value = backup.consoleList
121
+ .filter((item: any) => {
122
+ return (
123
+ item.args.some(
124
+ (arg: any) => arg.type === 'string' && arg.value.includes(value),
125
+ ) ||
126
+ item.position.includes(value) ||
127
+ item?.stack?.includes(value)
128
+ );
129
+ })
130
+ ?.map((item: any) => {
131
+ return {
132
+ ...item,
133
+ position: hightLight(item.position, searchConsole.value),
134
+ stack: hightLight(item.stack, searchConsole.value),
135
+ args: item.args.map((arg: any) => {
136
+ if (arg.type === 'string') {
137
+ return { type: 'string', value: hightLight(arg.value, value) };
138
+ }
139
+ return arg;
140
+ }),
141
+ };
142
+ });
143
+ }
144
+
145
+ function onNetworkChoose(type: string) {
146
+ if (type === 'clear') {
147
+ networkList.value = [];
148
+ backup.networkList = [];
149
+ basicSendMessage({ type: CMD_TYPE.NETWORK_CLEAR, data: {} });
150
+ } else if (type === 'all') {
151
+ currentNetworkType.value = type;
152
+ networkList.value = backup.networkList;
153
+ } else if (type === 'error') {
154
+ currentNetworkType.value = type;
155
+ networkList.value = backup.networkList.filter((item: any) => {
156
+ return item.status === 'error' || /[4,5]\d{2,}/.test(item.status + '');
157
+ });
158
+ } else {
159
+ currentNetworkType.value = type;
160
+ networkList.value = backup.networkList.filter(
161
+ (item: any) => item.method === type,
162
+ );
163
+ }
164
+ setWindowInfo();
165
+ }
166
+
167
+ function onSearchNetwork(value: string) {
168
+ networkList.value = backup.networkList
169
+ .filter((item: any) => {
170
+ if (currentNetworkType.value === 'all') return item;
171
+ return item.method === currentNetworkType.value;
172
+ })
173
+ ?.filter((item: any) => item?.url?.includes(value))
174
+ ?.map((item: any) => {
175
+ return { ...item, url: hightLight(item.url, value) };
176
+ });
177
+ }
178
+
179
+ function onSortNetwork(sort: -1 | 1) {
180
+ currentNetworkSort.value = sort;
181
+ const list = networkList.value.sort((a: any, b: any) => {
182
+ return sort === 1 ? b.startTime - a.startTime : a.startTime - b.startTime;
183
+ });
184
+ networkList.value = [...list];
185
+ }
186
+
187
+ function filterTransferList() {
188
+ transferList.value = backup.transferList.filter((item: any) => {
189
+ const typeMatch =
190
+ currentTransferCategory.value === 'all' ||
191
+ item.type === currentTransferCategory.value;
192
+ let statusMatch =
193
+ currentTransferType.value === 'all' ||
194
+ item.status === currentTransferType.value;
195
+
196
+ if (currentTransferType.value === 'pending') {
197
+ statusMatch = ['pending', 'uploading', 'downloading'].includes(
198
+ item.status,
199
+ );
200
+ }
201
+
202
+ return typeMatch && statusMatch;
203
+ });
204
+ }
205
+
206
+ function onTransferChoose(type: string) {
207
+ if (type === 'clear') {
208
+ transferList.value = [];
209
+ backup.transferList = [];
210
+ basicSendMessage({ type: CMD_TYPE.TRANSFER_CLEAR, data: {} });
211
+ } else {
212
+ currentTransferType.value = type;
213
+ filterTransferList();
214
+ }
215
+ }
216
+
217
+ function onTransferCategoryChoose(category: string) {
218
+ currentTransferCategory.value = category;
219
+ filterTransferList();
220
+ }
221
+
222
+ function onSearchTransfer(value: string) {
223
+ filterTransferList(); // Reset list based on filters first
224
+ transferList.value = transferList.value
225
+ .filter((item: any) => item.url?.includes(value))
226
+ ?.map((item: any) => {
227
+ return { ...item, url: hightLight(item.url, value) };
228
+ });
229
+ }
230
+
231
+ function onWebSocketChoose(type: string) {
232
+ if (type === 'clear') {
233
+ wsList.value = [];
234
+ backup.wsList = [];
235
+ basicSendMessage({ type: CMD_TYPE.WS_CLEAR, data: {} });
236
+ } else if (type === 'all') {
237
+ currentWebSocketType.value = type;
238
+ wsList.value = backup.wsList;
239
+ } else {
240
+ currentWebSocketType.value = type;
241
+ wsList.value = backup.wsList.filter(
242
+ (item: any) => item.readyState === type,
243
+ );
244
+ }
245
+ setWindowInfo();
246
+ }
247
+
248
+ function onSearchWs(value: string) {
249
+ wsList.value = backup.wsList
250
+ .filter((item: any) => {
251
+ if (currentWebSocketType.value === 'all') return item;
252
+ return item.readyState === currentWebSocketType.value;
253
+ })
254
+ .filter((item: any) => item.url.includes(value))
255
+ ?.map((item: any) => {
256
+ return { ...item, url: hightLight(item.url, value) };
257
+ });
258
+ }
259
+
260
+ function onStorageChoose(type: string) {
261
+ if (type === 'clear') {
262
+ backup.storageList = [];
263
+ storageList.value = [];
264
+ basicSendMessage({ type: CMD_TYPE.STORAGE_CLEAR, data: {} });
265
+ } else if (type === 'refresh') {
266
+ basicSendMessage({ type: CMD_TYPE.STORAGE_REFRESH, data: {} });
267
+ } else if (type === 'add') {
268
+ const key = '_new_' + Date.now();
269
+ const newItem = { key, _oldKey: key, value: JSON.stringify('') };
270
+ backup.storageList.unshift(newItem);
271
+ storageList.value.unshift(newItem);
272
+ basicSendMessage({
273
+ type: CMD_TYPE.STORAGE_ADD,
274
+ data: { key, value: newItem.value },
275
+ });
276
+ }
277
+ }
278
+
279
+ function onStorageRemove(key: string) {
280
+ backup.storageList = backup.storageList.filter(
281
+ (item: any) => item.key !== key,
282
+ );
283
+ storageList.value = backup.storageList;
284
+ basicSendMessage({ type: CMD_TYPE.STORAGE_REMOVE, data: { key } });
285
+ }
286
+
287
+ function onChangeStorage(data: DevTool.StorageItem) {
288
+ basicSendMessage({ type: CMD_TYPE.STORAGE_UPDATE, data });
289
+ }
290
+
291
+ function onSearchStorage(value: string) {
292
+ storageList.value = backup.storageList
293
+ .filter((item: any) => item._oldKey.includes(value))
294
+ ?.map((item: any) => {
295
+ return { ...item, _oldKey: hightLight(item._oldKey, value) };
296
+ });
297
+ }
298
+
299
+ function onElEventClear() {
300
+ elEventList.value = [];
301
+ basicSendMessage({ type: CMD_TYPE.EL_EVENT_CLEAR, data: {} });
302
+ }
303
+
304
+ function onUniEventClear() {
305
+ uniEventList.value = [];
306
+ eventCount.value = { on: 0, once: 0, emit: 0, off: 0 };
307
+ basicSendMessage({ type: CMD_TYPE.UNI_EVENT_CLEAR, data: {} });
308
+ }
309
+
310
+ function onCaptureScreenClear() {
311
+ screenList.value = [];
312
+ basicSendMessage({ type: CMD_TYPE.SCREEN_CLEAR, data: {} });
313
+ }
314
+
315
+ function onScanCodeListClear() {
316
+ scanCodeList.value = [];
317
+ basicSendMessage({ type: CMD_TYPE.SCAN_CODE_CLEAR, data: {} });
318
+ }
319
+
320
+ function onNfcClear() {
321
+ nfcList.value = [];
322
+ basicSendMessage({ type: CMD_TYPE.NFC_CLEAR, data: {} });
323
+ }
324
+
325
+ function onRouteRefresh() {
326
+ basicSendMessage({ type: CMD_TYPE.ROUTE_REFRESH, data: {} });
327
+ }
328
+
329
+ function onSearchRoute(value: string) {
330
+ routeList.value = backup.routeList
331
+ ?.filter(
332
+ (item: any) => item.path.includes(value) || item.name?.includes(value),
333
+ )
334
+ ?.map((item: any) => {
335
+ return {
336
+ ...item,
337
+ name: hightLight(item.name, value),
338
+ path: hightLight(item.path, value),
339
+ };
340
+ });
341
+ }
342
+
343
+ function onShowDevButton(show: boolean) {
344
+ basicSendMessage({ type: CMD_TYPE.BUTTON_TOGGLE, data: { show } });
345
+ }
346
+
347
+ function onRestartDevTool() {
348
+ basicSendMessage({ type: CMD_TYPE.RESTART_DEBUGGER, data: {} });
349
+ }
350
+
351
+ function onRestartApp() {
352
+ basicSendMessage({ type: CMD_TYPE.RESTART_APP, data: {} });
353
+ }
354
+
355
+ function onExportLog(exports: any) {
356
+ basicSendMessage({ type: CMD_TYPE.EXPORT_LOG, data: { ...exports } });
357
+ }
358
+
359
+ function onScreenshot() {
360
+ basicSendMessage({ type: 'dev-tool-hide-screenshot', data: {} });
361
+ }
362
+
363
+ function onClearCache() {
364
+ basicSendMessage({ type: CMD_TYPE.CACHE_CLEAR, data: {} });
365
+ }
366
+
367
+ function onDestroyDevTool() {
368
+ basicSendMessage({ type: CMD_TYPE.DESTROY, data: {} });
369
+ }
370
+
371
+ function onChangeTheme(t: string) {
372
+ theme.value = t;
373
+ setDevToolInfo({ theme: t });
374
+ emits('changeTheme', t);
375
+ }
376
+
377
+ function onChangeCacheInterceptConfig(value: boolean) {
378
+ setDevToolInfo({
379
+ cacheInterceptConfig: value,
380
+ interceptNetworkList: value ? interceptNetworkList.value : [],
381
+ });
382
+ basicSendMessage({
383
+ type: CMD_TYPE.SET_CACHE_INTERCEPT,
384
+ data: { cacheInterceptConfig: value },
385
+ });
386
+ }
387
+
388
+ function onChangeCacheNetworkLog(value: boolean) {
389
+ setDevToolInfo({
390
+ cacheNetworkLog: value,
391
+ });
392
+ cacheNetworkLog.value = value;
393
+ basicSendMessage({
394
+ type: CMD_TYPE.SET_CACHE_NETWORK_LOG,
395
+ data: { cacheNetworkLog: value },
396
+ });
397
+ }
398
+
399
+ function onChangeCacheConsoleLog(value: boolean) {
400
+ setDevToolInfo({
401
+ cacheConsoleLog: value,
402
+ });
403
+ cacheConsoleLog.value = value;
404
+ basicSendMessage({
405
+ type: CMD_TYPE.SET_CACHE_CONSOLE_LOG,
406
+ data: { cacheConsoleLog: value },
407
+ });
408
+ }
409
+
410
+ function onChangeUseTransition(value: boolean) {
411
+ useTransition.value = value;
412
+ setDevToolInfo({
413
+ useTransition: value,
414
+ });
415
+ basicSendMessage({
416
+ type: CMD_TYPE.SET_TRANSITION,
417
+ data: { useTransition: value },
418
+ });
419
+ }
420
+
421
+ function onChangeFontSize(data: {
422
+ baseFontSize: number;
423
+ tagFontSize: number;
424
+ tipsFontSize: number;
425
+ fontFamily: string;
426
+ fontWeight: string;
427
+ }) {
428
+ baseFontSize.value = data.baseFontSize;
429
+ tagFontSize.value = data.tagFontSize;
430
+ tipsFontSize.value = data.tipsFontSize;
431
+ fontFamily.value = data.fontFamily;
432
+ fontWeight.value = data.fontWeight;
433
+ setDevToolInfo(data);
434
+ basicSendMessage({
435
+ type: CMD_TYPE.SET_FONT,
436
+ data,
437
+ });
438
+ }
439
+
440
+ function onChangePerformance(show: boolean) {
441
+ state.performanceVisible.value = show;
442
+ setDevToolInfo({
443
+ performanceVisible: show,
444
+ });
445
+ uni.$emit(DEV_CORE_MESSAGE, { type: MSG_TYPE.PERF_VISIBLE, data: show });
446
+ }
447
+
448
+ function onChangePerformanceShowFps(show: boolean) {
449
+ state.performanceShowFps.value = show;
450
+ setDevToolInfo({
451
+ performanceShowFps: show,
452
+ });
453
+ uni.$emit('DEV_CHANGE_PERFORMANCE_SHOW_FPS', show);
454
+ }
455
+
456
+ function onChangePerformanceShowCpu(show: boolean) {
457
+ state.performanceShowCpu.value = show;
458
+ setDevToolInfo({
459
+ performanceShowCpu: show,
460
+ });
461
+ uni.$emit('DEV_CHANGE_PERFORMANCE_SHOW_CPU', show);
462
+ }
463
+
464
+ function onChangeBarrage(show: boolean) {
465
+ state.barrageVisible.value = show;
466
+ setDevToolInfo({
467
+ barrageVisible: show,
468
+ });
469
+ basicSendMessage({ type: CMD_TYPE.BARRAGE_TOGGLE, data: { show } });
470
+ uni.$emit(DEV_CORE_MESSAGE, { type: MSG_TYPE.BARRAGE_VISIBLE, data: show });
471
+ }
472
+
473
+ function onChangeVuex(value: any) {
474
+ basicSendMessage({ type: CMD_TYPE.VUEX_CHANGE, data: value });
475
+ }
476
+
477
+ function onChangePinia(value: any) {
478
+ basicSendMessage({ type: CMD_TYPE.PINIA_CHANGE, data: value });
479
+ }
480
+
481
+ function onClearWebSocketMessage(ws: DevTool.WS) {
482
+ basicSendMessage({ type: CMD_TYPE.WS_CLEAR_MESSAGE, data: ws });
483
+ }
484
+
485
+ function onSendWebSocket(data: { url: string; message: any }) {
486
+ basicSendMessage({ type: CMD_TYPE.WS_SEND, data });
487
+ }
488
+
489
+ function onConfirmInterceptConfig(ni: DevTool.NetworkItem) {
490
+ const index = interceptNetworkList.value.findIndex((item: any) => {
491
+ const key = `${item.method?.toUpperCase()}|${item.url?.split('?')[0]}`;
492
+ const niKey = `${ni.method?.toUpperCase()}|${ni.url?.split('?')[0]}`;
493
+ return key === niKey;
494
+ });
495
+ const list = [...interceptNetworkList.value];
496
+ if (index > -1) {
497
+ list[index] = ni;
498
+ } else {
499
+ list.unshift(ni);
500
+ }
501
+ setDevToolInfo({
502
+ cacheInterceptConfig: cacheInterceptConfig.value,
503
+ interceptNetworkList: cacheInterceptConfig.value ? list : [],
504
+ });
505
+ basicSendMessage({ type: CMD_TYPE.INTERCEPT_UPDATE, data: [ni] });
506
+ }
507
+
508
+ function onRemoveInterceptConfig(ni: DevTool.NetworkItem) {
509
+ basicSendMessage({ type: CMD_TYPE.INTERCEPT_UPDATE, data: ni });
510
+ }
511
+
512
+ function onChangeBarrageMaxTracks(val: number) {
513
+ state.barrageMaxTracks.value = val;
514
+ basicSendMessage({
515
+ type: CMD_TYPE.BARRAGE_MAX_TRACKS,
516
+ data: { value: val },
517
+ });
518
+ }
519
+
520
+ function onChangeBarrageTrackHeight(val: number) {
521
+ state.barrageTrackHeight.value = val;
522
+ basicSendMessage({
523
+ type: CMD_TYPE.BARRAGE_TRACK_HEIGHT,
524
+ data: { value: val },
525
+ });
526
+ }
527
+
528
+ function onChangeBarrageStartTop(val: number) {
529
+ state.barrageStartTop.value = val;
530
+ basicSendMessage({
531
+ type: CMD_TYPE.BARRAGE_START_TOP,
532
+ data: { value: val },
533
+ });
534
+ }
535
+
536
+ function onChangeBarrageDuration(val: number) {
537
+ state.barrageDuration.value = val;
538
+ basicSendMessage({
539
+ type: CMD_TYPE.BARRAGE_DURATION,
540
+ data: { value: val },
541
+ });
542
+ }
543
+
544
+ function onChangeBarrageMaxLength(val: number) {
545
+ state.barrageMaxLength.value = val;
546
+ basicSendMessage({
547
+ type: CMD_TYPE.BARRAGE_MAX_LENGTH,
548
+ data: { value: val },
549
+ });
550
+ }
551
+
552
+ function onChangeBarrageTypes(val: string[]) {
553
+ state.barrageTypes.value = val;
554
+ basicSendMessage({
555
+ type: CMD_TYPE.BARRAGE_TYPES,
556
+ data: { value: val },
557
+ });
558
+ }
559
+
560
+ function onChangeBarrageShowWhenOpen(val: boolean) {
561
+ state.barrageShowWhenOpen.value = val;
562
+ setDevToolInfo({
563
+ barrageShowWhenOpen: val,
564
+ });
565
+ basicSendMessage({
566
+ type: CMD_TYPE.SET_BARRAGE_SHOW_WHEN_OPEN,
567
+ data: { value: val },
568
+ });
569
+ }
570
+
571
+ return {
572
+ onCloseWindow,
573
+ onChangeTabs,
574
+ debounceScrollTabs,
575
+ onConsoleChoose,
576
+ onRunJS,
577
+ onSearchConsole,
578
+ onNetworkChoose,
579
+ onSearchNetwork,
580
+ onSortNetwork,
581
+ onTransferChoose,
582
+ onTransferCategoryChoose,
583
+ onSearchTransfer,
584
+ onWebSocketChoose,
585
+ onSearchWs,
586
+ onStorageChoose,
587
+ onStorageRemove,
588
+ onChangeStorage,
589
+ onSearchStorage,
590
+ onElEventClear,
591
+ onUniEventClear,
592
+ onCaptureScreenClear,
593
+ onScanCodeListClear,
594
+ onNfcClear,
595
+ onRouteRefresh,
596
+ onSearchRoute,
597
+ onShowDevButton,
598
+ onRestartDevTool,
599
+ onRestartApp,
600
+ onExportLog,
601
+ onScreenshot,
602
+ onClearCache,
603
+ onDestroyDevTool,
604
+ onChangeTheme,
605
+ onChangeCacheInterceptConfig,
606
+ onChangeCacheNetworkLog,
607
+ onChangeCacheConsoleLog,
608
+ onChangeUseTransition,
609
+ onChangeFontSize,
610
+ onChangeVuex,
611
+ onChangePinia,
612
+ onClearWebSocketMessage,
613
+ onSendWebSocket,
614
+ onConfirmInterceptConfig,
615
+ onRemoveInterceptConfig,
616
+ onChangePerformance,
617
+ onChangePerformanceShowFps,
618
+ onChangePerformanceShowCpu,
619
+ onChangeBarrage,
620
+ onChangeBarrageMaxTracks,
621
+ onChangeBarrageTrackHeight,
622
+ onChangeBarrageStartTop,
623
+ onChangeBarrageDuration,
624
+ onChangeBarrageMaxLength,
625
+ onChangeBarrageTypes,
626
+ onChangeBarrageShowWhenOpen,
627
+ basicSendMessage,
628
+ };
629
+ }