vite-uni-dev-tool 0.0.12 → 0.0.13

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 (181) hide show
  1. package/dist/const.d.ts +133 -0
  2. package/dist/const.d.ts.map +1 -0
  3. package/dist/const.js +36 -0
  4. package/dist/core.d.ts +52 -0
  5. package/dist/core.d.ts.map +1 -0
  6. package/dist/core.js +80 -0
  7. package/dist/devConsole/index.d.ts +169 -0
  8. package/dist/devConsole/index.d.ts.map +1 -0
  9. package/dist/devConsole/index.js +270 -0
  10. package/dist/devEvent/index.d.ts +286 -0
  11. package/dist/devEvent/index.d.ts.map +1 -0
  12. package/dist/devEvent/index.js +435 -0
  13. package/dist/devEventBus/index.d.ts +42 -0
  14. package/dist/devEventBus/index.d.ts.map +1 -0
  15. package/dist/devEventBus/index.js +70 -0
  16. package/dist/devIntercept/index.d.ts +119 -0
  17. package/dist/devIntercept/index.d.ts.map +1 -0
  18. package/dist/devIntercept/index.js +582 -0
  19. package/dist/devRunJS/index.d.ts +67 -0
  20. package/dist/devRunJS/index.d.ts.map +1 -0
  21. package/dist/devStore/index.d.ts +178 -0
  22. package/dist/devStore/index.d.ts.map +1 -0
  23. package/dist/devStore/index.js +395 -0
  24. package/dist/devToolInfo/index.d.ts +17 -0
  25. package/dist/devToolInfo/index.d.ts.map +1 -0
  26. package/dist/devToolInfo/index.js +15 -0
  27. package/{dev → dist}/plugins/uniDevTool/uniDevTool.d.ts +7 -1
  28. package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -0
  29. package/dist/plugins/uniDevTool/uniDevTool.js +35 -0
  30. package/{dev → dist}/plugins/utils/index.d.ts +3 -0
  31. package/{dev → dist}/plugins/utils/index.d.ts.map +1 -1
  32. package/dist/plugins/utils/index.js +1 -0
  33. package/dist/type.d.ts +264 -0
  34. package/dist/type.d.ts.map +1 -0
  35. package/dist/utils/array.d.ts +2 -0
  36. package/dist/utils/array.d.ts.map +1 -0
  37. package/dist/utils/array.js +12 -0
  38. package/dist/utils/date.d.ts +19 -0
  39. package/dist/utils/date.d.ts.map +1 -0
  40. package/dist/utils/date.js +40 -0
  41. package/dist/utils/file.d.ts +11 -0
  42. package/dist/utils/file.d.ts.map +1 -0
  43. package/dist/utils/file.js +87 -0
  44. package/dist/utils/function.d.ts +28 -0
  45. package/dist/utils/function.d.ts.map +1 -0
  46. package/dist/utils/function.js +46 -0
  47. package/dist/utils/index.d.ts +11 -0
  48. package/dist/utils/index.d.ts.map +1 -0
  49. package/dist/utils/index.js +55 -0
  50. package/dist/utils/ip.d.ts +5 -0
  51. package/dist/utils/ip.d.ts.map +1 -0
  52. package/dist/utils/ip.js +21 -0
  53. package/dist/utils/language.d.ts +29 -0
  54. package/dist/utils/language.d.ts.map +1 -0
  55. package/dist/utils/language.js +50 -0
  56. package/dist/utils/object.d.ts +49 -0
  57. package/dist/utils/object.d.ts.map +1 -0
  58. package/dist/utils/object.js +118 -0
  59. package/dist/utils/page.d.ts +7 -0
  60. package/dist/utils/page.d.ts.map +1 -0
  61. package/dist/utils/page.js +7 -0
  62. package/dist/utils/platform.d.ts +4 -0
  63. package/dist/utils/platform.d.ts.map +1 -0
  64. package/dist/utils/platform.js +14 -0
  65. package/dist/utils/string.d.ts +45 -0
  66. package/dist/utils/string.d.ts.map +1 -0
  67. package/dist/utils/string.js +88 -0
  68. package/dist/utils/utils.d.ts +16 -0
  69. package/dist/utils/utils.d.ts.map +1 -0
  70. package/dist/v2/AutoSizer/utils.d.ts +5 -0
  71. package/dist/v2/AutoSizer/utils.d.ts.map +1 -0
  72. package/dist/v2/JsonPretty/hooks/useClipboard.d.ts +4 -0
  73. package/dist/v2/JsonPretty/hooks/useClipboard.d.ts.map +1 -0
  74. package/dist/v2/JsonPretty/hooks/useError.d.ts +8 -0
  75. package/dist/v2/JsonPretty/hooks/useError.d.ts.map +1 -0
  76. package/dist/v2/JsonPretty/type.d.ts +93 -0
  77. package/dist/v2/JsonPretty/type.d.ts.map +1 -0
  78. package/dist/v3/AutoSizer/utils.d.ts +5 -0
  79. package/dist/v3/AutoSizer/utils.d.ts.map +1 -0
  80. package/dist/v3/ConsoleList/staticTips.d.ts +13 -0
  81. package/dist/v3/ConsoleList/staticTips.d.ts.map +1 -0
  82. package/dist/v3/JsonPretty/hooks/useClipboard.d.ts +4 -0
  83. package/dist/v3/JsonPretty/hooks/useClipboard.d.ts.map +1 -0
  84. package/dist/v3/JsonPretty/hooks/useError.d.ts +8 -0
  85. package/dist/v3/JsonPretty/hooks/useError.d.ts.map +1 -0
  86. package/dist/v3/JsonPretty/type.d.ts +93 -0
  87. package/dist/v3/JsonPretty/type.d.ts.map +1 -0
  88. package/dist/v3/JsonPretty/utils/index.d.ts +10 -0
  89. package/dist/v3/JsonPretty/utils/index.d.ts.map +1 -0
  90. package/package.json +5 -5
  91. package/dev/components/AppInfo/index.vue +0 -36
  92. package/dev/components/AutoSizer/index.vue +0 -193
  93. package/dev/components/AutoSizer/index1.vue +0 -186
  94. package/dev/components/AutoSizer/utils.ts +0 -49
  95. package/dev/components/Button/index.vue +0 -34
  96. package/dev/components/CaptureScreen/index.vue +0 -62
  97. package/dev/components/Checkbox/index.vue +0 -40
  98. package/dev/components/CloseButton/index.vue +0 -26
  99. package/dev/components/Code/index.vue +0 -230
  100. package/dev/components/Connection/index.vue +0 -88
  101. package/dev/components/ConsoleList/Code.vue +0 -227
  102. package/dev/components/ConsoleList/ConsoleItem.vue +0 -207
  103. package/dev/components/ConsoleList/RunJSInput.vue +0 -237
  104. package/dev/components/ConsoleList/index.vue +0 -139
  105. package/dev/components/ConsoleList/staticTips.ts +0 -1145
  106. package/dev/components/DevTool/index.vue +0 -188
  107. package/dev/components/DevToolButton/index.vue +0 -210
  108. package/dev/components/DevToolTitle/index.vue +0 -21
  109. package/dev/components/DevToolWindow/index.vue +0 -1053
  110. package/dev/components/DeviceInfo/index.vue +0 -32
  111. package/dev/components/Empty/empty.png +0 -0
  112. package/dev/components/Empty/index.vue +0 -28
  113. package/dev/components/FilterInput/index.vue +0 -86
  114. package/dev/components/JsonPretty/components/Brackets/index.vue +0 -23
  115. package/dev/components/JsonPretty/components/Carets/index.vue +0 -59
  116. package/dev/components/JsonPretty/components/CheckController/index.vue +0 -125
  117. package/dev/components/JsonPretty/components/TreeNode/index.vue +0 -349
  118. package/dev/components/JsonPretty/hooks/useClipboard.ts +0 -21
  119. package/dev/components/JsonPretty/hooks/useError.ts +0 -21
  120. package/dev/components/JsonPretty/index.vue +0 -476
  121. package/dev/components/JsonPretty/type.ts +0 -125
  122. package/dev/components/JsonPretty/utils/index.ts +0 -172
  123. package/dev/components/NetworkList/NetworkDetail.vue +0 -194
  124. package/dev/components/NetworkList/NetworkItem.vue +0 -119
  125. package/dev/components/NetworkList/index.vue +0 -128
  126. package/dev/components/PiniaList/index.vue +0 -64
  127. package/dev/components/RouteList/index.vue +0 -121
  128. package/dev/components/RunJS/index.vue +0 -128
  129. package/dev/components/SettingList/index.vue +0 -222
  130. package/dev/components/SourceCode/index.vue +0 -231
  131. package/dev/components/StorageList/index.vue +0 -170
  132. package/dev/components/SystemInfo/index.vue +0 -34
  133. package/dev/components/Tabs/index.vue +0 -123
  134. package/dev/components/Tag/index.vue +0 -89
  135. package/dev/components/UniEvent/UniEventItem.vue +0 -126
  136. package/dev/components/UniEvent/index.vue +0 -98
  137. package/dev/components/UploadList/UploadDetail.vue +0 -204
  138. package/dev/components/UploadList/UploadItem.vue +0 -117
  139. package/dev/components/UploadList/index.vue +0 -117
  140. package/dev/components/VirtualList/index.vue +0 -112
  141. package/dev/components/VirtualListPro/AutoSize.vue +0 -43
  142. package/dev/components/VirtualListPro/index.vue +0 -238
  143. package/dev/components/VirtualListPro/readme.md +0 -40
  144. package/dev/components/VuexList/index.vue +0 -54
  145. package/dev/components/WebSocket/WebSocketItem.vue +0 -103
  146. package/dev/components/WebSocket/WebSocketList.vue +0 -173
  147. package/dev/components/WebSocket/index.vue +0 -124
  148. package/dev/components/WindowInfo/index.vue +0 -33
  149. package/dev/const.ts +0 -164
  150. package/dev/core.ts +0 -118
  151. package/dev/devConsole/index.ts +0 -350
  152. package/dev/devEvent/index.ts +0 -810
  153. package/dev/devEventBus/index.ts +0 -94
  154. package/dev/devIntercept/index.ts +0 -745
  155. package/dev/devRunJS/index.ts +0 -170
  156. package/dev/devStore/index.ts +0 -732
  157. package/dev/devToolInfo/index.ts +0 -26
  158. package/dev/plugins/uniDevTool/uniDevTool.d.ts.map +0 -1
  159. package/dev/plugins/uniDevTool/uniDevTool.js +0 -36
  160. package/dev/plugins/utils/index.js +0 -1
  161. package/dev/shims-uni.d.ts +0 -43
  162. package/dev/type.ts +0 -291
  163. package/dev/utils/array.ts +0 -15
  164. package/dev/utils/date.ts +0 -75
  165. package/dev/utils/file.ts +0 -121
  166. package/dev/utils/function.ts +0 -192
  167. package/dev/utils/index.d.ts +0 -6
  168. package/dev/utils/index.ts +0 -51
  169. package/dev/utils/ip.ts +0 -79
  170. package/dev/utils/language.ts +0 -77
  171. package/dev/utils/object.ts +0 -306
  172. package/dev/utils/page.ts +0 -13
  173. package/dev/utils/platform.ts +0 -14
  174. package/dev/utils/string.ts +0 -133
  175. package/dev/utils/utils.ts +0 -198
  176. /package/{dev → dist}/index.d.ts +0 -0
  177. /package/{dev → dist}/index.d.ts.map +0 -0
  178. /package/{dev → dist}/index.js +0 -0
  179. /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.d.ts +0 -0
  180. /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +0 -0
  181. /package/{dev → dist}/plugins/uniGlobalComponents/uniGlobalComponents.js +0 -0
