|
| 1 | +<template> |
| 2 | + <transition name="slide"> |
| 3 | + <div class="user-center"> |
| 4 | + |
| 5 | + <div class="switch-wrapper"> |
| 6 | + <BaseSwitches |
| 7 | + :switchOptions="switchOptions" |
| 8 | + :currentSwitchIndex="switchIndex" |
| 9 | + @selectSwitch="toggleSwitchIndex" |
| 10 | + /> |
| 11 | + </div> |
| 12 | + |
| 13 | + <div class="back-btn" @click.stop="prevPage"> |
| 14 | + <i class="icon-back"></i> |
| 15 | + </div> |
| 16 | + |
| 17 | + <div class="random-play-btn" @click.stop="addAllSongsToList"> |
| 18 | + <i class="icon-play"></i> |
| 19 | + <span class="btn-text">随机播放全部</span> |
| 20 | + </div> |
| 21 | + |
| 22 | + <div class="list-wrapper"> |
| 23 | + <BaseScroll class="scroll-wrapper" v-if="switchIndex === 0"> |
| 24 | + <div class="favorite-list-wrapper"> |
| 25 | + <BaseSongsList |
| 26 | + :songsData="myFavoriteSongs" |
| 27 | + @select="addSongToList" |
| 28 | + /> |
| 29 | + </div> |
| 30 | + </BaseScroll> |
| 31 | + |
| 32 | + <BaseScroll class="scroll-wrapper" v-if="switchIndex === 1"> |
| 33 | + <div class="has-played-wrapper"> |
| 34 | + <BaseSongsList |
| 35 | + :songsData="playedHistory" |
| 36 | + @select="addSongToList" |
| 37 | + /> |
| 38 | + </div> |
| 39 | + </BaseScroll> |
| 40 | + </div> |
| 41 | + |
| 42 | + <div class="no-result-wrapper" v-if="showNoResult"> |
| 43 | + <BaseNoResult title="这里空空如也 ..."/> |
| 44 | + </div> |
| 45 | + |
| 46 | + </div> |
| 47 | + </transition> |
| 48 | +</template> |
| 49 | + |
| 50 | +<script> |
| 51 | +import BaseSwitches from 'base/base-switches/base-switches' |
| 52 | +import BaseScroll from 'base/base-scroll' |
| 53 | +import BaseSongsList from 'base/base-songs-list/base-songs-list' |
| 54 | +import BaseNoResult from 'base/base-no-result/base-no-result' |
| 55 | +import { mapGetters, mapActions } from 'vuex' |
| 56 | +import Song from 'common/js/normalize-song' |
| 57 | +
|
| 58 | +export default { |
| 59 | + data () { |
| 60 | + return { |
| 61 | + switchOptions: [{ name: '我喜欢的' }, { name: '最近播放' }], |
| 62 | + switchIndex: 0 |
| 63 | + } |
| 64 | + }, |
| 65 | +
|
| 66 | + methods: { |
| 67 | + addAllSongsToList () { |
| 68 | + if (this.switchIndex === 0) { |
| 69 | +
|
| 70 | + } else { |
| 71 | + const list = this.playedHistory.map(song => { |
| 72 | + return new Song(song) |
| 73 | + }) |
| 74 | +
|
| 75 | + this.randomPlay({ list }) |
| 76 | + } |
| 77 | + }, |
| 78 | +
|
| 79 | + addSongToList (song, index) { |
| 80 | + // song 是从 localStorage 读取而来,没有 Song 原型上的方法 getLyric |
| 81 | + this.insertSong(new Song(song)) |
| 82 | + }, |
| 83 | +
|
| 84 | + prevPage () { |
| 85 | + this.$router.back() |
| 86 | + }, |
| 87 | +
|
| 88 | + toggleSwitchIndex (index) { |
| 89 | + this.switchIndex = index |
| 90 | + }, |
| 91 | +
|
| 92 | + ...mapActions([ |
| 93 | + 'insertSong', |
| 94 | + 'randomPlay' |
| 95 | + ]) |
| 96 | + }, |
| 97 | +
|
| 98 | + computed: { |
| 99 | + showNoResult () { |
| 100 | + return (this.switchIndex === 0 && !this.myFavoriteSongs.length) || (this.switchIndex === 1 && !this.playedHistory.length) |
| 101 | + }, |
| 102 | +
|
| 103 | + ...mapGetters([ |
| 104 | + 'playedHistory', |
| 105 | + 'myFavoriteSongs' |
| 106 | + ]) |
| 107 | + }, |
| 108 | +
|
| 109 | + components: { |
| 110 | + BaseSwitches, |
| 111 | + BaseScroll, |
| 112 | + BaseSongsList, |
| 113 | + BaseNoResult |
| 114 | + } |
| 115 | +} |
| 116 | +</script> |
| 117 | + |
| 118 | +<style lang="scss" scoped> |
| 119 | +@import '~scss/variables'; |
| 120 | +
|
| 121 | +.user-center { |
| 122 | + position: fixed; |
| 123 | + top: 0; |
| 124 | + bottom: 0; |
| 125 | + width: 100%; |
| 126 | + z-index: 100; |
| 127 | + background-color: $color-background; |
| 128 | + font-size: 0; |
| 129 | + &.slide-enter, &.slide-leave-to { |
| 130 | + transform: translateX(100%); |
| 131 | + } |
| 132 | + &.slide-enter-active, &.slide-leave-active { |
| 133 | + transition: all .1s |
| 134 | + } |
| 135 | + .switch-wrapper { |
| 136 | + margin: 10px 0 30px; |
| 137 | + } |
| 138 | + .back-btn { |
| 139 | + position: absolute; |
| 140 | + top: 0; |
| 141 | + left: 6px; |
| 142 | + z-index: 50; |
| 143 | + .icon-back { |
| 144 | + display: inline-block; |
| 145 | + padding: 10px; |
| 146 | + font-size: $font-size-large-x; |
| 147 | + color: $color-theme; |
| 148 | + } |
| 149 | + } |
| 150 | + .random-play-btn { |
| 151 | + margin: 0 auto; |
| 152 | + padding: 7px 0; |
| 153 | + width: 135px; |
| 154 | + box-sizing: border-box; |
| 155 | + border: 1px solid $color-text-l; |
| 156 | + border-radius: 100px; |
| 157 | + text-align: center; |
| 158 | + color: $color-text-l; |
| 159 | + .icon-play { |
| 160 | + display: inline-block; |
| 161 | + vertical-align: middle; |
| 162 | + margin-right: 6px; |
| 163 | + font-size: $font-size-medium-x; |
| 164 | + } |
| 165 | + .btn-text { |
| 166 | + display: inline-block; |
| 167 | + vertical-align: middle; |
| 168 | + font-size: $font-size-small; |
| 169 | + } |
| 170 | + } |
| 171 | + .list-wrapper { |
| 172 | + position: absolute; |
| 173 | + top: 110px; |
| 174 | + bottom: 0; |
| 175 | + width: 100%; |
| 176 | + .scroll-wrapper { |
| 177 | + height: 100%; |
| 178 | + overflow: hidden; |
| 179 | + } |
| 180 | + } |
| 181 | + .no-result-wrapper { |
| 182 | + position: absolute; |
| 183 | + top: 50%; |
| 184 | + transform: translateY(-50%); |
| 185 | + width: 100%; |
| 186 | + } |
| 187 | +
|
| 188 | +} |
| 189 | +</style> |
0 commit comments