SongDetail.vue 7.7 KB
Newer Older
Z
Zachary 已提交
1 2
<template>
  <div class="main">
3 4 5 6 7
    <detail-info-card
      :obj="song"
      :commentCount="commentCount"
      @btnClick="cardClick"
    />
Z
Zachary 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

    <div class="detail_layout">
      <div class="detail_layout__main">
        <!--歌词 start-->
        <div class="mod_lyric">
          <div class="lyric__hd">
            <h2 class="lyric__tit">歌词</h2>
            <a
              class="btn_copy sprite"
              id="copy_link"
              title="复制歌词"
              @click="copyLyric"
              ><i class="icon_txt">复制</i></a
            >
          </div>
          <div
            class="lyric__cont"
            :class="isShowAllLyric ? '' : 'limit'"
            v-if="lyric"
          >
            <div class="lyric__cont_box" id="lrc_content">
              <p v-for="(item, idx) in lyric" :key="idx">{{ item }}</p>
            </div>
Z
Zachary 已提交
31
            <a class="c_tx_highlight js_open_lyric" @click="toggleLyric"
Z
Zachary 已提交
32 33 34 35 36
              >[{{ isShowAllLyric ? "收起" : "展开" }}]</a
            >
          </div>
        </div>
        <!--歌词 end-->
37 38 39 40 41 42 43 44 45

        <!-- comment -->
        <commont-box
          :comments="comments"
          :limit="pageSize"
          :currentPage="commentPage"
          :total="commentCount"
          @current-change="currentChange"
        />
Z
Zachary 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
      </div>
      <!--相似歌曲-->
      <div class="detail_layout__other">
        <div class="other_part" style="" id="song_playlist">
          <h3 class="other_part__tit">相似歌曲</h3>
          <div class="mod_playlist">
            <ul class="playlist__list" v-if="simiSongs">
              <li
                class="playlist__item"
                v-for="simiSong in simiSongs"
                :key="simiSong.id"
              >
                <div class="playlist__item_box">
                  <div class="playlist__cover mod_cover">
                    <a class="js_playlist" @click="gotoSongDetail(simiSong.id)">
                      <img
Z
Zachary 已提交
62 63
                        src=""
                        v-lazy="simiSong.img"
Z
Zachary 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
                        :alt="simiSong.name"
                        class="playlist__pic"
                      />
                      <i class="mod_cover__icon_play js_play"></i>
                    </a>
                  </div>
                  <h4 class="playlist__title">
                    <span class="playlist__title_txt"
                      ><a
                        class="js_playlist"
                        :title="simiSong.name"
                        @click="gotoSongDetail(simiSong.id)"
                        >{{ simiSong.name }}</a
                      ></span
                    >
                  </h4>
                  <div class="playlist__author">{{ simiSong.artistsText }}</div>
                </div>
              </li>
            </ul>
          </div>
        </div>
        <!--相关MV-->
        <div class="other_part" id="song_mv" v-if="mv">
          <h3 class="other_part__tit">相关MV</h3>
          <div class="mod_mv_list">
            <div class="mv_list__item_box">
              <a class="mv_list__cover mod_cover js_mv" hidefocus="true">
                <img
                  class="mv_list__pic"
Z
Zachary 已提交
94 95 96
                  src="//y.gtimg.cn/mediastyle/global/img/mv_300.png?max_age=31536000"
                  v-lazy="mv.img"
                  :alt="mv.name"
Z
Zachary 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
                />
                <i class="mod_cover__icon_play"></i>
              </a>
              <h3 class="mv_list__title">
                <a class="js_mv" :title="mv.name">{{ mv.name }}</a>
              </h3>

              <p class="mv_list__singer" title="mv.artistName">
                <a :title="mv.artistName" class="js_singer">
                  {{ mv.artistName }}
                </a>
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
Z
Zachary 已提交
115
  <black-tip :ifShow="ifShowTip" :tip="tip" />
Z
Zachary 已提交
116 117 118
</template>

<script>
Z
update  
Zachary 已提交
119
import DetailInfoCard from "components/common/DetailInfoCard";
Z
Zachary 已提交
120
import BlackTip from "components/common/BlackTip";
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
import CommontBox from "components/common/CommontBox";
import {
  getSongDetail,
  getSongLiyric,
  getSimiSong,
  getMvDetail,
  getCommentsNew,
} from "api";
import {
  createSong,
  formatDate,
  playTheSong,
  copyText,
  gotoSongDetail,
} from "common/utils";
Z
Zachary 已提交
136 137 138 139 140 141 142 143 144 145 146

