preview.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div class="preview-page">
  3. <a-row :gutter="[32, 16]" justify="flex-start" style="margin-top: 24px;">
  4. <a-col :span="4" v-for="card in cardList" :key="card.id" style="margin-bottom: 16px;">
  5. <a-card @click="handleClick(card)" :bordered="false" hoverable style="width: 100%;height: 320px;" :title="card.name" >
  6. <div class="card-bg" >
  7. <img style="width: 50%;Object-fit: contain;" :src="card.thumbnail" alt="example" />
  8. </div>
  9. </a-card>
  10. </a-col>
  11. </a-row>
  12. </div>
  13. </template>
  14. <script lang='ts' setup >
  15. import { onMounted, ref, watch } from 'vue'
  16. import { useRoute, useRouter } from 'vue-router'
  17. import { CardController } from '@/controller'
  18. const route = useRoute()
  19. const router = useRouter()
  20. const cardList = ref<API.Card[]>([])
  21. const getCardList = async () => {
  22. const { data } = await CardController.getCardList(route.query.id as string)
  23. cardList.value = data || []
  24. console.log('cardList:', cardList.value)
  25. }
  26. const handleClick = (card: API.Card) => {
  27. // 跳转到卡片详情页
  28. router.push({
  29. path: '/card',
  30. query: {
  31. id: card.id,
  32. name: card.name,
  33. img: card.img,
  34. parentId: card.parentId,
  35. card_type: Number(card.page) % 2 === 0 ? 21 : 5
  36. }
  37. })
  38. }
  39. watch(
  40. () => route.query.id,
  41. (newId) => {
  42. if (newId) {
  43. getCardList()
  44. }
  45. },
  46. { immediate: true }
  47. )
  48. onMounted(() => {
  49. console.log('route:', route)
  50. // getCardList()
  51. // 这里可以添加其他逻辑
  52. })
  53. </script>
  54. <style lang='less' scoped >
  55. .preview-page {
  56. .card-bg {
  57. width: 100%;
  58. height: 100%;
  59. display: flex;
  60. justify-content: center;
  61. align-items: center;
  62. background-color: #f5f5f5;
  63. border-radius: 8px;
  64. overflow: hidden;
  65. }
  66. }
  67. /deep/ .ant-card-body {
  68. padding: 0px;
  69. overflow: hidden;
  70. height: 265px;
  71. }
  72. </style>