@@ -13,7 +13,6 @@ const { dialogCount } = toRefs(dialogStore)
1313const route = useRoute ()
1414const { path } = toRefs (route )
1515
16- // #region 滚动相关逻辑
1716const { progress } = useLoadingIndicator ()
1817const canScroll = ref (false )
1918
@@ -30,9 +29,7 @@ const showPercent = ref(true)
3029function toggleShowPercent() {
3130 showPercent .value = ! showPercent .value
3231}
33- // #endregion
3432
35- // #region 评论相关逻辑
3633const commentWhiteList = [' /recently' ] // 在白名单中的路径不显示评论
3734
3835const hasComments = ref (false )
@@ -75,96 +72,18 @@ function scrollToTop() {
7572 })
7673 }
7774}
78- // #endregion
7975
80- // #region 音量控制相关逻辑
8176const isIdle = ref (true )
82- const volume = ref (0 )
83- const previousVolume = ref (0 )
84-
85- const volumeIcon = computed (() =>
86- volume .value > 0.5 ? ' lucide:volume-2' : volume .value > 0 ? ' lucide:volume-1' : ' lucide:volume-off' ,
87- )
8877
8978onMounted (() => {
9079 const { $audioPlayer } = useNuxtApp ()
91-
92- const unsubscribeIdle = $audioPlayer .subscribe ((state ) => {
93- isIdle .value = state .playbackState === ' idle'
94- })
95-
96- const unsubscribeVolume = $audioPlayer .subscribe ((state ) => {
97- volume .value = state .volume
98- })
99-
100- onUnmounted (() => {
101- unsubscribeIdle ()
102- unsubscribeVolume ()
103- })
80+ onUnmounted ($audioPlayer .subscribe (state => isIdle .value = state .playbackState === ' idle' ))
10481})
105-
106- function toggleMuted() {
107- const { $audioPlayer } = useNuxtApp ()
108- if ($audioPlayer .getState ().isMuted ) {
109- $audioPlayer .setVolume (previousVolume .value )
110- }
111- else {
112- previousVolume .value = volume .value
113- $audioPlayer .setVolume (0 )
114- }
115- }
116-
117- const showVolumePanel = ref (false )
118- function toggleShowVolumePanel() {
119- showVolumePanel .value = ! showVolumePanel .value
120- }
121-
122- const controllerHeight = computed (() => showVolumePanel .value ? ' 208px' : ' 56px' )
123-
124- function handleInput(e : Event ) {
125- const { $audioPlayer } = useNuxtApp ()
126- const target = e .target as HTMLInputElement
127- $audioPlayer .setVolume (target .valueAsNumber )
128- }
129- // #endregion
13082 </script >
13183
13284<template >
13385 <transition-group name =" controller" tag =" div" class =" fixed bottom-10 right-10 flex flex-col gap-4" >
134- <div
135- v-if =" dialogCount === 0 && !isIdle"
136- class =" relative w-14 overflow-hidden hana-card transition-all duration-300"
137- :style =" { height: controllerHeight }"
138- @mouseenter =" toggleShowVolumePanel"
139- @mouseleave =" toggleShowVolumePanel"
140- >
141- <div class =" absolute bottom-2 flex flex-col items-center gap-4" >
142- <p class =" text-xs text-text dark:text-hana-white-700" >
143- {{ Math.round(volume * 100) }}%
144- </p >
145- <input
146- id =" volume-progress"
147- class =" h-24 w-2 rounded outline-none transition-[box-shadow] duration-200 accent-hana-blue dark:bg-hana-black-700 focus-visible:ring-2 focus-visible:ring-hana-blue-300"
148- type =" range"
149- min =" 0"
150- max =" 1"
151- step =" 0.01"
152- :value =" volume"
153- :aria-valuemin =" 0"
154- :aria-valuemax =" 1"
155- :aria-valuenow =" volume"
156- aria-label =" 音量"
157- :style =" `--progress: ${volume}`"
158- @input =" handleInput"
159- >
160- <div
161- class =" mt-auto size-10 hana-button items-end items-center justify-center font-bold"
162- @click =" toggleMuted"
163- >
164- <icon :name =" volumeIcon" size =" 20" />
165- </div >
166- </div >
167- </div >
86+ <HanaControllerVolume v-if =" dialogCount === 0 && !isIdle" />
16887
16988 <div v-if =" dialogCount === 0 && hasComments" class =" relative hana-card" >
17089 <HanaTooltip content =" 滚到评论" position =" left" animation =" slide" >
@@ -213,22 +132,4 @@ function handleInput(e: Event) {
213132.controller-leave-active {
214133 position : absolute ;
215134}
216-
217- #volume-progress {
218- background : linear-gradient (to right ,
219- oklch(0.5 0.1102 250.04 ) calc (var (--progress ) * 100% ),
220- oklch(0.93 0.0358 205.23 ) calc (var (--progress ) * 100%)
221- );
222- writing-mode : vertical-lr ;
223- direction : rtl ;
224- }
225-
226- .dark {
227- #volume-progress {
228- background : linear-gradient (to right ,
229- oklch(0.75 0.0883 226.04 ) calc (var (--progress ) * 100% ),
230- oklch(0.93 0.0358 205.23 ) calc (var (--progress ) * 100%)
231- );
232- }
233- }
234135 </style >
0 commit comments