ModListMenu.vue 2.2 KB
Newer Older
Z
Zachary 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<template>
  <div class="mod_list_menu">
    <a
      class="list_menu__item list_menu__play js_play"
      title="播放"
      @click="play"
    >
      <i class="list_menu__icon_play"></i>
      <span class="icon_txt">播放</span>
    </a>
    <a
      class="list_menu__item list_menu__add js_fav"
      title="添加到歌单"
      aria-haspopup="true"
    >
      <i class="list_menu__icon_add"></i>
      <span class="icon_txt">添加到歌单</span>
    </a>
    <a
      class="list_menu__item list_menu__down js_down"
      title="下载"
      aria-haspopup="true"
Z
Zachary 已提交
23
      v-if="kind == 0"
Z
Zachary 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
    >
      <i class="list_menu__icon_down"></i>
      <span class="icon_txt">下载</span>
    </a>
    <a
      class="list_menu__item list_menu__share js_share"
      title="分享"
      aria-haspopup="true"
    >
      <i class="list_menu__icon_share"></i>
      <span class="icon_txt">分享</span>
    </a>
  </div>
</template>

<script>
Z
Zachary 已提交
40 41 42
import { playTheSong, playSonglist, createSongs } from "common/utils";
import { getPlaylistDetial, getSongDetail, getAlbum } from "api";

Z
Zachary 已提交
43 44 45 46 47 48
export default {
  props: {
    song: {
      type: Object,
      default: {},
    },
Z
Zachary 已提交
49 50 51
    id: { default: 0 },
    // 0: song, 1: album , 2: playlist
    kind: { default: 0 },
Z
Zachary 已提交
52 53 54
  },
  methods: {
    play() {
Z
Zachary 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
      switch (this.kind) {
        case 0:
          if (this.song) {
            playTheSong(this.song);
          }
          console.log(this.song);
          break;
        case 1:
          this.playAlbum(this.id);
          break;
        case 2:
          this.playTheList(this.id);
          break;
        default:
          console.log(this.kind);
Z
Zachary 已提交
70
      }
Z
Zachary 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    },
    playTheList(listId) {
      getPlaylistDetial(listId).then((res) => {
        let trackIds = res.data.playlist.trackIds.map(({ id }) => id);
        let songDetails = getSongDetail(trackIds.slice(0, 500)).then((res) => {
          let songs = createSongs(res.data.songs);
          //console.log(songs);
          playSonglist(songs);
        });
      });
    },
    playAlbum(id) {
      getAlbum(this.id).then((res) => {
        let ds = res.data;
        let songs = createSongs(ds.songs);
        console.log(this.songs);
        playSonglist(songs);
      });
Z
Zachary 已提交
89 90 91 92 93 94 95
    },
  },
};
</script>

<style scoped>
</style>