RecommendedBar.vue 5.3 KB
Newer Older
Z
Zachary 已提交
1
<template>
2
  <div class="recommended_main">
Z
Zachary 已提交
3
    <h1 class="recommended_list">歌单推荐</h1>
4 5 6 7 8 9 10 11 12 13 14
    <div class="target-bar">
      <a
        class="playlist"
        href="javascript:;"
        v-for="item in playlistType"
        :key="item.key"
        :class="item.key == selectType ? 'playlist__select' : ''"
        @click="switchType(item.key)"
        >{{ item.title }}</a
      >
    </div>
Z
Zachary 已提交
15

16 17 18 19 20 21 22 23 24 25 26 27
    <div class="target-list" v-loading="listLoading">
      <ul>
        <li class="playlist__i" v-for="item in playList" :key="item.name">
          <a class="js_playlist" @click="playTheList(item.id)">
            <img
              class="playlist__pic"
              :src="item.coverImgUrl"
              onerror="this.src='//y.gtimg.cn/mediastyle/global/img/playlist_300.png?max_age=31536000';"
              :alt="item.name"
            />
          </a>
          <h4 class="">
Z
update  
Zachary 已提交
28 29 30
            <span class="">
              <a @click="gotoPlaylistDetail(item.id)">{{ item.name }}</a>
            </span>
31 32 33 34 35
          </h4>
          <div class="">播放量:{{ processCount(item.playCount) }}</div>
        </li>
      </ul>
      <!--  <div >
Z
Zachary 已提交
36 37 38
      <a href="" class="arrow-btn arrow-btn-left"><i class="el-icon-arrow el-icon-arrow-left"></i></a> 
      <a href="" class="arrow-btn arrow-btn-right"><i class="el-icon-arrow el-icon-arrow-right"></i></a>
    </div> -->
39 40 41 42
    </div>
    <div
      class="mod_slide_switch js_switch"
      data-stat="y_new.index.playlist.pager"
Z
Zachary 已提交
43
    >
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
      <a
        href="javascript:;"
        tabindex="-1"
        class="js_jump slide_switch__item slide_switch__item--current"
        data-p="0"
      >
        <i class="slide_switch__bg"></i>
        <i class="icon_txt">1</i>
      </a>
      <a
        href="javascript:;"
        tabindex="-1"
        class="js_jump slide_switch__item"
        data-p="1"
      >
        <i class="slide_switch__bg"></i>
        <i class="icon_txt">2</i>
      </a>
    </div>
Z
Zachary 已提交
63 64 65 66
  </div>
</template>

<script>
Z
Zachary 已提交
67
import { getPlayList, getPlaylistDetial, getSongDetail } from "api";
Z
Zachary 已提交
68
import { processCount, createSong, playSonglist } from "common/utils";
Z
Zachary 已提交
69 70 71 72 73

export default {
  data() {
    return {
      listLoading: true,
74
      selectType: "全部",
Z
Zachary 已提交
75
      playlistType: [
Z
Zachary 已提交
76 77 78 79 80 81
        { title: "为你推荐", key: "全部" },
        { title: "R&B/Soul", key: "R&B/Soul" },
        { title: "网络歌曲", key: "网络歌曲" },
        { title: "ACG", key: "ACG" },
        { title: "怀旧", key: "怀旧" },
        { title: "流行", key: "流行" },
Z
Zachary 已提交
82 83
      ],
      playList: [],
Z
Zachary 已提交
84
    };
Z
Zachary 已提交
85 86
  },
  mounted() {
Z
Zachary 已提交
87
    this.updatePlayList("全部");
Z
Zachary 已提交
88 89 90 91
  },
  methods: {
    updatePlayList(key) {
      let limit = 10;
Z
Zachary 已提交
92 93 94 95
      getPlayList(limit, 1, key)
        .then((res) => {
          console.log(res);
          this.playList = res.data.playlists;
Z
Zachary 已提交
96
          this.listLoading = false;
Z
Zachary 已提交
97 98
        })
        .catch((err) => console.log(err));
Z
Zachary 已提交
99
    },
100 101 102 103 104
    switchType(key) {
      if (key != this.selectType) {
        this.selectType = key;
        this.updatePlayList(key);
      }
Z
Zachary 已提交
105
    },
Z
Zachary 已提交
106 107
    processCount(count) {
      return processCount(count);
108
    },
109 110
    playTheList(listId) {
      getPlaylistDetial(listId).then((res) => {
Z
Zachary 已提交
111 112 113
        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 已提交
114 115 116 117 118 119 120 121
            return createSong({
              id,
              name,
              artists: ar,
              duration: dt,
              mvId: mv,
              albumName: al.name,
              img: al.picUrl,
Z
Zachary 已提交
122 123
            });
          });
Z
Zachary 已提交
124
          console.log(songs);
Z
Zachary 已提交
125
          playSonglist(songs);
Z
Zachary 已提交
126
        });
127 128
      });
    },
Z
update  
Zachary 已提交
129 130 131 132 133 134
    gotoPlaylistDetail(id) {
      this.$router.push({
        path: "/musicLibrary/playlistDetail",
        query: { id: id },
      });
    },
Z
Zachary 已提交
135 136
  },
};
Z
Zachary 已提交
137 138
</script>

Z
Zachary 已提交
139
<style scoped>
Z
Zachary 已提交
140
/* play list */
Z
Zachary 已提交
141
.recommended_list {
Z
Zachary 已提交
142 143
  letter-spacing: 20px;
  text-align: center;
Z
Zachary 已提交
144
  font-size: 31px;
Z
Zachary 已提交
145 146 147 148 149 150 151
}
.playlist {
  display: inline-block;
  font-size: 18px;
  margin: 0 30px;
  text-decoration: none;
}
152 153 154
.playlist__select {
  color: #31c27c;
}
Z
Zachary 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
.playlist:hover {
  color: #31c27c;
}
.target-bar {
  text-align: center;
}
.target-list {
  margin-right: -20px;
  overflow: hidden;
  margin-bottom: 20px;
  position: relative;
}
.playlist__i {
  display: inline-block;
  width: 18%;
  padding-bottom: 44px;
  overflow: hidden;
  font-size: 14px;
  vertical-align: top;
  color: #000;
  margin-right: 20px;
}
.playlist__pic {
  width: 100%;
  height: 100%;
}
Z
Zachary 已提交
181

Z
Zachary 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
/* 切换小圆点 */
.mod_slide_switch {
  width: 100%;
  text-align: center;
  font-size: 0;
}
.slide_switch__item {
  display: inline-block;
  width: 28px;
  height: 12px;
  padding: 0 0 26px;
  margin: 0 1px;
  background: 0 0;
}
.slide_switch__bg {
  display: block;
  width: 8px;
  height: 8px;
  filter: progid:DXImageTransform.Microsoft.gradient(enabled='true', startColorstr='#19000000', endColorstr='#19000000');
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  margin: 0 auto;
}
.slide_switch__item--current .slide_switch__bg,
.slide_switch__item:hover .slide_switch__bg {
  filter: progid:DXImageTransform.Microsoft.gradient(enabled='true', startColorstr='#4C000000', endColorstr='#4C000000');
  background-color: rgba(0, 0, 0, 0.3);
}
Z
update  
Zachary 已提交
210 211 212
a:hover {
  color: #31c27c;
}
Z
Zachary 已提交
213
</style>