RecommendedBar.vue 5.4 KB
Newer Older
Z
Zachary 已提交
1
<template>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
  <div
    class="mod_slide_box"
    style="position: relative; background-image: linear-gradient(#f5f5f5, #fff)"
  >
    <div class="section_inner" style="z-index: 2">
      <h1 class="recommended_list">歌单推荐</h1>
      <div class="target-bar">
        <a
          class="playlist"
          v-for="item in playlistType"
          :key="item.key"
          :class="item.key == selectType ? 'playlist__select' : ''"
          @click="switchType(item.key)"
          >{{ item.title }}
        </a>
      </div>
Z
Zachary 已提交
18

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
      <div class="mod_playlist mod_slide" v-loading="listLoading">
        <ul
          class="playlist__list slide__list"
          :style="{ left: showNo ? '-100%' : '0' }"
        >
          <li
            class="playlist__item slide__item"
            v-for="item in playList"
            :key="item.name"
          >
            <div class="playlist__item_box">
              <div class="playlist__cover mod_cover">
                <a class="js_playlist" @click="playTheList(item.id)">
                  <img
                    class="playlist__pic"
Z
Zachary 已提交
34 35
                    src="//y.gtimg.cn/mediastyle/global/img/playlist_300.png?max_age=31536000"
                    v-lazy="item.coverImgUrl"
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
                    :alt="item.name"
                  /><i class="mod_cover__mask"></i
                  ><i class="mod_cover__icon_play js_play"></i>
                </a>
              </div>
              <h4 class="playlist__title">
                <span class="playlist__title_txt">
                  <a @click="gotoPlaylistDetail(item.id)">{{ item.name }}</a>
                </span>
              </h4>
              <div class="playlist__other">
                播放量:{{ processCount(item.playCount) }}
              </div>
            </div>
          </li>
        </ul>
      </div>

      <div
        class="mod_slide_switch js_switch"
        data-stat="y_new.index.playlist.pager"
57
      >
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
        <a
          class="js_jump slide_switch__item"
          :class="showNo ? '' : 'slide_switch__item--current'"
          @mouseover="switchShow(false)"
        >
          <i class="slide_switch__bg"></i>
          <i class="icon_txt">1</i>
        </a>
        <a
          class="js_jump slide_switch__item"
          :class="showNo ? 'slide_switch__item--current' : ''"
          @mouseover="switchShow(true)"
        >
          <i class="slide_switch__bg"></i>
          <i class="icon_txt">2</i>
        </a>
      </div>
75
    </div>
76
    <push-button @btnClick="btnClick" />
Z
Zachary 已提交
77 78 79 80
  </div>
</template>

<script>
81
import PushButton from "components/common/PushButton";
Z
Zachary 已提交
82
import { getPlayList, getPlaylistDetial, getSongDetail } from "api";
Z
Zachary 已提交
83 84 85 86 87 88
import {
  processCount,
  createSong,
  playSonglist,
  gotoPlaylistDetail,
} from "common/utils";
Z
Zachary 已提交
89 90 91 92 93

export default {
  data() {
    return {
      listLoading: true,
94
      showNo: false,
95
      selectType: "全部",
Z
Zachary 已提交
96
      playlistType: [
Z
Zachary 已提交
97 98 99 100 101 102
        { title: "为你推荐", key: "全部" },
        { title: "R&B/Soul", key: "R&B/Soul" },
        { title: "网络歌曲", key: "网络歌曲" },
        { title: "ACG", key: "ACG" },
        { title: "怀旧", key: "怀旧" },
        { title: "流行", key: "流行" },
Z
Zachary 已提交
103 104
      ],
      playList: [],
Z
Zachary 已提交
105
    };
Z
Zachary 已提交
106 107
  },
  mounted() {
Z
Zachary 已提交
108
    this.updatePlayList("全部");
Z
Zachary 已提交
109 110 111 112
  },
  methods: {
    updatePlayList(key) {
      let limit = 10;
Z
Zachary 已提交
113 114
      getPlayList(limit, 1, key)
        .then((res) => {
Z
Zachary 已提交
115
          //console.log(res);
Z
Zachary 已提交
116
          this.playList = res.data.playlists;
Z
Zachary 已提交
117
          this.listLoading = false;
Z
Zachary 已提交
118 119
        })
        .catch((err) => console.log(err));
Z
Zachary 已提交
120
    },
121 122 123 124 125
    switchType(key) {
      if (key != this.selectType) {
        this.selectType = key;
        this.updatePlayList(key);
      }
Z
Zachary 已提交
126
    },
127 128 129 130 131
    switchShow(flag) {
      if (flag != this.showNo) this.showNo = flag;
    },
    btnClick() {
      this.showNo = !this.showNo;
132
    },
133 134
    playTheList(listId) {
      getPlaylistDetial(listId).then((res) => {
Z
Zachary 已提交
135 136 137
        let trackIds = res.data.playlist.trackIds.map(({ id }) => id);
        let songDetails = getSongDetail(trackIds.slice(0, 500)).then((res) => {
          let songs = res.data.songs.map(({ id, name, al, ar, mv, dt }) => {
Z
Zachary 已提交
138 139 140 141 142 143 144 145
            return createSong({
              id,
              name,
              artists: ar,
              duration: dt,
              mvId: mv,
              albumName: al.name,
              img: al.picUrl,
Z
Zachary 已提交
146 147
            });
          });
Z
Zachary 已提交
148
          //console.log(songs);
Z
Zachary 已提交
149
          playSonglist(songs);
Z
Zachary 已提交
150
        });
151 152
      });
    },
153
    processCount,
Z
Zachary 已提交
154
    gotoPlaylistDetail,
Z
Zachary 已提交
155
  },
156 157 158
  components: {
    PushButton,
  },
Z
Zachary 已提交
159
};
Z
Zachary 已提交
160 161
</script>

Z
Zachary 已提交
162
<style scoped>
163
/* play list bar */
Z
Zachary 已提交
164
.recommended_list {
Z
Zachary 已提交
165 166
  letter-spacing: 20px;
  text-align: center;
Z
Zachary 已提交
167
  font-size: 31px;
Z
Zachary 已提交
168
}
169 170 171 172
.target-bar {
  text-align: center;
  padding-bottom: 18px;
}
Z
Zachary 已提交
173 174
.playlist {
  display: inline-block;
175
  font-size: 16px;
Z
Zachary 已提交
176 177 178
  margin: 0 30px;
  text-decoration: none;
}
179
.playlist:hover {
180 181
  color: #31c27c;
}
182
.playlist__select {
Z
Zachary 已提交
183 184
  color: #31c27c;
}
185

186 187 188
.mod_playlist .playlist__list {
  padding: 0;
}
189 190 191 192 193 194 195
/* list */
.mod_playlist {
  overflow: hidden;
  font-size: 0;
  margin-right: -20px;
}
.playlist__item {
Z
Zachary 已提交
196
  display: inline-block;
197
  /*width: 18%;*/
Z
Zachary 已提交
198 199 200 201 202
  padding-bottom: 44px;
  overflow: hidden;
  font-size: 14px;
  vertical-align: top;
  color: #000;
203
  /*margin-right: 20px;*/
Z
Zachary 已提交
204
}
205 206 207 208
.playlist__item {
  position: relative;
  width: 1.6%;
  padding-bottom: 0;
Z
Zachary 已提交
209
}
210 211 212 213 214
.mod_index--hot .playlist__item_box {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
Z
Zachary 已提交
215
}
216

Z
update  
Zachary 已提交
217 218 219
a:hover {
  color: #31c27c;
}
Z
Zachary 已提交
220
</style>