feat: align with upstream 1.5.9.9
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user