@@ -1,732 +0,0 @@
1
- import type { DevTool } from '../type';
2
-
3
- import { DEV_TOOL_INFO } from '../const';
4
-
5
- import {
6
- isNil,
7
- isNumber,
8
- setValueByPath,
9
- getLanIp,
10
- getMicroAppIp,
11
- getWifiIp,
12
- isBoolean,
13
- } from '../utils/index';
14
- import { backup } from '../core';
15
- import { getDevToolInfo, setDevToolInfo } from '../devToolInfo';
16
-
17
- /** 数据存储中心 */
18
- export class DevStore {
19
- /** 状态数据 */
20
- private state: DevTool.WindowData = {
21
- consoleList: [],
22
- networkList: [],
23
- storageList: [],
24
- routeList: [],
25
- vuexList: {},
26
- piniaList: {},
27
- deviceInfo: {},
28
- windowInfo: {},
29
- systemInfo: {},
30
- appInfo: {},
31
- wsList: [],
32
- netWorkStatus: {},
33
- uploadList: [],
34
- eventList: [],
35
- eventCount: {
36
- on: 0,
37
- once: 0,
38
- emit: 0,
39
- off: 0,
40
- },
41
- captureScreenList: [],
42
- };
43
-
44
- /** 调试配置 */
45
- private devToolOptions: DevTool.DevToolOptions | undefined;
46
- /** 日志最大值 */
47
- private uploadMaxSize = 1000;
48
- /** 日志最大值 */
49
- private consoleMaxSize = 1000;
50
- /** 网络最大值 */
51
- private networkMaxSize = 1000;
52
- /** ws数据最大值 */
53
- private wsDataMaxSize = 1000;
54
- /** 事件列表最大值 */
55
- private eventListMaxSize = 1000;
56
- /** 截屏最大值 */
57
- private captureScreenMaxSize = 1000;
58
-
59
- /** 缓存最大值 */
60
- cacheMaxSize = 8 * 1024 * 1024 * 10;
61
-
62
- private vuexStore: any;
63
-
64
- private piniaStore: any;
65
-
66
- private uploadTaskMap = new Map<number | string, UniApp.UploadTask>();
67
-
68
- private requestIndex = -1;
69
-
70
- private uploadIndex = -1;
71
-
72
- /** 是否显示按钮 */
73
- private devToolVisible = false;
74
-
75
- /** 是否销毁 */
76
- private devToolDestroy = false;
77
-
78
- /** 是否开启拦截Promise reject错误 */
79
- enableInterceptPromiseReject = false;
80
-
81
- private zIndex = 1000;
82
-
83
- constructor() {
84
- const { devToolDestroy = false, devToolButtonVisible = false } =
85
- uni.getStorageSync(DEV_TOOL_INFO);
86
-
87
- this.devToolDestroy = devToolDestroy;
88
- this.devToolVisible = devToolButtonVisible;
89
- }
90
-
91
- setDevToolVisible(visible: boolean) {
92
- this.devToolVisible = visible;
93
-
94
- setDevToolInfo({
95
- devToolButtonVisible: visible,
96
- });
97
- }
98
-
99
- getDevToolVisible() {
100
- return this.devToolVisible;
101
- }
102
-
103
- setWindowInfo(windowInfo: Record<string, any>) {
104
- this.state.windowInfo = windowInfo;
105
- }
106
-
107
- setDeviceInfo(deviceInfo: Record<string, any>) {
108
- this.state.deviceInfo = deviceInfo;
109
- }
110
-
111
- setSystemInfo(systemInfo: Record<string, any>) {
112
- this.state.systemInfo = systemInfo;
113
- }
114
-
115
- setNetWorkStatus(netWorkStatus: Record<string, any>) {
116
- this.state.netWorkStatus = netWorkStatus;
117
- }
118
-
119
- setVuexList(vuexList: Record<string, any>) {
120
- this.state.vuexList = vuexList;
121
- }
122
-
123
- setPiniaList(piniaList: Record<string, any>) {
124
- this.state.piniaList = {
125
- ...(this.state.piniaList || {}),
126
- ...piniaList,
127
- };
128
- }
129
-
130
- setRequestIndex(index: number) {
131
- this.requestIndex = index;
132
- return this.requestIndex;
133
- }
134
-
135
- getDevToolOptions() {
136
- return this.devToolOptions;
137
- }
138
-
139
- getRequestIndex() {
140
- return this.requestIndex;
141
- }
142
-
143
- setUploadIndex(index: number) {
144
- this.uploadIndex = index;
145
- return this.uploadIndex;
146
- }
147
-
148
- getUploadIndex() {
149
- return this.uploadIndex;
150
- }
151
-
152
- setDevToolOptions(options: DevTool.DevToolOptions) {
153
- this.devToolOptions = options;
154
- this.uploadMaxSize = options.uploadMaxSize || 1000;
155
- this.consoleMaxSize = options.consoleMaxSize || 1000;
156
- this.networkMaxSize = options.networkMaxSize || 1000;
157
- this.wsDataMaxSize = options.wsDataMaxSize || 1000;
158
- this.cacheMaxSize = options.cacheMaxSize || 8 * 1024 * 1024 * 10;
159
- this.eventListMaxSize = options.eventListMaxSize || 1000;
160
- this.captureScreenMaxSize = options.captureScreenMaxSize || 1000;
161
- this.zIndex = options.zIndex || 1000;
162
-
163
- const { devToolButtonVisible } = getDevToolInfo();
164
-
165
- this.devToolVisible = isBoolean(devToolButtonVisible)
166
- ? devToolButtonVisible
167
- : (options.initShowDevTool ?? true);
168
-
169
- this.setDevToolVisible(this.devToolVisible);
170
-
171
- const pages =
172
- options.pagesJson?.pages.map((page) => {
173
- const isNav = options.pagesJson?.tabBar?.list?.some(
174
- (nav) => nav.pagePath === page.path,
175
- );
176
- return {
177
- ...page,
178
- type: isNav ? 'nav' : 'main',
179
- };
180
- }) ?? [];
181
-
182
- // 处理 subPackages
183
- options.pagesJson?.subPackages?.forEach((pack) => {
184
- pack.pages.forEach((page) => {
185
- const p = {
186
- ...page,
187
- path: `${pack.root}/${page.path}`,
188
- type: 'sub',
189
- };
190
- pages.push(p);
191
- });
192
- });
193
-
194
- this.setRouteList(pages);
195
- }
196
-
197
- async getDevData() {
198
- const networkType = await uni.getNetworkType();
199
- const systemInfo = uni.getSystemInfoSync();
200
- const deviceInfo = uni.getDeviceInfo();
201
- const windowInfo = uni.getWindowInfo();
202
-
203
- const appInfo = {
204
- ...(await uni.getAppBaseInfo()),
205
-
206
- // #ifndef H5
207
- ...(await uni.getAppAuthorizeSetting()),
208
- // #endif
209
- };
210
- const ip = getWifiIp() || getLanIp() || (await getMicroAppIp());
211
- return {
212
- ...this.state,
213
- systemInfo,
214
- deviceInfo,
215
- windowInfo,
216
- devToolVisible: this.getDevToolVisible(),
217
- appInfo,
218
- netWorkStatus: {
219
- ip,
220
- ...networkType,
221
- isConnected: networkType.networkType !== 'none',
222
- },
223
- };
224
- }
225
-
226
- updateStore(data: { key: string; _oldKey: string; value: any }) {
227
- const { key, _oldKey, value } = data;
228
- if (_oldKey !== key) {
229
- uni.removeStorageSync(_oldKey);
230
- this.state.storageList = this.state.storageList?.filter(
231
- (item) => item.key === _oldKey,
232
- );
233
- }
234
- uni.setStorageSync(key, value);
235
- this.state.storageList?.push({
236
- key,
237
- _oldKey,
238
- value,
239
- });
240
-
241
- return this.state.storageList;
242
- }
243
-
244
- updateVuexStore(data: Record<string, any>) {
245
- try {
246
- // 更改vuex数据
247
- Object.assign(this.vuexStore?.state ?? {}, data);
248
- } catch (error) {
249
- console.error('[DevTool] updateVuexStore error', error);
250
- }
251
-
252
- // 更新vuexList
253
- this.setVuexList({
254
- ...(this.vuexStore?.state ?? {}),
255
- });
256
-
257
- return this.state.vuexList;
258
- }
259
-
260
- setPiniaStore(piniaStore: any) {
261
- this.piniaStore = piniaStore;
262
- }
263
-
264
- updatePiniaStore(data: Record<string, any>) {
265
- try {
266
- if (!this.piniaStore) {
267
- console.error('[DevTool] updatePiniaStore piniaStore is undefined');
268
- return {};
269
- }
270
-
271
- const [key, value] = Object.entries(data)[0];
272
-
273
- if (isNil(key)) {
274
- console.error('[DevTool] updatePiniaStore key is undefined or null');
275
- return {};
276
- }
277
-
278
- setValueByPath(this.piniaStore.state.value, key, value);
279
-
280
- this.setPiniaList({
281
- ...(this.piniaStore.state.value ?? {}),
282
- });
283
- } catch (error) {
284
- console.error('[DevTool] updatePiniaStore error', error);
285
- }
286
- return this.state.piniaList ?? {};
287
- }
288
-
289
- getExportData(exports: {
290
- exportLog: boolean;
291
- exportNetwork: boolean;
292
- exportStorage: boolean;
293
- exportWebSocket: boolean;
294
- exportUpload: boolean;
295
- exportWindow: boolean;
296
- exportDevice: boolean;
297
- exportSystem: boolean;
298
- }) {
299
- const data: DevTool.WindowData = {};
300
- if (exports.exportLog) {
301
- data['consoleList'] = this.state.consoleList;
302
- }
303
- if (exports.exportNetwork) {
304
- data['networkList'] = this.state.networkList;
305
- }
306
- if (exports.exportStorage) {
307
- data['storageList'] = this.state.storageList;
308
- data['vuexList'] = this.state.vuexList;
309
- data['piniaList'] = this.state.piniaList;
310
- }
311
- if (exports.exportUpload) {
312
- data['uploadList'] = this.state.uploadList;
313
- }
314
- if (exports.exportWebSocket) {
315
- data['wsList'] = this.state.wsList;
316
- }
317
- if (exports.exportWindow) {
318
- data['windowInfo'] = this.state.windowInfo;
319
- }
320
- if (exports.exportDevice) {
321
- data['deviceInfo'] = this.state.deviceInfo;
322
- }
323
- if (exports.exportSystem) {
324
- data['systemInfo'] = this.state.systemInfo;
325
- }
326
- return data;
327
- }
328
-
329
- clearConsoleList() {
330
- this.state.consoleList = [];
331
- }
332
-
333
- clearDevCache() {
334
- this.state.consoleList = [];
335
- this.state.networkList = [];
336
- this.state.wsList = [];
337
- this.state.uploadList = [];
338
- this.state.eventList = [];
339
- this.state.eventCount = {
340
- on: 0,
341
- once: 0,
342
- emit: 0,
343
- off: 0,
344
- };
345
- }
346
-
347
- clearAll() {
348
- this.state.consoleList = [];
349
- this.state.networkList = [];
350
- this.state.storageList = [];
351
- this.state.routeList = [];
352
- this.state.wsList = [];
353
- this.state.uploadList = [];
354
- this.state.vuexList = {};
355
- this.state.piniaList = {};
356
- this.state.deviceInfo = {};
357
- this.state.windowInfo = {};
358
- this.state.systemInfo = {};
359
- this.state.netWorkStatus = {};
360
- this.state.appInfo = {};
361
-
362
- this.state.eventList = [];
363
- this.state.eventCount = {
364
- on: 0,
365
- once: 0,
366
- emit: 0,
367
- off: 0,
368
- };
369
-
370
- this.state.captureScreenList = [];
371
- }
372
-
373
- addUploadTask(index: number | string, task: UniApp.UploadTask) {
374
- this.uploadTaskMap.set(index, task);
375
- }
376
-
377
- removeUploadTask(index: number | string) {
378
- this.uploadTaskMap.delete(index);
379
- }
380
-
381
- clearUploadTask() {
382
- this.uploadTaskMap.clear();
383
- }
384
-
385
- clearWsList() {
386
- this.state.wsList = [];
387
- }
388
-
389
- updateWsList(item: DevTool.WS) {
390
- if (!this.getDevToolVisible()) {
391
- return [];
392
- }
393
- const index =
394
- this.state?.wsList?.findIndex((w) => w.url === item.url) ?? -1;
395
-
396
- if (index > -1) {
397
- if (this.state.wsList?.[index]) {
398
- const ws = this.state.wsList[index];
399
-
400
- ws.headers = item.headers ?? ws.headers;
401
-
402
- ws.readyState = item.readyState ?? ws.readyState;
403
-
404
- ws.method = item.method ?? ws.method;
405
-
406
- ws.protocols = item.protocols ?? ws.protocols;
407
-
408
- ws.message = [
409
- ...(this.state.wsList[index].message ?? []),
410
- ...(item.message ?? []),
411
- ];
412
-
413
- const max = this.wsDataMaxSize;
414
- const len = ws?.message?.length ?? 0;
415
-
416
- if (Array.isArray(ws?.message) && len > max) {
417
- ws?.message?.splice(0, len - max);
418
- }
419
- }
420
- } else {
421
- this.state.wsList?.push(item);
422
- }
423
-
424
- return this.state.wsList;
425
- }
426
-
427
- clearWsMessage(url: string) {
428
- const wsIndex =
429
- this.state?.wsList?.findIndex((item) => item.url === url) ?? -1;
430
- if (wsIndex === -1) return;
431
- if (this.state.wsList?.[wsIndex]) {
432
- this.state.wsList[wsIndex].message = [];
433
- }
434
- }
435
-
436
- clearStorageList() {
437
- this.state.storageList = [];
438
- uni.clearStorage();
439
- return this.state.storageList;
440
- }
441
-
442
- setStorageList(items: DevTool.StorageItem[]) {
443
- if (!this.getDevToolVisible()) return;
444
- this.state.storageList = items;
445
- return this.state.storageList;
446
- }
447
-
448
- removeStorage(key: string) {
449
- this.state.storageList =
450
- this.state.storageList?.filter((item) => item.key !== key) ?? [];
451
- uni.removeStorageSync(key);
452
- return this.state.storageList;
453
- }
454
-
455
- addStorage(data: { key: string; value: any }) {
456
- const { key, value } = data;
457
-
458
- this.state.storageList?.unshift({
459
- key,
460
- _oldKey: key,
461
- value,
462
- });
463
-
464
- uni.setStorageSync(key, value);
465
- return this.state.storageList;
466
- }
467
-
468
- refreshStore() {
469
- const { keys } = uni.getStorageInfoSync();
470
- this.state.storageList = keys.map((key) => {
471
- const value = uni.getStorageSync(key);
472
- return {
473
- key,
474
- _oldKey: key,
475
- value,
476
- };
477
- });
478
- return this.state.storageList;
479
- }
480
-
481
- updateStoreList(addItems: DevTool.StorageItem[]) {
482
- const cur = addItems[0];
483
-
484
- const index =
485
- this.state.storageList?.findIndex((item) => item.key === cur._oldKey) ??
486
- -1;
487
-
488
- if (index > -1 && addItems.length === 1) {
489
- if (this.state.storageList?.[index]) {
490
- this.state.storageList[index] = addItems[0];
491
- }
492
- } else {
493
- this.state.storageList?.push(...addItems);
494
- }
495
-
496
- return this.state.storageList;
497
- }
498
-
499
- setRouteList(pages: DevTool.Page[], currentPath?: string) {
500
- if (!this.getDevToolVisible()) return;
501
- const currentP = currentPath || pages?.[0]?.path || '';
502
- this.state.routeList = pages.map((item, index) => {
503
- return {
504
- type: item.type,
505
- path: item.path,
506
- style: item.style,
507
- index:
508
- item.path === currentP && index === 0
509
- ? 4
510
- : item.path === currentP
511
- ? 3
512
- : index === 0
513
- ? 2
514
- : 1,
515
- name: item.style.navigationBarTitleText || '无名',
516
- };
517
- });
518
- return this.state.routeList;
519
- }
520
-
521
- getRouteList() {
522
- return this.state.routeList;
523
- }
524
-
525
- updateCurrentPagePath(path: string) {
526
- if (!this.getDevToolVisible()) return;
527
-
528
- path = path === '/' ? (this.state.routeList?.[0]?.path ?? path) : path;
529
-
530
- this.state.routeList =
531
- this.state.routeList?.map((item, index) => {
532
- return {
533
- type: item.type,
534
- path: item.path,
535
- style: item.style,
536
- index:
537
- item.path === path && index === 0
538
- ? 4
539
- : item.path === path
540
- ? 3
541
- : index === 0
542
- ? 2
543
- : 1,
544
- name: item.style.navigationBarTitleText || '无名',
545
- };
546
- }) ?? [];
547
-
548
- return this.state.routeList;
549
- }
550
-
551
- setConsoleList(items: DevTool.ConsoleItem[]) {
552
- if (!this.getDevToolVisible()) return;
553
-
554
- if (
555
- (this.state?.consoleList?.length ?? 0) + items.length >
556
- this.consoleMaxSize
557
- ) {
558
- this.state.consoleList = [];
559
- }
560
- this.state.consoleList = items;
561
- }
562
-
563
- updateConsoleList(addItems: DevTool.ConsoleItem[], index?: number) {
564
- if (!this.getDevToolVisible()) return;
565
- if (isNumber(index) && index > -1 && addItems.length === 1) {
566
- if (this.state.consoleList?.[index]) {
567
- this.state.consoleList[index] = addItems[0];
568
- }
569
- } else {
570
- if (
571
- (this.state?.consoleList?.length ?? 0) + addItems.length >
572
- this.cacheMaxSize
573
- ) {
574
- this.state.consoleList?.splice(
575
- 0,
576
- this.state.consoleList.length - this.cacheMaxSize - addItems.length,
577
- );
578
- }
579
- this.state?.consoleList?.push(...addItems);
580
- }
581
- return this.state.consoleList;
582
- }
583
-
584
- clearNetworkList() {
585
- this.state.networkList = [];
586
- }
587
-
588
- setNetworkList(items: DevTool.NetworkItem[]) {
589
- if (!this.getDevToolVisible()) return;
590
- if (
591
- (this.state?.networkList?.length ?? 0) + items.length >
592
- this.networkMaxSize
593
- ) {
594
- this.state.networkList = [];
595
- }
596
- this.state.networkList = items;
597
- }
598
-
599
- updateNetworkList(addItems: DevTool.NetworkItem[], index?: number) {
600
- if (isNumber(index) && index > -1) {
601
- if (this.state?.networkList?.[index]) {
602
- this.state.networkList[index] = addItems[0];
603
- }
604
- } else {
605
- const max = this.networkMaxSize;
606
- const len = this.state?.networkList?.length ?? 0;
607
-
608
- if (len + addItems.length > max) {
609
- this.state.networkList?.splice(0, len - max - addItems.length);
610
- }
611
- this.state?.networkList?.push(...addItems);
612
- }
613
- return this.state.networkList;
614
- }
615
-
616
- updateUploadList(addItems: DevTool.UploadItem[], index?: number) {
617
- if (isNumber(index) && index > -1 && addItems.length === 1) {
618
- if (this.state.uploadList?.[index]) {
619
- this.state.uploadList[index] = {
620
- ...this.state.uploadList[index],
621
- ...addItems[0],
622
- };
623
- } else {
624
- const max = this.uploadMaxSize;
625
- const len = this.state?.uploadList?.length ?? 0;
626
- if (len + addItems.length > max) {
627
- this.state.uploadList?.splice(0, len - max - addItems.length);
628
- }
629
- this.state.uploadList?.push(addItems[0]);
630
- }
631
- }
632
- return this.state.uploadList;
633
- }
634
-
635
- clearUploadList() {
636
- this.state.uploadList = [];
637
- }
638
-
639
- setDevToolDestroy(destroy: boolean) {
640
- this.devToolDestroy = destroy;
641
-
642
- setDevToolInfo({
643
- devToolDestroy: destroy,
644
- });
645
- }
646
-
647
- getDevToolDestroy() {
648
- const { devToolDestroy = false } = uni.getStorageSync(DEV_TOOL_INFO);
649
-
650
- return this.devToolDestroy ?? devToolDestroy;
651
- }
652
-
653
- getCurrentPagePath() {
654
- let pages = getCurrentPages();
655
- let item = pages[pages.length - 1];
656
- if (item && item.route) {
657
- return item.route;
658
- }
659
- return '';
660
- }
661
-
662
- /**
663
- * 新增事件
664
- *
665
- * @param {DevTool.EventItem} event
666
- * @memberof DevStore
667
- */
668
- addEventItem(event: DevTool.EventItem) {
669
- if (!this.state.eventList) {
670
- this.state.eventList = [];
671
- }
672
- this.state.eventList?.push(event);
673
- }
674
-
675
- /**
676
- * 增加注册事件的数量
677
- *
678
- * @param {DevTool.EventCountKey} type
679
- * @memberof DevStore
680
- */
681
- updateUniEventCount(type: DevTool.EventCountKey) {
682
- if (!this.state.eventCount) {
683
- this.state.eventCount = {
684
- on: 0,
685
- once: 0,
686
- emit: 0,
687
- off: 0,
688
- };
689
- }
690
- this.state.eventCount[type] = this.state.eventCount[type] + 1;
691
- }
692
-
693
- updateUniEventList(evenList: DevTool.EventItem[]) {
694
- const len = this.state.eventList?.length ?? 0;
695
- const max = this.eventListMaxSize;
696
-
697
- if (len + evenList.length > max) {
698
- this.state.eventList?.splice(0, len - max - evenList.length);
699
- }
700
- this.state.eventList?.push(...evenList);
701
-
702
- return this.state.eventList;
703
- }
704
-
705
- uniEventClear() {
706
- this.state.eventCount = {
707
- on: 0,
708
- once: 0,
709
- emit: 0,
710
- off: 0,
711
- };
712
- this.state.eventList = [];
713
- }
714
-
715
- updateCaptureScreenList(captureScreenList: DevTool.CaptureScreenItem[]) {
716
- const len = this.state.captureScreenList?.length ?? 0;
717
- const max = this.captureScreenMaxSize;
718
- if (len + captureScreenList.length > max) {
719
- this.state.captureScreenList?.splice(
720
- 0,
721
- len - max - captureScreenList.length,
722
- );
723
- }
724
- this.state.captureScreenList?.push(...captureScreenList);
725
-
726
- return this.state.captureScreenList;
727
- }
728
-
729
- clearCaptureScreenList() {
730
- this.state.captureScreenList = [];
731
- }
732
- }