MiniPlayer.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view v-if="showMiniPlayer" class="mini-player" @click="goToPlayer">
  3. <!-- 封面 -->
  4. <view class="mini-cover" :style="{ background: coverGradient }">
  5. <text class="cover-icon">{{ getTitleLetter(audioStore.currentAudio?.title || '') }}</text>
  6. </view>
  7. <!-- 信息 -->
  8. <view class="mini-info">
  9. <text class="mini-title">{{ audioStore.currentAudio?.title || '未知音频' }}</text>
  10. <text class="mini-subtitle">{{ formatTime(audioStore.currentTime) }} / {{ formatTime(audioStore.duration) }}</text>
  11. </view>
  12. <!-- 控制按钮 -->
  13. <view class="mini-controls">
  14. <view class="control-btn" @click.stop="togglePlay">
  15. <text>{{ audioStore.isPlaying ? '⏸' : '▶' }}</text>
  16. </view>
  17. <view class="control-btn" @click.stop="playNext">
  18. <text>⏭</text>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script setup lang="ts">
  24. import { computed } from 'vue';
  25. import { onShow } from '@dcloudio/uni-app';
  26. import { useAudioStore } from '../store/audio';
  27. import { getCoverGradient, getTitleLetter } from '../composables/useCoverStyle';
  28. const audioStore = useAudioStore();
  29. const showMiniPlayer = computed(() => {
  30. // 获取当前页面路径
  31. const pages = getCurrentPages();
  32. const currentPage = pages[pages.length - 1];
  33. const currentPath = currentPage?.route || '';
  34. // 如果在播放器页面,不显示迷你播放器
  35. if (currentPath.includes('player')) {
  36. return false;
  37. }
  38. // 如果有当前音频,显示迷你播放器
  39. return !!audioStore.currentAudio;
  40. });
  41. // 封面颜色
  42. const coverGradient = computed(() => {
  43. const voiceId = audioStore.currentAudio?.voiceId || 'voice_01';
  44. return getCoverGradient(voiceId);
  45. });
  46. // 格式化时间
  47. function formatTime(seconds: number): string {
  48. if (!seconds || isNaN(seconds)) return '0:00';
  49. const mins = Math.floor(seconds / 60);
  50. const secs = Math.floor(seconds % 60);
  51. return `${mins}:${secs.toString().padStart(2, '0')}`;
  52. }
  53. // 切换播放
  54. function togglePlay() {
  55. audioStore.togglePlay();
  56. }
  57. // 播放下一首
  58. function playNext() {
  59. audioStore.playNext();
  60. }
  61. // 跳转到播放器页面
  62. function goToPlayer() {
  63. uni.navigateTo({ url: '/pages/player/index' });
  64. }
  65. </script>
  66. <style scoped>
  67. .mini-player {
  68. position: fixed;
  69. bottom: 120rpx;
  70. left: 16rpx;
  71. right: 16rpx;
  72. height: 96rpx;
  73. background: rgba(255, 255, 255, 0.9);
  74. backdrop-filter: blur(28px);
  75. -webkit-backdrop-filter: blur(28px);
  76. border-radius: 48rpx;
  77. box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.12), 0 0 0 0.5rpx rgba(0, 0, 0, 0.06);
  78. display: flex;
  79. align-items: center;
  80. padding: 0 16rpx;
  81. z-index: 999;
  82. transition: transform 0.3s cubic-bezier(0.22, 0.61, 0.36, 1);
  83. animation: miniPlayerIn 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
  84. }
  85. @keyframes miniPlayerIn {
  86. from { opacity: 0; transform: translateY(20px); }
  87. to { opacity: 1; transform: translateY(0); }
  88. }
  89. .mini-player:active {
  90. transform: scale(0.98);
  91. }
  92. .mini-cover {
  93. width: 68rpx;
  94. height: 68rpx;
  95. border-radius: 14rpx;
  96. display: flex;
  97. align-items: center;
  98. justify-content: center;
  99. flex-shrink: 0;
  100. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  101. }
  102. .cover-icon {
  103. font-size: 28rpx;
  104. opacity: 0.7;
  105. }
  106. .mini-info {
  107. flex: 1;
  108. margin-left: 16rpx;
  109. overflow: hidden;
  110. }
  111. .mini-title {
  112. font-size: 26rpx;
  113. color: #111827;
  114. font-weight: 600;
  115. display: block;
  116. overflow: hidden;
  117. text-overflow: ellipsis;
  118. white-space: nowrap;
  119. }
  120. .mini-subtitle {
  121. font-size: 20rpx;
  122. color: #9ca3af;
  123. margin-top: 2rpx;
  124. display: block;
  125. }
  126. .mini-controls {
  127. display: flex;
  128. align-items: center;
  129. gap: 8rpx;
  130. }
  131. .control-btn {
  132. width: 60rpx;
  133. height: 60rpx;
  134. border-radius: 50%;
  135. background: rgba(79, 70, 229, 0.08);
  136. display: flex;
  137. align-items: center;
  138. justify-content: center;
  139. font-size: 26rpx;
  140. color: #4f46e5;
  141. transition: all 0.2s;
  142. }
  143. .control-btn:active {
  144. transform: scale(0.9);
  145. background: rgba(79, 70, 229, 0.18);
  146. }
  147. </style>