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