preview.vue 1.9 KB

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