File size: 16,857 Bytes
a1eddda 25e7862 a1eddda 25e7862 a1eddda |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
<template>
<div class="desktop-sidebar hidden-mobile">
<!-- 应用Logo和标题 -->
<div class="sidebar-header">
<div class="app-logo">
<i class="fas fa-music"></i>
</div>
<div class="app-title">云音乐</div>
</div>
<!-- 导航菜单 -->
<nav class="sidebar-nav">
<router-link
v-for="item in navItems"
:key="item.name"
:to="item.path"
class="nav-item"
:class="{ active: currentRoute === item.name }"
@click="handleNavClick(item)"
>
<i :class="item.icon" class="nav-icon"></i>
<span class="nav-label">{{ item.label }}</span>
<div class="nav-indicator" v-if="currentRoute === item.name"></div>
</router-link>
</nav>
<!-- 播放控制区域 -->
<div class="sidebar-player" v-if="currentSong">
<!-- 当前播放歌曲信息 -->
<div class="current-song" @click="openFullPlayer">
<div class="song-cover">
<img
:src="currentCoverUrl || defaultCover"
:alt="currentSong.name"
class="cover-image"
@error="handleImageError"
/>
<div class="play-overlay" @click.stop="togglePlay">
<i :class="isPlaying ? 'fas fa-pause' : 'fas fa-play'"></i>
</div>
</div>
<div class="song-details">
<div class="song-name" :title="currentSong.name">{{ currentSong.name }}</div>
<div class="song-artist" :title="formattedArtist">{{ formattedArtist }}</div>
</div>
</div>
<!-- 播放控制按钮 -->
<div class="player-controls">
<button class="control-btn" @click="playPrevious" title="上一首">
<i class="fas fa-step-backward"></i>
</button>
<button class="control-btn play-btn" @click="togglePlay" :title="isPlaying ? '暂停' : '播放'">
<i :class="isPlaying ? 'fas fa-pause' : 'fas fa-play'"></i>
</button>
<button class="control-btn" @click="playNext" title="下一首">
<i class="fas fa-step-forward"></i>
</button>
<button class="control-btn" @click="openFullPlayer" title="打开播放器">
<i class="fas fa-expand"></i>
</button>
</div>
<!-- 进度条 -->
<div class="progress-container">
<div class="progress-background" @click="handleProgressClick" ref="progressRef">
<div
class="progress-fill"
:style="{ width: `${progress}%` }"
></div>
</div>
</div>
<!-- 音量控制 -->
<div class="volume-control">
<button class="volume-btn" @click="toggleMute">
<i :class="volumeIcon"></i>
</button>
<input
type="range"
min="0"
max="100"
:value="volume"
@input="handleVolumeChange"
class="volume-slider"
/>
</div>
</div>
<!-- 播放统计 -->
<div class="sidebar-stats" v-if="!currentSong">
<div class="stats-item">
<i class="fas fa-music"></i>
<div class="stats-info">
<div class="stats-label">暂无播放</div>
<div class="stats-value">选择音乐开始播放</div>
</div>
</div>
</div>
<!-- 快捷操作 -->
<div class="sidebar-actions">
<button class="action-btn" @click="toggleTheme" :title="isDarkTheme ? '切换到亮色主题' : '切换到暗色主题'">
<i :class="isDarkTheme ? 'fas fa-sun' : 'fas fa-moon'"></i>
</button>
<button class="action-btn" @click="openSettings" title="设置">
<i class="fas fa-cog"></i>
</button>
</div>
</div>
</template>
<script setup>
import { computed, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { usePlayerStore } from '@/stores/player'
import { usePlayQueueStore } from '@/stores/playqueue'
import { useSettingsStore } from '@/stores/settings'
import { utils } from '@/services/musicApi'
const route = useRoute()
const router = useRouter()
const playerStore = usePlayerStore()
const playQueueStore = usePlayQueueStore()
const settingsStore = useSettingsStore()
// 播放器相关状态
const currentCoverUrl = ref('')
const isMuted = ref(false)
const lastVolume = ref(80)
const progressRef = ref(null)
// 导航项配置
const navItems = [
{
name: 'Home',
path: '/home',
label: '首页',
icon: 'fas fa-home'
},
{
name: 'Favorites',
path: '/favorites',
label: '我喜欢',
icon: 'fas fa-heart'
},
{
name: 'Playlists',
path: '/playlists',
label: '歌单',
icon: 'fas fa-music'
},
{
name: 'PlayQueue',
path: '/play-queue',
label: '播放列表',
icon: 'fas fa-list'
},
{
name: 'History',
path: '/history',
label: '播放历史',
icon: 'fas fa-history'
}
]
// 计算属性
const currentRoute = computed(() => route.name)
const currentSong = computed(() => playerStore.currentSong)
const isPlaying = computed(() => playerStore.isPlaying)
const progress = computed(() => playerStore.progress)
const volume = computed(() => playerStore.volume || 80)
const isDarkTheme = computed(() => settingsStore.settings.theme === 'dark')
const formattedArtist = computed(() => {
if (!currentSong.value?.artist) return ''
return utils.formatArtist(currentSong.value.artist)
})
// 默认封面
const defaultCover = computed(() => {
return 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjY0IiBoZWlnaHQ9IjY0IiBmaWxsPSJyZ2JhKDI1NSwyNTUsMjU1LDAuMSkiIHJ4PSI4Ii8+CjxwYXRoIGQ9Ik0zMiAyMEw0MCAzMkgzNlY0NEgyOFYzMkgyNEwzMiAyMFoiIGZpbGw9InJnYmEoMjU1LDI1NSwyNTUsMC4zKSIvPgo8L3N2Zz4K'
})
// 音量图标
const volumeIcon = computed(() => {
if (isMuted.value || volume.value === 0) {
return 'fas fa-volume-mute'
} else if (volume.value < 30) {
return 'fas fa-volume-off'
} else if (volume.value < 70) {
return 'fas fa-volume-down'
} else {
return 'fas fa-volume-up'
}
})
// 方法
const handleNavClick = (item) => {
console.log('导航到:', item.label)
}
// 播放器控制方法
const togglePlay = () => {
// 通过全局事件触发App.vue中的播放控制
window.dispatchEvent(new CustomEvent('sidebarTogglePlay'))
}
const playPrevious = () => {
const prevSong = playQueueStore.playPrevious()
if (prevSong) {
// 强制从头开始播放上一首歌曲
playerStore.setCurrentTime(0)
playerStore.playSong(prevSong)
}
}
const playNext = () => {
const nextSong = playQueueStore.playNext()
if (nextSong) {
// 强制从头开始播放下一首歌曲
playerStore.setCurrentTime(0)
playerStore.playSong(nextSong)
}
}
const openFullPlayer = () => {
if (currentSong.value) {
router.push('/player')
}
}
// 进度条控制
const handleProgressClick = (event) => {
if (!progressRef.value || !playerStore.duration) return
const rect = progressRef.value.getBoundingClientRect()
const percent = (event.clientX - rect.left) / rect.width
const newTime = percent * playerStore.duration
playerStore.seekTo(newTime)
}
// 音量控制
const toggleMute = () => {
if (isMuted.value) {
playerStore.setVolume(lastVolume.value)
isMuted.value = false
} else {
lastVolume.value = volume.value
playerStore.setVolume(0)
isMuted.value = true
}
}
const handleVolumeChange = (event) => {
const newVolume = parseInt(event.target.value)
playerStore.setVolume(newVolume)
isMuted.value = newVolume === 0
}
// 图片加载错误处理
const handleImageError = () => {
currentCoverUrl.value = defaultCover.value
}
// 加载专辑封面
const loadAlbumCover = async () => {
if (!currentSong.value) {
currentCoverUrl.value = defaultCover.value
return
}
try {
const coverUrlResult = await playerStore.getAlbumCover(currentSong.value, 300)
if (coverUrlResult) {
currentCoverUrl.value = coverUrlResult
} else {
currentCoverUrl.value = defaultCover.value
}
} catch (error) {
console.error('加载侧边栏封面失败:', error)
currentCoverUrl.value = defaultCover.value
}
}
const toggleTheme = () => {
const newTheme = isDarkTheme.value ? 'light' : 'dark'
settingsStore.updateSetting('theme', newTheme)
settingsStore.applyTheme(newTheme)
}
const openSettings = () => {
router.push('/settings')
}
// 监听当前歌曲变化
watch(currentSong, (newSong) => {
if (newSong) {
loadAlbumCover()
} else {
currentCoverUrl.value = defaultCover.value
}
}, { immediate: true })
</script>
<style scoped>
.desktop-sidebar {
width: 280px;
height: 100vh;
background: var(--bg-card);
border-right: 1px solid var(--border-light);
display: flex;
flex-direction: column;
position: fixed;
left: 0;
top: 0;
z-index: 100;
backdrop-filter: blur(20px);
}
/* 应用头部 */
.sidebar-header {
display: flex;
align-items: center;
gap: 12px;
padding: 24px 20px;
border-bottom: 1px solid var(--border-lighter);
}
.app-logo {
width: 40px;
height: 40px;
background: linear-gradient(135deg, var(--primary-color), var(--primary-color-hover));
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 18px;
box-shadow: 0 4px 12px var(--glow-color);
}
.app-title {
font-size: 20px;
font-weight: 700;
color: var(--text-primary);
}
/* 导航菜单 */
.sidebar-nav {
flex: 1;
padding: 16px 0;
overflow-y: auto;
}
.nav-item {
display: flex;
align-items: center;
gap: 12px;
padding: 16px 20px;
text-decoration: none;
color: var(--text-secondary);
transition: all var(--transition-fast);
position: relative;
margin: 0 12px;
border-radius: 12px;
}
.nav-item:hover {
background: var(--overlay-lighter);
color: var(--text-primary);
transform: translateX(4px);
}
.nav-item.active {
background: linear-gradient(135deg, var(--primary-color), var(--primary-color-hover));
color: white;
box-shadow: 0 4px 12px var(--glow-color);
}
.nav-item.active .nav-icon {
color: white;
}
.nav-icon {
font-size: 18px;
width: 20px;
text-align: center;
transition: var(--transition-fast);
}
.nav-label {
font-size: 16px;
font-weight: 500;
}
.nav-indicator {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
width: 4px;
height: 20px;
background: white;
border-radius: 2px;
opacity: 0.8;
}
/* 播放统计 */
.sidebar-stats {
padding: 16px 20px;
border-top: 1px solid var(--border-lighter);
border-bottom: 1px solid var(--border-lighter);
}
.stats-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 0;
}
.stats-item i {
font-size: 16px;
color: var(--primary-color);
width: 20px;
text-align: center;
}
.stats-info {
flex: 1;
min-width: 0;
}
.stats-label {
font-size: 12px;
color: var(--text-tertiary);
margin-bottom: 2px;
}
.stats-value {
font-size: 14px;
font-weight: 600;
color: var(--text-primary);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* 快捷操作 */
.sidebar-actions {
display: flex;
gap: 8px;
padding: 16px 20px;
}
.action-btn {
flex: 1;
height: 40px;
border: none;
background: var(--overlay-lighter);
color: var(--text-secondary);
border-radius: 10px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
transition: var(--transition-fast);
}
.action-btn:hover {
background: var(--overlay-light);
color: var(--text-primary);
transform: scale(1.05);
}
/* 滚动条样式 */
.sidebar-nav::-webkit-scrollbar {
width: 4px;
}
.sidebar-nav::-webkit-scrollbar-track {
background: transparent;
}
.sidebar-nav::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.2);
border-radius: 2px;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover {
background: rgba(255, 255, 255, 0.4);
}
/* 黑色主题适配 */
[data-theme="dark"] .sidebar-nav::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.1);
}
[data-theme="dark"] .sidebar-nav::-webkit-scrollbar-thumb:hover {
background: rgba(255, 255, 255, 0.2);
}
/* 侧边栏播放器 */
.sidebar-player {
padding: 20px;
border-top: 1px solid var(--border-lighter);
border-bottom: 1px solid var(--border-lighter);
background: var(--overlay-lighter);
backdrop-filter: blur(10px);
}
.current-song {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 16px;
cursor: pointer;
transition: var(--transition-fast);
border-radius: 8px;
padding: 4px;
}
.current-song:hover {
background: var(--overlay-lighter);
transform: scale(1.02);
}
.song-cover {
position: relative;
width: 48px;
height: 48px;
border-radius: 8px;
overflow: hidden;
flex-shrink: 0;
}
.cover-image {
width: 100%;
height: 100%;
object-fit: cover;
}
.play-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
transition: var(--transition-fast);
cursor: pointer;
}
.song-cover:hover .play-overlay {
opacity: 1;
}
.play-overlay i {
color: white;
font-size: 14px;
}
.song-details {
flex: 1;
min-width: 0;
}
.song-name {
font-size: 14px;
font-weight: 600;
color: var(--text-primary);
margin-bottom: 2px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.song-artist {
font-size: 12px;
color: var(--text-secondary);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* 播放控制按钮 */
.player-controls {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
margin-bottom: 16px;
}
.control-btn {
width: 32px;
height: 32px;
border-radius: 50%;
background: var(--overlay-light);
border: 1px solid var(--border-light);
color: var(--text-secondary);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
transition: var(--transition-fast);
}
.control-btn:hover {
background: var(--overlay-light);
color: var(--text-primary);
transform: scale(1.1);
}
.control-btn.play-btn {
width: 36px;
height: 36px;
font-size: 14px;
background: var(--primary-color);
color: white;
border-color: var(--primary-color);
}
.control-btn.play-btn:hover {
background: var(--primary-color-hover);
border-color: var(--primary-color-hover);
box-shadow: 0 0 12px var(--glow-color);
}
/* 进度条 */
.progress-container {
margin-bottom: 16px;
}
.progress-background {
height: 4px;
background: var(--border-light);
border-radius: 2px;
cursor: pointer;
position: relative;
transition: var(--transition-fast);
}
.progress-background:hover {
height: 6px;
transform: scaleY(1.2);
}
.progress-fill {
height: 100%;
background: var(--primary-color);
border-radius: 2px;
transition: width 0.1s ease;
position: relative;
}
.progress-fill::after {
content: '';
position: absolute;
right: -2px;
top: 50%;
transform: translateY(-50%);
width: 8px;
height: 8px;
background: var(--primary-color);
border-radius: 50%;
opacity: 0;
transition: var(--transition-fast);
}
.progress-background:hover .progress-fill::after {
opacity: 1;
}
/* 音量控制 */
.volume-control {
display: flex;
align-items: center;
gap: 12px;
}
.volume-btn {
width: 28px;
height: 28px;
border-radius: 50%;
background: var(--overlay-lighter);
border: none;
color: var(--text-secondary);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 10px;
transition: var(--transition-fast);
flex-shrink: 0;
}
.volume-btn:hover {
background: var(--overlay-light);
color: var(--text-primary);
}
.volume-slider {
flex: 1;
height: 3px;
background: var(--border-light);
border-radius: 2px;
outline: none;
appearance: none;
cursor: pointer;
transition: var(--transition-fast);
}
.volume-slider::-webkit-slider-thumb {
appearance: none;
width: 12px;
height: 12px;
border-radius: 50%;
background: var(--primary-color);
cursor: pointer;
border: 2px solid white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
transition: var(--transition-fast);
}
.volume-slider::-webkit-slider-thumb:hover {
transform: scale(1.2);
}
.volume-slider::-moz-range-thumb {
width: 12px;
height: 12px;
border-radius: 50%;
background: var(--primary-color);
cursor: pointer;
border: 2px solid white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
transition: var(--transition-fast);
}
/* 响应式 - 只在PC端显示 */
@media (max-width: 1023px) {
.desktop-sidebar {
display: none;
}
}
</style> |