vite-uni-dev-tool 0.0.6 → 0.0.8
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 +16 -0
- package/dev/components/Code/index.vue +227 -0
- package/dev/components/Connection/index.vue +11 -21
- package/dev/components/ConsoleList/Code.vue +1 -1
- package/dev/components/ConsoleList/ConsoleItem.vue +38 -12
- package/dev/components/ConsoleList/RunJSInput.vue +59 -0
- package/dev/components/ConsoleList/index.vue +24 -8
- package/dev/components/DevTool/index.vue +10 -9
- package/dev/components/DevToolButton/index.vue +10 -10
- package/dev/components/DevToolTitle/index.vue +21 -0
- package/dev/components/DevToolWindow/index.vue +62 -5
- package/dev/components/FilterInput/index.vue +1 -1
- package/dev/components/JsonPretty/components/CheckController/index.vue +22 -5
- package/dev/components/JsonPretty/components/TreeNode/index.vue +16 -15
- package/dev/components/JsonPretty/index.vue +77 -75
- package/dev/components/JsonPretty/type.ts +2 -0
- package/dev/components/NetworkList/NetworkDetail.vue +1 -1
- package/dev/components/RunJS/index.vue +128 -0
- package/dev/components/SettingList/index.vue +10 -20
- package/dev/components/UniEvent/UniEventItem.vue +124 -0
- package/dev/components/UniEvent/index.vue +94 -0
- package/dev/components/UploadList/UploadDetail.vue +1 -1
- package/dev/components/VirtualList/index.vue +112 -0
- package/dev/components/WebSocket/WebSocketList.vue +1 -1
- package/dev/const.ts +101 -28
- package/dev/core.ts +12 -3
- package/dev/devConsole/index.ts +21 -4
- package/dev/devEvent/index.ts +122 -8
- package/dev/devEventBus/index.ts +94 -0
- package/dev/devIntercept/index.ts +61 -18
- package/dev/devRunJS/index.ts +170 -0
- package/dev/devStore/index.ts +83 -0
- package/dev/index.d.ts +3 -2
- package/dev/index.js +1 -1
- package/dev/plugins/uniDevTool/uniDevTool.d.ts +2 -1
- package/dev/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
- package/dev/plugins/uniDevTool/uniDevTool.js +36 -38
- package/dev/plugins/uniGlobalComponents/uniGlobalComponents.d.ts +2 -1
- package/dev/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +1 -1
- package/dev/plugins/uniGlobalComponents/uniGlobalComponents.js +7 -9
- package/dev/plugins/utils/index.d.ts +10 -2
- package/dev/plugins/utils/index.d.ts.map +1 -1
- package/dev/plugins/utils/index.js +1 -1
- package/dev/type.ts +58 -1
- package/dev/utils/index.ts +10 -1
- package/dev/utils/language.ts +53 -0
- package/dev/utils/object.ts +64 -1
- package/dev/utils/string.ts +5 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -151,7 +151,23 @@ uni.__dev__console.log('hello vite-uni-dev-tool');
|
|
|
151
151
|
|
|
152
152
|
## 更新日志
|
|
153
153
|
|
|
154
|
+
### 0.0.8
|
|
155
|
+
|
|
156
|
+
- 修复多 template 注入调试工具异常
|
|
157
|
+
- 修复 json pretty 逗号位置
|
|
158
|
+
- 修复 json pretty symbol 类型转换异常
|
|
159
|
+
- json pretty 自动判断虚拟列表
|
|
160
|
+
- 虚拟列表抽离到独立文件
|
|
161
|
+
|
|
162
|
+
### 0.0.7
|
|
163
|
+
|
|
164
|
+
- 监听uni.$on
|
|
165
|
+
- 监听uni.%once
|
|
166
|
+
- 监听uni.$emit
|
|
167
|
+
- 监听uni.$of
|
|
168
|
+
|
|
154
169
|
### 0.0.6
|
|
170
|
+
|
|
155
171
|
- 修复 app 查看 source 重启
|
|
156
172
|
|
|
157
173
|
### 0.0.5
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="dev-tool-code">
|
|
3
|
+
<view class="dev-tool-code-control">
|
|
4
|
+
<FilterInput
|
|
5
|
+
v-model="modelValue"
|
|
6
|
+
style="width: 100%"
|
|
7
|
+
@search="onSearch"
|
|
8
|
+
/>
|
|
9
|
+
<CloseButton style="margin-left: auto" @click="onClose" />
|
|
10
|
+
</view>
|
|
11
|
+
<view class="dev-tool-code-title">{{ fileName }}</view>
|
|
12
|
+
<scroll-view
|
|
13
|
+
scroll-y="true"
|
|
14
|
+
scroll-x="true"
|
|
15
|
+
class="dev-tool-code-list"
|
|
16
|
+
scroll-with-animation="true"
|
|
17
|
+
:scroll-top="scrollTop"
|
|
18
|
+
:scroll-into-view="scrollIntoView"
|
|
19
|
+
>
|
|
20
|
+
<view
|
|
21
|
+
v-for="(code, index) in codes"
|
|
22
|
+
:id="`dev-tool-code-item-${index}`"
|
|
23
|
+
:key="index"
|
|
24
|
+
:class="`dev-tool-code-item ${index === activeRowCol.activeRow ? 'dev-tool-code-item-active' : ''}`"
|
|
25
|
+
>
|
|
26
|
+
<view class="dev-tool-code-item-index"> {{ index + 1 }}</view>
|
|
27
|
+
|
|
28
|
+
<view class="dev-tool-code-item-content" v-html="code"></view>
|
|
29
|
+
</view>
|
|
30
|
+
<Empty v-if="!codes || codes.length === 0" />
|
|
31
|
+
</scroll-view>
|
|
32
|
+
</view>
|
|
33
|
+
</template>
|
|
34
|
+
<script lang="ts" setup>
|
|
35
|
+
import { computed, ref, nextTick, onMounted } from 'vue';
|
|
36
|
+
import FilterInput from '../FilterInput/index.vue';
|
|
37
|
+
import CloseButton from '../CloseButton/index.vue';
|
|
38
|
+
import Empty from '../Empty/index.vue';
|
|
39
|
+
import { escapeHTML, hightLight, isAndroid, parseStock } from '../../utils';
|
|
40
|
+
|
|
41
|
+
const props = defineProps<{
|
|
42
|
+
url: string;
|
|
43
|
+
sourceFileServers?: string[];
|
|
44
|
+
mode?: string;
|
|
45
|
+
}>();
|
|
46
|
+
|
|
47
|
+
const emit = defineEmits<{ (e: 'close'): void }>();
|
|
48
|
+
|
|
49
|
+
const modelValue = ref('');
|
|
50
|
+
const scrollTop = ref(0);
|
|
51
|
+
const fileName = computed(() => {
|
|
52
|
+
const name =
|
|
53
|
+
props?.url?.split('/')?.pop()?.replace(/\)|\(/, '') ?? '文件名称未知';
|
|
54
|
+
return name;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const activeRowCol = ref({ row: -1, col: -1, activeRow: -1 });
|
|
58
|
+
|
|
59
|
+
let backupCodes: string[] = [];
|
|
60
|
+
|
|
61
|
+
const codes = ref<string[]>([]);
|
|
62
|
+
|
|
63
|
+
const scrollIntoView = ref('');
|
|
64
|
+
|
|
65
|
+
function onClose() {
|
|
66
|
+
emit('close');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function onSearch(value: string) {
|
|
70
|
+
codes.value = backupCodes.map((code) => {
|
|
71
|
+
return hightLight(code, value);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let index = 0;
|
|
76
|
+
function getCode(url: string, i: number = 0) {
|
|
77
|
+
let allUrl = url;
|
|
78
|
+
// 平台判断
|
|
79
|
+
if (isAndroid()) {
|
|
80
|
+
if (!props.sourceFileServers?.[i]) {
|
|
81
|
+
index = 0;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
allUrl = props.sourceFileServers?.[i] + '/src/' + url;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
uni.showLoading({ mask: true });
|
|
89
|
+
uni.request({
|
|
90
|
+
url: allUrl,
|
|
91
|
+
success: (res) => {
|
|
92
|
+
if (typeof res.data === 'string') {
|
|
93
|
+
// 为什么要注释掉?
|
|
94
|
+
// 在 Android 识别到标签后会进行重启,导致代码无法显示
|
|
95
|
+
// TODO: 还有其它原因导致重启
|
|
96
|
+
const str = res.data
|
|
97
|
+
?.replace(/<jscript/, '// [DevTool] 注释 <javascript')
|
|
98
|
+
?.replace(/<\/script>/, '// [DevTool] 注释 </javascript>')
|
|
99
|
+
?.replace(/<style/, '// [DevTool] 注释 <style')
|
|
100
|
+
?.replace(/<\/style>/, '// [DevTool] 注释 </style>');
|
|
101
|
+
backupCodes = escapeHTML(str ?? '')
|
|
102
|
+
.toString()
|
|
103
|
+
.split('\n');
|
|
104
|
+
|
|
105
|
+
const start =
|
|
106
|
+
activeRowCol.value.row - 20 > 0 ? activeRowCol.value.row - 20 : 0;
|
|
107
|
+
|
|
108
|
+
const end =
|
|
109
|
+
activeRowCol.value.row + 20 > backupCodes.length
|
|
110
|
+
? backupCodes.length
|
|
111
|
+
: activeRowCol.value.row + 20;
|
|
112
|
+
|
|
113
|
+
// backupCodes.slice(start, end);
|
|
114
|
+
|
|
115
|
+
codes.value = backupCodes.slice(start, end);
|
|
116
|
+
|
|
117
|
+
activeRowCol.value.activeRow = activeRowCol.value.row - start;
|
|
118
|
+
|
|
119
|
+
nextTick(() => {
|
|
120
|
+
scrollIntoView.value = `dev-tool-code-item-${activeRowCol.value.activeRow}`;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
fail: (err) => {
|
|
125
|
+
index++;
|
|
126
|
+
getCode(url, index);
|
|
127
|
+
uni.showToast({ icon: 'none', title: '正在重新尝试中...' });
|
|
128
|
+
},
|
|
129
|
+
complete: () => {
|
|
130
|
+
uni.hideLoading();
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** 开发环境获取源代码 */
|
|
136
|
+
function getSourceCodeDev(url: string) {
|
|
137
|
+
if (!url) {
|
|
138
|
+
uni.showToast({ icon: 'none', title: '[DevTool] url 处理异常' });
|
|
139
|
+
uni?.__dev__console?.log('[DevTool] url 处理异常');
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getCode(url, index);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
onMounted(() => {
|
|
147
|
+
let url = props?.url;
|
|
148
|
+
|
|
149
|
+
const { path, col, row } = parseStock(props?.url ?? '');
|
|
150
|
+
|
|
151
|
+
if (path) {
|
|
152
|
+
url = path;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
activeRowCol.value.col = col;
|
|
156
|
+
activeRowCol.value.row = row;
|
|
157
|
+
|
|
158
|
+
if (props.mode === 'development') {
|
|
159
|
+
// 开发环境查看源码
|
|
160
|
+
getSourceCodeDev(url);
|
|
161
|
+
} else if (props.mode === 'production') {
|
|
162
|
+
// TODO 生产环境查看源码
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
</script>
|
|
166
|
+
<style scoped>
|
|
167
|
+
.dev-tool-code {
|
|
168
|
+
position: fixed;
|
|
169
|
+
width: 100vw;
|
|
170
|
+
height: 100vh;
|
|
171
|
+
z-index: 1000;
|
|
172
|
+
top: 0;
|
|
173
|
+
left: 0;
|
|
174
|
+
padding: 0 16px;
|
|
175
|
+
/* #ifdef H5 */
|
|
176
|
+
padding: 50px 16px;
|
|
177
|
+
/* #endif */
|
|
178
|
+
|
|
179
|
+
background-color: rgba(255, 255, 255, 0.95);
|
|
180
|
+
box-sizing: border-box;
|
|
181
|
+
color: #000;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.dev-tool-code-control {
|
|
185
|
+
display: flex;
|
|
186
|
+
align-items: center;
|
|
187
|
+
gap: 12px;
|
|
188
|
+
height: 32px;
|
|
189
|
+
border-bottom: 1px solid var(--dev-tool-border-color);
|
|
190
|
+
box-sizing: border-box;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.dev-tool-code-title {
|
|
194
|
+
height: 32px;
|
|
195
|
+
line-height: 32px;
|
|
196
|
+
margin-bottom: 4px;
|
|
197
|
+
border-bottom: 1px solid var(--dev-tool-border-color);
|
|
198
|
+
box-sizing: border-box;
|
|
199
|
+
white-space: nowrap;
|
|
200
|
+
overflow: auto;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.dev-tool-code-list {
|
|
204
|
+
height: calc(100% - 68px);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.dev-tool-code-item {
|
|
208
|
+
display: flex;
|
|
209
|
+
align-items: center;
|
|
210
|
+
height: 28px;
|
|
211
|
+
}
|
|
212
|
+
.dev-tool-code-item-active {
|
|
213
|
+
color: #fff;
|
|
214
|
+
background-color: var(--dev-tool-main-color);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.dev-tool-code-item-index {
|
|
218
|
+
flex-shrink: 0;
|
|
219
|
+
width: 20px;
|
|
220
|
+
margin-right: 8px;
|
|
221
|
+
text-align: right;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.dev-tool-code-item-content {
|
|
225
|
+
white-space: pre;
|
|
226
|
+
}
|
|
227
|
+
</style>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="connection-content">
|
|
3
3
|
<view class="connection-item">
|
|
4
|
-
<
|
|
4
|
+
<DevToolTitle>网络连接</DevToolTitle>
|
|
5
5
|
<view class="connection-item-content">
|
|
6
6
|
<view class="connection-row">
|
|
7
7
|
<view>IP地址:</view>
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
netWorkStatus?.isConnected === undefined || netWorkStatus?.ip
|
|
11
11
|
? 'info'
|
|
12
12
|
: netWorkStatus?.isConnected && netWorkStatus?.ip
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
? 'success'
|
|
14
|
+
: 'error'
|
|
15
15
|
"
|
|
16
16
|
>
|
|
17
17
|
{{
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
netWorkStatus?.isConnected === undefined
|
|
29
29
|
? 'info'
|
|
30
30
|
: netWorkStatus?.isConnected
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
? 'success'
|
|
32
|
+
: 'error'
|
|
33
33
|
"
|
|
34
34
|
>
|
|
35
35
|
{{
|
|
36
36
|
netWorkStatus?.isConnected === undefined
|
|
37
37
|
? '未获取'
|
|
38
38
|
: netWorkStatus?.isConnected
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
? '已连接'
|
|
40
|
+
: '已断开'
|
|
41
41
|
}}
|
|
42
42
|
</Tag>
|
|
43
43
|
</view>
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
</template>
|
|
60
60
|
<script lang="ts" setup>
|
|
61
61
|
import Tag from '../Tag/index.vue';
|
|
62
|
+
import DevToolTitle from '../DevToolTitle/index.vue';
|
|
62
63
|
defineProps<{
|
|
63
64
|
netWorkStatus: {
|
|
64
65
|
isConnected?: boolean;
|
|
@@ -73,23 +74,12 @@ defineProps<{
|
|
|
73
74
|
overflow: auto;
|
|
74
75
|
font-size: var(--dev-tool-base-font-size);
|
|
75
76
|
}
|
|
76
|
-
.connection-
|
|
77
|
+
.connection-item {
|
|
77
78
|
padding: 16px 16px 0 16px;
|
|
78
79
|
box-sizing: border-box;
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
-
|
|
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 {
|
|
81
|
+
|
|
82
|
+
.connection-row {
|
|
93
83
|
display: flex;
|
|
94
84
|
align-items: center;
|
|
95
85
|
justify-content: space-between;
|
|
@@ -1,19 +1,38 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view :class="`console-item console-item-${consoleItem.type}`">
|
|
2
|
+
<view :id="id" :class="`console-item console-item-${consoleItem.type}`">
|
|
3
3
|
<view class="console-info">
|
|
4
4
|
<view class="console-args">
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
<template v-for="(item, index) in consoleItem.args">
|
|
6
|
+
<view
|
|
7
|
+
v-if="item.type !== 'array' && item.type !== 'object'"
|
|
8
|
+
class="console-arg"
|
|
9
|
+
:key="index"
|
|
10
|
+
v-html="item.value"
|
|
11
|
+
>
|
|
12
|
+
</view>
|
|
13
|
+
<JsonPretty
|
|
14
|
+
v-else
|
|
15
|
+
:data="item.value"
|
|
16
|
+
collapsed
|
|
17
|
+
showLength
|
|
18
|
+
:autoVirtualRow="100"
|
|
19
|
+
/>
|
|
20
|
+
</template>
|
|
12
21
|
</view>
|
|
13
22
|
<view class="console-position">
|
|
14
|
-
<
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
<view class="console-tags">
|
|
24
|
+
<Tag
|
|
25
|
+
v-if="consoleItem.mode"
|
|
26
|
+
mode="log"
|
|
27
|
+
style="margin-right: 6px; justify-content: center"
|
|
28
|
+
>
|
|
29
|
+
{{ consoleItem.mode }}
|
|
30
|
+
</Tag>
|
|
31
|
+
<Tag :mode="consoleItem.type">
|
|
32
|
+
{{ consoleItem.type }}
|
|
33
|
+
</Tag>
|
|
34
|
+
</view>
|
|
35
|
+
|
|
17
36
|
<view>
|
|
18
37
|
<view class="console-time">{{ consoleItem.time }}</view>
|
|
19
38
|
<view class="console-other" v-html="consoleItem.position"></view>
|
|
@@ -40,14 +59,16 @@
|
|
|
40
59
|
<script setup lang="ts">
|
|
41
60
|
import { ref, computed } from 'vue';
|
|
42
61
|
import Tag from '../Tag/index.vue';
|
|
43
|
-
import Code from '
|
|
62
|
+
import Code from '../Code/index.vue';
|
|
44
63
|
import type { DevTool } from '../../type';
|
|
45
64
|
import { isAndroid, isMockWX } from '../../utils';
|
|
65
|
+
import JsonPretty from '../JsonPretty/index.vue';
|
|
46
66
|
const props = defineProps<{
|
|
47
67
|
consoleItem: DevTool.ConsoleItem;
|
|
48
68
|
sourceFileServers?: string[];
|
|
49
69
|
mode?: string;
|
|
50
70
|
useDevSource?: boolean;
|
|
71
|
+
id: string;
|
|
51
72
|
}>();
|
|
52
73
|
|
|
53
74
|
const openCode = ref(false);
|
|
@@ -126,6 +147,11 @@ function onCloseCode() {
|
|
|
126
147
|
color: #616161;
|
|
127
148
|
text-align: right;
|
|
128
149
|
}
|
|
150
|
+
|
|
151
|
+
.console-tags {
|
|
152
|
+
display: flex;
|
|
153
|
+
align-items: center;
|
|
154
|
+
}
|
|
129
155
|
.console-time {
|
|
130
156
|
margin-right: auto;
|
|
131
157
|
word-break: break-all;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="run-js-input-wrapper">
|
|
3
|
+
<view class="run-js-input-icon"></view>
|
|
4
|
+
<input
|
|
5
|
+
v-model="code"
|
|
6
|
+
class="run-js-input"
|
|
7
|
+
placeholder="run..."
|
|
8
|
+
@confirm="onConfirm"
|
|
9
|
+
/>
|
|
10
|
+
</view>
|
|
11
|
+
</template>
|
|
12
|
+
<script lang="ts" setup>
|
|
13
|
+
import { ref } from 'vue';
|
|
14
|
+
|
|
15
|
+
const emit = defineEmits<{
|
|
16
|
+
(e: 'run', value: string): void;
|
|
17
|
+
}>();
|
|
18
|
+
|
|
19
|
+
const code = ref('');
|
|
20
|
+
|
|
21
|
+
function onConfirm() {
|
|
22
|
+
const value = code.value;
|
|
23
|
+
if (!value) return;
|
|
24
|
+
code.value = '';
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
emit('run', value);
|
|
27
|
+
}, 100);
|
|
28
|
+
}
|
|
29
|
+
</script>
|
|
30
|
+
<style scoped>
|
|
31
|
+
.run-js-input-wrapper {
|
|
32
|
+
position: relative;
|
|
33
|
+
display: flex;
|
|
34
|
+
padding: 0 16px;
|
|
35
|
+
min-height: 28px;
|
|
36
|
+
border-top: 1px solid var(--dev-tool-border-color);
|
|
37
|
+
border-bottom: 1px solid var(--dev-tool-border-color);
|
|
38
|
+
overflow: hidden;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.run-js-input-icon {
|
|
42
|
+
margin: 10px 0 10px -4px;
|
|
43
|
+
width: 8px;
|
|
44
|
+
height: 8px;
|
|
45
|
+
border: 1px solid #000;
|
|
46
|
+
border-bottom-color: transparent;
|
|
47
|
+
border-left-color: transparent;
|
|
48
|
+
overflow: hidden;
|
|
49
|
+
transform: rotate(45deg);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.run-js-input {
|
|
53
|
+
margin: 1px 0 1px 16px;
|
|
54
|
+
min-height: 26px;
|
|
55
|
+
width: 100%;
|
|
56
|
+
border: 1px solid transparent;
|
|
57
|
+
font-size: var(--dev-tool-base-font-size);
|
|
58
|
+
}
|
|
59
|
+
</style>
|
|
@@ -11,11 +11,16 @@
|
|
|
11
11
|
:mode="item.value"
|
|
12
12
|
:key="item.value"
|
|
13
13
|
:active="currentConsoleType === item.value"
|
|
14
|
-
@click="
|
|
14
|
+
@click="emit('choose', item.value)"
|
|
15
15
|
>{{ item.label }}</Tag
|
|
16
16
|
>
|
|
17
17
|
</view>
|
|
18
|
-
<view
|
|
18
|
+
<scroll-view
|
|
19
|
+
class="console-list"
|
|
20
|
+
scroll-y
|
|
21
|
+
scroll-with-animation="true"
|
|
22
|
+
:scroll-into-view="scrollIntoView"
|
|
23
|
+
>
|
|
19
24
|
<ConsoleItem
|
|
20
25
|
v-for="(item, index) in consoleList"
|
|
21
26
|
:consoleItem="item"
|
|
@@ -23,9 +28,11 @@
|
|
|
23
28
|
:sourceFileServers="sourceFileServers"
|
|
24
29
|
:mode="mode"
|
|
25
30
|
:useDevSource="useDevSource"
|
|
31
|
+
:id="`dev-console-${index}`"
|
|
26
32
|
/>
|
|
27
33
|
<Empty v-if="!consoleList || consoleList.length === 0" />
|
|
28
|
-
</view>
|
|
34
|
+
</scroll-view>
|
|
35
|
+
<RunJSInput @run="emit('run', $event)" />
|
|
29
36
|
</view>
|
|
30
37
|
</template>
|
|
31
38
|
<script setup lang="ts">
|
|
@@ -33,9 +40,12 @@ import ConsoleItem from './ConsoleItem.vue';
|
|
|
33
40
|
import Tag from '../Tag/index.vue';
|
|
34
41
|
import Empty from '../Empty/index.vue';
|
|
35
42
|
import FilterInput from '../FilterInput/index.vue';
|
|
43
|
+
import RunJSInput from './RunJSInput.vue';
|
|
36
44
|
import type { DevTool } from '../../type';
|
|
45
|
+
import { ref, watch } from 'vue';
|
|
46
|
+
import { debounce } from '../../utils';
|
|
37
47
|
type ConsoleType = 'all' | 'log' | 'info' | 'warn' | 'error' | 'clear';
|
|
38
|
-
defineProps<{
|
|
48
|
+
const props = defineProps<{
|
|
39
49
|
consoleList: DevTool.ConsoleItem[];
|
|
40
50
|
currentConsoleType: string;
|
|
41
51
|
modelValue: string;
|
|
@@ -47,6 +57,7 @@ const emit = defineEmits<{
|
|
|
47
57
|
(e: 'choose', type: ConsoleType): void;
|
|
48
58
|
(e: 'search', value: string): void;
|
|
49
59
|
(e: 'update:modelValue', value: string): void;
|
|
60
|
+
(e: 'run', value: string): void;
|
|
50
61
|
}>();
|
|
51
62
|
const consoleFilterItems: {
|
|
52
63
|
label: string;
|
|
@@ -78,9 +89,14 @@ const consoleFilterItems: {
|
|
|
78
89
|
},
|
|
79
90
|
];
|
|
80
91
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
const scrollIntoView = ref('');
|
|
93
|
+
|
|
94
|
+
const debounceWatch = debounce(() => {
|
|
95
|
+
scrollIntoView.value = `dev-console-${props.consoleList.length - 1}`;
|
|
96
|
+
console.log('props.consoleList: ', props.consoleList);
|
|
97
|
+
}, 200);
|
|
98
|
+
|
|
99
|
+
watch(() => props.consoleList, debounceWatch);
|
|
84
100
|
</script>
|
|
85
101
|
<style scoped>
|
|
86
102
|
.console-content {
|
|
@@ -88,7 +104,7 @@ function onChoose(type: ConsoleType) {
|
|
|
88
104
|
font-size: var(--dev-tool-base-font-size);
|
|
89
105
|
}
|
|
90
106
|
.console-list {
|
|
91
|
-
height: calc(100% - 32px);
|
|
107
|
+
height: calc(100% - 32px - 32px);
|
|
92
108
|
overflow: auto;
|
|
93
109
|
}
|
|
94
110
|
.console-control {
|
|
@@ -28,6 +28,7 @@ import { onShow, onHide, onUnload, onLoad } from '@dcloudio/uni-app';
|
|
|
28
28
|
import { reactive, ref, nextTick } from 'vue';
|
|
29
29
|
import DevToolButton from '../DevToolButton/index.vue';
|
|
30
30
|
import DevToolWindow from '../DevToolWindow/index.vue';
|
|
31
|
+
import { eventBus } from '../../core';
|
|
31
32
|
|
|
32
33
|
import {
|
|
33
34
|
EVENT_DEV_BUTTON,
|
|
@@ -82,7 +83,7 @@ async function onShowDevToolWindow(show: boolean) {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
function onSendMessage(param: { type: string; data: Record<string, any> }) {
|
|
85
|
-
|
|
86
|
+
eventBus.emit(DEV_WINDOW_MESSAGE, param);
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
function onDevOptionSend(options: DevTool.DevToolOptions) {
|
|
@@ -110,22 +111,22 @@ onLoad(() => {
|
|
|
110
111
|
isActive = true;
|
|
111
112
|
devToolButtonVisible.value = uni.getStorageSync(EVENT_DEV_BUTTON) || false;
|
|
112
113
|
devToolWindowVisible.value = show;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
eventBus.on(EVENT_DEV_BUTTON, onShowDevToolButton);
|
|
115
|
+
eventBus.on(EVENT_DEV_WINDOW, onShowDevToolWindow);
|
|
116
|
+
eventBus.on(DEV_OPTION_SEND, onDevOptionSend);
|
|
116
117
|
|
|
117
118
|
nextTick(() => {
|
|
118
|
-
|
|
119
|
+
eventBus.emit(DEV_WINDOW_MESSAGE, { type: DEV_OPTION_GET, data: {} });
|
|
119
120
|
});
|
|
120
121
|
});
|
|
121
122
|
|
|
122
123
|
onUnload(() => {
|
|
123
|
-
|
|
124
|
+
eventBus.emit(DEV_WINDOW_MESSAGE, {
|
|
124
125
|
type: DEV_WINDOW_CLOSE,
|
|
125
126
|
data: {},
|
|
126
127
|
});
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
eventBus.off(EVENT_DEV_BUTTON, onShowDevToolButton);
|
|
129
|
+
eventBus.off(EVENT_DEV_WINDOW, onShowDevToolWindow);
|
|
129
130
|
});
|
|
130
131
|
|
|
131
132
|
onShow(() => {
|
|
@@ -166,7 +167,7 @@ onHide(() => {
|
|
|
166
167
|
|
|
167
168
|
.dev-tool-canvas {
|
|
168
169
|
position: fixed;
|
|
169
|
-
z-index: -
|
|
170
|
+
z-index: -1000;
|
|
170
171
|
top: 0;
|
|
171
172
|
left: 0;
|
|
172
173
|
width: 100vw;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
width: props.buttonSize + 'px',
|
|
10
10
|
height: props.buttonSize + 'px',
|
|
11
11
|
cursor: isDragging ? 'move' : 'pointer',
|
|
12
|
-
...buttonPosition
|
|
12
|
+
...buttonPosition,
|
|
13
13
|
}"
|
|
14
14
|
@touchstart="onTouchStart"
|
|
15
15
|
@touchmove="onTouchMove"
|
|
@@ -33,7 +33,7 @@ const props = withDefaults(
|
|
|
33
33
|
buttonFontSize?: string;
|
|
34
34
|
buttonBackgroundColor?: string;
|
|
35
35
|
}>(),
|
|
36
|
-
{ buttonSize: 50 }
|
|
36
|
+
{ buttonSize: 50 },
|
|
37
37
|
);
|
|
38
38
|
const sizeHalf = props.buttonSize / 2;
|
|
39
39
|
|
|
@@ -45,7 +45,7 @@ const { windowWidth, windowHeight } = uni.getSystemInfoSync();
|
|
|
45
45
|
const buttonPosition = reactive({
|
|
46
46
|
left: windowWidth - props.buttonSize + 'px',
|
|
47
47
|
top: '80vh',
|
|
48
|
-
transition: 'none'
|
|
48
|
+
transition: 'none',
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
const isTouchDevice = computed(() => {
|
|
@@ -71,7 +71,7 @@ function onTouchMove(touch: TouchEvent) {
|
|
|
71
71
|
updatePosition(
|
|
72
72
|
touch.touches[0].pageX,
|
|
73
73
|
touch.touches[0].pageY,
|
|
74
|
-
isTouchDevice.value
|
|
74
|
+
isTouchDevice.value,
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -102,7 +102,7 @@ function onMouseDown(event: MouseEvent) {
|
|
|
102
102
|
buttonPosition.transition = 'none';
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
let timer:
|
|
105
|
+
let timer: number | null = null;
|
|
106
106
|
function onResize() {
|
|
107
107
|
const { windowWidth } = uni.getSystemInfoSync();
|
|
108
108
|
|
|
@@ -116,7 +116,7 @@ function onResize() {
|
|
|
116
116
|
|
|
117
117
|
uni.setStorageSync(DEV_BUTTON_INFO, {
|
|
118
118
|
left: buttonPosition.left,
|
|
119
|
-
top: buttonPosition.top
|
|
119
|
+
top: buttonPosition.top,
|
|
120
120
|
});
|
|
121
121
|
}, 350);
|
|
122
122
|
}
|
|
@@ -124,7 +124,7 @@ function onResize() {
|
|
|
124
124
|
onMounted(() => {
|
|
125
125
|
const { left, top } = uni.getStorageSync(DEV_BUTTON_INFO) || {
|
|
126
126
|
left: windowWidth - props.buttonSize + 'px',
|
|
127
|
-
top: '80vh'
|
|
127
|
+
top: '80vh',
|
|
128
128
|
};
|
|
129
129
|
buttonPosition.left = left;
|
|
130
130
|
buttonPosition.top = top;
|
|
@@ -133,7 +133,7 @@ onMounted(() => {
|
|
|
133
133
|
onShow(() => {
|
|
134
134
|
const { left, top } = uni.getStorageSync(DEV_BUTTON_INFO) || {
|
|
135
135
|
left: windowWidth - props.buttonSize + 'px',
|
|
136
|
-
top: '80vh'
|
|
136
|
+
top: '80vh',
|
|
137
137
|
};
|
|
138
138
|
buttonPosition.left = left;
|
|
139
139
|
buttonPosition.top = top;
|
|
@@ -164,7 +164,7 @@ function onMouseMove(event: MouseEvent) {
|
|
|
164
164
|
updatePosition(mouseX, mouseY);
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
let mouseUpTimer:
|
|
167
|
+
let mouseUpTimer: number | null = null;
|
|
168
168
|
function onMouseUp() {
|
|
169
169
|
isDragging.value = false; // 鼠标释放时取消拖拽状态
|
|
170
170
|
if (Date.now() - startTime < 150) {
|
|
@@ -195,7 +195,7 @@ function updatePosition(x: number, y: number, isTouch = false) {
|
|
|
195
195
|
<style scoped>
|
|
196
196
|
.dev-tool-button {
|
|
197
197
|
position: fixed;
|
|
198
|
-
z-index:
|
|
198
|
+
z-index: 1000;
|
|
199
199
|
top: 80vh;
|
|
200
200
|
right: 0;
|
|
201
201
|
display: flex;
|