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

Commit c6ca109

Browse files
committed
构建 - playlist 组件 模式切换、展示/消失逻辑
1 parent 5abd3dc commit c6ca109

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

src/base/base-confirm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<transition name="confirm-fade">
3-
<div class="confirm" v-show="showFlag">
3+
<div class="confirm" v-show="showFlag" @click.self="chooseCancel">
44
<div class="confirm-wrapper">
55
<div class="confirm-content">
66
<p class="text">{{ title }}</p>

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<transition name="list-fade">
3-
<div class="playlist" v-show="hasShowPlaylist" @click="closePlaylist">
4-
<div class="list-wrapper" @click.stop>
3+
<div class="playlist" v-show="hasShowPlaylist" @click.self="closePlaylist">
4+
<div class="list-wrapper">
55

66
<div class="list-header">
77
<h1 class="title">
@@ -13,12 +13,13 @@
1313
</h1>
1414
</div>
1515

16-
<BaseScroll class="list-content" :data="playlist">
16+
<BaseScroll class="list-content" :data="sequenceList">
1717
<ul>
1818
<li
1919
class="content-item"
20-
v-for="(song, index) of playlist"
20+
v-for="(song, index) of sequenceList"
2121
:key="index"
22+
@click="selectItem(song, index)"
2223
>
2324
<i class="current"></i>
2425
<span class="item-text">{{ song.name }}</span>
@@ -58,7 +59,7 @@
5859
<script>
5960
import BaseScroll from 'base/base-scroll'
6061
import BaseConfirm from 'base/base-confirm'
61-
import { mapGetters, mapMutations, mapActions } from 'vuex'
62+
import { mapGetters, mapMutations } from 'vuex'
6263
import { shuffle } from 'common/js/util'
6364
import { playMode } from 'common/js/config'
6465
@@ -70,9 +71,18 @@ export default {
7071
},
7172
7273
methods: {
74+
selectItem (song, index) {
75+
if (this.mode === playMode.random) {
76+
index = this.playlist.findIndex(item => {
77+
return song.id === item.id
78+
})
79+
}
80+
this.setCurrentIndex(index)
81+
this.setPlayingState(true)
82+
},
83+
7384
cleanPlaylist () {
7485
// TODO:
75-
// this.resetPlayStatus()
7686
},
7787
7888
showConfirm () {
@@ -113,12 +123,9 @@ export default {
113123
...mapMutations({
114124
setPlayMode: 'SET_PLAY_MODE',
115125
setCurrentIndex: 'SET_CURRENT_INDEX',
116-
setPlaylist: 'SET_PLAYLIST'
117-
}),
118-
119-
...mapActions([
120-
'resetPlayStatus'
121-
])
126+
setPlaylist: 'SET_PLAYLIST',
127+
setPlayingState: 'SET_PLAYING_STATE'
128+
})
122129
},
123130
124131
computed: {

src/store/actions.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,3 @@ export const deleteSearchHistory = function ({ commit }, query) {
108108
export const clearAllHistory = function ({ commit }) {
109109
commit(types.SET_SEARCH_HISTORY, deleteAllSearchItem())
110110
}
111-
112-
export const resetPlayStatus = function ({ commit }) {
113-
commit(types.SET_PLAY_MODE, playMode.sequence)
114-
commit(types.SET_SEQUENCE_LIST, [])
115-
commit(types.SET_PLAYLIST, [])
116-
commit(types.SET_CURRENT_INDEX, 0)
117-
commit(types.SET_FULL_SCREEN, false)
118-
commit(types.SET_PLAYING_STATE, false)
119-
}

src/store/state.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const state = { // 只保留最基础的数据,由基础数据可计算得到
55
artist: {},
66
playing: false, // 播放/暂停
77
fullScreen: false, // 全屏
8-
playlist: [], // 当前播放列表,其中顺序是 sequenceList 属性设置
9-
sequenceList: [], // 播放列表的播放顺序列表
8+
playlist: [], // 当前播放列表,其中的顺序即是播放顺序
9+
sequenceList: [], // 展示性播放列表
1010
mode: playMode.sequence, // 语义化值,而不是直接写属性值
1111
currentIndex: -1, // 当前播放歌曲的索引,驱动歌曲的播放行为
1212
recommendItem: [], // 用户点击的推荐歌单项

0 commit comments

Comments
 (0)