collection.vue 1.95 KB
<template>
  <div class="book-video-list">
    <template v-for="item in prodList" :key="item" style="height: 3rem;">
      <video-card :item="item"></video-card>
    </template>
    <div style="height: 2rem;"></div>
  </div>
  <van-empty v-if="emptyStatus"
    class="custom-image"
    :image="no_image"
    description="暂无收藏"
  />
</template>

<script setup>
import VideoCard from '@/components/VideoCard/index.vue'
import Cookies from 'js-cookie'
import no_image from '@images/que-shuju@2x.png'
import { mainStore } from '@/store'
import { storeToRefs } from 'pinia'
import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router'
import { ref } from 'vue'
import axios from '@/utils/axios';
import { Toast } from 'vant';
import $ from 'jquery'
import _ from 'lodash'

/******************** 返回点击位置 ********************/
const store = mainStore();
const { scrollTopCollection } = storeToRefs(store);
// 嵌套滚动,执行两个,先滚外面再滚里面
_.times(2, () => {
  $("html,body").animate({ "scrollTop": String(scrollTopCollection.value) + 'px' });
});

onBeforeRouteLeave(() => {
  // 监听记录滚动位置
  store.changeScrollTopCollection(window.scrollY)
})
/*****************************************************/

// 处理书籍下作品列表
const prodList = ref([])
// 因为不能让空图标提前出来的写法
const emptyStatus = ref(false);
axios.get('/srv/?a=my_favor')
  .then(res => {
    if (res.data.code === 1) {
      prodList.value = res.data.data.prod;
      _.each(prodList.value, (item) => {
        item.type = 'read-only' // 特殊标识,判断入口 为keepAlive使用
      });
      if (!res.data.data.prod.length) {
        emptyStatus.value = true;
      }
    } else {
      console.warn(res);
      if (!res.data.show) return false;
      Toast({
        icon: 'close',
        message: res.data.msg
      });
    }
  })
  .catch(err => {
    console.error(err);
  });


</script>

<style lang="less" scoped>
</style>