Classified.vue 12.2 KB
Newer Older
Z
Zachary 已提交
1
<template>
Z
Zachary 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  <div class="main1" style="">
    <!-- 标签筛选 -->
    <div class="mod_playlist_tag" id="taglist">
      <div class="js_normal" style="display: ">
        <div v-for="(key, idx) in categories" :key="key">
          <div
            class="playlist_tag__list"
            :data="idx"
            :class="idx == 0 ? 'playlist_tag__list--lang' : ''"
          >
            <h3 class="playlist_tag__tit c_tx_thin">{{ key }}</h3>
            <i class="playlist_tag__line"></i>
            <ul class="playlist_tag__tags">
              <li
                class="playlist_tag__itembox"
                v-for="item in getShowTypes(idx, playlistTpyes[idx].list)"
                :key="item.name"
              >
                <a
                  class="playlist_tag__item js_tag"
                  :class="
                    selectedType == item.name
                      ? 'playlist_tag__item--expand'
                      : ''
                  "
                  @click="selectType(item.name)"
                  >{{ item.name }}</a
                >
              </li>

              <li
                class="playlist_tag__itembox"
                v-if="ifMore(idx, playlistTpyes[idx].list)"
              >
                <a
                  class="playlist_tag__item js_more_tag"
                  :class="
                    playlistTpyes[idx].showMore
                      ? 'playlist_tag__item--expand'
                      : ''
                  "
                  @click="showMoreTypes(idx)"
                  >更多<i class="playlist_tag__arrow sprite"></i
                ></a>
              </li>
            </ul>
          </div>
          <div
            class="popup_tag"
            :style="{
              display: playlistTpyes[idx].showMore ? 'block' : 'none',
            }"
            v-if="ifMore(idx, playlistTpyes[idx].list)"
          >
            <ul class="playlist_tag__tags">
              <li
                class="playlist_tag__itembox"
                v-for="item in getHiddenTypes(idx, playlistTpyes[idx].list)"
                :key="item.name"
              >
                <a
                  class="playlist_tag__item js_tag"
                  :class="
                    selectedType == item.name
                      ? 'playlist_tag__item--expand'
                      : ''
                  "
                  @click="selectType(item.name)"
                  >{{ item.name }}</a
                >
              </li>
            </ul>
          </div>
Y
yuqi 已提交
75
        </div>
Z
Zachary 已提交
76 77
      </div>
    </div>
Y
yuqi 已提交
78

Z
Zachary 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    <div class="mod_part_detail">
      <!-- 选择类型展示 -->
      <div class="part_detail__hd">
        <h2 class="part_detail__tit">
          <span v-if="selectedType == '全部'">全部歌单</span>
          <span class="part_tags" v-else>
            {{ selectedType }}
            <a
              class="part_tags__delete js_delete_tags sprite"
              @click="deleteSeleted"
              ><i class="icon_txt">删除</i></a
            >
          </span>
        </h2>
        <div class="part_switch" id="sortbox" aria-label="排列方式">
          <a
            href="javascript:;"
            class="part_switch__item js_sort part_switch__item--left"
            title="最热"
            :class="selectedOrder == 'hot' ? 'part_switch__item--select' : ''"
            @click="selectOrder('hot')"
            >最热</a
          ><a
            href="javascript:;"
            class="part_switch__item part_switch__item--right js_sort"
            title="最新"
            :class="selectedOrder == 'new' ? 'part_switch__item--select' : ''"
            @click="selectOrder('new')"
            >最新</a
          >
        </div>
      </div>

      <!-- 歌单展示 -->
      <div class="mod_playlist mod_playlist--all">
        <ul class="playlist__list" id="playlist_box">
          <li class="playlist__item" v-for="list in playlists" :key="list.id">
            <div class="playlist__item_box">
              <div
                class="playlist__cover mod_cover"
                style="visibility: visible"
              >
                <a
                  class="js_playlist"
                  :title="list.name"
                  @click="playTheList(list.id)"
                  ><img
                    class="playlist__pic"
                    style="display: block; visibility: visible"
                    onerror="this.src='//y.gtimg.cn/mediastyle/global/img/cover_playlist.png?max_age=31536000';this.onerror=null;"
                    :src="list.img"
                    :alt="list.name"
                  />
                  <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="list.name"
                    @click="gotoDetail(list.id)"
                    >{{ list.name }}</a
                  >
                </span>
              </h4>
              <div class="playlist__author">
                <a class="js_user" :title="list.creatorName">{{
                  list.creatorName
                }}</a>
              </div>
              <div class="playlist__other">播放量: {{ list.playCount }}</div>
              <a class="btn_operate_menu js_playlist_more"
                ><span class="icon_txt">更多</span></a
              >
            </div>
          </li>
        </ul>
      </div>
