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
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# vite-uni-dev-tool
|
|
2
|
+
|
|
3
|
+
用于 vue3 + ts + uni-app 的开发调试插件
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```cmd
|
|
8
|
+
# 使用 npm 安装
|
|
9
|
+
npm i vite-uni-dev-tool
|
|
10
|
+
|
|
11
|
+
# 使用 pnpm 安装
|
|
12
|
+
pnpm i vite-uni-dev-tool
|
|
13
|
+
|
|
14
|
+
# 使用 yarn 安装
|
|
15
|
+
yarn add vite-uni-dev-tool
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 使用方法
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { defineConfig } from 'vite';
|
|
22
|
+
import uni from '@dcloudio/vite-plugin-uni';
|
|
23
|
+
|
|
24
|
+
import uniDevTool from 'vite-uni-dev-tool';
|
|
25
|
+
import pages from './src/pages.json';
|
|
26
|
+
import * as path from 'path';
|
|
27
|
+
|
|
28
|
+
// https://vitejs.dev/config/
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
plugins: [
|
|
31
|
+
// 一定要在 uni() 之前调用 否则微信小程序将无法解组件
|
|
32
|
+
uniDevTool({
|
|
33
|
+
pages,
|
|
34
|
+
}),
|
|
35
|
+
uni(),
|
|
36
|
+
],
|
|
37
|
+
server: {
|
|
38
|
+
host: true,
|
|
39
|
+
port: 10088,
|
|
40
|
+
},
|
|
41
|
+
resolve: {
|
|
42
|
+
alias: {
|
|
43
|
+
'@': path.resolve(__dirname, 'src'),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 注意事项
|
|
50
|
+
|
|
51
|
+
### 兼容性说明
|
|
52
|
+
|
|
53
|
+
| vue2 | vue3 |
|
|
54
|
+
| ---- | ---- |
|
|
55
|
+
| x | √ |
|
|
56
|
+
|
|
57
|
+
| 微信小程序 | 安卓 | 其他 |
|
|
58
|
+
| ---------- | ---- | ---- |
|
|
59
|
+
| √ | √ | x |
|
|
60
|
+
|
|
61
|
+
### 预览
|
|
62
|
+
|
|
63
|
+
- 支持 console 日志
|
|
64
|
+
|
|
65
|
+

|
|
66
|
+
|
|
67
|
+
- 支持 network 监控
|
|
68
|
+
|
|
69
|
+

|
|
70
|
+

|
|
71
|
+

|
|
72
|
+

|
|
73
|
+
|
|
74
|
+
- 支持 upload 监控
|
|
75
|
+
|
|
76
|
+

|
|
77
|
+

|
|
78
|
+

|
|
79
|
+

|
|
80
|
+
|
|
81
|
+
- 支持 websocket 监控
|
|
82
|
+
|
|
83
|
+

|
|
84
|
+

|
|
85
|
+
|
|
86
|
+
- 支持 connection 网络状态查看
|
|
87
|
+
|
|
88
|
+

|
|
89
|
+
|
|
90
|
+
- 支持 route 查看,跳转
|
|
91
|
+
|
|
92
|
+

|
|
93
|
+
|
|
94
|
+
- 支持 storage 监控,编辑
|
|
95
|
+
|
|
96
|
+

|
|
97
|
+
|
|
98
|
+
- 支持 vuex 监控,编辑
|
|
99
|
+
|
|
100
|
+

|
|
101
|
+
|
|
102
|
+
- 支持 pinia 监控,编辑
|
|
103
|
+
|
|
104
|
+

|
|
105
|
+
|
|
106
|
+
- 支持查看 window 信息
|
|
107
|
+
|
|
108
|
+

|
|
109
|
+
|
|
110
|
+
- 支持查看 device 信息
|
|
111
|
+
|
|
112
|
+

|
|
113
|
+
|
|
114
|
+
- 支持查看 system 信息
|
|
115
|
+
|
|
116
|
+

|
|
117
|
+
|
|
118
|
+
- setting 页,支持重启,导出日志(h5,app)
|
|
119
|
+
|
|
120
|
+

|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="button" :style="style" @click="onClick">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
<script lang="ts" setup>
|
|
7
|
+
defineProps<{ style?: any }>();
|
|
8
|
+
const emit = defineEmits<{ (e: 'click', event?: MouseEvent): void }>();
|
|
9
|
+
const onClick = (e: MouseEvent) => {
|
|
10
|
+
emit('click', e);
|
|
11
|
+
};
|
|
12
|
+
</script>
|
|
13
|
+
<style scoped>
|
|
14
|
+
.button {
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
width: 100%;
|
|
19
|
+
height: 32px;
|
|
20
|
+
border-radius: 4px;
|
|
21
|
+
color: #fff;
|
|
22
|
+
outline: none;
|
|
23
|
+
border: 1px solid transparent;
|
|
24
|
+
background-color: var(--dev-tool-main-color);
|
|
25
|
+
transform: all 0.3s;
|
|
26
|
+
font-size: var(--dev-tool-base-font-size);
|
|
27
|
+
padding: 0;
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.button:active {
|
|
32
|
+
background-color: darken(#9254de, 10%);
|
|
33
|
+
}
|
|
34
|
+
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
:class="`checkbox ${modelValue ? 'checkbox-active' : ''}`"
|
|
4
|
+
@click="onClickCheckbox"
|
|
5
|
+
>
|
|
6
|
+
{{ modelValue ? '√' : '' }}
|
|
7
|
+
</view>
|
|
8
|
+
</template>
|
|
9
|
+
<script lang="ts" setup>
|
|
10
|
+
const props = defineProps<{
|
|
11
|
+
modelValue?: boolean;
|
|
12
|
+
}>();
|
|
13
|
+
const emit = defineEmits<{
|
|
14
|
+
(e: 'update:modelValue', value: boolean): void;
|
|
15
|
+
(e: 'change', value: boolean): void;
|
|
16
|
+
}>();
|
|
17
|
+
|
|
18
|
+
function onClickCheckbox() {
|
|
19
|
+
const value = !props.modelValue;
|
|
20
|
+
emit('update:modelValue', value);
|
|
21
|
+
emit('change', value);
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
<style scoped>
|
|
25
|
+
.checkbox {
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
width: 18px;
|
|
30
|
+
height: 18px;
|
|
31
|
+
border-radius: 4px;
|
|
32
|
+
border: 1px solid var(--dev-tool-main-color);
|
|
33
|
+
transition: all 0.3s;
|
|
34
|
+
color: #fff;
|
|
35
|
+
box-sizing: border-box;
|
|
36
|
+
}
|
|
37
|
+
.checkbox-active {
|
|
38
|
+
background-color: var(--dev-tool-main-color);
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="close-button" @click="onClick"> × </view>
|
|
3
|
+
</template>
|
|
4
|
+
<script lang="ts" setup>
|
|
5
|
+
const emit = defineEmits<{ (e: 'click'): void }>();
|
|
6
|
+
|
|
7
|
+
function onClick() {
|
|
8
|
+
emit('click');
|
|
9
|
+
}
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<style scoped>
|
|
13
|
+
.close-button {
|
|
14
|
+
flex-shrink: 0;
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
width: 24px;
|
|
19
|
+
height: 24px;
|
|
20
|
+
margin-left: auto;
|
|
21
|
+
border-radius: 50%;
|
|
22
|
+
border: 1px solid #000;
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
}
|
|
25
|
+
</style>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="connection-content">
|
|
3
|
+
<view class="connection-item">
|
|
4
|
+
<view class="connection-item-title">网络连接</view>
|
|
5
|
+
<view class="connection-item-content">
|
|
6
|
+
<view class="connection-row">
|
|
7
|
+
<view>IP地址:</view>
|
|
8
|
+
<Tag
|
|
9
|
+
:mode="
|
|
10
|
+
netWorkStatus?.isConnected === undefined || netWorkStatus?.ip
|
|
11
|
+
? 'info'
|
|
12
|
+
: netWorkStatus?.isConnected && netWorkStatus?.ip
|
|
13
|
+
? 'success'
|
|
14
|
+
: 'error'
|
|
15
|
+
"
|
|
16
|
+
>
|
|
17
|
+
{{
|
|
18
|
+
netWorkStatus?.isConnected === undefined
|
|
19
|
+
? '未获取'
|
|
20
|
+
: netWorkStatus?.ip || '未获取'
|
|
21
|
+
}}
|
|
22
|
+
</Tag>
|
|
23
|
+
</view>
|
|
24
|
+
<view class="connection-row">
|
|
25
|
+
<view>连接状态:</view>
|
|
26
|
+
<Tag
|
|
27
|
+
:mode="
|
|
28
|
+
netWorkStatus?.isConnected === undefined
|
|
29
|
+
? 'info'
|
|
30
|
+
: netWorkStatus?.isConnected
|
|
31
|
+
? 'success'
|
|
32
|
+
: 'error'
|
|
33
|
+
"
|
|
34
|
+
>
|
|
35
|
+
{{
|
|
36
|
+
netWorkStatus?.isConnected === undefined
|
|
37
|
+
? '未获取'
|
|
38
|
+
: netWorkStatus?.isConnected
|
|
39
|
+
? '已连接'
|
|
40
|
+
: '已断开'
|
|
41
|
+
}}
|
|
42
|
+
</Tag>
|
|
43
|
+
</view>
|
|
44
|
+
<view class="connection-row">
|
|
45
|
+
<view>网络类型:</view>
|
|
46
|
+
<Tag mode="info">{{ netWorkStatus?.networkType ?? '未获取' }}</Tag>
|
|
47
|
+
</view>
|
|
48
|
+
<!-- <view class="connection-row">
|
|
49
|
+
<view>上传速度:</view>
|
|
50
|
+
<view>0 B/s</view>
|
|
51
|
+
</view>
|
|
52
|
+
<view class="connection-row">
|
|
53
|
+
<view>下载速度:</view>
|
|
54
|
+
<view>0 B/s</view>
|
|
55
|
+
</view> -->
|
|
56
|
+
</view>
|
|
57
|
+
</view>
|
|
58
|
+
</view>
|
|
59
|
+
</template>
|
|
60
|
+
<script lang="ts" setup>
|
|
61
|
+
import Tag from '../Tag/index.vue';
|
|
62
|
+
defineProps<{
|
|
63
|
+
netWorkStatus: {
|
|
64
|
+
isConnected?: boolean;
|
|
65
|
+
networkType?: string;
|
|
66
|
+
ip?: string;
|
|
67
|
+
};
|
|
68
|
+
}>();
|
|
69
|
+
</script>
|
|
70
|
+
<style scoped>
|
|
71
|
+
.connection-content {
|
|
72
|
+
height: 100%;
|
|
73
|
+
overflow: auto;
|
|
74
|
+
font-size: var(--dev-tool-base-font-size);
|
|
75
|
+
}
|
|
76
|
+
.connection-content .connection-item {
|
|
77
|
+
padding: 16px 16px 0 16px;
|
|
78
|
+
box-sizing: border-box;
|
|
79
|
+
}
|
|
80
|
+
.connection-content .connection-item .connection-item-title {
|
|
81
|
+
display: flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
}
|
|
84
|
+
.connection-content .connection-item .connection-item-title::before {
|
|
85
|
+
content: '';
|
|
86
|
+
margin-right: 8px;
|
|
87
|
+
width: 2px;
|
|
88
|
+
height: 18px;
|
|
89
|
+
border-radius: 2px;
|
|
90
|
+
background-color: var(--dev-tool-main-color);
|
|
91
|
+
}
|
|
92
|
+
.connection-content .connection-item .connection-item-content .connection-row {
|
|
93
|
+
display: flex;
|
|
94
|
+
align-items: center;
|
|
95
|
+
justify-content: space-between;
|
|
96
|
+
margin: 8px 0;
|
|
97
|
+
}
|
|
98
|
+
</style>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="`console-item console-item-${consoleItem.type}`">
|
|
3
|
+
<view class="console-info">
|
|
4
|
+
<view class="console-args">
|
|
5
|
+
<view
|
|
6
|
+
class="console-arg"
|
|
7
|
+
v-for="(item, index) in consoleItem.args"
|
|
8
|
+
:key="index"
|
|
9
|
+
v-html="item"
|
|
10
|
+
>
|
|
11
|
+
</view>
|
|
12
|
+
</view>
|
|
13
|
+
<view class="console-position">
|
|
14
|
+
<Tag :mode="consoleItem.type" style="margin: 0 4px">
|
|
15
|
+
{{ consoleItem.type }}
|
|
16
|
+
</Tag>
|
|
17
|
+
<view>
|
|
18
|
+
<view class="console-time">{{ consoleItem.time }}</view>
|
|
19
|
+
<view class="console-other" v-html="consoleItem.position"></view>
|
|
20
|
+
<view
|
|
21
|
+
class="console-other"
|
|
22
|
+
v-if="consoleItem.stack"
|
|
23
|
+
v-html="consoleItem.stack"
|
|
24
|
+
></view>
|
|
25
|
+
</view>
|
|
26
|
+
</view>
|
|
27
|
+
</view>
|
|
28
|
+
<!-- <view class="console-copy">C</view> -->
|
|
29
|
+
</view>
|
|
30
|
+
</template>
|
|
31
|
+
|
|
32
|
+
<script setup lang="ts">
|
|
33
|
+
import Tag from '../Tag/index.vue';
|
|
34
|
+
import type { DevTool } from '../../type';
|
|
35
|
+
defineProps<{ consoleItem: DevTool.ConsoleItem }>();
|
|
36
|
+
</script>
|
|
37
|
+
<style scoped>
|
|
38
|
+
.console-item {
|
|
39
|
+
display: flex;
|
|
40
|
+
padding: 16px;
|
|
41
|
+
border-bottom: 1px solid var(--dev-tool-border-color);
|
|
42
|
+
font-size: var(--dev-tool-base-font-size);
|
|
43
|
+
}
|
|
44
|
+
.console-item .console-info {
|
|
45
|
+
flex: 1;
|
|
46
|
+
}
|
|
47
|
+
.console-item .console-info .console-args {
|
|
48
|
+
display: flex;
|
|
49
|
+
flex-wrap: wrap;
|
|
50
|
+
color: #000;
|
|
51
|
+
}
|
|
52
|
+
.console-item .console-info .console-args .console-arg {
|
|
53
|
+
margin-right: 4px;
|
|
54
|
+
word-break: break-all;
|
|
55
|
+
}
|
|
56
|
+
.console-item .console-info .console-position {
|
|
57
|
+
display: flex;
|
|
58
|
+
align-items: flex-start;
|
|
59
|
+
justify-content: space-between;
|
|
60
|
+
margin-top: 4px;
|
|
61
|
+
color: #616161;
|
|
62
|
+
text-align: right;
|
|
63
|
+
}
|
|
64
|
+
.console-item .console-info .console-position .console-time {
|
|
65
|
+
margin-right: auto;
|
|
66
|
+
word-break: break-all;
|
|
67
|
+
}
|
|
68
|
+
.console-item .console-info .console-position .console-other {
|
|
69
|
+
word-break: break-all;
|
|
70
|
+
}
|
|
71
|
+
.console-item .console-copy {
|
|
72
|
+
flex-shrink: 0;
|
|
73
|
+
margin-left: 16px;
|
|
74
|
+
display: flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
justify-content: center;
|
|
77
|
+
width: 24px;
|
|
78
|
+
height: 24px;
|
|
79
|
+
color: #fff;
|
|
80
|
+
border-radius: 50%;
|
|
81
|
+
background-color: var(--dev-tool-success-color);
|
|
82
|
+
}
|
|
83
|
+
.console-item-info {
|
|
84
|
+
color: #9c9c9c;
|
|
85
|
+
}
|
|
86
|
+
.console-item-log {
|
|
87
|
+
color: #f9f9f9;
|
|
88
|
+
}
|
|
89
|
+
</style>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="console-content">
|
|
3
|
+
<view class="console-control">
|
|
4
|
+
<FilterInput
|
|
5
|
+
:modelValue="modelValue"
|
|
6
|
+
@search="emit('search', $event)"
|
|
7
|
+
@update:modelValue="emit('update:modelValue', $event)"
|
|
8
|
+
/>
|
|
9
|
+
<Tag
|
|
10
|
+
v-for="item in consoleFilterItems"
|
|
11
|
+
:mode="item.value"
|
|
12
|
+
:key="item.value"
|
|
13
|
+
:active="currentConsoleType === item.value"
|
|
14
|
+
@click="onChoose(item.value)"
|
|
15
|
+
>{{ item.label }}</Tag
|
|
16
|
+
>
|
|
17
|
+
</view>
|
|
18
|
+
<view class="console-list">
|
|
19
|
+
<ConsoleItem
|
|
20
|
+
v-for="(item, index) in consoleList"
|
|
21
|
+
:consoleItem="item"
|
|
22
|
+
:key="index"
|
|
23
|
+
/>
|
|
24
|
+
<Empty v-if="!consoleList || consoleList.length === 0" />
|
|
25
|
+
</view>
|
|
26
|
+
</view>
|
|
27
|
+
</template>
|
|
28
|
+
<script setup lang="ts">
|
|
29
|
+
import ConsoleItem from './ConsoleItem.vue';
|
|
30
|
+
import Tag from '../Tag/index.vue';
|
|
31
|
+
import Empty from '../Empty/index.vue';
|
|
32
|
+
import FilterInput from '../FilterInput/index.vue';
|
|
33
|
+
import type { DevTool } from '../../type';
|
|
34
|
+
type ConsoleType = 'all' | 'log' | 'info' | 'warn' | 'error' | 'clear';
|
|
35
|
+
defineProps<{
|
|
36
|
+
consoleList: DevTool.ConsoleItem[];
|
|
37
|
+
currentConsoleType: string;
|
|
38
|
+
modelValue: string;
|
|
39
|
+
}>();
|
|
40
|
+
const emit = defineEmits<{
|
|
41
|
+
(e: 'choose', type: ConsoleType): void;
|
|
42
|
+
(e: 'search', value: string): void;
|
|
43
|
+
(e: 'update:modelValue', value: string): void;
|
|
44
|
+
}>();
|
|
45
|
+
const consoleFilterItems: {
|
|
46
|
+
label: string;
|
|
47
|
+
value: ConsoleType;
|
|
48
|
+
}[] = [
|
|
49
|
+
{
|
|
50
|
+
label: '全部',
|
|
51
|
+
value: 'all',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
label: 'info',
|
|
55
|
+
value: 'info',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
label: 'log',
|
|
59
|
+
value: 'log',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: 'warn',
|
|
63
|
+
value: 'warn',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
label: 'error',
|
|
67
|
+
value: 'error',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
label: '清除',
|
|
71
|
+
value: 'clear',
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
function onChoose(type: ConsoleType) {
|
|
76
|
+
emit('choose', type);
|
|
77
|
+
}
|
|
78
|
+
</script>
|
|
79
|
+
<style scoped>
|
|
80
|
+
.console-content {
|
|
81
|
+
height: 100%;
|
|
82
|
+
font-size: var(--dev-tool-base-font-size);
|
|
83
|
+
}
|
|
84
|
+
.console-list {
|
|
85
|
+
height: calc(100% - 32px);
|
|
86
|
+
overflow: auto;
|
|
87
|
+
}
|
|
88
|
+
.console-control {
|
|
89
|
+
display: flex;
|
|
90
|
+
align-items: center;
|
|
91
|
+
justify-content: space-between;
|
|
92
|
+
gap: 8px;
|
|
93
|
+
padding: 0 16px;
|
|
94
|
+
height: 32px;
|
|
95
|
+
border-bottom: 1px solid var(--dev-tool-border-color);
|
|
96
|
+
box-sizing: border-box;
|
|
97
|
+
}
|
|
98
|
+
</style>
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="dev-tool">
|
|
3
|
+
<DevToolButton
|
|
4
|
+
v-if="devToolButtonVisible"
|
|
5
|
+
:buttonSize="buttonProps.buttonSize"
|
|
6
|
+
:buttonText="buttonProps.buttonText"
|
|
7
|
+
:buttonColor="buttonProps.buttonColor"
|
|
8
|
+
:buttonFontSize="buttonProps.buttonFontSize"
|
|
9
|
+
:buttonBackgroundColor="buttonProps.buttonBackgroundColor"
|
|
10
|
+
@click="onDevToolButtonClick"
|
|
11
|
+
/>
|
|
12
|
+
<DevToolWindow
|
|
13
|
+
:open="devToolWindowVisible"
|
|
14
|
+
:data="windowData"
|
|
15
|
+
@close="onShowDevToolWindow(false)"
|
|
16
|
+
@sendMessage="onSendMessage"
|
|
17
|
+
/>
|
|
18
|
+
<!-- <view class="devTool-canvas">
|
|
19
|
+
<canvas canvas-id="fullscreenCanvas" id="fullscreenCanvas" />
|
|
20
|
+
</view> -->
|
|
21
|
+
</view>
|
|
22
|
+
</template>
|
|
23
|
+
<script lang="ts" setup>
|
|
24
|
+
import { onShow, onHide, onUnload, onLoad } from '@dcloudio/uni-app';
|
|
25
|
+
import { reactive, ref, nextTick } from 'vue';
|
|
26
|
+
import DevToolButton from '../DevToolButton/index.vue';
|
|
27
|
+
import DevToolWindow from '../DevToolWindow/index.vue';
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
EVENT_DEV_BUTTON,
|
|
31
|
+
EVENT_DEV_WINDOW,
|
|
32
|
+
DEV_WINDOW_MESSAGE,
|
|
33
|
+
DEV_WINDOW_OPEN,
|
|
34
|
+
DEV_WINDOW_CLOSE,
|
|
35
|
+
DEV_OPTION_GET,
|
|
36
|
+
DEV_OPTION_SEND,
|
|
37
|
+
} from '../../const';
|
|
38
|
+
import type { DevTool } from '../../type';
|
|
39
|
+
|
|
40
|
+
let isActive = false;
|
|
41
|
+
|
|
42
|
+
const buttonProps = reactive({
|
|
43
|
+
buttonSize: 50,
|
|
44
|
+
buttonText: '🐜',
|
|
45
|
+
buttonColor: '#fff',
|
|
46
|
+
buttonFontSize: '16px',
|
|
47
|
+
buttonBackgroundColor: 'rgba(255, 255, 255, 0)',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const windowData = ref<DevTool.WindowData>({});
|
|
51
|
+
|
|
52
|
+
const devToolWindowVisible = ref(false);
|
|
53
|
+
const devToolButtonVisible = ref(false);
|
|
54
|
+
function onDevToolButtonClick() {
|
|
55
|
+
onShowDevToolWindow(true);
|
|
56
|
+
onSendMessage({
|
|
57
|
+
type: DEV_WINDOW_OPEN,
|
|
58
|
+
data: {},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function onShowDevToolButton(show: boolean) {
|
|
63
|
+
if (!isActive) return;
|
|
64
|
+
devToolButtonVisible.value = show ?? uni.getStorageSync(EVENT_DEV_BUTTON);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function onShowDevToolWindow(show: boolean) {
|
|
68
|
+
if (!isActive) return;
|
|
69
|
+
|
|
70
|
+
devToolWindowVisible.value = show;
|
|
71
|
+
uni.setStorageSync(EVENT_DEV_WINDOW, show);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function onSendMessage(param: { type: string; data: Record<string, any> }) {
|
|
75
|
+
uni.$emit(DEV_WINDOW_MESSAGE, param);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function onDevOptionSend(options: DevTool.DevToolOptions) {
|
|
79
|
+
if (options) {
|
|
80
|
+
buttonProps.buttonSize = options.buttonSize ?? 50;
|
|
81
|
+
buttonProps.buttonText = options.buttonText ?? '🐜';
|
|
82
|
+
buttonProps.buttonColor = options.buttonColor ?? '#fff';
|
|
83
|
+
buttonProps.buttonFontSize = options.buttonFontSize ?? '16px';
|
|
84
|
+
buttonProps.buttonBackgroundColor =
|
|
85
|
+
options.buttonBackgroundColor ?? 'rgba(255, 255, 255, 0)';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
onLoad(() => {
|
|
90
|
+
// 共享状态
|
|
91
|
+
|
|
92
|
+
const show = uni.getStorageSync(EVENT_DEV_WINDOW) || false;
|
|
93
|
+
|
|
94
|
+
isActive = true;
|
|
95
|
+
devToolButtonVisible.value = uni.getStorageSync(EVENT_DEV_BUTTON) || false;
|
|
96
|
+
devToolWindowVisible.value = show;
|
|
97
|
+
uni.$on(EVENT_DEV_BUTTON, onShowDevToolButton);
|
|
98
|
+
uni.$on(EVENT_DEV_WINDOW, onShowDevToolWindow);
|
|
99
|
+
uni.$on(DEV_OPTION_SEND, onDevOptionSend);
|
|
100
|
+
|
|
101
|
+
nextTick(() => {
|
|
102
|
+
uni.$emit(DEV_WINDOW_MESSAGE, { type: DEV_OPTION_GET, data: {} });
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
onUnload(() => {
|
|
107
|
+
uni.$emit(DEV_WINDOW_MESSAGE, {
|
|
108
|
+
type: DEV_WINDOW_CLOSE,
|
|
109
|
+
data: {},
|
|
110
|
+
});
|
|
111
|
+
uni.$off(EVENT_DEV_BUTTON, onShowDevToolButton);
|
|
112
|
+
uni.$off(EVENT_DEV_WINDOW, onShowDevToolWindow);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
onShow(() => {
|
|
116
|
+
isActive = true;
|
|
117
|
+
devToolWindowVisible.value = uni.getStorageSync(EVENT_DEV_WINDOW) || false;
|
|
118
|
+
devToolButtonVisible.value = uni.getStorageSync(EVENT_DEV_BUTTON) || false;
|
|
119
|
+
if (devToolWindowVisible.value) {
|
|
120
|
+
onSendMessage({
|
|
121
|
+
type: DEV_WINDOW_OPEN,
|
|
122
|
+
data: {},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
onHide(() => {
|
|
127
|
+
isActive = false;
|
|
128
|
+
devToolWindowVisible.value = false;
|
|
129
|
+
});
|
|
130
|
+
</script>
|
|
131
|
+
<style scoped>
|
|
132
|
+
.dev-tool {
|
|
133
|
+
--dev-tool-main-color: #9254de;
|
|
134
|
+
--dev-tool-border-color: #f0f0f0;
|
|
135
|
+
--dev-tool-normal-bg-color: #f9f9f9;
|
|
136
|
+
--dev-tool-warn-color: #ffa940;
|
|
137
|
+
--dev-tool-warn-bg-color: #fff7e6;
|
|
138
|
+
--dev-tool-error-color: #ff4d4f;
|
|
139
|
+
--dev-tool-error-bg-color: #fff1f0;
|
|
140
|
+
--dev-tool-success-color: #bae637;
|
|
141
|
+
--dev-tool-success-bg-color: #fcffe6;
|
|
142
|
+
|
|
143
|
+
--dev-tool-base-font-size: 12px;
|
|
144
|
+
--dev-tool-tag-font-size: 10px;
|
|
145
|
+
--dev-tool-tips-font-size: 10px;
|
|
146
|
+
font-size: 12px;
|
|
147
|
+
|
|
148
|
+
-webkit-tap-highlight-color: transparent;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.dev-tool-canvas {
|
|
152
|
+
position: fixed;
|
|
153
|
+
z-index: -99999;
|
|
154
|
+
top: 0;
|
|
155
|
+
left: 0;
|
|
156
|
+
width: 100vw;
|
|
157
|
+
height: 100vh;
|
|
158
|
+
opacity: 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
#fullscreenCanvas {
|
|
162
|
+
width: 100vw;
|
|
163
|
+
height: 100vh;
|
|
164
|
+
}
|
|
165
|
+
</style>
|