vite-uni-dev-tool 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -0
- package/dev/components/Button/index.vue +34 -0
- package/dev/components/Checkbox/index.vue +40 -0
- package/dev/components/CloseButton/index.vue +25 -0
- package/dev/components/Connection/index.vue +98 -0
- package/dev/components/ConsoleList/ConsoleItem.vue +89 -0
- package/dev/components/ConsoleList/index.vue +98 -0
- package/dev/components/DevTool/index.vue +165 -0
- package/dev/components/DevToolButton/index.vue +213 -0
- package/dev/components/DevToolWindow/index.vue +847 -0
- package/dev/components/DeviceInfo/index.vue +32 -0
- package/dev/components/Empty/empty.png +0 -0
- package/dev/components/Empty/index.vue +28 -0
- package/dev/components/FilterInput/index.vue +86 -0
- package/dev/components/JsonPretty/components/Brackets/index.vue +23 -0
- package/dev/components/JsonPretty/components/Carets/index.vue +63 -0
- package/dev/components/JsonPretty/components/CheckController/index.vue +108 -0
- package/dev/components/JsonPretty/components/TreeNode/index.vue +348 -0
- package/dev/components/JsonPretty/hooks/useClipboard.ts +21 -0
- package/dev/components/JsonPretty/hooks/useError.ts +21 -0
- package/dev/components/JsonPretty/index.vue +463 -0
- package/dev/components/JsonPretty/type.ts +123 -0
- package/dev/components/JsonPretty/utils/index.ts +172 -0
- package/dev/components/NetworkList/NetworkDetail.vue +197 -0
- package/dev/components/NetworkList/NetworkItem.vue +106 -0
- package/dev/components/NetworkList/index.vue +108 -0
- package/dev/components/PiniaList/index.vue +64 -0
- package/dev/components/RouteList/index.vue +98 -0
- package/dev/components/SettingList/index.vue +235 -0
- package/dev/components/StorageList/index.vue +170 -0
- package/dev/components/SystemInfo/index.vue +34 -0
- package/dev/components/Tabs/index.vue +110 -0
- package/dev/components/Tag/index.vue +89 -0
- package/dev/components/UploadList/UploadDetail.vue +208 -0
- package/dev/components/UploadList/UploadItem.vue +111 -0
- package/dev/components/UploadList/index.vue +94 -0
- package/dev/components/VuexList/index.vue +54 -0
- package/dev/components/WebSocket/WebSocketItem.vue +98 -0
- package/dev/components/WebSocket/WebSocketList.vue +176 -0
- package/dev/components/WebSocket/index.vue +99 -0
- package/dev/components/WindowInfo/index.vue +33 -0
- package/dev/const.ts +95 -0
- package/dev/core.ts +103 -0
- package/dev/devConsole/index.ts +334 -0
- package/dev/devEvent/index.ts +665 -0
- package/dev/devIntercept/index.ts +629 -0
- package/dev/devStore/index.ts +581 -0
- package/dev/index.d.ts +6 -0
- package/dev/index.d.ts.map +1 -0
- package/dev/index.js +1 -0
- package/dev/plugins/uniDevTool/uniDevTool.d.ts +66 -0
- package/dev/plugins/uniDevTool/uniDevTool.d.ts.map +1 -0
- package/dev/plugins/uniDevTool/uniDevTool.js +13 -0
- package/dev/plugins/uniGlobalComponents/uniGlobalComponents.d.ts +28 -0
- package/dev/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +1 -0
- package/dev/plugins/uniGlobalComponents/uniGlobalComponents.js +5 -0
- package/dev/shims-uni.d.ts +43 -0
- package/dev/type.ts +188 -0
- package/dev/utils/date.ts +75 -0
- package/dev/utils/file.ts +121 -0
- package/dev/utils/function.ts +192 -0
- package/dev/utils/index.ts +25 -0
- package/dev/utils/ip.ts +79 -0
- package/dev/utils/language.ts +19 -0
- package/dev/utils/object.ts +235 -0
- package/dev/utils/page.ts +13 -0
- package/dev/utils/string.ts +23 -0
- package/dev/utils/utils.ts +198 -0
- package/package.json +34 -0
|
@@ -0,0 +1,581 @@
|
|
|
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
|
+
} from '../utils/index';
|
|
13
|
+
|
|
14
|
+
/** 数据存储中心 */
|
|
15
|
+
export class DevStore {
|
|
16
|
+
/** 状态数据 */
|
|
17
|
+
private state: DevTool.WindowData = {
|
|
18
|
+
consoleList: [],
|
|
19
|
+
networkList: [],
|
|
20
|
+
storageList: [],
|
|
21
|
+
routeList: [],
|
|
22
|
+
vuexList: {},
|
|
23
|
+
piniaList: {},
|
|
24
|
+
deviceInfo: {},
|
|
25
|
+
windowInfo: {},
|
|
26
|
+
systemInfo: {},
|
|
27
|
+
wsList: [],
|
|
28
|
+
netWorkStatus: {},
|
|
29
|
+
uploadList: [],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** 调试配置 */
|
|
33
|
+
private devToolOptions: DevTool.DevToolOptions | undefined;
|
|
34
|
+
/** 日志最大值 */
|
|
35
|
+
private uploadMaxSize = 1000;
|
|
36
|
+
/** 日志最大值 */
|
|
37
|
+
private consoleMaxSize = 1000;
|
|
38
|
+
/** 网络最大值 */
|
|
39
|
+
private networkMaxSize = 1000;
|
|
40
|
+
/** ws数据最大值 */
|
|
41
|
+
private wsDataMaxSize = 1000;
|
|
42
|
+
/** 缓存最大值 */
|
|
43
|
+
cacheMaxSize = 8 * 1024 * 1024 * 10;
|
|
44
|
+
|
|
45
|
+
private vuexStore: any;
|
|
46
|
+
|
|
47
|
+
private piniaStore: any;
|
|
48
|
+
|
|
49
|
+
private uploadTaskMap = new Map<number | string, UniApp.UploadTask>();
|
|
50
|
+
|
|
51
|
+
private requestIndex = -1;
|
|
52
|
+
|
|
53
|
+
private uploadIndex = -1;
|
|
54
|
+
|
|
55
|
+
/** 是否显示按钮 */
|
|
56
|
+
private devToolVisible = false;
|
|
57
|
+
|
|
58
|
+
/** 是否销毁 */
|
|
59
|
+
private devToolDestroy = false;
|
|
60
|
+
|
|
61
|
+
/** 是否开启拦截Promise reject错误 */
|
|
62
|
+
enableInterceptPromiseReject = false;
|
|
63
|
+
|
|
64
|
+
constructor() {
|
|
65
|
+
this.devToolDestroy = uni.getStorageSync(DEV_IS_DESTROY) ?? false;
|
|
66
|
+
this.devToolVisible = uni.getStorageSync(EVENT_DEV_BUTTON) ?? false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
setDevToolVisible(visible: boolean) {
|
|
70
|
+
this.devToolVisible = visible;
|
|
71
|
+
uni.setStorageSync(EVENT_DEV_BUTTON, visible);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getDevToolVisible() {
|
|
75
|
+
return this.devToolVisible;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
setWindowInfo(windowInfo: Record<string, any>) {
|
|
79
|
+
this.state.windowInfo = windowInfo;
|
|
80
|
+
}
|
|
81
|
+
setDeviceInfo(deviceInfo: Record<string, any>) {
|
|
82
|
+
this.state.deviceInfo = deviceInfo;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setSystemInfo(systemInfo: Record<string, any>) {
|
|
86
|
+
this.state.systemInfo = systemInfo;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
setNetWorkStatus(netWorkStatus: Record<string, any>) {
|
|
90
|
+
this.state.netWorkStatus = netWorkStatus;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setVuexList(vuexList: Record<string, any>) {
|
|
94
|
+
this.state.vuexList = vuexList;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
setPiniaList(piniaList: Record<string, any>) {
|
|
98
|
+
this.state.piniaList = {
|
|
99
|
+
...(this.state.piniaList || {}),
|
|
100
|
+
...piniaList,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
setRequestIndex(index: number) {
|
|
105
|
+
this.requestIndex = index;
|
|
106
|
+
return this.requestIndex;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
getDevToolOptions() {
|
|
110
|
+
return this.devToolOptions;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
getRequestIndex() {
|
|
114
|
+
return this.requestIndex;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
setUploadIndex(index: number) {
|
|
118
|
+
this.uploadIndex = index;
|
|
119
|
+
return this.uploadIndex;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getUploadIndex() {
|
|
123
|
+
return this.uploadIndex;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
setDevToolOptions(options: DevTool.DevToolOptions) {
|
|
127
|
+
this.devToolOptions = options;
|
|
128
|
+
this.uploadMaxSize = options.uploadMaxSize || 1000;
|
|
129
|
+
this.consoleMaxSize = options.consoleMaxSize || 1000;
|
|
130
|
+
this.networkMaxSize = options.networkMaxSize || 1000;
|
|
131
|
+
this.wsDataMaxSize = options.wsDataMaxSize || 1000;
|
|
132
|
+
this.cacheMaxSize = options.cacheMaxSize || 8 * 1024 * 1024 * 10;
|
|
133
|
+
|
|
134
|
+
const pages =
|
|
135
|
+
options.pagesJson?.pages.map((page) => {
|
|
136
|
+
const isNav = options.pagesJson?.tabBar?.list?.some(
|
|
137
|
+
(nav) => nav.pagePath === page.path,
|
|
138
|
+
);
|
|
139
|
+
return {
|
|
140
|
+
...page,
|
|
141
|
+
isNav,
|
|
142
|
+
};
|
|
143
|
+
}) ?? [];
|
|
144
|
+
this.setRouteList(pages);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async getDevData() {
|
|
148
|
+
const networkType = await uni.getNetworkType();
|
|
149
|
+
const systemInfo = uni.getSystemInfoSync();
|
|
150
|
+
const deviceInfo = uni.getDeviceInfo();
|
|
151
|
+
const windowInfo = uni.getWindowInfo();
|
|
152
|
+
const ip = getWifiIp() || getLanIp() || (await getMicroAppIp());
|
|
153
|
+
return {
|
|
154
|
+
...this.state,
|
|
155
|
+
systemInfo,
|
|
156
|
+
deviceInfo,
|
|
157
|
+
windowInfo,
|
|
158
|
+
devToolVisible: this.getDevToolVisible(),
|
|
159
|
+
netWorkStatus: {
|
|
160
|
+
ip,
|
|
161
|
+
...networkType,
|
|
162
|
+
isConnected: networkType.networkType !== 'none',
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
updateStore(data: { key: string; _oldKey: string; value: any }) {
|
|
168
|
+
const { key, _oldKey, value } = data;
|
|
169
|
+
if (_oldKey !== key) {
|
|
170
|
+
uni.removeStorageSync(_oldKey);
|
|
171
|
+
this.state.storageList = this.state.storageList?.filter(
|
|
172
|
+
(item) => item.key === _oldKey,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
uni.setStorageSync(key, value);
|
|
176
|
+
this.state.storageList?.push({
|
|
177
|
+
key,
|
|
178
|
+
_oldKey,
|
|
179
|
+
value,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
return this.state.storageList;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
updateVuexStore(data: Record<string, any>) {
|
|
186
|
+
try {
|
|
187
|
+
// 更改vuex数据
|
|
188
|
+
Object.assign(this.vuexStore?.state ?? {}, data);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.error('[DevTool] updateVuexStore error', error);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 更新vuexList
|
|
194
|
+
this.setVuexList({
|
|
195
|
+
...(this.vuexStore?.state ?? {}),
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
return this.state.vuexList;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
setPiniaStore(piniaStore: any) {
|
|
202
|
+
this.piniaStore = piniaStore;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
updatePiniaStore(data: Record<string, any>) {
|
|
206
|
+
try {
|
|
207
|
+
if (!this.piniaStore) {
|
|
208
|
+
console.error('[DevTool] updatePiniaStore piniaStore is undefined');
|
|
209
|
+
return {};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const [key, value] = Object.entries(data)[0];
|
|
213
|
+
|
|
214
|
+
if (isNil(key)) {
|
|
215
|
+
console.error('[DevTool] updatePiniaStore key is undefined or null');
|
|
216
|
+
return {};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
setValueByPath(this.piniaStore.state.value, key, value);
|
|
220
|
+
|
|
221
|
+
console.log('this.piniaStore.state.value: ', this.piniaStore.state.value);
|
|
222
|
+
|
|
223
|
+
this.setPiniaList({
|
|
224
|
+
...(this.piniaStore.state.value ?? {}),
|
|
225
|
+
});
|
|
226
|
+
} catch (error) {
|
|
227
|
+
console.error('[DevTool] updatePiniaStore error', error);
|
|
228
|
+
}
|
|
229
|
+
return this.state.piniaList ?? {};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
getExportData(exports: {
|
|
233
|
+
exportLog: boolean;
|
|
234
|
+
exportNetwork: boolean;
|
|
235
|
+
exportStorage: boolean;
|
|
236
|
+
exportWebSocket: boolean;
|
|
237
|
+
exportUpload: boolean;
|
|
238
|
+
exportWindow: boolean;
|
|
239
|
+
exportDevice: boolean;
|
|
240
|
+
exportSystem: boolean;
|
|
241
|
+
}) {
|
|
242
|
+
const data: DevTool.WindowData = {};
|
|
243
|
+
if (exports.exportLog) {
|
|
244
|
+
data['consoleList'] = this.state.consoleList;
|
|
245
|
+
}
|
|
246
|
+
if (exports.exportNetwork) {
|
|
247
|
+
data['networkList'] = this.state.networkList;
|
|
248
|
+
}
|
|
249
|
+
if (exports.exportStorage) {
|
|
250
|
+
data['storageList'] = this.state.storageList;
|
|
251
|
+
data['vuexList'] = this.state.vuexList;
|
|
252
|
+
data['piniaList'] = this.state.piniaList;
|
|
253
|
+
}
|
|
254
|
+
if (exports.exportUpload) {
|
|
255
|
+
data['uploadList'] = this.state.uploadList;
|
|
256
|
+
}
|
|
257
|
+
if (exports.exportWebSocket) {
|
|
258
|
+
data['wsList'] = this.state.wsList;
|
|
259
|
+
}
|
|
260
|
+
if (exports.exportWindow) {
|
|
261
|
+
data['windowInfo'] = this.state.windowInfo;
|
|
262
|
+
}
|
|
263
|
+
if (exports.exportDevice) {
|
|
264
|
+
data['deviceInfo'] = this.state.deviceInfo;
|
|
265
|
+
}
|
|
266
|
+
if (exports.exportSystem) {
|
|
267
|
+
data['systemInfo'] = this.state.systemInfo;
|
|
268
|
+
}
|
|
269
|
+
return data;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
clearConsoleList() {
|
|
273
|
+
this.state.consoleList = [];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
clearDevCache() {
|
|
277
|
+
this.state.consoleList = [];
|
|
278
|
+
this.state.networkList = [];
|
|
279
|
+
this.state.wsList = [];
|
|
280
|
+
this.state.uploadList = [];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
clearAll() {
|
|
284
|
+
this.state.consoleList = [];
|
|
285
|
+
this.state.networkList = [];
|
|
286
|
+
this.state.storageList = [];
|
|
287
|
+
this.state.routeList = [];
|
|
288
|
+
this.state.wsList = [];
|
|
289
|
+
this.state.uploadList = [];
|
|
290
|
+
this.state.vuexList = {};
|
|
291
|
+
this.state.piniaList = {};
|
|
292
|
+
this.state.deviceInfo = {};
|
|
293
|
+
this.state.windowInfo = {};
|
|
294
|
+
this.state.systemInfo = {};
|
|
295
|
+
this.state.netWorkStatus = {};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
addUploadTask(index: number | string, task: UniApp.UploadTask) {
|
|
299
|
+
this.uploadTaskMap.set(index, task);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
removeUploadTask(index: number | string) {
|
|
303
|
+
this.uploadTaskMap.delete(index);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
clearUploadTask() {
|
|
307
|
+
this.uploadTaskMap.clear();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
clearWsList() {
|
|
311
|
+
this.state.wsList = [];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
updateWsList(item: DevTool.WS) {
|
|
315
|
+
if (!this.getDevToolVisible()) {
|
|
316
|
+
return [];
|
|
317
|
+
}
|
|
318
|
+
const index =
|
|
319
|
+
this.state?.wsList?.findIndex((w) => w.url === item.url) ?? -1;
|
|
320
|
+
|
|
321
|
+
if (index > -1) {
|
|
322
|
+
if (this.state.wsList?.[index]) {
|
|
323
|
+
const ws = this.state.wsList[index];
|
|
324
|
+
|
|
325
|
+
ws.headers = item.headers ?? ws.headers;
|
|
326
|
+
|
|
327
|
+
ws.readyState = item.readyState ?? ws.readyState;
|
|
328
|
+
|
|
329
|
+
ws.method = item.method ?? ws.method;
|
|
330
|
+
|
|
331
|
+
ws.protocols = item.protocols ?? ws.protocols;
|
|
332
|
+
|
|
333
|
+
ws.message = [
|
|
334
|
+
...(this.state.wsList[index].message ?? []),
|
|
335
|
+
...(item.message ?? []),
|
|
336
|
+
];
|
|
337
|
+
|
|
338
|
+
const max = this.wsDataMaxSize;
|
|
339
|
+
const len = ws?.message?.length ?? 0;
|
|
340
|
+
|
|
341
|
+
if (Array.isArray(ws?.message) && len > max) {
|
|
342
|
+
ws?.message?.splice(0, len - max);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
} else {
|
|
346
|
+
this.state.wsList?.push(item);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return this.state.wsList;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
clearWsMessage(url: string) {
|
|
353
|
+
const wsIndex =
|
|
354
|
+
this.state?.wsList?.findIndex((item) => item.url === url) ?? -1;
|
|
355
|
+
if (wsIndex === -1) return;
|
|
356
|
+
if (this.state.wsList?.[wsIndex]) {
|
|
357
|
+
this.state.wsList[wsIndex].message = [];
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
clearStorageList() {
|
|
362
|
+
this.state.storageList = [];
|
|
363
|
+
uni.clearStorage();
|
|
364
|
+
return this.state.storageList;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
setStorageList(items: DevTool.StorageItem[]) {
|
|
368
|
+
if (!this.getDevToolVisible()) return;
|
|
369
|
+
this.state.storageList = items;
|
|
370
|
+
return this.state.storageList;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
removeStorage(key: string) {
|
|
374
|
+
this.state.storageList =
|
|
375
|
+
this.state.storageList?.filter((item) => item.key !== key) ?? [];
|
|
376
|
+
uni.removeStorageSync(key);
|
|
377
|
+
return this.state.storageList;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
addStorage(data: { key: string; value: any }) {
|
|
381
|
+
const { key, value } = data;
|
|
382
|
+
|
|
383
|
+
this.state.storageList?.unshift({
|
|
384
|
+
key,
|
|
385
|
+
_oldKey: key,
|
|
386
|
+
value,
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
uni.setStorageSync(key, value);
|
|
390
|
+
return this.state.storageList;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
refreshStore() {
|
|
394
|
+
const { keys } = uni.getStorageInfoSync();
|
|
395
|
+
this.state.storageList = keys.map((key) => {
|
|
396
|
+
const value = uni.getStorageSync(key);
|
|
397
|
+
return {
|
|
398
|
+
key,
|
|
399
|
+
_oldKey: key,
|
|
400
|
+
value,
|
|
401
|
+
};
|
|
402
|
+
});
|
|
403
|
+
return this.state.storageList;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
updateStoreList(addItems: DevTool.StorageItem[]) {
|
|
407
|
+
const cur = addItems[0];
|
|
408
|
+
|
|
409
|
+
const index =
|
|
410
|
+
this.state.storageList?.findIndex((item) => item.key === cur._oldKey) ??
|
|
411
|
+
-1;
|
|
412
|
+
|
|
413
|
+
if (index > -1 && addItems.length === 1) {
|
|
414
|
+
if (this.state.storageList?.[index]) {
|
|
415
|
+
this.state.storageList[index] = addItems[0];
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
this.state.storageList?.push(...addItems);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
return this.state.storageList;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
setRouteList(pages: DevTool.Page[], currentPath?: string) {
|
|
425
|
+
if (!this.getDevToolVisible()) return;
|
|
426
|
+
const currentP = currentPath || pages?.[0]?.path || '';
|
|
427
|
+
this.state.routeList = pages.map((item, index) => {
|
|
428
|
+
return {
|
|
429
|
+
isNav: item.isNav,
|
|
430
|
+
path: item.path,
|
|
431
|
+
style: item.style,
|
|
432
|
+
index:
|
|
433
|
+
item.path === currentP && index === 0
|
|
434
|
+
? 4
|
|
435
|
+
: item.path === currentP
|
|
436
|
+
? 3
|
|
437
|
+
: index === 0
|
|
438
|
+
? 2
|
|
439
|
+
: 1,
|
|
440
|
+
name: item.style.navigationBarTitleText || '无名',
|
|
441
|
+
};
|
|
442
|
+
});
|
|
443
|
+
return this.state.routeList;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
getRouteList() {
|
|
447
|
+
return this.state.routeList;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
updateCurrentPagePath(path: string) {
|
|
451
|
+
if (!this.getDevToolVisible()) return;
|
|
452
|
+
|
|
453
|
+
path = path === '/' ? (this.state.routeList?.[0]?.path ?? path) : path;
|
|
454
|
+
|
|
455
|
+
this.state.routeList =
|
|
456
|
+
this.state.routeList?.map((item, index) => {
|
|
457
|
+
return {
|
|
458
|
+
isNav: item.isNav,
|
|
459
|
+
path: item.path,
|
|
460
|
+
style: item.style,
|
|
461
|
+
index:
|
|
462
|
+
item.path === path && index === 0
|
|
463
|
+
? 4
|
|
464
|
+
: item.path === path
|
|
465
|
+
? 3
|
|
466
|
+
: index === 0
|
|
467
|
+
? 2
|
|
468
|
+
: 1,
|
|
469
|
+
name: item.style.navigationBarTitleText || '无名',
|
|
470
|
+
};
|
|
471
|
+
}) ?? [];
|
|
472
|
+
|
|
473
|
+
return this.state.routeList;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
setConsoleList(items: DevTool.ConsoleItem[]) {
|
|
477
|
+
if (!this.getDevToolVisible()) return;
|
|
478
|
+
|
|
479
|
+
if (
|
|
480
|
+
(this.state?.consoleList?.length ?? 0) + items.length >
|
|
481
|
+
this.consoleMaxSize
|
|
482
|
+
) {
|
|
483
|
+
this.state.consoleList = [];
|
|
484
|
+
}
|
|
485
|
+
this.state.consoleList = items;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
updateConsoleList(addItems: DevTool.ConsoleItem[], index?: number) {
|
|
489
|
+
if (!this.getDevToolVisible()) return;
|
|
490
|
+
if (isNumber(index) && index > -1 && addItems.length === 1) {
|
|
491
|
+
if (this.state.consoleList?.[index]) {
|
|
492
|
+
this.state.consoleList[index] = addItems[0];
|
|
493
|
+
}
|
|
494
|
+
} else {
|
|
495
|
+
if (
|
|
496
|
+
(this.state?.consoleList?.length ?? 0) + addItems.length >
|
|
497
|
+
this.cacheMaxSize
|
|
498
|
+
) {
|
|
499
|
+
this.state.consoleList?.splice(
|
|
500
|
+
0,
|
|
501
|
+
this.state.consoleList.length - this.cacheMaxSize - addItems.length,
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
this.state?.consoleList?.push(...addItems);
|
|
505
|
+
}
|
|
506
|
+
return this.state.consoleList;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
clearNetworkList() {
|
|
510
|
+
this.state.networkList = [];
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
setNetworkList(items: DevTool.NetworkItem[]) {
|
|
514
|
+
if (!this.getDevToolVisible()) return;
|
|
515
|
+
if (
|
|
516
|
+
(this.state?.networkList?.length ?? 0) + items.length >
|
|
517
|
+
this.networkMaxSize
|
|
518
|
+
) {
|
|
519
|
+
this.state.networkList = [];
|
|
520
|
+
}
|
|
521
|
+
this.state.networkList = items;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
updateNetworkList(addItems: DevTool.NetworkItem[], index?: number) {
|
|
525
|
+
if (isNumber(index) && index > -1) {
|
|
526
|
+
if (this.state?.networkList?.[index]) {
|
|
527
|
+
this.state.networkList[index] = addItems[0];
|
|
528
|
+
}
|
|
529
|
+
} else {
|
|
530
|
+
const max = this.networkMaxSize;
|
|
531
|
+
const len = this.state?.networkList?.length ?? 0;
|
|
532
|
+
|
|
533
|
+
if (len + addItems.length > max) {
|
|
534
|
+
this.state.networkList?.splice(0, len - max - addItems.length);
|
|
535
|
+
}
|
|
536
|
+
this.state?.networkList?.push(...addItems);
|
|
537
|
+
}
|
|
538
|
+
return this.state.networkList;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
updateUploadList(addItems: DevTool.UploadItem[], index?: number) {
|
|
542
|
+
if (isNumber(index) && index > -1 && addItems.length === 1) {
|
|
543
|
+
if (this.state.uploadList?.[index]) {
|
|
544
|
+
this.state.uploadList[index] = {
|
|
545
|
+
...this.state.uploadList[index],
|
|
546
|
+
...addItems[0],
|
|
547
|
+
};
|
|
548
|
+
} else {
|
|
549
|
+
const max = this.uploadMaxSize;
|
|
550
|
+
const len = this.state?.uploadList?.length ?? 0;
|
|
551
|
+
if (len + addItems.length > max) {
|
|
552
|
+
this.state.uploadList?.splice(0, len - max - addItems.length);
|
|
553
|
+
}
|
|
554
|
+
this.state.uploadList?.push(addItems[0]);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
return this.state.uploadList;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
clearUploadList() {
|
|
561
|
+
this.state.uploadList = [];
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
setDevToolDestroy(destroy: boolean) {
|
|
565
|
+
uni.setStorageSync(DEV_IS_DESTROY, destroy);
|
|
566
|
+
this.devToolDestroy = destroy;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
getDevToolDestroy() {
|
|
570
|
+
return this.devToolDestroy ?? (uni.getStorageSync(DEV_IS_DESTROY) || false);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
getCurrentPagePath() {
|
|
574
|
+
let pages = getCurrentPages();
|
|
575
|
+
let item = pages[pages.length - 1];
|
|
576
|
+
if (item && item.route) {
|
|
577
|
+
return item.route;
|
|
578
|
+
}
|
|
579
|
+
return '';
|
|
580
|
+
}
|
|
581
|
+
}
|
package/dev/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { default as uniGlobalComponents } from './plugins/uniGlobalComponents/uniGlobalComponents';
|
|
2
|
+
import { default as uniDevTool } from './plugins/uniDevTool/uniDevTool';
|
|
3
|
+
|
|
4
|
+
export { uniDevTool, uniGlobalComponents };
|
|
5
|
+
export default uniDevTool;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../plugins/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,mDAAmD,CAAC;AACpF,OAAO,UAAU,MAAM,iCAAiC,CAAC;AAGzD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,CAAC;AAE3C,eAAgB,UAAU,CAAA"}
|
package/dev/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("./plugins/uniGlobalComponents/uniGlobalComponents.js"),e=require("./plugins/uniDevTool/uniDevTool.js");exports.uniGlobalComponents=o;exports.default=e;exports.uniDevTool=e;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* vite-uni-dev-tool 插件
|
|
5
|
+
*
|
|
6
|
+
* 自动在 main.ts 中注入调试插件,并在每个页面的模板中注入 DevTool 组件。
|
|
7
|
+
*
|
|
8
|
+
* 如果组件不是用 template 定义的,则不会被该插件添加。
|
|
9
|
+
*
|
|
10
|
+
* 如果在编译成微信小程序(开发环境 hbuilder 4.29) 组件 <dev-tool ></dev-tool> 中没有内容,应该开启 supportWX: true, 该属性默认关闭
|
|
11
|
+
*
|
|
12
|
+
* @export
|
|
13
|
+
* @param {{
|
|
14
|
+
* pages: {
|
|
15
|
+
* pages: {
|
|
16
|
+
* path: string;
|
|
17
|
+
* }[];
|
|
18
|
+
* };
|
|
19
|
+
* }} {
|
|
20
|
+
* pages,
|
|
21
|
+
* }
|
|
22
|
+
* @return {*} {Plugin}
|
|
23
|
+
*/
|
|
24
|
+
export default function uniDevTool({ pages, supportWX, ...reset }: {
|
|
25
|
+
/** 是否拦截Promise.reject 最好不要拦截 默认禁用 */
|
|
26
|
+
enableInterceptPromiseReject?: boolean;
|
|
27
|
+
/** 打开窗口时隐藏按钮 */
|
|
28
|
+
openWindowHideButton?: boolean;
|
|
29
|
+
/** 最大的console条数 */
|
|
30
|
+
consoleMaxSize?: number;
|
|
31
|
+
/** 最大的网络请求条数 */
|
|
32
|
+
networkMaxSize?: number;
|
|
33
|
+
/** 最大的上传文件条数 */
|
|
34
|
+
uploadMaxSize?: number;
|
|
35
|
+
/** 最大的套接字消息条数 */
|
|
36
|
+
wsDataMaxSize?: number;
|
|
37
|
+
/** 最大占用缓存空间 bytes */
|
|
38
|
+
cacheMaxSize?: number;
|
|
39
|
+
/** 按钮大小 */
|
|
40
|
+
buttonSize?: number;
|
|
41
|
+
/** 按钮文本 */
|
|
42
|
+
buttonText?: string;
|
|
43
|
+
/** 按钮文本颜色 */
|
|
44
|
+
buttonColor?: string;
|
|
45
|
+
/** 按钮字体大小 */
|
|
46
|
+
buttonFontSize?: string;
|
|
47
|
+
/** 按钮背景颜色 */
|
|
48
|
+
buttonBackgroundColor?: string;
|
|
49
|
+
/** 初始化时是否显示调试按钮,默认显示 */
|
|
50
|
+
initShowDevTool?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* 在 hbuilder 4.29 可开发环境中无法正确的将 DevTool 组件编译完整 只有 wxml 文件其他是缺失的,开启该项将不使用 app.component('DevTool', DevTool) 方式注册组件, 将在每个 page 中直接引入组件
|
|
53
|
+
*
|
|
54
|
+
* 在 hbuilder 4.66 中还是这样...
|
|
55
|
+
*
|
|
56
|
+
* 打包构建完成之后 组件编译是完整的,可以关闭该项
|
|
57
|
+
*/
|
|
58
|
+
supportWX?: boolean;
|
|
59
|
+
/** 页面配置 用于读取路由 */
|
|
60
|
+
pages: {
|
|
61
|
+
pages: {
|
|
62
|
+
path: string;
|
|
63
|
+
}[];
|
|
64
|
+
};
|
|
65
|
+
}): Plugin;
|
|
66
|
+
//# sourceMappingURL=uniDevTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAkBnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,KAAK,EACL,SAAS,EACT,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;IAEtB,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;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kBAAkB;IAClB,KAAK,EAAE;QACL,KAAK,EAAE;YACL,IAAI,EAAE,MAAM,CAAC;SACd,EAAE,CAAC;KACL,CAAC;CACH,GAAG,MAAM,CAkHT"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";const u=/<template[^>]*>([\s\S]*?)<\/template>/,v=/<script[^>]*>([\s\S]*?)<\/script>/;function f(p,s){for(let i=0;i<p.length;i++)if(s(p[i]))return i+1;return-1}function T({pages:p,supportWX:s,...i}){return{name:"vite-uni-dev-tool",enforce:"pre",transform(e,m){if(m.endsWith("/src/main.ts"))try{const r=e.split(`
|
|
2
|
+
`);let n=[...r];const c=f(n,t=>t.trim().startsWith("import")||t.trim().startsWith("export"));c!==-1&&n.splice(c,0,s?"":"import DevTool from 'vite-uni-dev-tool/dev/components/DevTool/index.vue';","import { initDevTool } from 'vite-uni-dev-tool/dev/core';","import pagesJson from './pages.json';");const o=f(n,t=>t.includes(".mount(")||t.includes("createApp("));if(o!==-1&&n.splice(o+1,0,s?"":" app.component('DevTool', DevTool);",` initDevTool({
|
|
3
|
+
pagesJson,
|
|
4
|
+
...${JSON.stringify(i)}
|
|
5
|
+
});`),n.length!==r.length)return{code:n.join(`
|
|
6
|
+
`),map:null}}catch(r){return console.error("[DevTool] 转换 main 文件时出错:",r),{code:e,map:null}}if(m.endsWith(".vue")){const r=e.includes("<template>"),n=p.pages.some(o=>m.includes(o.path)),c=["<DevTool />"];if(n&&r){const o=e.match(u);let t=e;if(o&&o[1]){const a=`${o[1].trim()}
|
|
7
|
+
${c.join(`
|
|
8
|
+
`)}`;t=e.replace(u,`<template>
|
|
9
|
+
${a}
|
|
10
|
+
</template>`)}if(s){const l=e.match(v);if(l&&l[1]){const d=`import DevTool from 'vite-uni-dev-tool/dev/components/DevTool/index.vue';
|
|
11
|
+
${l[1].trim()}`;t=t.replace(v,`<script lang="ts" setup>
|
|
12
|
+
${d}
|
|
13
|
+
<\/script>`)}}return{code:t,map:null}}}return{code:e,map:null}}}}module.exports=T;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* uni-global-components 插件,用于在页面中添加全局组件
|
|
5
|
+
*
|
|
6
|
+
* 该插件会在每个页面的template中添加全局组件,以达到全局组件的效果。
|
|
7
|
+
*
|
|
8
|
+
* 如果组件不是用 template 定义的,则不会被该插件添加。
|
|
9
|
+
*
|
|
10
|
+
* @export
|
|
11
|
+
* @param {{
|
|
12
|
+
* pages: { pages: { path: string }[] };
|
|
13
|
+
* components: string[];
|
|
14
|
+
* }} {
|
|
15
|
+
* pages,
|
|
16
|
+
* components
|
|
17
|
+
* }
|
|
18
|
+
* @return {*} {Plugin}
|
|
19
|
+
*/
|
|
20
|
+
export default function uniGlobalComponents({ pages, components, }: {
|
|
21
|
+
pages: {
|
|
22
|
+
pages: {
|
|
23
|
+
path: string;
|
|
24
|
+
}[];
|
|
25
|
+
};
|
|
26
|
+
components: string[];
|
|
27
|
+
}): Plugin;
|
|
28
|
+
//# sourceMappingURL=uniGlobalComponents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniGlobalComponents.d.ts","sourceRoot":"","sources":["../../../../plugins/src/plugins/uniGlobalComponents/uniGlobalComponents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,KAAK,EACL,UAAU,GACX,EAAE;IACD,KAAK,EAAE;QAAE,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;KAAE,CAAC;IACrC,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,GAAG,MAAM,CAmCT"}
|