Y
yuqi 已提交
158
    </div>
Z
Zachary 已提交
159
  </div>
Z
Zachary 已提交
160 161 162
</template>

<script>
Z
Zachary 已提交
163 164 165
import { getCatList, getPlayList, getPlaylistDetial, getSongDetail } from "api";
import { createPlaylists, createSongs, playSonglist } from "common/utils";

Z
Zachary 已提交
166
export default {
Z
Zachary 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
  data() {
    return {
      loading: true,
      subLoading: true,
      categories: {},
      playlistTpyes: [],
      selectedType: "全部",
      selectedOrder: "hot",
      currentPage: 1,
      allPage: 1,
      playlists: [],
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      getCatList().then((res) => {
        this.categories = res.data.categories;
        let subs = res.data.sub;
        let d = {};
        for (let v of Object.keys(this.categories)) {
          d[v] = { showMore: false, list: [] };
        }
        for (let sub of subs) {
          d[sub.category].list.push({
            name: sub.name,
            category: sub.category,
            hot: sub.hot,
            count: sub.resourceCount,
          });
        }
        this.playlistTpyes = d;
        this.updatePlaylist();
      });
    },
    updatePlaylist() {
      let limit = 20;
      getPlayList(
        limit,
        this.currentPage,
        this.selectedType,
        this.selectedOrder
      ).then((res) => {
        let lists = createPlaylists(res.data.playlists);
        console.log(res.data);
        console.log(lists);
        this.playlists = lists;
      });
    },
    playTheList(id) {
      getPlaylistDetial(id).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);
        });
      });
    },
    gotoDetail(id) {
      this.$router.push({
        path: "/musicLibrary/playlistDetail",
        query: { id: id },
      });
    },
    ifMore(idx, list) {
      if (idx == 0) return list.length > 6 ? true : false;
      else return list.length > 9 ? true : false;
    },
    getShowTypes(idx, list) {
      if (idx == 0) return list.length > 6 ? list.slice(0, 5) : list;
      else return list.length > 9 ? list.slice(0, 8) : list;
    },
    getHiddenTypes(idx, list) {
      if (idx == 0) return list.length > 6 ? list.slice(6) : list;
      else return list.length > 9 ? list.slice(9) : list;
    },
    showMoreTypes(idx) {
      this.playlistTpyes[idx].showMore = !this.playlistTpyes[idx].showMore;
    },
    selectType(type) {
      if (this.selectedType != type) this.selectedType = type;
    },
    deleteSeleted() {
      this.selectedType = "全部";
    },
    selectOrder(order) {
      this.selectedOrder = order;
      this.currentPage = 1;
      this.updatePlaylist();
    },
  },
  watch: {
    selectedType(type) {
      this.updatePlaylist();
    },
  },
};
Z
Zachary 已提交
267 268 269
</script>

<style scoped>
Y
yuqi 已提交
270
.main1 {
Z
Zachary 已提交
271
  z-index: 2;
Y
yuqi 已提交
272
}
Z
Zachary 已提交
273 274 275 276
.main1 {
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
Y
yuqi 已提交
277 278 279
}

.mod_playlist_tag {
Z
Zachary 已提交
280 281 282 283
  position: relative;
  padding: 60px 0 32px 0;
  margin-right: -24px;
  height: 118px;
Y
yuqi 已提交
284 285 286
}

.playlist_tag__list {
Z
Zachary 已提交
287 288 289 290 291
  position: relative;
  float: left;
  width: 238px;
  line-height: 26px;
  margin-right: 22px;
Y
yuqi 已提交
292 293
}
.playlist_tag__list--lang {
Z
Zachary 已提交
294
  width: 160px;
Y
yuqi 已提交
295 296
}
.playlist_tag__tit {
Z
Zachary 已提交
297 298 299 300 301
  font-weight: 400;
  font-size: 14px;
  padding-left: 8px;
  margin-bottom: 8px;
  margin-top: -6px;
Y
yuqi 已提交
302 303
}
.c_tx_thin {
Z
Zachary 已提交
304
  color: #999;
Y
yuqi 已提交
305 306
}
.playlist_tag__line {
Z
Zachary 已提交
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
  position: absolute;
  top: 0;
  right: 0;
  width: 1px;
  height: 108px;
  background-color: #eeeef0;
}
a:hover {
  color: #31c27c;
}
button,
h1,
h2,
h3,
h4,
h5,
h6,
ul,
li,
p {
  margin: 0;
  padding: 0;
}
h1,
h2,
h3,
h4,
h5,
h6 {
  font-size: 100%;
}
img {
  width: 250px;
Y
yuqi 已提交
340
}
Z
Zachary 已提交
341

