vite-uni-dev-tool 1.0.0 → 1.1.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 (168) hide show
  1. package/README.md +46 -0
  2. package/dist/const.cjs +1 -1
  3. package/dist/const.d.ts +12 -0
  4. package/dist/const.d.ts.map +1 -1
  5. package/dist/const.js +1 -1
  6. package/dist/core-shared.d.ts +1 -1
  7. package/dist/core-shared.d.ts.map +1 -1
  8. package/dist/core-shared.js +1 -1
  9. package/dist/core.d.ts +10 -3
  10. package/dist/core.d.ts.map +1 -1
  11. package/dist/core.js +2 -2
  12. package/dist/i18n/locales/en.cjs +1 -1
  13. package/dist/i18n/locales/en.d.ts +81 -0
  14. package/dist/i18n/locales/en.d.ts.map +1 -1
  15. package/dist/i18n/locales/en.js +1 -1
  16. package/dist/i18n/locales/zh-Hans.cjs +1 -1
  17. package/dist/i18n/locales/zh-Hans.d.ts +82 -1
  18. package/dist/i18n/locales/zh-Hans.d.ts.map +1 -1
  19. package/dist/i18n/locales/zh-Hans.js +1 -1
  20. package/dist/modules/devConsole/index.cjs +1 -1
  21. package/dist/modules/devConsole/index.js +3 -3
  22. package/dist/modules/devEvent/index.cjs +3 -3
  23. package/dist/modules/devEvent/index.d.ts +1 -0
  24. package/dist/modules/devEvent/index.d.ts.map +1 -1
  25. package/dist/modules/devEvent/index.js +3 -3
  26. package/dist/modules/devIntercept/index.cjs +14 -13
  27. package/dist/modules/devIntercept/index.d.ts +19 -0
  28. package/dist/modules/devIntercept/index.d.ts.map +1 -1
  29. package/dist/modules/devIntercept/index.js +14 -13
  30. package/dist/modules/devStore/index.cjs +1 -1
  31. package/dist/modules/devStore/index.d.ts +21 -0
  32. package/dist/modules/devStore/index.d.ts.map +1 -1
  33. package/dist/modules/devStore/index.js +1 -1
  34. package/dist/plugins/uniDevTool/transform/transformMain.cjs +1 -1
  35. package/dist/plugins/uniDevTool/transform/transformMain.js +1 -1
  36. package/dist/type.d.ts +47 -2
  37. package/dist/type.d.ts.map +1 -1
  38. package/dist/utils/language.cjs +1 -1
  39. package/dist/utils/language.d.ts.map +1 -1
  40. package/dist/utils/language.js +1 -1
  41. package/dist/utils/object.cjs +1 -1
  42. package/dist/utils/object.d.ts.map +1 -1
  43. package/dist/utils/object.js +1 -1
  44. package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -0
  45. package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -0
  46. package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -0
  47. package/dist/v3/{CaptureScreen → DevTool/components/CaptureScreen}/index.vue +109 -109
  48. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/ConsoleItem.vue +225 -224
  49. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/RunJSInput.vue +247 -249
  50. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/index.vue +171 -160
  51. package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/staticTips.ts +1145 -1145
  52. package/dist/v3/{DevToolButton → DevTool/components/DevToolButton}/index.vue +7 -4
  53. package/dist/v3/{DevToolTitle → DevTool/components/DevToolTitle}/index.vue +24 -24
  54. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/DevToolOverlay.vue +197 -182
  55. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/const.ts +28 -5
  56. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/dataUtils.ts +48 -48
  57. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolData.ts +387 -338
  58. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolHandlers.ts +629 -549
  59. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolOverlay.ts +197 -184
  60. package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.vue +67 -16
  61. package/dist/v3/{ElEvent → DevTool/components/ElEvent}/ElEventItem.vue +105 -105
  62. package/dist/v3/{ElEvent → DevTool/components/ElEvent}/index.vue +106 -109
  63. package/dist/v3/{Instance → DevTool/components/Instance}/components/InstanceTreeNode.vue +265 -265
  64. package/dist/v3/{Instance → DevTool/components/Instance}/flatten.ts +226 -226
  65. package/dist/v3/{Instance → DevTool/components/Instance}/index.vue +94 -94
  66. package/dist/v3/{Instance → DevTool/components/Instance}/registry.ts +49 -49
  67. package/dist/v3/{Instance → DevTool/components/Instance}/transformTree.ts +375 -375
  68. package/dist/v3/{Instance → DevTool/components/Instance}/transformTreeCtx.ts +268 -268
  69. package/dist/v3/{Instance → DevTool/components/Instance}/typing.d.ts +43 -43
  70. package/dist/v3/{InstanceDetail → DevTool/components/InstanceDetail}/index.vue +485 -485
  71. package/dist/v3/{JsonDetail → DevTool/components/JsonDetail}/index.vue +70 -70
  72. package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCItem.vue +112 -113
  73. package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCTool.vue +454 -478
  74. package/dist/v3/{NFCList → DevTool/components/NFCList}/const.ts +56 -56
  75. package/dist/v3/{NFCList → DevTool/components/NFCList}/index.vue +94 -98
  76. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptConfig.vue +624 -608
  77. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptItem.vue +140 -140
  78. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkDetail.vue +287 -296
  79. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkIntercept.vue +88 -93
  80. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkItem.vue +163 -167
  81. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkSend.vue +589 -556
  82. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/const.ts +4 -4
  83. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/hooks/useNetworkForm.ts +86 -86
  84. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/index.vue +160 -160
  85. package/dist/v3/{NetworkList → DevTool/components/NetworkList}/utils.ts +101 -101
  86. package/dist/v3/{Performance → DevTool/components/Performance}/index.vue +498 -495
  87. package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceMetrics.vue +153 -153
  88. package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceWidget.vue +12 -9
  89. package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceChart.ts +460 -460
  90. package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceData.ts +258 -258
  91. package/dist/v3/{PiniaList → DevTool/components/PiniaList}/index.vue +93 -94
  92. package/dist/v3/{RouteList → DevTool/components/RouteList}/index.vue +21 -24
  93. package/dist/v3/{RunJS → DevTool/components/RunJS}/index.vue +148 -148
  94. package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/ScanCodeItem.vue +97 -98
  95. package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/index.vue +100 -104
  96. package/dist/v3/{SettingButton → DevTool/components/SettingButton}/index.vue +45 -45
  97. package/dist/v3/{SettingList → DevTool/components/SettingList}/index.vue +218 -150
  98. package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +304 -0
  99. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingDevTool.vue +212 -208
  100. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingInfo.vue +157 -119
  101. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLanguage.vue +74 -74
  102. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLog.vue +230 -230
  103. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingNetwork.vue +3 -3
  104. package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingTheme.vue +37 -7
  105. package/dist/v3/{SettingList → DevTool/components/SettingList}/typing.d.ts +2 -2
  106. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/Line.vue +127 -116
  107. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/index.vue +8 -8
  108. package/dist/v3/{SourceCode → DevTool/components/SourceCode}/parseCode.ts +609 -701
  109. package/dist/v3/{StorageList → DevTool/components/StorageList}/index.vue +174 -174
  110. package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferDetail.vue +268 -268
  111. package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferItem.vue +4 -4
  112. package/dist/v3/{TransferList → DevTool/components/TransferList}/index.vue +8 -8
  113. package/dist/v3/{UniEvent → DevTool/components/UniEvent}/UniEventItem.vue +6 -7
  114. package/dist/v3/{UniEvent → DevTool/components/UniEvent}/index.vue +6 -6
  115. package/dist/v3/{VuexList → DevTool/components/VuexList}/index.vue +84 -84
  116. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketDetail.vue +8 -8
  117. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketItem.vue +4 -4
  118. package/dist/v3/{WebSocket → DevTool/components/WebSocket}/index.vue +8 -8
  119. package/dist/v3/DevTool/index.vue +179 -5
  120. package/dist/v3/{AppTransition → components/AppTransition}/index.vue +176 -170
  121. package/dist/v3/{AutoSizer → components/AutoSizer}/index.vue +192 -192
  122. package/dist/v3/{AutoSizer → components/AutoSizer}/index1.vue +184 -184
  123. package/dist/v3/{AutoSizer → components/AutoSizer}/utils.ts +49 -49
  124. package/dist/v3/components/Barrage/BarrageItem.vue +137 -0
  125. package/dist/v3/components/Barrage/index.vue +202 -0
  126. package/dist/v3/{CircularButton → components/CircularButton}/index.vue +84 -84
  127. package/dist/v3/{CustomSwiper → components/CustomSwiper}/CustomSwiperItem.vue +49 -49
  128. package/dist/v3/{CustomSwiper → components/CustomSwiper}/index.vue +104 -104
  129. package/dist/v3/{DraggableContainer → components/DraggableContainer}/index.vue +1 -1
  130. package/dist/v3/{Empty → components/Empty}/index.vue +29 -29
  131. package/dist/v3/{FilterInput → components/FilterInput}/index.vue +1 -1
  132. package/dist/v3/{FilterSelect → components/FilterSelect}/index.vue +179 -179
  133. package/dist/v3/{JsonPretty → components/JsonPretty}/components/Brackets/index.vue +27 -27
  134. package/dist/v3/{JsonPretty → components/JsonPretty}/components/Carets/index.vue +59 -59
  135. package/dist/v3/{JsonPretty → components/JsonPretty}/components/CheckController/index.vue +136 -136
  136. package/dist/v3/{JsonPretty → components/JsonPretty}/components/TreeNode/index.vue +387 -381
  137. package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useClipboard.ts +21 -21
  138. package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useError.ts +21 -21
  139. package/dist/v3/{JsonPretty → components/JsonPretty}/index.vue +16 -13
  140. package/dist/v3/{JsonPretty → components/JsonPretty}/type.ts +127 -126
  141. package/dist/v3/{JsonPretty → components/JsonPretty}/utils/index.ts +169 -169
  142. package/dist/v3/{MovableContainer → components/MovableContainer}/index.vue +1 -1
  143. package/dist/v3/{Pick → components/Pick}/index.vue +322 -322
  144. package/dist/v3/{Tabs → components/Tabs}/index.vue +30 -4
  145. package/dist/v3/{Tag → components/Tag}/index.vue +113 -113
  146. package/dist/v3/{VirtualList → components/VirtualList}/AutoSize.vue +40 -40
  147. package/dist/v3/{VirtualList → components/VirtualList}/index.vue +416 -412
  148. package/dist/v3/hooks/useBluetooth/index.ts +561 -0
  149. package/dist/v3/hooks/useContainerStyle.ts +153 -153
  150. package/dist/v3/hooks/useNFC/index.ts +107 -107
  151. package/dist/v3/hooks/useNFC/typing.d.ts +396 -396
  152. package/dist/v3/hooks/useNFC/useNFCAndroid.ts +966 -966
  153. package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +812 -812
  154. package/dist/v3/hooks/useNFC/utils.ts +754 -754
  155. package/dist/v3/hooks/useRequest/index.ts +586 -573
  156. package/dist/v3/hooks/useRequest/utils.ts +267 -267
  157. package/dist/v3/hooks/useScanCode/index.ts +206 -206
  158. package/dist/v3/hooks/useWebsocket/README.md +79 -0
  159. package/dist/v3/hooks/useWebsocket/index.ts +253 -0
  160. package/dist/v3/styles/theme.css +17 -10
  161. package/dist/v3/styles/theme.ts +12 -12
  162. package/package.json +59 -64
  163. package/dist/plugins/uniParseStock/index.d.ts +0 -10
  164. package/dist/plugins/uniParseStock/index.d.ts.map +0 -1
  165. /package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.css +0 -0
  166. /package/dist/v3/{SettingList → DevTool/components/SettingList}/index.css +0 -0
  167. /package/dist/v3/{Empty → components/Empty}/empty.png +0 -0
  168. /package/dist/v3/{VirtualList → components/VirtualList}/readme.md +0 -0
