index.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <van-tabs v-if="model" ref="tabsRef" v-model:active="active" scrollspy sticky class="birds">
  3. <van-tab title="前言" :name="0">
  4. <img class="birds__title" src="@/assets/images/birds/icon_pre_bird@2x-min.png" />
  5. <div class="birds__preface">
  6. <div v-html="model.preface" />
  7. </div>
  8. <div class="birds__bg b0" :style="{ background: '#FFFDF5' }" />
  9. </van-tab>
  10. <van-tab v-for="item in model.list" :title="item.label" :key="item.id" :name="item.id">
  11. <img class="birds__title" :src="item.labelImg" />
  12. <div v-if="item.info" class="birds__info">
  13. <p :style="{ color: item.infoColor }" v-html="item.info" />
  14. </div>
  15. <div class="birds-cards">
  16. <div
  17. v-for="subItem in item.list"
  18. :key="subItem.id"
  19. class="birds-card"
  20. @click="handleCard(item.id, subItem.id)"
  21. >
  22. <div class="birds-card__img">
  23. <van-image lazy-load fit="cover" width="100%" height="100%" :src="subItem.imgs[0]" />
  24. </div>
  25. <p class="birds-card__title limit-line">{{ subItem.title }}</p>
  26. <p class="birds-card__subtitle limit-line">{{ subItem.author }}</p>
  27. </div>
  28. </div>
  29. <div
  30. v-if="item.bgColor"
  31. :class="['birds__bg', `b${item.id}`]"
  32. :style="{ background: item.bgColor }"
  33. />
  34. </van-tab>
  35. <van-tab title="结语">
  36. <img class="birds__title" src="@/assets/images/birds/icon_end_bird@2x-min.png" />
  37. <div class="birds__preface">
  38. <div v-html="model.epilogue" :style="{ color: '#533D23' }" />
  39. </div>
  40. <div class="birds__bg b0" :style="{ background: '#FFFDF5' }" />
  41. </van-tab>
  42. </van-tabs>
  43. <div v-if="loading" class="loading-page">
  44. <van-loading color="#52c1ff" :size="48" />
  45. </div>
  46. </template>
  47. <script lang="ts">
  48. export default {
  49. name: 'birds'
  50. }
  51. </script>
  52. <script lang="ts" setup>
  53. import { ref, onMounted, computed } from 'vue'
  54. import { useRoute, useRouter } from 'vue-router'
  55. import type { TabsInstance } from 'vant'
  56. import { useBirdsStore } from '@/stores/birds'
  57. const route = useRoute()
  58. const router = useRouter()
  59. const active = ref(0)
  60. const loading = ref(true)
  61. const birds = useBirdsStore()
  62. const tabsRef = ref<TabsInstance>()
  63. const model = computed(() => birds.data.find((item) => item.id === Number(route.params.id)))
  64. onMounted(() => {
  65. setTimeout(() => {
  66. tabsRef.value?.scrollTo(Number(route.params.secondId))
  67. loading.value = false
  68. }, 500)
  69. })
  70. const handleCard = (pId: number, id: number) => {
  71. router.push({
  72. name: 'birds-detail',
  73. params: {
  74. id: route.params.id,
  75. sid: pId,
  76. detailId: id
  77. }
  78. })
  79. }
  80. </script>
  81. <style lang="scss">
  82. @import './index.scss';
  83. </style>