vite-uni-dev-tool 0.0.13 → 0.0.14
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/dist/v2/AppInfo/index.vue +41 -0
- package/dist/v2/AutoSizer/index.vue +189 -0
- package/dist/v2/AutoSizer/index1.vue +193 -0
- package/dist/v2/AutoSizer/utils.ts +49 -0
- package/dist/v2/CaptureScreen/index.vue +78 -0
- package/dist/v2/CloseButton/index.vue +32 -0
- package/dist/v2/Connection/index.vue +94 -0
- package/dist/v2/ConsoleList/ConsoleItem.vue +235 -0
- package/dist/v2/ConsoleList/RunJSInput.vue +243 -0
- package/dist/v2/ConsoleList/index.vue +164 -0
- package/dist/v2/ConsoleList/staticTips.js +1144 -0
- package/dist/v2/DevTool/index.vue +162 -0
- package/dist/v2/DevToolButton/index.vue +228 -0
- package/dist/v2/DevToolTitle/index.vue +28 -0
- package/dist/v2/DevToolWindow/index.vue +1051 -0
- package/dist/v2/DeviceInfo/index.vue +48 -0
- package/dist/v2/Empty/empty.png +0 -0
- package/dist/v2/Empty/index.vue +40 -0
- package/dist/v2/FilterInput/index.vue +100 -0
- package/dist/v2/JsonPretty/components/Brackets/index.vue +30 -0
- package/dist/v2/JsonPretty/components/Carets/index.vue +65 -0
- package/dist/v2/JsonPretty/components/CheckController/index.vue +127 -0
- package/dist/v2/JsonPretty/components/TreeNode/index.vue +417 -0
- package/dist/v2/JsonPretty/hooks/useClipboard.ts +21 -0
- package/dist/v2/JsonPretty/hooks/useError.ts +21 -0
- package/dist/v2/JsonPretty/index.vue +531 -0
- package/dist/v2/JsonPretty/type.ts +125 -0
- package/dist/v2/JsonPretty/utils/index.js +211 -0
- package/dist/v2/NetworkList/NetworkDetail.vue +215 -0
- package/dist/v2/NetworkList/NetworkItem.vue +135 -0
- package/dist/v2/NetworkList/index.vue +148 -0
- package/dist/v2/PiniaList/index.vue +79 -0
- package/dist/v2/RouteList/index.vue +137 -0
- package/dist/v2/RunJS/index.vue +128 -0
- package/dist/v2/SettingList/index.vue +318 -0
- package/dist/v2/SourceCode/index.vue +237 -0
- package/dist/v2/StorageList/index.vue +165 -0
- package/dist/v2/SystemInfo/index.vue +49 -0
- package/dist/v2/Tabs/index.vue +127 -0
- package/dist/v2/Tag/index.vue +91 -0
- package/dist/v2/UniEvent/UniEventItem.vue +157 -0
- package/dist/v2/UniEvent/index.vue +127 -0
- package/dist/v2/UploadList/UploadDetail.vue +204 -0
- package/dist/v2/UploadList/UploadItem.vue +134 -0
- package/dist/v2/UploadList/index.vue +143 -0
- package/dist/v2/VirtualList/index.vue +140 -0
- package/dist/v2/VirtualListPro/AutoSize.vue +50 -0
- package/dist/v2/VirtualListPro/index.vue +255 -0
- package/dist/v2/VirtualListPro/readme.md +40 -0
- package/dist/v2/VuexList/index.vue +80 -0
- package/dist/v2/WebSocket/WebSocketItem.vue +129 -0
- package/dist/v2/WebSocket/WebSocketList.vue +183 -0
- package/dist/v2/WebSocket/index.vue +155 -0
- package/dist/v2/WindowInfo/index.vue +49 -0
- package/dist/v3/AppInfo/index.vue +35 -0
- package/dist/v3/AutoSizer/index.vue +193 -0
- package/dist/v3/AutoSizer/index1.vue +186 -0
- package/dist/v3/AutoSizer/utils.ts +49 -0
- package/dist/v3/CaptureScreen/index.vue +62 -0
- package/dist/v3/CloseButton/index.vue +29 -0
- package/dist/v3/Connection/index.vue +88 -0
- package/dist/v3/ConsoleList/ConsoleItem.vue +208 -0
- package/dist/v3/ConsoleList/RunJSInput.vue +240 -0
- package/dist/v3/ConsoleList/index.vue +139 -0
- package/dist/v3/ConsoleList/staticTips.ts +1145 -0
- package/dist/v3/DevTool/index.vue +217 -0
- package/dist/v3/DevToolButton/index.vue +210 -0
- package/dist/v3/DevToolTitle/index.vue +21 -0
- package/dist/v3/DevToolWindow/index.vue +1116 -0
- package/dist/v3/DeviceInfo/index.vue +32 -0
- package/dist/v3/Empty/empty.png +0 -0
- package/dist/v3/Empty/index.vue +28 -0
- package/dist/v3/FilterInput/index.vue +87 -0
- package/dist/v3/JsonPretty/components/Brackets/index.vue +23 -0
- package/dist/v3/JsonPretty/components/Carets/index.vue +59 -0
- package/dist/v3/JsonPretty/components/CheckController/index.vue +125 -0
- package/dist/v3/JsonPretty/components/TreeNode/index.vue +349 -0
- package/dist/v3/JsonPretty/hooks/useClipboard.ts +21 -0
- package/dist/v3/JsonPretty/hooks/useError.ts +21 -0
- package/dist/v3/JsonPretty/index.vue +476 -0
- package/dist/v3/JsonPretty/type.ts +125 -0
- package/dist/v3/JsonPretty/utils/index.ts +172 -0
- package/dist/v3/NetworkList/NetworkDetail.vue +194 -0
- package/dist/v3/NetworkList/NetworkItem.vue +120 -0
- package/dist/v3/NetworkList/index.vue +128 -0
- package/dist/v3/PiniaList/index.vue +64 -0
- package/dist/v3/RouteList/index.vue +121 -0
- package/dist/v3/RunJS/index.vue +128 -0
- package/dist/v3/SettingList/index.vue +313 -0
- package/dist/v3/SourceCode/index.vue +231 -0
- package/dist/v3/StorageList/index.vue +170 -0
- package/dist/v3/SystemInfo/index.vue +34 -0
- package/dist/v3/Tabs/index.vue +123 -0
- package/dist/v3/Tag/index.vue +89 -0
- package/dist/v3/UniEvent/UniEventItem.vue +126 -0
- package/dist/v3/UniEvent/index.vue +98 -0
- package/dist/v3/UploadList/UploadDetail.vue +192 -0
- package/dist/v3/UploadList/UploadItem.vue +117 -0
- package/dist/v3/UploadList/index.vue +117 -0
- package/dist/v3/VirtualList/index.vue +112 -0
- package/dist/v3/VirtualListPro/AutoSize.vue +43 -0
- package/dist/v3/VirtualListPro/index.vue +238 -0
- package/dist/v3/VirtualListPro/readme.md +40 -0
- package/dist/v3/VuexList/index.vue +54 -0
- package/dist/v3/WebSocket/WebSocketItem.vue +103 -0
- package/dist/v3/WebSocket/WebSocketList.vue +161 -0
- package/dist/v3/WebSocket/index.vue +124 -0
- package/dist/v3/WindowInfo/index.vue +33 -0
- package/package.json +1 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="`dev-tool dev-tool-${theme}`">
|
|
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
|
+
:zIndex="zIndex"
|
|
11
|
+
@click="onDevToolButtonClick"
|
|
12
|
+
/>
|
|
13
|
+
<DevToolWindow
|
|
14
|
+
:open="devToolWindowVisible"
|
|
15
|
+
:data="windowData"
|
|
16
|
+
:sourceFileServers="sourceFileServers"
|
|
17
|
+
:mode="mode"
|
|
18
|
+
:useDevSource="useDevSource"
|
|
19
|
+
:zIndex="zIndex + 1"
|
|
20
|
+
:theme="theme"
|
|
21
|
+
@close="onShowDevToolWindow(false)"
|
|
22
|
+
@sendMessage="onSendMessage"
|
|
23
|
+
@changeTheme="onChangeTheme"
|
|
24
|
+
/>
|
|
25
|
+
</view>
|
|
26
|
+
</template>
|
|
27
|
+
<script lang="ts" setup>
|
|
28
|
+
import { onShow, onHide, onUnload, onLoad } from '@dcloudio/uni-app';
|
|
29
|
+
import { reactive, ref, nextTick } from 'vue';
|
|
30
|
+
import DevToolButton from '../DevToolButton/index.vue';
|
|
31
|
+
import DevToolWindow from '../DevToolWindow/index.vue';
|
|
32
|
+
import { eventBus } from '../../core';
|
|
33
|
+
|
|
34
|
+
import {
|
|
35
|
+
DEV_BUTTON_VISIBLE,
|
|
36
|
+
DEV_WINDOW_VISIBLE,
|
|
37
|
+
DEV_WINDOW_MESSAGE,
|
|
38
|
+
DEV_WINDOW_OPEN,
|
|
39
|
+
DEV_WINDOW_CLOSE,
|
|
40
|
+
DEV_OPTION_GET,
|
|
41
|
+
DEV_OPTION_SEND,
|
|
42
|
+
} from '../../const';
|
|
43
|
+
import type { DevTool } from '../../type';
|
|
44
|
+
import { getDevToolInfo, setDevToolInfo } from '../../devToolInfo';
|
|
45
|
+
|
|
46
|
+
let isActive = false;
|
|
47
|
+
|
|
48
|
+
const buttonProps = reactive({
|
|
49
|
+
buttonSize: 50,
|
|
50
|
+
buttonText: '🐜',
|
|
51
|
+
buttonColor: '#fff',
|
|
52
|
+
buttonFontSize: '16px',
|
|
53
|
+
buttonBackgroundColor: 'rgba(255, 255, 255, 0)',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const windowData = ref<DevTool.WindowData>({});
|
|
57
|
+
|
|
58
|
+
const devToolWindowVisible = ref(false);
|
|
59
|
+
const devToolButtonVisible = ref(false);
|
|
60
|
+
|
|
61
|
+
const sourceFileServers = ref<string[]>([]);
|
|
62
|
+
|
|
63
|
+
const mode = ref<string>();
|
|
64
|
+
|
|
65
|
+
const zIndex = ref(1000);
|
|
66
|
+
|
|
67
|
+
const useDevSource = ref(false);
|
|
68
|
+
|
|
69
|
+
const theme = ref<string>('dart');
|
|
70
|
+
|
|
71
|
+
function onDevToolButtonClick() {
|
|
72
|
+
onShowDevToolWindow(true);
|
|
73
|
+
onSendMessage({
|
|
74
|
+
type: DEV_WINDOW_OPEN,
|
|
75
|
+
data: {},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function onShowDevToolButton(show: boolean) {
|
|
80
|
+
if (!isActive) return;
|
|
81
|
+
|
|
82
|
+
const { devToolButtonVisible: showButton = false } = getDevToolInfo();
|
|
83
|
+
|
|
84
|
+
devToolButtonVisible.value = show ?? showButton;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function onShowDevToolWindow(show: boolean) {
|
|
88
|
+
if (!isActive) return;
|
|
89
|
+
|
|
90
|
+
devToolWindowVisible.value = show;
|
|
91
|
+
|
|
92
|
+
setDevToolInfo({
|
|
93
|
+
devToolWindowVisible: show,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function onSendMessage(param: { type: string; data: Record<string, any> }) {
|
|
98
|
+
eventBus.emit(DEV_WINDOW_MESSAGE, param);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function onDevOptionSend(options: DevTool.DevToolOptions) {
|
|
102
|
+
if (options) {
|
|
103
|
+
buttonProps.buttonSize = options.buttonSize ?? 50;
|
|
104
|
+
buttonProps.buttonText = options.buttonText ?? '🐜';
|
|
105
|
+
buttonProps.buttonColor = options.buttonColor ?? '#fff';
|
|
106
|
+
buttonProps.buttonFontSize = options.buttonFontSize ?? '16px';
|
|
107
|
+
buttonProps.buttonBackgroundColor =
|
|
108
|
+
options.buttonBackgroundColor ?? 'rgba(255, 255, 255, 0)';
|
|
109
|
+
|
|
110
|
+
sourceFileServers.value = options.sourceFileServers ?? [];
|
|
111
|
+
|
|
112
|
+
mode.value = options.mode ?? '';
|
|
113
|
+
|
|
114
|
+
useDevSource.value = options.useDevSource ?? false;
|
|
115
|
+
|
|
116
|
+
zIndex.value = options.zIndex ?? 1000;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function onChangeTheme(t: string) {
|
|
121
|
+
theme.value = t;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
onLoad(() => {
|
|
125
|
+
// 共享状态
|
|
126
|
+
|
|
127
|
+
const {
|
|
128
|
+
devToolButtonVisible: showButton = false,
|
|
129
|
+
|
|
130
|
+
devToolWindowVisible: showWindow = false,
|
|
131
|
+
} = getDevToolInfo();
|
|
132
|
+
|
|
133
|
+
isActive = true;
|
|
134
|
+
devToolButtonVisible.value = showButton;
|
|
135
|
+
devToolWindowVisible.value = showWindow;
|
|
136
|
+
eventBus.on(DEV_BUTTON_VISIBLE, onShowDevToolButton);
|
|
137
|
+
eventBus.on(DEV_WINDOW_VISIBLE, onShowDevToolWindow);
|
|
138
|
+
eventBus.on(DEV_OPTION_SEND, onDevOptionSend);
|
|
139
|
+
|
|
140
|
+
nextTick(() => {
|
|
141
|
+
eventBus.emit(DEV_WINDOW_MESSAGE, { type: DEV_OPTION_GET, data: {} });
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
onUnload(() => {
|
|
146
|
+
eventBus.emit(DEV_WINDOW_MESSAGE, {
|
|
147
|
+
type: DEV_WINDOW_CLOSE,
|
|
148
|
+
data: {},
|
|
149
|
+
});
|
|
150
|
+
eventBus.off(DEV_BUTTON_VISIBLE, onShowDevToolButton);
|
|
151
|
+
eventBus.off(DEV_WINDOW_VISIBLE, onShowDevToolWindow);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
onShow(() => {
|
|
155
|
+
isActive = true;
|
|
156
|
+
const {
|
|
157
|
+
devToolButtonVisible: showButton = false,
|
|
158
|
+
|
|
159
|
+
devToolWindowVisible: showWindow = false,
|
|
160
|
+
} = getDevToolInfo();
|
|
161
|
+
|
|
162
|
+
devToolWindowVisible.value = showWindow;
|
|
163
|
+
devToolButtonVisible.value = showButton;
|
|
164
|
+
|
|
165
|
+
if (devToolWindowVisible.value) {
|
|
166
|
+
onSendMessage({
|
|
167
|
+
type: DEV_WINDOW_OPEN,
|
|
168
|
+
data: {},
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
onHide(() => {
|
|
173
|
+
isActive = false;
|
|
174
|
+
devToolWindowVisible.value = false;
|
|
175
|
+
});
|
|
176
|
+
</script>
|
|
177
|
+
<style scoped>
|
|
178
|
+
.dev-tool {
|
|
179
|
+
--dev-tool-main-color: #9254de;
|
|
180
|
+
--dev-tool-normal-bg-color: #f9f9f9;
|
|
181
|
+
--dev-tool-warn-color: #ffa940;
|
|
182
|
+
--dev-tool-warn-bg-color: #fff7e6;
|
|
183
|
+
--dev-tool-error-color: #ff4d4f;
|
|
184
|
+
--dev-tool-error-bg-color: #fff1f0;
|
|
185
|
+
--dev-tool-success-color: #bae637;
|
|
186
|
+
--dev-tool-success-bg-color: #fcffe6;
|
|
187
|
+
|
|
188
|
+
--dev-tool-base-font-size: 12px;
|
|
189
|
+
--dev-tool-tag-font-size: 10px;
|
|
190
|
+
--dev-tool-tips-font-size: 10px;
|
|
191
|
+
-webkit-tap-highlight-color: transparent;
|
|
192
|
+
}
|
|
193
|
+
.dev-tool-light {
|
|
194
|
+
--dev-tool-bg-color: rgba(255, 255, 255, 0.8);
|
|
195
|
+
--dev-tool-bg2-color: rgba(255, 255, 255, 0.95);
|
|
196
|
+
|
|
197
|
+
--dev-tool-text-color: #000;
|
|
198
|
+
--dev-tool-border-color: #f0f0f0;
|
|
199
|
+
--dev-tool-info-color: #9c9c9c;
|
|
200
|
+
--dev-tool-log-color: #f9f9f9;
|
|
201
|
+
--dev-tool-nil-color: #020201;
|
|
202
|
+
--dev-tool-string-color: #888888;
|
|
203
|
+
--dev-tool-number-color: #1d8ce0;
|
|
204
|
+
--dev-tool-boolean-color: #1d8ce0;
|
|
205
|
+
--dev-tool-symbol-color: bisque;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.dev-tool-dart {
|
|
209
|
+
--dev-tool-bg-color: rgba(0, 0, 0, 0.8);
|
|
210
|
+
--dev-tool-bg2-color: rgba(43, 43, 43, 0.8);
|
|
211
|
+
|
|
212
|
+
--dev-tool-text-color: #fff;
|
|
213
|
+
--dev-tool-border-color: #3d3d3d;
|
|
214
|
+
|
|
215
|
+
--dev-tool-log-color: #f9f9f9;
|
|
216
|
+
}
|
|
217
|
+
</style>
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
ref="buttonRef"
|
|
4
|
+
class="dev-tool-button"
|
|
5
|
+
:style="{
|
|
6
|
+
fontSize: props.buttonFontSize,
|
|
7
|
+
backgroundColor: props.buttonBackgroundColor,
|
|
8
|
+
color: props.buttonColor,
|
|
9
|
+
width: props.buttonSize + 'px',
|
|
10
|
+
height: props.buttonSize + 'px',
|
|
11
|
+
cursor: isDragging ? 'move' : 'pointer',
|
|
12
|
+
zIndex: zIndex,
|
|
13
|
+
...buttonPosition,
|
|
14
|
+
}"
|
|
15
|
+
@touchstart="onTouchStart"
|
|
16
|
+
@touchmove="onTouchMove"
|
|
17
|
+
@touchend="onTouchEnd"
|
|
18
|
+
@mousedown="onMouseDown"
|
|
19
|
+
>
|
|
20
|
+
{{ buttonText }}
|
|
21
|
+
</view>
|
|
22
|
+
</template>
|
|
23
|
+
<script lang="ts" setup>
|
|
24
|
+
import { onShow, onHide } from '@dcloudio/uni-app';
|
|
25
|
+
import { ref, computed, reactive, onMounted } from 'vue';
|
|
26
|
+
import { getDevToolInfo, setDevToolInfo } from '../../devToolInfo';
|
|
27
|
+
|
|
28
|
+
const emit = defineEmits<{ (e: 'click'): void }>();
|
|
29
|
+
const props = withDefaults(
|
|
30
|
+
defineProps<{
|
|
31
|
+
buttonSize?: number;
|
|
32
|
+
buttonText?: string;
|
|
33
|
+
buttonColor?: string;
|
|
34
|
+
buttonFontSize?: string;
|
|
35
|
+
buttonBackgroundColor?: string;
|
|
36
|
+
zIndex?: number;
|
|
37
|
+
}>(),
|
|
38
|
+
{ buttonSize: 50, zIndex: 1000 },
|
|
39
|
+
);
|
|
40
|
+
const sizeHalf = props.buttonSize / 2;
|
|
41
|
+
|
|
42
|
+
let page: { pageX: number; pageY: number } = { pageX: 0, pageY: 0 };
|
|
43
|
+
let startTime = 0;
|
|
44
|
+
|
|
45
|
+
const { windowWidth, windowHeight } = uni.getSystemInfoSync();
|
|
46
|
+
// const buttonRef = ref();
|
|
47
|
+
const buttonPosition = reactive({
|
|
48
|
+
left: windowWidth - props.buttonSize + 'px',
|
|
49
|
+
top: '80vh',
|
|
50
|
+
transition: 'none',
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const isTouchDevice = computed(() => {
|
|
54
|
+
return typeof window !== 'undefined' && 'ontouchstart' in window;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
function onTouchStart(touch: TouchEvent) {
|
|
58
|
+
page.pageX = touch.touches?.[0]?.pageX;
|
|
59
|
+
page.pageY = touch.touches?.[0]?.pageY;
|
|
60
|
+
startTime = Date.now();
|
|
61
|
+
buttonPosition.transition = 'none';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function onTouchMove(touch: TouchEvent) {
|
|
65
|
+
touch?.preventDefault?.();
|
|
66
|
+
touch?.stopPropagation?.();
|
|
67
|
+
if (!page) return;
|
|
68
|
+
if (Date.now() - startTime < 150) return;
|
|
69
|
+
|
|
70
|
+
if (mouseUpTimer) {
|
|
71
|
+
clearTimeout(mouseUpTimer);
|
|
72
|
+
}
|
|
73
|
+
updatePosition(
|
|
74
|
+
touch.touches[0].pageX,
|
|
75
|
+
touch.touches[0].pageY,
|
|
76
|
+
isTouchDevice.value,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function onTouchEnd() {
|
|
81
|
+
if (Date.now() - startTime < 100) {
|
|
82
|
+
emit('click');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (mouseUpTimer) {
|
|
86
|
+
clearTimeout(mouseUpTimer);
|
|
87
|
+
}
|
|
88
|
+
mouseUpTimer = setTimeout(() => {
|
|
89
|
+
onResize();
|
|
90
|
+
}, 3000);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let isDragging = ref(false); // 是否开始拖拽
|
|
94
|
+
|
|
95
|
+
// 鼠标事件处理
|
|
96
|
+
function onMouseDown(event: MouseEvent) {
|
|
97
|
+
if (isTouchDevice.value) return;
|
|
98
|
+
page.pageX = event.pageX;
|
|
99
|
+
page.pageY = event.pageY;
|
|
100
|
+
startTime = Date.now();
|
|
101
|
+
isDragging.value = true; // 开始鼠标按下时标记为拖拽状态
|
|
102
|
+
event.preventDefault(); // 防止选中内容
|
|
103
|
+
event.stopPropagation(); // 防止事件冒泡
|
|
104
|
+
buttonPosition.transition = 'none';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let timer: number | null = null;
|
|
108
|
+
function onResize() {
|
|
109
|
+
const { windowWidth } = uni.getSystemInfoSync();
|
|
110
|
+
|
|
111
|
+
buttonPosition.transition = 'all 0.3s ease-in-out';
|
|
112
|
+
buttonPosition.left = windowWidth - props.buttonSize + 'px';
|
|
113
|
+
if (timer) {
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
}
|
|
116
|
+
timer = setTimeout(() => {
|
|
117
|
+
buttonPosition.transition = 'none';
|
|
118
|
+
setDevToolInfo({
|
|
119
|
+
left: buttonPosition.left,
|
|
120
|
+
top: buttonPosition.top,
|
|
121
|
+
});
|
|
122
|
+
}, 350);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
onMounted(() => {
|
|
126
|
+
const { left = windowWidth - props.buttonSize + 'px', top = '80vh' } =
|
|
127
|
+
getDevToolInfo();
|
|
128
|
+
buttonPosition.left = left;
|
|
129
|
+
buttonPosition.top = top;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
onShow(() => {
|
|
133
|
+
const { left = windowWidth - props.buttonSize + 'px', top = '80vh' } =
|
|
134
|
+
getDevToolInfo();
|
|
135
|
+
buttonPosition.left = left;
|
|
136
|
+
buttonPosition.top = top;
|
|
137
|
+
|
|
138
|
+
// #ifdef H5
|
|
139
|
+
window.addEventListener('mousemove', onMouseMove);
|
|
140
|
+
window.addEventListener('mouseup', onMouseUp);
|
|
141
|
+
window.addEventListener('resize', onResize);
|
|
142
|
+
// #endif
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
onHide(() => {
|
|
146
|
+
// #ifdef H5
|
|
147
|
+
window.removeEventListener('mousemove', onMouseMove);
|
|
148
|
+
window.removeEventListener('mouseup', onMouseUp);
|
|
149
|
+
window.removeEventListener('resize', onResize);
|
|
150
|
+
// #endif
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
function onMouseMove(event: MouseEvent) {
|
|
154
|
+
if (!isDragging.value) return; // 不是拖拽状态则不处理
|
|
155
|
+
event.preventDefault(); // 防止默认行为
|
|
156
|
+
const mouseX = event.pageX;
|
|
157
|
+
const mouseY = event.pageY;
|
|
158
|
+
if (mouseUpTimer) {
|
|
159
|
+
clearTimeout(mouseUpTimer);
|
|
160
|
+
}
|
|
161
|
+
updatePosition(mouseX, mouseY);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let mouseUpTimer: number | null = null;
|
|
165
|
+
function onMouseUp() {
|
|
166
|
+
isDragging.value = false; // 鼠标释放时取消拖拽状态
|
|
167
|
+
if (Date.now() - startTime < 150) {
|
|
168
|
+
emit('click');
|
|
169
|
+
}
|
|
170
|
+
if (mouseUpTimer) {
|
|
171
|
+
clearTimeout(mouseUpTimer);
|
|
172
|
+
}
|
|
173
|
+
mouseUpTimer = setTimeout(() => {
|
|
174
|
+
onResize();
|
|
175
|
+
}, 3000);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 统一的位置更新函数
|
|
179
|
+
function updatePosition(x: number, y: number, isTouch = false) {
|
|
180
|
+
if (y - sizeHalf > 0 && y < windowHeight - sizeHalf) {
|
|
181
|
+
if (isTouch) {
|
|
182
|
+
buttonPosition.top = y + sizeHalf + 'px';
|
|
183
|
+
} else {
|
|
184
|
+
buttonPosition.top = y - sizeHalf + 'px';
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (x - sizeHalf > 0 && x < windowWidth - sizeHalf) {
|
|
188
|
+
buttonPosition.left = x - sizeHalf + 'px';
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
</script>
|
|
192
|
+
<style scoped>
|
|
193
|
+
.dev-tool-button {
|
|
194
|
+
position: fixed;
|
|
195
|
+
z-index: 1000;
|
|
196
|
+
top: 80vh;
|
|
197
|
+
right: 0;
|
|
198
|
+
display: flex;
|
|
199
|
+
align-items: center;
|
|
200
|
+
justify-content: center;
|
|
201
|
+
|
|
202
|
+
width: 50px;
|
|
203
|
+
height: 50px;
|
|
204
|
+
border-radius: 50%;
|
|
205
|
+
font-size: 16px;
|
|
206
|
+
|
|
207
|
+
background-color: rgba(255, 255, 255, 0);
|
|
208
|
+
cursor: pointer;
|
|
209
|
+
}
|
|
210
|
+
</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="dev-tool-title" :style="innerStyle"> <slot /> </view>
|
|
3
|
+
</template>
|
|
4
|
+
<script lang="ts" setup>
|
|
5
|
+
defineProps<{ innerStyle?: any }>();
|
|
6
|
+
</script>
|
|
7
|
+
<style scoped>
|
|
8
|
+
.dev-tool-title {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
height: 32px;
|
|
12
|
+
}
|
|
13
|
+
.dev-tool-title::before {
|
|
14
|
+
content: '';
|
|
15
|
+
margin-right: 8px;
|
|
16
|
+
width: 2px;
|
|
17
|
+
height: 18px;
|
|
18
|
+
border-radius: 2px;
|
|
19
|
+
background-color: var(--dev-tool-main-color);
|
|
20
|
+
}
|
|
21
|
+
</style>
|