export default {
  data() {
    return {
      isShowAllLyric: false,
      ifShowTip: false,
      tip: "",
      song: {},
      lyric: [],
      simiSongs: null,
      mv: null,
147 148 149 150
      pageSize: 20,
      commentPage: 1,
      commentCount: 0,
      comments: [],
Z
Zachary 已提交
151 152 153 154 155 156 157 158 159 160 161
    };
  },
  created() {
    this.songId = this.$route.query.id;
    this.init();
  },
  methods: {
    init() {
      // 获取歌曲信息
      getSongDetail(this.songId).then((res) => {
        let d = res.data.songs[0];
Z
Zachary 已提交
162
        //console.log(res);
Z
Zachary 已提交
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
        this.song = createSong({
          id: d.id,
          name: d.name,
          artists: d.ar,
          duration: d.dt,
          albumName: d.al.name,
          mvId: d.mv,
          img: d.al.picUrl,
          publishTime:
            d.publishTime == 0
              ? "未知"
              : formatDate(d.publishTime, "yyyy-MM-dd"),
        });
        // 如果有mv, 获取mv信息
        if (d.mv != 0) {
          getMvDetail(d.mv).then((res) => {
179
            //console.log(res);
Z
Zachary 已提交
180 181 182 183 184 185 186 187 188
            let d = res.data.data;
            this.mv = {
              id: d.id,
              name: d.name,
              img: d.cover,
              artistName: d.artistName,
            };
          });
        }
189
        this.getComment();
Z
Zachary 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
      });
      // 获取歌词
      getSongLiyric(this.songId).then((res) => {
        let d = res.data.lrc.lyric;
        this.lyric = d.split("\n").map((i) => i.slice(11));
      });
      // 获取相似歌曲
      getSimiSong(this.songId).then((res) => {
        let ds = res.data.songs;
        this.simiSongs = ds.map((d) => {
          return createSong({
            id: d.id,
            name: d.name,
            artists: d.artists,
            duration: d.duration,
            albumName: d.album.name,
            mvId: d.mv,
            img: d.album.blurPicUrl,
          });
        });
      });
    },
    toggleLyric() {
      this.isShowAllLyric = !this.isShowAllLyric;
    },
    copyLyric() {
      if (this.lyric) {
        let lyricText = this.lyric.join(" ");
Z
Zachary 已提交
218
        copyText(lyricText);
Z
Zachary 已提交
219 220 221 222 223 224 225 226 227 228 229
        this.showTip("复制成功");
      }
    },
    showTip(tip) {
      this.tip = tip;
      this.ifShowTip = true;
      if (this.tipTimer) clearTimeout(this.tipTimer);
      setTimeout(() => {
        this.ifShowTip = false;
      }, 1000);
    },
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
    gotoSongDetail,
    cardClick(v) {
      if (v == "all") playTheSong(this.song);
    },
    getComment() {
      let params = {
        type: 0,
        pageSize: this.pageSize,
        pageNo: this.commentPage,
        id: this.song.id,
        sortType: 2,
      };
      getCommentsNew(params).then((res) => {
        this.commentCount =
          res.data.data.totalCount > 5000 ? 5000 : res.data.data.totalCount;
        this.comments = res.data.data.comments;
Z
Zachary 已提交
246 247
      });
    },
248 249
    currentChange(v) {
      this.commentPage = v;
Z
update  
Zachary 已提交
250
    },
251 252 253 254
  },
  watch: {
    commentPage() {
      this.getComment();
Z
update  
Zachary 已提交
255 256 257 258
    },
  },
  components: {
    DetailInfoCard,
Z
Zachary 已提交
259
    BlackTip,
260
    CommontBox,
Z
Zachary 已提交
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
  },
};
</script>

<style scoped>
li,
ol,
p,
ul {
  margin: 0;
  margin-right: 0px;
  padding: 0;
}

.lyric__hd {
  overflow: hidden;
  line-height: 46px;
}
.lyric__tit {
  float: left;
  font-size: 20px;
  font-weight: 400;
  margin-right: 10px;
}
.btn_copy {
  float: left;
  width: 16px;
  height: 16px;
  background-position: -100px -40px;
  margin-top: 13px;
  overflow: hidden;
}
.lyric__cont {
  font-size: 14px;
  color: #000;
  line-height: 26px;
  margin-bottom: 40px;
}
.lyric__cont.limit .lyric__cont_box {
  max-height: 390px;
  overflow: hidden;
}
</style>