feat: align with upstream 1.5.9.9
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<template>
|
||||
<audio
|
||||
ref="audioPlayer"
|
||||
:key="audioKey"
|
||||
:src="audioSrc"
|
||||
:crossorigin="crossOriginVal"
|
||||
:referrerpolicy="referrerPolicyVal"
|
||||
playsinline
|
||||
preload="auto"
|
||||
webkit-playsinline
|
||||
@canplay="$emit('canplay', $event)"
|
||||
@ended="$emit('ended', $event)"
|
||||
@error="$emit('error', $event)"
|
||||
@loadedmetadata="$emit('loadedmetadata', $event)"
|
||||
@loadstart="$emit('loadstart', $event)"
|
||||
@pause="$emit('pause', $event)"
|
||||
@play="$emit('play', $event)"
|
||||
@timeupdate="$emit('timeupdate', $event)"
|
||||
></audio>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch, nextTick, computed } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
song: {
|
||||
type: Object,
|
||||
default: null
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits([
|
||||
'timeupdate',
|
||||
'ended',
|
||||
'loadedmetadata',
|
||||
'error',
|
||||
'play',
|
||||
'pause',
|
||||
'loadstart',
|
||||
'canplay'
|
||||
])
|
||||
|
||||
const audioPlayer = ref(null)
|
||||
|
||||
const crossOriginVal = computed(() => {
|
||||
return props.song?.musicPlatform === 'migu' ? null : 'anonymous'
|
||||
})
|
||||
const referrerPolicyVal = computed(() => {
|
||||
return props.song?.musicPlatform === 'migu' ? null : 'no-referrer'
|
||||
})
|
||||
const audioSrc = computed(() => {
|
||||
return props.song?.musicUrl || undefined
|
||||
})
|
||||
const audioKey = computed(() => {
|
||||
// 当平台改变时,使用不同的 key 强制重新创建元素
|
||||
return props.song?.musicPlatform || 'default'
|
||||
})
|
||||
|
||||
// 错误消息常量,避免使用魔法字符串
|
||||
const ERROR_MESSAGES = {
|
||||
BILIBILI_NO_AUDIO: 'No audio URL available for Bilibili video'
|
||||
}
|
||||
|
||||
// 监听 song 变化,如果没有 musicUrl 则立即触发错误
|
||||
watch(
|
||||
() => props.song,
|
||||
(newSong, oldSong) => {
|
||||
if (newSong && !newSong.musicUrl) {
|
||||
// 使用 nextTick 确保 DOM 已更新
|
||||
nextTick(() => {
|
||||
// 创建一个自定义错误对象
|
||||
const error = new Error(ERROR_MESSAGES.BILIBILI_NO_AUDIO)
|
||||
error.name = 'BilibiliNoAudioError'
|
||||
|
||||
// 立即触发错误事件
|
||||
emit('error', error)
|
||||
})
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
defineExpose({
|
||||
audioPlayer
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,317 @@
|
||||
<template>
|
||||
<div class="player-controls">
|
||||
<div class="progress-container">
|
||||
<div class="control-with-progress">
|
||||
<!-- 上一首按钮 -->
|
||||
<button
|
||||
:disabled="!hasPrevious"
|
||||
:title="hasPrevious ? locale.previous : locale.noPrevious"
|
||||
class="control-btn prev-btn"
|
||||
@click="$emit('previous')"
|
||||
>
|
||||
<Icon :size="24" color="white" name="skip-back" />
|
||||
</button>
|
||||
|
||||
<!-- 播放/暂停按钮 -->
|
||||
<button
|
||||
:disabled="hasError || isLoadingTrack"
|
||||
class="control-btn play-pause-btn"
|
||||
@click="$emit('togglePlay')"
|
||||
>
|
||||
<AppSpinner v-if="isLoadingTrack" :size="18" color="white" />
|
||||
<Icon v-else-if="isPlaying" :size="18" color="white" name="pause" />
|
||||
<Icon v-else :size="18" color="white" name="play" />
|
||||
</button>
|
||||
|
||||
<!-- 下一首按钮 -->
|
||||
<button
|
||||
:disabled="!hasNext"
|
||||
:title="hasNext ? locale.next : locale.noNext"
|
||||
class="control-btn next-btn"
|
||||
@click="$emit('next')"
|
||||
>
|
||||
<Icon :size="24" color="white" name="skip-forward" />
|
||||
</button>
|
||||
|
||||
<div class="progress-container-wrapper">
|
||||
<div
|
||||
ref="progressBar"
|
||||
class="progress-bar"
|
||||
@click="handleProgressClick"
|
||||
@mousedown="handleProgressMouseDown"
|
||||
@touchstart="handleProgressTouchStart"
|
||||
>
|
||||
<div
|
||||
:class="{ dragging: isDragging }"
|
||||
:style="{ '--progress-width': `${progress}%` }"
|
||||
class="progress"
|
||||
>
|
||||
<div :class="{ dragging: isDragging }" class="progress-thumb" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="time-display">
|
||||
<span class="current-time">{{ formatTime(currentTime) }}</span>
|
||||
<span class="duration">{{ formatTime(duration) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import Icon from '~/components/UI/Icon.vue'
|
||||
import AppSpinner from '~/components/UI/Common/AppSpinner.vue'
|
||||
import { useLocale } from '~/utils/locale'
|
||||
|
||||
const props = defineProps({
|
||||
isPlaying: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
hasError: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
hasPrevious: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
hasNext: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
progress: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
isDragging: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
currentTime: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
duration: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
isLoading: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
isLoadingTrack: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits([
|
||||
'togglePlay',
|
||||
'previous',
|
||||
'next',
|
||||
'startDrag',
|
||||
'startTouchDrag',
|
||||
'seekToPosition'
|
||||
])
|
||||
|
||||
const progressBar = ref(null)
|
||||
const { ui } = useLocale()
|
||||
const locale = computed(() => ui.value?.playerControls || {})
|
||||
|
||||
const formatTime = (time) => {
|
||||
if (!time || isNaN(time)) return '0:00'
|
||||
const minutes = Math.floor(time / 60)
|
||||
const seconds = Math.floor(time % 60)
|
||||
return `${minutes}:${seconds.toString().padStart(2, '0')}`
|
||||
}
|
||||
|
||||
// 进度条事件处理
|
||||
const handleProgressMouseDown = (event) => {
|
||||
emit('startDrag', event, progressBar.value)
|
||||
}
|
||||
|
||||
const handleProgressTouchStart = (event) => {
|
||||
emit('startTouchDrag', event, progressBar.value)
|
||||
}
|
||||
|
||||
const handleProgressClick = (event) => {
|
||||
// 防止拖拽时触发点击
|
||||
if (props.isDragging) return
|
||||
emit('seekToPosition', event)
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
progressBar
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.player-controls {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.progress-container {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.control-with-progress {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
background: var(--overlay-10);
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
backdrop-filter: blur(10px);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.control-btn:hover:not(:disabled) {
|
||||
background: var(--overlay-20);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.control-btn:active:not(:disabled) {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
.control-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.play-pause-btn {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
background: var(--overlay-15);
|
||||
}
|
||||
|
||||
.progress-container-wrapper {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
width: 100%;
|
||||
height: 20px; /* 增加触摸区域 */
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
touch-action: none; /* 防止移动端滚动 */
|
||||
}
|
||||
|
||||
.progress {
|
||||
width: 100%;
|
||||
height: 4px;
|
||||
background: var(--overlay-20);
|
||||
border-radius: 2px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
transition: height 0.2s ease;
|
||||
}
|
||||
|
||||
.progress::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
width: var(--progress-width, 0%);
|
||||
background: linear-gradient(90deg, var(--color-accent-light) 0%, var(--color-cyan) 100%);
|
||||
border-radius: 2px;
|
||||
transition: width 0.05s linear;
|
||||
will-change: width;
|
||||
}
|
||||
|
||||
.progress-thumb {
|
||||
position: absolute;
|
||||
left: calc(var(--progress-width, 0%) - 6px);
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
background: white;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 2px 4px var(--mask-20);
|
||||
opacity: 0;
|
||||
transition:
|
||||
opacity 0.2s ease,
|
||||
transform 0.1s ease;
|
||||
will-change: opacity, transform;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.progress-bar:hover .progress,
|
||||
.progress.dragging {
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
.progress-bar:hover .progress-thumb,
|
||||
.progress-thumb.dragging {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.progress-thumb.dragging {
|
||||
transform: translateY(-50%) scale(1.2);
|
||||
}
|
||||
|
||||
/* 移动端优化 */
|
||||
@media (hover: none) and (pointer: coarse) {
|
||||
.progress-bar {
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
.progress {
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
.progress-thumb {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
left: calc(var(--progress-width, 0%) - 8px);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.progress-bar:active .progress {
|
||||
height: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.time-display {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 11px;
|
||||
color: var(--overlay-80);
|
||||
text-shadow: 0 1px 2px var(--mask-30);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.current-time,
|
||||
.duration {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,190 @@
|
||||
<template>
|
||||
<div class="player-info">
|
||||
<div class="cover-container" :title="locale.openLyrics" @click="openLyrics">
|
||||
<template v-if="song.cover && !coverError">
|
||||
<img
|
||||
:src="convertToHttps(song.cover)"
|
||||
:alt="locale.coverAlt"
|
||||
class="player-cover"
|
||||
referrerpolicy="no-referrer"
|
||||
@error="handleImageError"
|
||||
>
|
||||
</template>
|
||||
<div v-else class="text-cover">
|
||||
{{ getFirstChar(song.title || '') }}
|
||||
</div>
|
||||
<!-- 悬浮提示层 -->
|
||||
<div class="lyrics-overlay">
|
||||
<svg
|
||||
fill="none"
|
||||
height="20"
|
||||
viewBox="0 0 24 24"
|
||||
width="20"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M3 5h18v2H3V5zm0 4h14v2H3V9zm0 4h18v2H3v-2zm0 4h10v2H3v-2z"
|
||||
fill="currentColor"
|
||||
opacity="0.9"
|
||||
/>
|
||||
<circle cx="20" cy="11" fill="currentColor" opacity="0.7" r="2" />
|
||||
<circle cx="18" cy="15" fill="currentColor" opacity="0.7" r="1.5" />
|
||||
</svg>
|
||||
<span class="lyrics-text">{{ locale.lyrics }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="player-text">
|
||||
<h4>{{ song.title }}</h4>
|
||||
<p>{{ song.artist }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { convertToHttps } from '~/utils/url'
|
||||
import { useLocale } from '~/utils/locale'
|
||||
|
||||
const props = defineProps({
|
||||
song: {
|
||||
type: Object,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['openLyrics'])
|
||||
|
||||
const { ui } = useLocale()
|
||||
const locale = computed(() => ui.value?.playerInfo || {})
|
||||
const coverError = ref(false)
|
||||
|
||||
const handleImageError = () => {
|
||||
coverError.value = true
|
||||
}
|
||||
|
||||
const getFirstChar = (title) => {
|
||||
if (!title) return locale.value.textCoverFallback
|
||||
return title.trim().charAt(0)
|
||||
}
|
||||
|
||||
const openLyrics = () => {
|
||||
emit('openLyrics')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.player-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
--player-lyrics-overlay: rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
.cover-container {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
aspect-ratio: 1;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-collab-hover) 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.cover-container:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.lyrics-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: var(--player-lyrics-overlay);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
color: white;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.cover-container:hover .lyrics-overlay {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.lyrics-text {
|
||||
font-size: 10px;
|
||||
font-weight: 500;
|
||||
text-shadow: 0 1px 2px var(--mask-50);
|
||||
}
|
||||
|
||||
.player-cover {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
/* 添加辉光效果 */
|
||||
box-shadow:
|
||||
0 0 10px var(--overlay-30),
|
||||
0 0 20px var(--overlay-20),
|
||||
0 0 30px var(--overlay-10);
|
||||
transition: box-shadow 0.3s ease;
|
||||
}
|
||||
|
||||
.player-cover:hover {
|
||||
box-shadow:
|
||||
0 0 15px var(--overlay-40),
|
||||
0 0 30px var(--overlay-30),
|
||||
0 0 45px var(--overlay-20);
|
||||
}
|
||||
|
||||
.text-cover {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
aspect-ratio: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-collab-hover) 100%);
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
text-shadow: 0 1px 2px var(--mask-30);
|
||||
}
|
||||
|
||||
.player-text {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.player-text h4 {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: white;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
text-shadow: 0 1px 2px var(--mask-30);
|
||||
}
|
||||
|
||||
.player-text p {
|
||||
margin: 2px 0 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--overlay-80);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
text-shadow: 0 1px 2px var(--mask-30);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,340 @@
|
||||
<template>
|
||||
<div
|
||||
class="volume-control-container"
|
||||
@mouseenter="handleMouseEnter"
|
||||
@mouseleave="handleMouseLeave"
|
||||
@wheel.prevent="handleWheel"
|
||||
>
|
||||
<!-- 弹出的音量条 (仅 PC 端 hover 或移动端点击时显示) -->
|
||||
<Transition name="volume-slide">
|
||||
<div v-show="showSlider" class="volume-slider-popup">
|
||||
<div
|
||||
ref="sliderRef"
|
||||
class="volume-slider"
|
||||
@mousedown="startDrag"
|
||||
@touchstart.prevent="startTouchDrag"
|
||||
@click="handleSliderClick"
|
||||
>
|
||||
<div class="volume-slider-bg">
|
||||
<div
|
||||
class="volume-slider-fill"
|
||||
:style="{ height: `${volumePercentage}%` }"
|
||||
/>
|
||||
<div
|
||||
class="volume-slider-thumb"
|
||||
:style="{ bottom: `${volumePercentage}%` }"
|
||||
:class="{ dragging: isDragging }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
|
||||
<!-- 底部按钮区 -->
|
||||
<div
|
||||
class="volume-btn"
|
||||
:class="{ active: showSlider }"
|
||||
@click="toggleMuteOrShowSlider"
|
||||
>
|
||||
<!-- 显示百分比或图标 -->
|
||||
<Transition name="fade-icon" mode="out-in">
|
||||
<span v-if="showSlider" class="volume-text sf-pro">
|
||||
{{ Math.round(volumePercentage) }}%
|
||||
</span>
|
||||
<Icon
|
||||
v-else
|
||||
:name="volumeIcon"
|
||||
:size="20"
|
||||
:class="{ 'muted-icon': isMuted }"
|
||||
/>
|
||||
</Transition>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||
import Icon from '../Icon.vue'
|
||||
import { useAudioPlayerControl } from '~/composables/useAudioPlayerControl'
|
||||
|
||||
const control = useAudioPlayerControl()
|
||||
|
||||
const isMobile = ref(false)
|
||||
const showSlider = ref(false)
|
||||
const sliderRef = ref<HTMLElement | null>(null)
|
||||
const isDragging = ref(false)
|
||||
const hideTimer = ref<number | null>(null)
|
||||
|
||||
const volumePercentage = computed(() => {
|
||||
return (control.volume.value || 0) * 100
|
||||
})
|
||||
|
||||
const isMuted = computed(() => {
|
||||
return control.isMuted.value || control.volume.value === 0
|
||||
})
|
||||
|
||||
const volumeIcon = computed(() => {
|
||||
if (isMuted.value || control.volume.value === 0) return 'volume-mute'
|
||||
return 'volume'
|
||||
})
|
||||
|
||||
const checkMobile = () => {
|
||||
if (import.meta.client) {
|
||||
isMobile.value = window.innerWidth <= 768
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
checkMobile()
|
||||
window.addEventListener('resize', checkMobile)
|
||||
document.addEventListener('click', handleClickOutside)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', checkMobile)
|
||||
document.removeEventListener('click', handleClickOutside)
|
||||
if (hideTimer.value !== null) {
|
||||
clearTimeout(hideTimer.value)
|
||||
}
|
||||
})
|
||||
|
||||
// PC端 Hover 效果
|
||||
const handleMouseEnter = () => {
|
||||
if (isMobile.value || isDragging.value) return
|
||||
if (hideTimer.value !== null) clearTimeout(hideTimer.value)
|
||||
showSlider.value = true
|
||||
}
|
||||
|
||||
const handleMouseLeave = () => {
|
||||
if (isMobile.value || isDragging.value) return
|
||||
hideTimer.value = window.setTimeout(() => {
|
||||
showSlider.value = false
|
||||
}, 300)
|
||||
}
|
||||
|
||||
// 移动端点击处理
|
||||
const toggleMuteOrShowSlider = (e: Event) => {
|
||||
if (isMobile.value) {
|
||||
e.stopPropagation()
|
||||
showSlider.value = !showSlider.value
|
||||
} else {
|
||||
// PC端点击直接静音/取消静音
|
||||
control.toggleMute()
|
||||
}
|
||||
}
|
||||
|
||||
// 滚轮控制音量
|
||||
const handleWheel = (e: WheelEvent) => {
|
||||
if (!showSlider.value && !isMobile.value) return
|
||||
// 向上滚增加音量,向下滚减小音量
|
||||
const delta = e.deltaY > 0 ? -0.05 : 0.05
|
||||
control.setVolume(control.volume.value + delta)
|
||||
}
|
||||
|
||||
// 拖拽控制
|
||||
const updateVolumeFromEvent = (clientY: number) => {
|
||||
if (!sliderRef.value) return
|
||||
const rect = sliderRef.value.getBoundingClientRect()
|
||||
// 计算相对于底部的百分比
|
||||
const y = Math.max(0, Math.min(rect.height, rect.bottom - clientY))
|
||||
const percentage = y / rect.height
|
||||
control.setVolume(percentage)
|
||||
}
|
||||
|
||||
const handleSliderClick = (e: MouseEvent) => {
|
||||
updateVolumeFromEvent(e.clientY)
|
||||
}
|
||||
|
||||
const startDrag = (e: MouseEvent) => {
|
||||
isDragging.value = true
|
||||
updateVolumeFromEvent(e.clientY)
|
||||
|
||||
const onMouseMove = (e: MouseEvent) => {
|
||||
updateVolumeFromEvent(e.clientY)
|
||||
}
|
||||
|
||||
const onMouseUp = () => {
|
||||
isDragging.value = false
|
||||
document.removeEventListener('mousemove', onMouseMove)
|
||||
document.removeEventListener('mouseup', onMouseUp)
|
||||
// 如果鼠标已经离开区域,隐藏 slider
|
||||
if (!isMobile.value) {
|
||||
hideTimer.value = window.setTimeout(() => {
|
||||
showSlider.value = false
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('mousemove', onMouseMove)
|
||||
document.addEventListener('mouseup', onMouseUp)
|
||||
}
|
||||
|
||||
const startTouchDrag = (e: TouchEvent) => {
|
||||
isDragging.value = true
|
||||
updateVolumeFromEvent(e.touches[0].clientY)
|
||||
|
||||
const onTouchMove = (e: TouchEvent) => {
|
||||
updateVolumeFromEvent(e.touches[0].clientY)
|
||||
}
|
||||
|
||||
const onTouchEnd = () => {
|
||||
isDragging.value = false
|
||||
document.removeEventListener('touchmove', onTouchMove)
|
||||
document.removeEventListener('touchend', onTouchEnd)
|
||||
}
|
||||
|
||||
document.addEventListener('touchmove', onTouchMove, { passive: false })
|
||||
document.addEventListener('touchend', onTouchEnd)
|
||||
}
|
||||
|
||||
const handleClickOutside = (e: Event) => {
|
||||
if (isMobile.value && showSlider.value) {
|
||||
const target = e.target as HTMLElement
|
||||
if (!target.closest('.volume-control-container')) {
|
||||
showSlider.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.volume-control-container {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 39px;
|
||||
height: 39px;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
/* 底部按钮 */
|
||||
.volume-btn {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--text-primary-60);
|
||||
cursor: pointer;
|
||||
transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
||||
border-radius: 50%;
|
||||
background: transparent;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.volume-btn:hover {
|
||||
color: var(--text-primary);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.volume-btn.active {
|
||||
color: var(--text-primary);
|
||||
background: var(--overlay-10);
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.muted-icon {
|
||||
color: var(--volume-control-muted-color);
|
||||
}
|
||||
|
||||
.volume-text {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
|
||||
/* 图标/文本切换动画 */
|
||||
.fade-icon-enter-active,
|
||||
.fade-icon-leave-active {
|
||||
transition: opacity 0.2s ease, transform 0.2s ease;
|
||||
}
|
||||
.fade-icon-enter-from,
|
||||
.fade-icon-leave-to {
|
||||
opacity: 0;
|
||||
transform: scale(0.8);
|
||||
}
|
||||
|
||||
/* 弹出层 */
|
||||
.volume-slider-popup {
|
||||
position: absolute;
|
||||
bottom: calc(100% + 8px);
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 36px;
|
||||
height: 120px;
|
||||
background: linear-gradient(135deg, var(--overlay-15), var(--overlay-5)),
|
||||
var(--volume-control-panel-bg);
|
||||
backdrop-filter: blur(20px) saturate(1.8);
|
||||
-webkit-backdrop-filter: blur(20px) saturate(1.8);
|
||||
border: 1px solid var(--overlay-10);
|
||||
border-radius: 18px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 10px 30px var(--mask-30), inset 0 1px 0 var(--overlay-20);
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
/* 弹出动画 */
|
||||
.volume-slide-enter-active {
|
||||
transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
|
||||
transform-origin: bottom center;
|
||||
}
|
||||
.volume-slide-leave-active {
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
transform-origin: bottom center;
|
||||
}
|
||||
.volume-slide-enter-from,
|
||||
.volume-slide-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(10px) scale(0.8);
|
||||
}
|
||||
|
||||
/* 滑动条容器 */
|
||||
.volume-slider {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
.volume-slider-bg {
|
||||
position: relative;
|
||||
width: 6px;
|
||||
height: 100%;
|
||||
background: var(--overlay-20);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.volume-slider-fill {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
background: linear-gradient(to top, var(--color-accent-light), var(--color-cyan));
|
||||
border-radius: 3px;
|
||||
transition: height 0.1s linear;
|
||||
}
|
||||
|
||||
.volume-slider-thumb {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translate(-50%, 50%);
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
background: var(--text-primary);
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 2px 6px var(--mask-30);
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.volume-slider-thumb.dragging,
|
||||
.volume-slider:hover .volume-slider-thumb {
|
||||
transform: translate(-50%, 50%) scale(1.2);
|
||||
box-shadow: 0 4px 10px var(--mask-40);
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user