仰望星辰工作室

starmusic-mobile

starmusic-mobile/ components/player-bar.vue 3.7 KB · 152 行 原始文件
1<template>
2 <view v-if="musicInfo" class="player-bar tv-item d-slide-up d-press" data-navid="player-bar" @click="handleClick">
3 <image v-if="pic" class="player-pic" :src="pic" mode="aspectFill" />
4 <view v-else class="player-pic player-pic-placeholder">
5 <lx-icon name="music" :size="44" color="#c0c4cc" />
6 </view>
7 <view class="player-info">
8 <text class="player-name">{{ musicInfo.name || '未知歌曲' }}</text>
9 <text class="player-singer">{{ musicInfo.singer || '未知歌手' }}</text>
10 </view>
11 <view class="player-controls">
12 <view class="control-btn tv-item d-press" data-navid="player-play" @click.stop="handleTogglePlay">
13 <lx-icon :name="isPlay ? 'pause' : 'play'" :size="52" color="theme" />
14 </view>
15 <view class="control-btn tv-item d-press" data-navid="player-next" @click.stop="handleNext">
16 <lx-icon name="next" :size="48" color="#303133" />
17 </view>
18 </view>
19 </view>
20</template>
21
22<script>
23import * as player from '../common/player.js'
24import event from '../common/event.js'
25import LxIcon from './lx-icon/lx-icon.vue'
26
27export default {
28 name: 'PlayerBar',
29 components: { LxIcon },
30 data() {
31 return {
32 musicInfo: null,
33 pic: '',
34 isPlay: false,
35 }
36 },
37 created() {
38 const state = player.getPlayState()
39 this.musicInfo = state.playMusicInfo
40 this.isPlay = state.isPlay
41 if (state.playMusicInfo && state.playMusicInfo.img) this.pic = state.playMusicInfo.img
42 this.bindEvents()
43 },
44 beforeUnmount() {
45 this.unbindEvents()
46 },
47 methods: {
48 bindEvents() {
49 this._onMusicInfo = (data) => {
50 this.musicInfo = data.musicInfo
51 }
52 this._onState = (data) => {
53 this.isPlay = data.isPlay
54 }
55 this._onPic = (url) => {
56 this.pic = url
57 }
58 this._offList = []
59 this._offList.push(event.on('playerMusicInfoChanged', this._onMusicInfo))
60 this._offList.push(event.on('playerStateChanged', this._onState))
61 this._offList.push(event.on('playerPicUpdated', this._onPic))
62 },
63 unbindEvents() {
64 if (this._offList) {
65 this._offList.forEach((off) => off && off())
66 this._offList = []
67 }
68 },
69 handleClick() {
70 uni.navigateTo({ url: '/pages/play-detail/play-detail' })
71 },
72 handleTogglePlay() {
73 player.togglePlay()
74 },
75 handleNext() {
76 player.playNext(false)
77 },
78 },
79}
80</script>
81
82<style lang="scss" scoped>
83.player-bar {
84 display: flex;
85 align-items: center;
86 margin: 12rpx 24rpx;
87 padding: 16rpx 24rpx;
88 background: var(--card-bg, #fff);
89 /* 半透明底 + 背景模糊:仅背景图开启时生效(变量由 background.js 注入),否则 none 跳过合成 */
90 backdrop-filter: var(--glass-blur, none);
91 -webkit-backdrop-filter: var(--glass-blur, none);
92 border-radius: 24rpx;
93 box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
94}
95
96.player-pic {
97 width: 88rpx;
98 height: 88rpx;
99 border-radius: 16rpx;
100 margin-right: 20rpx;
101 flex-shrink: 0;
102}
103
104.player-pic-placeholder {
105 display: flex;
106 align-items: center;
107 justify-content: center;
108 background: var(--fill-bg, #f2f3f5);
109}
110
111.player-info {
112 flex: 1;
113 min-width: 0;
114 display: flex;
115 flex-direction: column;
116}
117
118.player-name {
119 font-size: 28rpx;
120 color: #303133;
121 overflow: hidden;
122 text-overflow: ellipsis;
123 white-space: nowrap;
124}
125
126.player-singer {
127 margin-top: 4rpx;
128 font-size: 24rpx;
129 color: var(--text-muted, #909399);
130 overflow: hidden;
131 text-overflow: ellipsis;
132 white-space: nowrap;
133}
134
135
136
137.player-controls {
138 display: flex;
139 align-items: center;
140 margin-left: 16rpx;
141 flex-shrink: 0;
142}
143
144.control-btn {
145 width: 72rpx;
146 height: 72rpx;
147 display: flex;
148 align-items: center;
149 justify-content: center;
150}
151
152</style>