@@ -1,549 +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
- } = state;
43
-
44
- /** 发送消息给核心模块 */
45
- function basicSendMessage(message: {
46
- type: string;
47
- data: Record<string, any>;
48
- }) {
49
- emits('sendMessage', message);
50
- }
51
-
52
- function setWindowInfo() {
53
- setDevToolInfo({
54
- activeTab: activeTab.value,
55
- currentConsoleType: currentConsoleType.value,
56
- currentNetworkType: currentNetworkType.value,
57
- currentWebSocketType: currentWebSocketType.value,
58
- theme: theme.value,
59
- tabScrollLeft: tabScrollLeft.value,
60
- cacheInterceptConfig: cacheInterceptConfig.value,
61
- cacheNetworkLog: cacheNetworkLog.value,
62
- cacheConsoleLog: cacheConsoleLog.value,
63
- useTransition: useTransition.value,
64
- baseFontSize: baseFontSize.value,
65
- tagFontSize: tagFontSize.value,
66
- tipsFontSize: tipsFontSize.value,
67
- fontFamily: fontFamily.value,
68
- fontWeight: fontWeight.value,
69
- interceptNetworkList: interceptNetworkList.value,
70
- performanceShowFps: state.performanceShowFps.value,
71
- performanceShowCpu: state.performanceShowCpu.value,
72
- });
73
- }
74
-
75
- const debounceSetWindowInfo = debounce(setWindowInfo, 200);
76
-
77
- function onCloseWindow() {
78
- emits('close');
79
- setWindowInfo();
80
- }
81
-
82
- function onChangeTabs(index: number) {
83
- activeTab.value = index;
84
- setWindowInfo();
85
- }
86
-
87
- function onScrollTabs(e: any) {
88
- tabScrollLeft.value = e.detail.scrollLeft;
89
- debounceSetWindowInfo();
90
- }
91
-
92
- const debounceScrollTabs = debounce(onScrollTabs, 200);
93
-
94
- function onConsoleChoose(type: string) {
95
- if (type === 'clear') {
96
- consoleList.value = [];
97
- backup.consoleList = [];
98
- basicSendMessage({ type: CMD_TYPE.CONSOLE_CLEAR, data: {} });
99
- } else if (type === 'all') {
100
- currentConsoleType.value = type;
101
- consoleList.value = backup.consoleList;
102
- } else {
103
- currentConsoleType.value = type;
104
- consoleList.value = backup.consoleList.filter(
105
- (item: any) => item.type === type,
106
- );
107
- }
108
- setWindowInfo();
109
- }
110
-
111
- function onRunJS(code: string) {
112
- basicSendMessage({ type: CMD_TYPE.RUN_JS, data: { code } });
113
- }
114
-
115
- function onSearchConsole(value: string) {
116
- consoleList.value = backup.consoleList
117
- .filter((item: any) => {
118
- return (
119
- item.args.some(
120
- (arg: any) => arg.type === 'string' && arg.value.includes(value),
121
- ) ||
122
- item.position.includes(value) ||
123
- item?.stack?.includes(value)
124
- );
125
- })
126
- ?.map((item: any) => {
127
- return {
128
- ...item,
129
- position: hightLight(item.position, searchConsole.value),
130
- stack: hightLight(item.stack, searchConsole.value),
131
- args: item.args.map((arg: any) => {
132
- if (arg.type === 'string') {
133
- return { type: 'string', value: hightLight(arg.value, value) };
134
- }
135
- return arg;
136
- }),
137
- };
138
- });
139
- }
140
-
141
- function onNetworkChoose(type: string) {
142
- if (type === 'clear') {
143
- networkList.value = [];
144
- backup.networkList = [];
145
- basicSendMessage({ type: CMD_TYPE.NETWORK_CLEAR, data: {} });
146
- } else if (type === 'all') {
147
- currentNetworkType.value = type;
148
- networkList.value = backup.networkList;
149
- } else if (type === 'error') {
150
- currentNetworkType.value = type;
151
- networkList.value = backup.networkList.filter((item: any) => {
152
- return item.status === 'error' || /[4,5]\d{2,}/.test(item.status + '');
153
- });
154
- } else {
155
- currentNetworkType.value = type;
156
- networkList.value = backup.networkList.filter(
157
- (item: any) => item.method === type,
158
- );
159
- }
160
- setWindowInfo();
161
- }
162
-
163
- function onSearchNetwork(value: string) {
164
- networkList.value = backup.networkList
165
- .filter((item: any) => {
166
- if (currentNetworkType.value === 'all') return item;
167
- return item.method === currentNetworkType.value;
168
- })
169
- ?.filter((item: any) => item?.url?.includes(value))
170
- ?.map((item: any) => {
171
- return { ...item, url: hightLight(item.url, value) };
172
- });
173
- }
174
-
175
- function onSortNetwork(sort: -1 | 1) {
176
- currentNetworkSort.value = sort;
177
- const list = networkList.value.sort((a: any, b: any) => {
178
- return sort === 1 ? b.startTime - a.startTime : a.startTime - b.startTime;
179
- });
180
- networkList.value = [...list];
181
- }
182
-
183
- function filterTransferList() {
184
- transferList.value = backup.transferList.filter((item: any) => {
185
- const typeMatch =
186
- currentTransferCategory.value === 'all' ||
187
- item.type === currentTransferCategory.value;
188
- let statusMatch =
189
- currentTransferType.value === 'all' ||
190
- item.status === currentTransferType.value;
191
-
192
- if (currentTransferType.value === 'pending') {
193
- statusMatch = ['pending', 'uploading', 'downloading'].includes(
194
- item.status,
195
- );
196
- }
197
-
198
- return typeMatch && statusMatch;
199
- });
200
- }
201
-
202
- function onTransferChoose(type: string) {
203
- if (type === 'clear') {
204
- transferList.value = [];
205
- backup.transferList = [];
206
- basicSendMessage({ type: CMD_TYPE.TRANSFER_CLEAR, data: {} });
207
- } else {
208
- currentTransferType.value = type;
209
- filterTransferList();
210
- }
211
- }
212
-
213
- function onTransferCategoryChoose(category: string) {
214
- currentTransferCategory.value = category;
215
- filterTransferList();
216
- }
217
-
218
- function onSearchTransfer(value: string) {
219
- filterTransferList(); // Reset list based on filters first
220
- transferList.value = transferList.value
221
- .filter((item: any) => item.url?.includes(value))
222
- ?.map((item: any) => {
223
- return { ...item, url: hightLight(item.url, value) };
224
- });
225
- }
226
-
227
- function onWebSocketChoose(type: string) {
228
- if (type === 'clear') {
229
- wsList.value = [];
230
- backup.wsList = [];
231
- basicSendMessage({ type: CMD_TYPE.WS_CLEAR, data: {} });
232
- } else if (type === 'all') {
233
- currentWebSocketType.value = type;
234
- wsList.value = backup.wsList;
235
- } else {
236
- currentWebSocketType.value = type;
237
- wsList.value = backup.wsList.filter(
238
- (item: any) => item.readyState === type,
239
- );
240
- }
241
- setWindowInfo();
242
- }
243
-
244
- function onSearchWs(value: string) {
245
- wsList.value = backup.wsList
246
- .filter((item: any) => {
247
- if (currentWebSocketType.value === 'all') return item;
248
- return item.readyState === currentWebSocketType.value;
249
- })
250
- .filter((item: any) => item.url.includes(value))
251
- ?.map((item: any) => {
252
- return { ...item, url: hightLight(item.url, value) };
253
- });
254
- }
255
-
256
- function onStorageChoose(type: string) {
257
- if (type === 'clear') {
258
- backup.storageList = [];
259
- storageList.value = [];
260
- basicSendMessage({ type: CMD_TYPE.STORAGE_CLEAR, data: {} });
261
- } else if (type === 'refresh') {
262
- basicSendMessage({ type: CMD_TYPE.STORAGE_REFRESH, data: {} });
263
- } else if (type === 'add') {
264
- const key = '_new_' + Date.now();
265
- const newItem = { key, _oldKey: key, value: JSON.stringify('') };
266
- backup.storageList.unshift(newItem);
267
- storageList.value.unshift(newItem);
268
- basicSendMessage({
269
- type: CMD_TYPE.STORAGE_ADD,
270
- data: { key, value: newItem.value },
271
- });
272
- }
273
- }
274
-
275
- function onStorageRemove(key: string) {
276
- backup.storageList = backup.storageList.filter(
277
- (item: any) => item.key !== key,
278
- );
279
- storageList.value = backup.storageList;
280
- basicSendMessage({ type: CMD_TYPE.STORAGE_REMOVE, data: { key } });
281
- }
282
-
283
- function onChangeStorage(data: DevTool.StorageItem) {
284
- basicSendMessage({ type: CMD_TYPE.STORAGE_UPDATE, data });
285
- }
286
-
287
- function onSearchStorage(value: string) {
288
- storageList.value = backup.storageList
289
- .filter((item: any) => item._oldKey.includes(value))
290
- ?.map((item: any) => {
291
- return { ...item, _oldKey: hightLight(item._oldKey, value) };
292
- });
293
- }
294
-
295
- function onElEventClear() {
296
- elEventList.value = [];
297
- basicSendMessage({ type: CMD_TYPE.EL_EVENT_CLEAR, data: {} });
298
- }
299
-
300
- function onUniEventClear() {
301
- uniEventList.value = [];
302
- eventCount.value = { on: 0, once: 0, emit: 0, off: 0 };
303
- basicSendMessage({ type: CMD_TYPE.UNI_EVENT_CLEAR, data: {} });
304
- }
305
-
306
- function onCaptureScreenClear() {
307
- screenList.value = [];
308
- basicSendMessage({ type: CMD_TYPE.SCREEN_CLEAR, data: {} });
309
- }
310
-
311
- function onScanCodeListClear() {
312
- scanCodeList.value = [];
313
- basicSendMessage({ type: CMD_TYPE.SCAN_CODE_CLEAR, data: {} });
314
- }
315
-
316
- function onNfcClear() {
317
- nfcList.value = [];
318
- basicSendMessage({ type: CMD_TYPE.NFC_CLEAR, data: {} });
319
- }
320
-
321
- function onRouteRefresh() {
322
- basicSendMessage({ type: CMD_TYPE.ROUTE_REFRESH, data: {} });
323
- }
324
-
325
- function onSearchRoute(value: string) {
326
- routeList.value = backup.routeList
327
- ?.filter(
328
- (item: any) => item.path.includes(value) || item.name?.includes(value),
329
- )
330
- ?.map((item: any) => {
331
- return {
332
- ...item,
333
- name: hightLight(item.name, value),
334
- path: hightLight(item.path, value),
335
- };
336
- });
337
- }
338
-
339
- function onShowDevButton(show: boolean) {
340
- basicSendMessage({ type: CMD_TYPE.BUTTON_TOGGLE, data: { show } });
341
- }
342
-
343
- function onRestartDevTool() {
344
- basicSendMessage({ type: CMD_TYPE.RESTART_DEBUGGER, data: {} });
345
- }
346
-
347
- function onRestartApp() {
348
- basicSendMessage({ type: CMD_TYPE.RESTART_APP, data: {} });
349
- }
350
-
351
- function onExportLog(exports: any) {
352
- basicSendMessage({ type: CMD_TYPE.EXPORT_LOG, data: { ...exports } });
353
- }
354
-
355
- function onScreenshot() {
356
- basicSendMessage({ type: 'dev-tool-hide-screenshot', data: {} });
357
- }
358
-
359
- function onClearCache() {
360
- basicSendMessage({ type: CMD_TYPE.CACHE_CLEAR, data: {} });
361
- }
362
-
363
- function onDestroyDevTool() {
364
- basicSendMessage({ type: CMD_TYPE.DESTROY, data: {} });
365
- }
366
-
367
- function onChangeTheme(t: string) {
368
- theme.value = t;
369
- setDevToolInfo({ theme: t });
370
- emits('changeTheme', t);
371
- }
372
-
373
- function onChangeCacheInterceptConfig(value: boolean) {
374
- setDevToolInfo({
375
- cacheInterceptConfig: value,
376
- interceptNetworkList: value ? interceptNetworkList.value : [],
377
- });
378
- basicSendMessage({
379
- type: CMD_TYPE.SET_CACHE_INTERCEPT,
380
- data: { cacheInterceptConfig: value },
381
- });
382
- }
383
-
384
- function onChangeCacheNetworkLog(value: boolean) {
385
- setDevToolInfo({
386
- cacheNetworkLog: value,
387
- });
388
- cacheNetworkLog.value = value;
389
- basicSendMessage({
390
- type: CMD_TYPE.SET_CACHE_NETWORK_LOG,
391
- data: { cacheNetworkLog: value },
392
- });
393
- }
394
-
395
- function onChangeCacheConsoleLog(value: boolean) {
396
- setDevToolInfo({
397
- cacheConsoleLog: value,
398
- });
399
- cacheConsoleLog.value = value;
400
- basicSendMessage({
401
- type: CMD_TYPE.SET_CACHE_CONSOLE_LOG,
402
- data: { cacheConsoleLog: value },
403
- });
404
- }
405
-
406
- function onChangeUseTransition(value: boolean) {
407
- useTransition.value = value;
408
- setDevToolInfo({
409
- useTransition: value,
410
- });
411
- basicSendMessage({
412
- type: CMD_TYPE.SET_TRANSITION,
413
- data: { useTransition: value },
414
- });
415
- }
416
-
417
- function onChangeFontSize(data: {
418
- baseFontSize: number;
419
- tagFontSize: number;
420
- tipsFontSize: number;
421
- fontFamily: string;
422
- fontWeight: string;
423
- }) {
424
- baseFontSize.value = data.baseFontSize;
425
- tagFontSize.value = data.tagFontSize;
426
- tipsFontSize.value = data.tipsFontSize;
427
- fontFamily.value = data.fontFamily;
428
- fontWeight.value = data.fontWeight;
429
- setDevToolInfo(data);
430
- basicSendMessage({
431
- type: CMD_TYPE.SET_FONT,
432
- data,
433
- });
434
- }
435
-
436
- function onChangePerformance(show: boolean) {
437
- state.performanceVisible.value = show;
438
- setDevToolInfo({
439
- performanceVisible: show,
440
- });
441
- uni.$emit(DEV_CORE_MESSAGE, { type: MSG_TYPE.PERF_VISIBLE, data: show });
442
- }
443
-
444
- function onChangePerformanceShowFps(show: boolean) {
445
- state.performanceShowFps.value = show;
446
- setDevToolInfo({
447
- performanceShowFps: show,
448
- });
449
- uni.$emit('DEV_CHANGE_PERFORMANCE_SHOW_FPS', show);
450
- }
451
-
452
- function onChangePerformanceShowCpu(show: boolean) {
453
- state.performanceShowCpu.value = show;
454
- setDevToolInfo({
455
- performanceShowCpu: show,
456
- });
457
- uni.$emit('DEV_CHANGE_PERFORMANCE_SHOW_CPU', show);
458
- }
459
-
460
- function onChangeVuex(value: any) {
461
- basicSendMessage({ type: CMD_TYPE.VUEX_CHANGE, data: value });
462
- }
463
-
464
- function onChangePinia(value: any) {
465
- basicSendMessage({ type: CMD_TYPE.PINIA_CHANGE, data: value });
466
- }
467
-
468
- function onClearWebSocketMessage(ws: DevTool.WS) {
469
- basicSendMessage({ type: CMD_TYPE.WS_CLEAR_MESSAGE, data: ws });
470
- }
471
-
472
- function onSendWebSocket(data: { url: string; message: any }) {
473
- basicSendMessage({ type: CMD_TYPE.WS_SEND, data });
474
- }
475
-
476
- function onConfirmInterceptConfig(ni: DevTool.NetworkItem) {
477
- const index = interceptNetworkList.value.findIndex((item: any) => {
478
- const key = `${item.method?.toUpperCase()}|${item.url?.split('?')[0]}`;
479
- const niKey = `${ni.method?.toUpperCase()}|${ni.url?.split('?')[0]}`;
480
- return key === niKey;
481
- });
482
- const list = [...interceptNetworkList.value];
483
- if (index > -1) {
484
- list[index] = ni;
485
- } else {
486
- list.unshift(ni);
487
- }
488
- setDevToolInfo({
489
- cacheInterceptConfig: cacheInterceptConfig.value,
490
- interceptNetworkList: cacheInterceptConfig.value ? list : [],
491
- });
492
- basicSendMessage({ type: CMD_TYPE.INTERCEPT_UPDATE, data: [ni] });
493
- }
494
-
495
- function onRemoveInterceptConfig(ni: DevTool.NetworkItem) {
496
- basicSendMessage({ type: CMD_TYPE.INTERCEPT_UPDATE, data: ni });
497
- }
498
-
499
- return {
500
- onCloseWindow,
501
- onChangeTabs,
502
- debounceScrollTabs,
503
- onConsoleChoose,
504
- onRunJS,
505
- onSearchConsole,
506
- onNetworkChoose,
507
- onSearchNetwork,
508
- onSortNetwork,
509
- onTransferChoose,
510
- onTransferCategoryChoose,
511
- onSearchTransfer,
512
- onWebSocketChoose,
513
- onSearchWs,
514
- onStorageChoose,
515
- onStorageRemove,
516
- onChangeStorage,
517
- onSearchStorage,
518
- onElEventClear,
519
- onUniEventClear,
520
- onCaptureScreenClear,
521
- onScanCodeListClear,
522
- onNfcClear,
523
- onRouteRefresh,
524
- onSearchRoute,
525
- onShowDevButton,
526
- onRestartDevTool,
527
- onRestartApp,
528
- onExportLog,
529
- onScreenshot,
530
- onClearCache,
531
- onDestroyDevTool,
532
- onChangeTheme,
533
- onChangeCacheInterceptConfig,
534
- onChangeCacheNetworkLog,
535
- onChangeCacheConsoleLog,
536
- onChangeUseTransition,
537
- onChangeFontSize,
538
- onChangeVuex,
539
- onChangePinia,
540
- onClearWebSocketMessage,
541
- onSendWebSocket,
542
- onConfirmInterceptConfig,
543
- onRemoveInterceptConfig,
544
- onChangePerformance,
545
- onChangePerformanceShowFps,
546
- onChangePerformanceShowCpu,
547
- basicSendMessage,
548
- };
549
- }
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
+ }