vite-uni-dev-tool 1.1.0 → 1.2.0
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 +8 -0
- package/dist/const.cjs +1 -1
- package/dist/const.d.ts +1 -0
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +1 -1
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +2 -2
- package/dist/i18n/locales/en.cjs +1 -1
- package/dist/i18n/locales/en.d.ts +5 -0
- package/dist/i18n/locales/en.d.ts.map +1 -1
- package/dist/i18n/locales/en.js +1 -1
- package/dist/i18n/locales/zh-Hans.cjs +1 -1
- package/dist/i18n/locales/zh-Hans.d.ts +5 -0
- package/dist/i18n/locales/zh-Hans.d.ts.map +1 -1
- package/dist/i18n/locales/zh-Hans.js +1 -1
- package/dist/modules/devIntercept/index.cjs +9 -9
- package/dist/modules/devIntercept/index.d.ts +1 -1
- package/dist/modules/devIntercept/index.d.ts.map +1 -1
- package/dist/modules/devIntercept/index.js +9 -9
- package/dist/modules/devStore/index.cjs +1 -1
- package/dist/modules/devStore/index.d.ts.map +1 -1
- package/dist/modules/devStore/index.js +1 -1
- package/dist/plugins/uniDevTool/transform/transformMain.cjs +3 -3
- package/dist/plugins/uniDevTool/transform/transformMain.d.ts +2 -1
- package/dist/plugins/uniDevTool/transform/transformMain.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/transform/transformMain.js +3 -3
- package/dist/plugins/uniDevTool/transform/transformVue.cjs +31 -25
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts +2 -1
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/transform/transformVue.js +30 -24
- package/dist/plugins/uniDevTool/uniDevTool.cjs +3 -3
- package/dist/plugins/uniDevTool/uniDevTool.d.ts +3 -1
- package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/uniDevTool.js +3 -3
- package/dist/type.d.ts +3 -0
- package/dist/type.d.ts.map +1 -1
- package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -199
- package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -730
- package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -167
- package/dist/v3/DevTool/components/CaptureScreen/index.vue +109 -109
- package/dist/v3/DevTool/components/ConsoleList/ConsoleItem.vue +230 -225
- package/dist/v3/DevTool/components/ConsoleList/RunJSInput.vue +247 -247
- package/dist/v3/DevTool/components/ConsoleList/index.vue +171 -171
- package/dist/v3/DevTool/components/ConsoleList/staticTips.ts +1145 -1145
- package/dist/v3/DevTool/components/DevToolTitle/index.vue +24 -24
- package/dist/v3/DevTool/components/DevToolWindow/DevToolOverlay.vue +197 -197
- package/dist/v3/DevTool/components/DevToolWindow/hooks/dataUtils.ts +48 -48
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolData.ts +387 -387
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolHandlers.ts +629 -629
- package/dist/v3/DevTool/components/DevToolWindow/hooks/useDevToolOverlay.ts +201 -197
- package/dist/v3/DevTool/components/ElEvent/ElEventItem.vue +105 -105
- package/dist/v3/DevTool/components/ElEvent/index.vue +106 -106
- package/dist/v3/DevTool/components/Instance/components/InstanceTreeNode.vue +265 -265
- package/dist/v3/DevTool/components/Instance/flatten.ts +226 -226
- package/dist/v3/DevTool/components/Instance/index.vue +94 -94
- package/dist/v3/DevTool/components/Instance/registry.ts +49 -49
- package/dist/v3/DevTool/components/Instance/transformTree.ts +375 -375
- package/dist/v3/DevTool/components/Instance/transformTreeCtx.ts +268 -268
- package/dist/v3/DevTool/components/Instance/typing.d.ts +43 -43
- package/dist/v3/DevTool/components/InstanceDetail/index.vue +485 -485
- package/dist/v3/DevTool/components/JsonDetail/index.vue +70 -70
- package/dist/v3/DevTool/components/NFCList/NFCItem.vue +112 -112
- package/dist/v3/DevTool/components/NFCList/NFCTool.vue +454 -454
- package/dist/v3/DevTool/components/NFCList/const.ts +56 -56
- package/dist/v3/DevTool/components/NFCList/index.vue +94 -94
- package/dist/v3/DevTool/components/NetworkList/InterceptConfig.vue +624 -624
- package/dist/v3/DevTool/components/NetworkList/InterceptItem.vue +140 -140
- package/dist/v3/DevTool/components/NetworkList/NetworkDetail.vue +287 -287
- package/dist/v3/DevTool/components/NetworkList/NetworkIntercept.vue +88 -88
- package/dist/v3/DevTool/components/NetworkList/NetworkItem.vue +163 -163
- package/dist/v3/DevTool/components/NetworkList/NetworkSend.vue +589 -589
- package/dist/v3/DevTool/components/NetworkList/const.ts +4 -4
- package/dist/v3/DevTool/components/NetworkList/hooks/useNetworkForm.ts +86 -86
- package/dist/v3/DevTool/components/NetworkList/index.vue +160 -160
- package/dist/v3/DevTool/components/NetworkList/utils.ts +101 -101
- package/dist/v3/DevTool/components/Performance/index.vue +498 -498
- package/dist/v3/DevTool/components/Performance/modules/PerformanceMetrics.vue +153 -153
- package/dist/v3/DevTool/components/Performance/modules/usePerformanceChart.ts +460 -460
- package/dist/v3/DevTool/components/Performance/modules/usePerformanceData.ts +258 -258
- package/dist/v3/DevTool/components/PiniaList/index.vue +93 -93
- package/dist/v3/DevTool/components/RunJS/index.vue +148 -148
- package/dist/v3/DevTool/components/ScanCodeList/ScanCodeItem.vue +97 -97
- package/dist/v3/DevTool/components/ScanCodeList/index.vue +100 -100
- package/dist/v3/DevTool/components/SettingButton/index.vue +45 -45
- package/dist/v3/DevTool/components/SettingList/index.vue +218 -218
- package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +304 -304
- package/dist/v3/DevTool/components/SettingList/modules/SettingDevTool.vue +212 -212
- package/dist/v3/DevTool/components/SettingList/modules/SettingInfo.vue +157 -157
- package/dist/v3/DevTool/components/SettingList/modules/SettingLanguage.vue +74 -74
- package/dist/v3/DevTool/components/SettingList/modules/SettingLog.vue +230 -230
- package/dist/v3/DevTool/components/SettingList/typing.d.ts +2 -2
- package/dist/v3/DevTool/components/SourceCode/Line.vue +127 -127
- package/dist/v3/DevTool/components/SourceCode/parseCode.ts +609 -609
- package/dist/v3/DevTool/components/StorageList/index.vue +174 -174
- package/dist/v3/DevTool/components/TransferList/TransferDetail.vue +268 -268
- package/dist/v3/DevTool/components/VuexList/index.vue +84 -84
- package/dist/v3/DevTool/index.vue +1 -0
- package/dist/v3/components/AppTransition/index.vue +176 -176
- package/dist/v3/components/AutoSizer/index.vue +192 -192
- package/dist/v3/components/AutoSizer/index1.vue +184 -184
- package/dist/v3/components/AutoSizer/utils.ts +49 -49
- package/dist/v3/components/Barrage/BarrageItem.vue +137 -137
- package/dist/v3/components/Barrage/index.vue +202 -202
- package/dist/v3/components/CircularButton/index.vue +84 -84
- package/dist/v3/components/CustomSwiper/CustomSwiperItem.vue +49 -49
- package/dist/v3/components/CustomSwiper/index.vue +104 -104
- package/dist/v3/components/DevErrorBoundary/index.vue +380 -0
- package/dist/v3/components/Empty/index.vue +29 -29
- package/dist/v3/components/FilterSelect/index.vue +179 -179
- package/dist/v3/components/JsonPretty/components/Brackets/index.vue +27 -27
- package/dist/v3/components/JsonPretty/components/Carets/index.vue +59 -59
- package/dist/v3/components/JsonPretty/components/CheckController/index.vue +136 -136
- package/dist/v3/components/JsonPretty/components/TreeNode/index.vue +387 -387
- package/dist/v3/components/JsonPretty/hooks/useClipboard.ts +21 -21
- package/dist/v3/components/JsonPretty/hooks/useError.ts +21 -21
- package/dist/v3/components/JsonPretty/type.ts +127 -127
- package/dist/v3/components/JsonPretty/utils/index.ts +169 -169
- package/dist/v3/components/MovableContainer/index.vue +8 -4
- package/dist/v3/components/Pick/index.vue +322 -322
- package/dist/v3/components/Tag/index.vue +113 -113
- package/dist/v3/components/VirtualList/AutoSize.vue +40 -40
- package/dist/v3/components/VirtualList/index.vue +416 -416
- package/dist/v3/hooks/useBluetooth/index.ts +561 -561
- package/dist/v3/hooks/useContainerStyle.ts +153 -153
- package/dist/v3/hooks/useNFC/index.ts +107 -107
- package/dist/v3/hooks/useNFC/typing.d.ts +396 -396
- package/dist/v3/hooks/useNFC/useNFCAndroid.ts +966 -966
- package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +812 -812
- package/dist/v3/hooks/useNFC/utils.ts +754 -754
- package/dist/v3/hooks/useRequest/index.ts +586 -586
- package/dist/v3/hooks/useRequest/utils.ts +267 -267
- package/dist/v3/hooks/useScanCode/index.ts +206 -206
- package/dist/v3/hooks/useWebsocket/index.ts +253 -253
- package/dist/v3/styles/theme.ts +12 -12
- package/package.json +9 -1
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="barrage-item" :style="itemStyle" @animationend="onAnimationEnd">
|
|
3
|
-
<view class="barrage-content" :class="type">
|
|
4
|
-
<view class="barrage-type-tag">
|
|
5
|
-
{{ typeTag }}
|
|
6
|
-
</view>
|
|
7
|
-
<view class="barrage-text">{{ text }}</view>
|
|
8
|
-
</view>
|
|
9
|
-
</view>
|
|
10
|
-
</template>
|
|
11
|
-
|
|
12
|
-
<script setup lang="ts">
|
|
13
|
-
import { computed } from 'vue';
|
|
14
|
-
|
|
15
|
-
const props = defineProps<{
|
|
16
|
-
text: string;
|
|
17
|
-
type: string;
|
|
18
|
-
top: number;
|
|
19
|
-
duration: number;
|
|
20
|
-
delay?: number; // 新增延迟属性,毫秒单位
|
|
21
|
-
maxLength?: number;
|
|
22
|
-
color?: string;
|
|
23
|
-
}>();
|
|
24
|
-
|
|
25
|
-
const emit = defineEmits<{
|
|
26
|
-
(e: 'remove'): void;
|
|
27
|
-
}>();
|
|
28
|
-
|
|
29
|
-
const typeTag = computed(() => {
|
|
30
|
-
const t = props.type.toLowerCase();
|
|
31
|
-
if (t === 'network') return 'NET';
|
|
32
|
-
return t.toUpperCase();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const itemStyle = computed(() => ({
|
|
36
|
-
top: `${props.top}px`,
|
|
37
|
-
'--barrage-duration': `${props.duration}s`,
|
|
38
|
-
'--barrage-delay': `${props.delay || 0}ms`,
|
|
39
|
-
'--barrage-max-width': props.maxLength ? 'none' : '300px',
|
|
40
|
-
color: props.color || 'inherit',
|
|
41
|
-
}));
|
|
42
|
-
|
|
43
|
-
function onAnimationEnd() {
|
|
44
|
-
emit('remove');
|
|
45
|
-
}
|
|
46
|
-
</script>
|
|
47
|
-
|
|
48
|
-
<style scoped>
|
|
49
|
-
.barrage-item {
|
|
50
|
-
position: fixed;
|
|
51
|
-
left: 100%;
|
|
52
|
-
top: 0;
|
|
53
|
-
white-space: nowrap;
|
|
54
|
-
pointer-events: none;
|
|
55
|
-
z-index: 10001;
|
|
56
|
-
display: flex;
|
|
57
|
-
will-change: transform;
|
|
58
|
-
animation: barrage-move var(--barrage-duration) linear var(--barrage-delay)
|
|
59
|
-
forwards;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
.barrage-item:hover {
|
|
63
|
-
animation-play-state: paused;
|
|
64
|
-
z-index: 20000;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@keyframes barrage-move {
|
|
68
|
-
from {
|
|
69
|
-
transform: translateX(0);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
to {
|
|
73
|
-
transform: translateX(calc(-100vw - 100%));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.barrage-content {
|
|
78
|
-
display: flex;
|
|
79
|
-
align-items: center;
|
|
80
|
-
padding: 4px 12px;
|
|
81
|
-
border-radius: 16px;
|
|
82
|
-
background: rgb(0 0 0 / 60%);
|
|
83
|
-
backdrop-filter: blur(4px);
|
|
84
|
-
color: #fff;
|
|
85
|
-
font-size: 12px;
|
|
86
|
-
box-shadow: 0 2px 8px rgb(0 0 0 / 20%);
|
|
87
|
-
pointer-events: auto;
|
|
88
|
-
cursor: pointer;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/* Log & Info: 白色/中性系 */
|
|
92
|
-
.barrage-content.log,
|
|
93
|
-
.barrage-content.info {
|
|
94
|
-
background: rgb(255 255 255 / 90%);
|
|
95
|
-
color: #333;
|
|
96
|
-
box-shadow: 0 2px 10px rgb(0 0 0 / 10%);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.barrage-content.log .barrage-type-tag,
|
|
100
|
-
.barrage-content.info .barrage-type-tag {
|
|
101
|
-
background: rgb(0 0 0 / 10%);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/* Warn: 黄橙色系 */
|
|
105
|
-
.barrage-content.warn {
|
|
106
|
-
background: rgb(180 100 0 / 75%);
|
|
107
|
-
box-shadow: 0 0 10px rgb(255 149 0 / 30%);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/* Error & Network: 红色系 */
|
|
111
|
-
.barrage-content.error,
|
|
112
|
-
.barrage-content.network {
|
|
113
|
-
background: rgb(180 30 20 / 75%);
|
|
114
|
-
box-shadow: 0 0 10px rgb(255 59 48 / 30%);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/* Debug: 灰色系 */
|
|
118
|
-
.barrage-content.debug {
|
|
119
|
-
background: rgb(80 80 80 / 75%);
|
|
120
|
-
box-shadow: 0 0 10px rgb(142 142 147 / 30%);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
.barrage-type-tag {
|
|
124
|
-
font-weight: bold;
|
|
125
|
-
margin-right: 6px;
|
|
126
|
-
font-size: 10px;
|
|
127
|
-
padding: 2px 4px;
|
|
128
|
-
background: rgb(0 0 0 / 5%);
|
|
129
|
-
border-radius: 4px;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
.barrage-text {
|
|
133
|
-
max-width: var(--barrage-max-width, 300px);
|
|
134
|
-
overflow: hidden;
|
|
135
|
-
text-overflow: ellipsis;
|
|
136
|
-
}
|
|
137
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<view class="barrage-item" :style="itemStyle" @animationend="onAnimationEnd">
|
|
3
|
+
<view class="barrage-content" :class="type">
|
|
4
|
+
<view class="barrage-type-tag">
|
|
5
|
+
{{ typeTag }}
|
|
6
|
+
</view>
|
|
7
|
+
<view class="barrage-text">{{ text }}</view>
|
|
8
|
+
</view>
|
|
9
|
+
</view>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
import { computed } from 'vue';
|
|
14
|
+
|
|
15
|
+
const props = defineProps<{
|
|
16
|
+
text: string;
|
|
17
|
+
type: string;
|
|
18
|
+
top: number;
|
|
19
|
+
duration: number;
|
|
20
|
+
delay?: number; // 新增延迟属性,毫秒单位
|
|
21
|
+
maxLength?: number;
|
|
22
|
+
color?: string;
|
|
23
|
+
}>();
|
|
24
|
+
|
|
25
|
+
const emit = defineEmits<{
|
|
26
|
+
(e: 'remove'): void;
|
|
27
|
+
}>();
|
|
28
|
+
|
|
29
|
+
const typeTag = computed(() => {
|
|
30
|
+
const t = props.type.toLowerCase();
|
|
31
|
+
if (t === 'network') return 'NET';
|
|
32
|
+
return t.toUpperCase();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const itemStyle = computed(() => ({
|
|
36
|
+
top: `${props.top}px`,
|
|
37
|
+
'--barrage-duration': `${props.duration}s`,
|
|
38
|
+
'--barrage-delay': `${props.delay || 0}ms`,
|
|
39
|
+
'--barrage-max-width': props.maxLength ? 'none' : '300px',
|
|
40
|
+
color: props.color || 'inherit',
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
function onAnimationEnd() {
|
|
44
|
+
emit('remove');
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<style scoped>
|
|
49
|
+
.barrage-item {
|
|
50
|
+
position: fixed;
|
|
51
|
+
left: 100%;
|
|
52
|
+
top: 0;
|
|
53
|
+
white-space: nowrap;
|
|
54
|
+
pointer-events: none;
|
|
55
|
+
z-index: 10001;
|
|
56
|
+
display: flex;
|
|
57
|
+
will-change: transform;
|
|
58
|
+
animation: barrage-move var(--barrage-duration) linear var(--barrage-delay)
|
|
59
|
+
forwards;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.barrage-item:hover {
|
|
63
|
+
animation-play-state: paused;
|
|
64
|
+
z-index: 20000;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@keyframes barrage-move {
|
|
68
|
+
from {
|
|
69
|
+
transform: translateX(0);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
to {
|
|
73
|
+
transform: translateX(calc(-100vw - 100%));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.barrage-content {
|
|
78
|
+
display: flex;
|
|
79
|
+
align-items: center;
|
|
80
|
+
padding: 4px 12px;
|
|
81
|
+
border-radius: 16px;
|
|
82
|
+
background: rgb(0 0 0 / 60%);
|
|
83
|
+
backdrop-filter: blur(4px);
|
|
84
|
+
color: #fff;
|
|
85
|
+
font-size: 12px;
|
|
86
|
+
box-shadow: 0 2px 8px rgb(0 0 0 / 20%);
|
|
87
|
+
pointer-events: auto;
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* Log & Info: 白色/中性系 */
|
|
92
|
+
.barrage-content.log,
|
|
93
|
+
.barrage-content.info {
|
|
94
|
+
background: rgb(255 255 255 / 90%);
|
|
95
|
+
color: #333;
|
|
96
|
+
box-shadow: 0 2px 10px rgb(0 0 0 / 10%);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.barrage-content.log .barrage-type-tag,
|
|
100
|
+
.barrage-content.info .barrage-type-tag {
|
|
101
|
+
background: rgb(0 0 0 / 10%);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Warn: 黄橙色系 */
|
|
105
|
+
.barrage-content.warn {
|
|
106
|
+
background: rgb(180 100 0 / 75%);
|
|
107
|
+
box-shadow: 0 0 10px rgb(255 149 0 / 30%);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* Error & Network: 红色系 */
|
|
111
|
+
.barrage-content.error,
|
|
112
|
+
.barrage-content.network {
|
|
113
|
+
background: rgb(180 30 20 / 75%);
|
|
114
|
+
box-shadow: 0 0 10px rgb(255 59 48 / 30%);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* Debug: 灰色系 */
|
|
118
|
+
.barrage-content.debug {
|
|
119
|
+
background: rgb(80 80 80 / 75%);
|
|
120
|
+
box-shadow: 0 0 10px rgb(142 142 147 / 30%);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.barrage-type-tag {
|
|
124
|
+
font-weight: bold;
|
|
125
|
+
margin-right: 6px;
|
|
126
|
+
font-size: 10px;
|
|
127
|
+
padding: 2px 4px;
|
|
128
|
+
background: rgb(0 0 0 / 5%);
|
|
129
|
+
border-radius: 4px;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.barrage-text {
|
|
133
|
+
max-width: var(--barrage-max-width, 300px);
|
|
134
|
+
overflow: hidden;
|
|
135
|
+
text-overflow: ellipsis;
|
|
136
|
+
}
|
|
137
|
+
</style>
|
|
@@ -1,202 +1,202 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view
|
|
3
|
-
v-if="actualVisible"
|
|
4
|
-
class="barrage-container"
|
|
5
|
-
:style="{ zIndex: props.zIndex }">
|
|
6
|
-
<BarrageItem
|
|
7
|
-
v-for="item in items"
|
|
8
|
-
:key="item.id"
|
|
9
|
-
:text="item.text"
|
|
10
|
-
:type="item.type"
|
|
11
|
-
:top="item.top"
|
|
12
|
-
:duration="item.duration"
|
|
13
|
-
:delay="item.delay"
|
|
14
|
-
:maxLength="props.maxLength"
|
|
15
|
-
@remove="removeItem(item.id)" />
|
|
16
|
-
</view>
|
|
17
|
-
</template>
|
|
18
|
-
|
|
19
|
-
<script setup lang="ts">
|
|
20
|
-
import { ref, onMounted, watch, computed } from 'vue';
|
|
21
|
-
import { onShow, onHide } from '@dcloudio/uni-app';
|
|
22
|
-
import BarrageItem from './BarrageItem.vue';
|
|
23
|
-
|
|
24
|
-
const props = withDefaults(
|
|
25
|
-
defineProps<{
|
|
26
|
-
maxTracks?: number;
|
|
27
|
-
trackHeight?: number;
|
|
28
|
-
startTop?: number;
|
|
29
|
-
duration?: number;
|
|
30
|
-
maxLength?: number;
|
|
31
|
-
visible?: boolean;
|
|
32
|
-
zIndex?: number;
|
|
33
|
-
}>(),
|
|
34
|
-
{
|
|
35
|
-
maxTracks: 10,
|
|
36
|
-
trackHeight: 36,
|
|
37
|
-
startTop: 40,
|
|
38
|
-
duration: 6,
|
|
39
|
-
maxLength: 100,
|
|
40
|
-
visible: true,
|
|
41
|
-
zIndex: 10000,
|
|
42
|
-
},
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const actualVisible = computed(() => props.visible);
|
|
46
|
-
|
|
47
|
-
const items = ref<
|
|
48
|
-
{
|
|
49
|
-
id: number;
|
|
50
|
-
text: string;
|
|
51
|
-
type: string;
|
|
52
|
-
top: number;
|
|
53
|
-
duration: number;
|
|
54
|
-
delay: number;
|
|
55
|
-
}[]
|
|
56
|
-
>([]);
|
|
57
|
-
let nextId = 0;
|
|
58
|
-
|
|
59
|
-
// 页面是否在前台(用于防止页面隐藏时弹幕堆积)
|
|
60
|
-
let isPageActive = true;
|
|
61
|
-
|
|
62
|
-
// 记录每个轨道的最后一条弹幕开始的时间 + 安全间隔
|
|
63
|
-
const laneNextAvailableTime = ref<number[]>(new Array(props.maxTracks).fill(0));
|
|
64
|
-
const laneLastWidth = ref<number[]>(new Array(props.maxTracks).fill(0));
|
|
65
|
-
|
|
66
|
-
watch(
|
|
67
|
-
() => props.maxTracks,
|
|
68
|
-
(val: number) => {
|
|
69
|
-
laneNextAvailableTime.value = new Array(val).fill(0);
|
|
70
|
-
laneLastWidth.value = new Array(val).fill(0);
|
|
71
|
-
},
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const screenWidth = ref(375);
|
|
75
|
-
|
|
76
|
-
function getBestLane(
|
|
77
|
-
text: string,
|
|
78
|
-
duration: number,
|
|
79
|
-
): { index: number; delay: number } {
|
|
80
|
-
const now = Date.now();
|
|
81
|
-
const chineseCount = (text.match(/[\u4e00-\u9fa5]/g) || []).length;
|
|
82
|
-
const emojiCount = (
|
|
83
|
-
text.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|\u2600-\u27BF/g) || []
|
|
84
|
-
).length;
|
|
85
|
-
const otherCount = text.length - chineseCount - emojiCount;
|
|
86
|
-
const estimatedWidth =
|
|
87
|
-
chineseCount * 14 + emojiCount * 20 + otherCount * 8 + 80;
|
|
88
|
-
|
|
89
|
-
let bestLane = 0;
|
|
90
|
-
let minStartTime = Infinity;
|
|
91
|
-
|
|
92
|
-
for (let i = 0; i < props.maxTracks; i++) {
|
|
93
|
-
const nextCanStart = laneNextAvailableTime.value[i] || 0;
|
|
94
|
-
if (nextCanStart <= now) {
|
|
95
|
-
bestLane = i;
|
|
96
|
-
minStartTime = now;
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
if (nextCanStart < minStartTime) {
|
|
100
|
-
minStartTime = nextCanStart;
|
|
101
|
-
bestLane = i;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const startTime = Math.max(now, minStartTime);
|
|
106
|
-
const delay = startTime - now;
|
|
107
|
-
const lastWidth = laneLastWidth.value[bestLane] || 0;
|
|
108
|
-
const s = screenWidth.value || 375;
|
|
109
|
-
|
|
110
|
-
const enterTimeNew =
|
|
111
|
-
(estimatedWidth / ((s + estimatedWidth) / duration)) * 1000;
|
|
112
|
-
const enterTimePrev = (lastWidth / ((s + lastWidth) / duration)) * 1000;
|
|
113
|
-
const safeInterval = Math.max(enterTimeNew, enterTimePrev) + 300;
|
|
114
|
-
|
|
115
|
-
laneNextAvailableTime.value[bestLane] = startTime + safeInterval;
|
|
116
|
-
laneLastWidth.value[bestLane] = estimatedWidth;
|
|
117
|
-
|
|
118
|
-
return { index: bestLane, delay };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* 添加一条弹幕 (通用接口)
|
|
123
|
-
* @param text 文字内容
|
|
124
|
-
* @param type 类型,用于区分颜色样式
|
|
125
|
-
*/
|
|
126
|
-
function add(text: string, type: string = 'log') {
|
|
127
|
-
if (!isPageActive || !actualVisible.value) return;
|
|
128
|
-
|
|
129
|
-
const id = nextId++;
|
|
130
|
-
const duration = props.duration;
|
|
131
|
-
|
|
132
|
-
let finalText = text;
|
|
133
|
-
if (finalText.length > props.maxLength) {
|
|
134
|
-
finalText = finalText.slice(0, props.maxLength) + '...';
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const { index: laneIndex, delay } = getBestLane(finalText, duration);
|
|
138
|
-
const top = props.startTop + laneIndex * props.trackHeight;
|
|
139
|
-
|
|
140
|
-
items.value.push({
|
|
141
|
-
id,
|
|
142
|
-
text: finalText,
|
|
143
|
-
type,
|
|
144
|
-
top,
|
|
145
|
-
duration,
|
|
146
|
-
delay,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function removeItem(id: number) {
|
|
151
|
-
const index = items.value.findIndex((item) => item.id === id);
|
|
152
|
-
if (index !== -1) {
|
|
153
|
-
items.value.splice(index, 1);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 清空弹幕
|
|
159
|
-
*/
|
|
160
|
-
function clear() {
|
|
161
|
-
items.value = [];
|
|
162
|
-
laneNextAvailableTime.value = new Array(props.maxTracks).fill(0);
|
|
163
|
-
laneLastWidth.value = new Array(props.maxTracks).fill(0);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
onMounted(() => {
|
|
167
|
-
try {
|
|
168
|
-
const sys = uni.getSystemInfoSync();
|
|
169
|
-
if (sys.windowWidth) screenWidth.value = sys.windowWidth;
|
|
170
|
-
} catch (_err) {
|
|
171
|
-
// 降级使用 375 默认宽度
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
onShow(() => {
|
|
176
|
-
isPageActive = true;
|
|
177
|
-
clear();
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
onHide(() => {
|
|
181
|
-
isPageActive = false;
|
|
182
|
-
items.value = [];
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
defineExpose({
|
|
186
|
-
add,
|
|
187
|
-
clear,
|
|
188
|
-
});
|
|
189
|
-
</script>
|
|
190
|
-
|
|
191
|
-
<style scoped>
|
|
192
|
-
.barrage-container {
|
|
193
|
-
position: fixed;
|
|
194
|
-
top: 0;
|
|
195
|
-
left: 0;
|
|
196
|
-
width: 100%;
|
|
197
|
-
height: 100%;
|
|
198
|
-
pointer-events: none;
|
|
199
|
-
z-index: 10000;
|
|
200
|
-
overflow: hidden;
|
|
201
|
-
}
|
|
202
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
v-if="actualVisible"
|
|
4
|
+
class="barrage-container"
|
|
5
|
+
:style="{ zIndex: props.zIndex }">
|
|
6
|
+
<BarrageItem
|
|
7
|
+
v-for="item in items"
|
|
8
|
+
:key="item.id"
|
|
9
|
+
:text="item.text"
|
|
10
|
+
:type="item.type"
|
|
11
|
+
:top="item.top"
|
|
12
|
+
:duration="item.duration"
|
|
13
|
+
:delay="item.delay"
|
|
14
|
+
:maxLength="props.maxLength"
|
|
15
|
+
@remove="removeItem(item.id)" />
|
|
16
|
+
</view>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script setup lang="ts">
|
|
20
|
+
import { ref, onMounted, watch, computed } from 'vue';
|
|
21
|
+
import { onShow, onHide } from '@dcloudio/uni-app';
|
|
22
|
+
import BarrageItem from './BarrageItem.vue';
|
|
23
|
+
|
|
24
|
+
const props = withDefaults(
|
|
25
|
+
defineProps<{
|
|
26
|
+
maxTracks?: number;
|
|
27
|
+
trackHeight?: number;
|
|
28
|
+
startTop?: number;
|
|
29
|
+
duration?: number;
|
|
30
|
+
maxLength?: number;
|
|
31
|
+
visible?: boolean;
|
|
32
|
+
zIndex?: number;
|
|
33
|
+
}>(),
|
|
34
|
+
{
|
|
35
|
+
maxTracks: 10,
|
|
36
|
+
trackHeight: 36,
|
|
37
|
+
startTop: 40,
|
|
38
|
+
duration: 6,
|
|
39
|
+
maxLength: 100,
|
|
40
|
+
visible: true,
|
|
41
|
+
zIndex: 10000,
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const actualVisible = computed(() => props.visible);
|
|
46
|
+
|
|
47
|
+
const items = ref<
|
|
48
|
+
{
|
|
49
|
+
id: number;
|
|
50
|
+
text: string;
|
|
51
|
+
type: string;
|
|
52
|
+
top: number;
|
|
53
|
+
duration: number;
|
|
54
|
+
delay: number;
|
|
55
|
+
}[]
|
|
56
|
+
>([]);
|
|
57
|
+
let nextId = 0;
|
|
58
|
+
|
|
59
|
+
// 页面是否在前台(用于防止页面隐藏时弹幕堆积)
|
|
60
|
+
let isPageActive = true;
|
|
61
|
+
|
|
62
|
+
// 记录每个轨道的最后一条弹幕开始的时间 + 安全间隔
|
|
63
|
+
const laneNextAvailableTime = ref<number[]>(new Array(props.maxTracks).fill(0));
|
|
64
|
+
const laneLastWidth = ref<number[]>(new Array(props.maxTracks).fill(0));
|
|
65
|
+
|
|
66
|
+
watch(
|
|
67
|
+
() => props.maxTracks,
|
|
68
|
+
(val: number) => {
|
|
69
|
+
laneNextAvailableTime.value = new Array(val).fill(0);
|
|
70
|
+
laneLastWidth.value = new Array(val).fill(0);
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const screenWidth = ref(375);
|
|
75
|
+
|
|
76
|
+
function getBestLane(
|
|
77
|
+
text: string,
|
|
78
|
+
duration: number,
|
|
79
|
+
): { index: number; delay: number } {
|
|
80
|
+
const now = Date.now();
|
|
81
|
+
const chineseCount = (text.match(/[\u4e00-\u9fa5]/g) || []).length;
|
|
82
|
+
const emojiCount = (
|
|
83
|
+
text.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|\u2600-\u27BF/g) || []
|
|
84
|
+
).length;
|
|
85
|
+
const otherCount = text.length - chineseCount - emojiCount;
|
|
86
|
+
const estimatedWidth =
|
|
87
|
+
chineseCount * 14 + emojiCount * 20 + otherCount * 8 + 80;
|
|
88
|
+
|
|
89
|
+
let bestLane = 0;
|
|
90
|
+
let minStartTime = Infinity;
|
|
91
|
+
|
|
92
|
+
for (let i = 0; i < props.maxTracks; i++) {
|
|
93
|
+
const nextCanStart = laneNextAvailableTime.value[i] || 0;
|
|
94
|
+
if (nextCanStart <= now) {
|
|
95
|
+
bestLane = i;
|
|
96
|
+
minStartTime = now;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (nextCanStart < minStartTime) {
|
|
100
|
+
minStartTime = nextCanStart;
|
|
101
|
+
bestLane = i;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const startTime = Math.max(now, minStartTime);
|
|
106
|
+
const delay = startTime - now;
|
|
107
|
+
const lastWidth = laneLastWidth.value[bestLane] || 0;
|
|
108
|
+
const s = screenWidth.value || 375;
|
|
109
|
+
|
|
110
|
+
const enterTimeNew =
|
|
111
|
+
(estimatedWidth / ((s + estimatedWidth) / duration)) * 1000;
|
|
112
|
+
const enterTimePrev = (lastWidth / ((s + lastWidth) / duration)) * 1000;
|
|
113
|
+
const safeInterval = Math.max(enterTimeNew, enterTimePrev) + 300;
|
|
114
|
+
|
|
115
|
+
laneNextAvailableTime.value[bestLane] = startTime + safeInterval;
|
|
116
|
+
laneLastWidth.value[bestLane] = estimatedWidth;
|
|
117
|
+
|
|
118
|
+
return { index: bestLane, delay };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 添加一条弹幕 (通用接口)
|
|
123
|
+
* @param text 文字内容
|
|
124
|
+
* @param type 类型,用于区分颜色样式
|
|
125
|
+
*/
|
|
126
|
+
function add(text: string, type: string = 'log') {
|
|
127
|
+
if (!isPageActive || !actualVisible.value) return;
|
|
128
|
+
|
|
129
|
+
const id = nextId++;
|
|
130
|
+
const duration = props.duration;
|
|
131
|
+
|
|
132
|
+
let finalText = text;
|
|
133
|
+
if (finalText.length > props.maxLength) {
|
|
134
|
+
finalText = finalText.slice(0, props.maxLength) + '...';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const { index: laneIndex, delay } = getBestLane(finalText, duration);
|
|
138
|
+
const top = props.startTop + laneIndex * props.trackHeight;
|
|
139
|
+
|
|
140
|
+
items.value.push({
|
|
141
|
+
id,
|
|
142
|
+
text: finalText,
|
|
143
|
+
type,
|
|
144
|
+
top,
|
|
145
|
+
duration,
|
|
146
|
+
delay,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function removeItem(id: number) {
|
|
151
|
+
const index = items.value.findIndex((item) => item.id === id);
|
|
152
|
+
if (index !== -1) {
|
|
153
|
+
items.value.splice(index, 1);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 清空弹幕
|
|
159
|
+
*/
|
|
160
|
+
function clear() {
|
|
161
|
+
items.value = [];
|
|
162
|
+
laneNextAvailableTime.value = new Array(props.maxTracks).fill(0);
|
|
163
|
+
laneLastWidth.value = new Array(props.maxTracks).fill(0);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
onMounted(() => {
|
|
167
|
+
try {
|
|
168
|
+
const sys = uni.getSystemInfoSync();
|
|
169
|
+
if (sys.windowWidth) screenWidth.value = sys.windowWidth;
|
|
170
|
+
} catch (_err) {
|
|
171
|
+
// 降级使用 375 默认宽度
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
onShow(() => {
|
|
176
|
+
isPageActive = true;
|
|
177
|
+
clear();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
onHide(() => {
|
|
181
|
+
isPageActive = false;
|
|
182
|
+
items.value = [];
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
defineExpose({
|
|
186
|
+
add,
|
|
187
|
+
clear,
|
|
188
|
+
});
|
|
189
|
+
</script>
|
|
190
|
+
|
|
191
|
+
<style scoped>
|
|
192
|
+
.barrage-container {
|
|
193
|
+
position: fixed;
|
|
194
|
+
top: 0;
|
|
195
|
+
left: 0;
|
|
196
|
+
width: 100%;
|
|
197
|
+
height: 100%;
|
|
198
|
+
pointer-events: none;
|
|
199
|
+
z-index: 10000;
|
|
200
|
+
overflow: hidden;
|
|
201
|
+
}
|
|
202
|
+
</style>
|