Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.

Commit 8ce40af

Browse files
committed
构建 - currentSong 的滚动逻辑
1 parent c6ca109 commit 8ce40af

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/common/scss/variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $color-background-d: rgba(0, 0, 0, 0.3);
44
$color-highlight-background: #333;
55
$color-dialog-background: #666;
66
$color-theme: #ffeb3b; // #ffcd32
7-
$color-theme-d: rgba(255, 205, 49, 0.5);
7+
$color-theme-d: #ffeb3b; // rgba(255, 205, 49, 0.5);
88
$color-sub-theme: #d93f30;
99
$color-text: #fff;
1010
$color-text-d: rgba(255, 255, 255, 0.3);

src/components/parts-playlist/parts-playlist.vue

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
</h1>
1414
</div>
1515

16-
<BaseScroll class="list-content" :data="sequenceList">
16+
<BaseScroll ref="contentScroll" class="list-content" :data="sequenceList">
1717
<ul>
1818
<li
19+
ref="playlistItem"
1920
class="content-item"
2021
v-for="(song, index) of sequenceList"
2122
:key="index"
22-
@click="selectItem(song, index)"
23+
@click="selectSong(song, index)"
2324
>
24-
<i class="current"></i>
25+
<i :class="['current', getCurrentIcon(song)]"></i>
2526
<span class="item-text">{{ song.name }}</span>
2627
<span class="like-btn">
2728
<i class="icon-not-like"></i>
@@ -71,7 +72,24 @@ export default {
7172
},
7273
7374
methods: {
74-
selectItem (song, index) {
75+
scrollToCurrentSong (current) {
76+
const index = this.sequenceList.findIndex(item => {
77+
return current.id === item.id
78+
})
79+
80+
this.$refs.contentScroll.scrollToElement(this.$refs.playlistItem[index], 300)
81+
},
82+
83+
getCurrentIcon (item) {
84+
if (this.currentSong.id === item.id) {
85+
return 'icon-play'
86+
} else {
87+
return ''
88+
}
89+
},
90+
91+
selectSong (song, index) {
92+
// 传入的 Index 即是展示性列表 sequenceList 中的 Index
7593
if (this.mode === playMode.random) {
7694
index = this.playlist.findIndex(item => {
7795
return song.id === item.id
@@ -114,6 +132,11 @@ export default {
114132
115133
showPlaylist () {
116134
this.hasShowPlaylist = true
135+
// 只有在 display 非 none 值之后才是正确的计算元素高度的时机
136+
setTimeout(() => { // this.$nextTick
137+
this.$refs.contentScroll.refresh()
138+
this.scrollToCurrentSong(this.currentSong)
139+
}, 20)
117140
},
118141
119142
closePlaylist () {
@@ -128,6 +151,16 @@ export default {
128151
})
129152
},
130153
154+
watch: {
155+
currentSong (newSong, oldSong) {
156+
if (!this.showPlaylist || newSong.id === oldSong.id) {
157+
return
158+
}
159+
160+
this.scrollToCurrentSong(newSong)
161+
}
162+
},
163+
131164
computed: {
132165
playModeIcon () {
133166
return this.mode === 0 ? 'icon-sequence' : this.mode === 1 ? 'icon-loop' : 'icon-random'

0 commit comments

Comments
 (0)