Y
yuqi 已提交
342
.playlist_tag__itembox {
Z
Zachary 已提交
343 344 345
  float: left;
  width: 76px;
  margin-bottom: 4px;
Y
yuqi 已提交
346 347
}
.playlist_tag__item {
Z
Zachary 已提交
348 349 350 351 352 353 354 355 356 357 358 359 360
  float: left;
  padding: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 68px;
}
.playlist_tag__item--expand,
.playlist_tag__item--expand:hover,
.playlist_tag__item--select,
.playlist_tag__item--select:hover {
  background-color: #31c27c;
  color: #fff;
Y
yuqi 已提交
361 362
}
.playlist_tag__item {
Z
Zachary 已提交
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
  float: left;
  padding: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 68px;
}

.mod_part,
.mod_part_detail {
  position: relative;
  margin-bottom: 30px;
}
.part__hd,
.part_detail__hd {
  overflow: hidden;
  height: 60px;
}
.part__tit,
.part_detail__tit {
  float: left;
  font-size: 24px;
  font-weight: 400;
  line-height: 58px;
Y
yuqi 已提交
387 388
}
.mod_playlist .playlist__item {
Z
Zachary 已提交
389 390 391 392 393 394
  display: inline-block;
  width: 20%;
  padding-bottom: 44px;
  overflow: hidden;
  font-size: 14px;
  vertical-align: top;
Y
yuqi 已提交
395 396
}
.mod_playlist .playlist__cover {
Z
Zachary 已提交
397 398 399 400
  position: relative;
  display: block;
  overflow: hidden;
  margin-bottom: 15px;
Y
yuqi 已提交
401 402
}
.mod_playlist .playlist__title {
Z
Zachary 已提交
403
  overflow: hidden;
Y
yuqi 已提交
404 405
}
.mod_playlist .playlist__title_txt {
Z
Zachary 已提交
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
  float: left;
  max-width: 100%;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 22px;
  max-height: 44px;
}
.mod_playlist .playlist__author,
.mod_playlist .playlist__author a,
.mod_playlist .playlist__other {
  color: #999;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  height: 22px;
Y
yuqi 已提交
422 423
}
.mod_playlist .playlist__item_box {
Z
Zachary 已提交
424 425
  position: relative;
  margin-right: 20px;
Y
yuqi 已提交
426 427
}
.mod_playlist {
Z
Zachary 已提交
428 429
  overflow: hidden;
  font-size: 0;
Y
yuqi 已提交
430 431
}
.mod_playlist .playlist__list {
Z
Zachary 已提交
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
  margin-right: -20px;
}

/* 弹出分类框 */
.popup_tag {
  position: absolute;
  top: 175px;
  left: 0;
  right: 24px;
  border: 1px solid #bfbfbf;
  background-color: #fff;
  padding: 19px 0 15px;
  z-index: 4;
}
.popup_tag {
  box-shadow: 0 0 10px rgba(183, 183, 183, 0.65);
  border: 0 none;
}
.popup_tag .playlist_tag__tags {
  margin-left: 16px;
  line-height: 26px;
}
.popup_tag .playlist_tag__itembox {
  width: auto;
  margin-right: 32px;
}

/* 箭头 */
.playlist_tag__arrow {
  display: inline-block;
  width: 10px;
  height: 6px;
  background-position: -120px -260px;
  margin-left: 3px;
  vertical-align: 1px;
}
.playlist_tag__item:hover .playlist_tag__arrow {
  background-position: -140px -260px;
}
.playlist_tag__item--expand .playlist_tag__arrow,
.playlist_tag__item--expand:hover .playlist_tag__arrow {
  background-position: -100px -260px;
}

/* 选中类型时 */
.part_tags {
  position: relative;
  float: left;
  line-height: 38px;
  margin: 8px 6px 0 0;
  padding: 0 25px 0 10px;
  border: 1px solid #c9c9c9;
  border-radius: 2px;
  font-size: 14px;
}
.part_tags:hover {
  background-color: #37c27c;
  border-color: #37c27c;
  color: #fff;
}
.part_tags__delete {
  position: absolute;
  top: 50%;
  right: 4px;
  margin-top: -8px;
  width: 16px;
  height: 16px;
  background-position: -160px -120px;
  overflow: hidden;
}
.part_tags:hover .part_tags__delete {
  background-position: -160px -80px;
}
.part_tags .part_tags__delete:hover {
  background-color: rgba(225, 225, 225, 0.3);
  border-radius: 12px;
Y
yuqi 已提交
508
}
Z
Zachary 已提交
509
</style>