feat(课程详情页): 添加富文本图片点击预览功能
在课程介绍富文本区域添加点击事件处理,当点击图片时调用vant的图片预览组件
Showing
2 changed files
with
21 additions
and
5 deletions
| ... | @@ -13,6 +13,8 @@ | ... | @@ -13,6 +13,8 @@ |
| 13 | "MaybeRefOrGetter": true, | 13 | "MaybeRefOrGetter": true, |
| 14 | "PropType": true, | 14 | "PropType": true, |
| 15 | "Ref": true, | 15 | "Ref": true, |
| 16 | + "Slot": true, | ||
| 17 | + "Slots": true, | ||
| 16 | "VNode": true, | 18 | "VNode": true, |
| 17 | "WritableComputedRef": true, | 19 | "WritableComputedRef": true, |
| 18 | "computed": true, | 20 | "computed": true, |
| ... | @@ -74,8 +76,6 @@ | ... | @@ -74,8 +76,6 @@ |
| 74 | "watch": true, | 76 | "watch": true, |
| 75 | "watchEffect": true, | 77 | "watchEffect": true, |
| 76 | "watchPostEffect": true, | 78 | "watchPostEffect": true, |
| 77 | - "watchSyncEffect": true, | 79 | + "watchSyncEffect": true |
| 78 | - "Slot": true, | ||
| 79 | - "Slots": true | ||
| 80 | } | 80 | } |
| 81 | } | 81 | } | ... | ... |
| ... | @@ -69,7 +69,7 @@ | ... | @@ -69,7 +69,7 @@ |
| 69 | <div v-html="course?.feature"></div> | 69 | <div v-html="course?.feature"></div> |
| 70 | </div> --> | 70 | </div> --> |
| 71 | 71 | ||
| 72 | - <div v-if="activeTab === '课程介绍'"> | 72 | + <div v-if="activeTab === '课程介绍'" @click="handleIntroduceClick"> |
| 73 | <!-- <p v-html="course?.introduce" class="text-gray-700 whitespace-pre-line"></p> --> | 73 | <!-- <p v-html="course?.introduce" class="text-gray-700 whitespace-pre-line"></p> --> |
| 74 | <p v-html="course?.introduce" class="text-gray-700"></p> | 74 | <p v-html="course?.introduce" class="text-gray-700"></p> |
| 75 | </div> | 75 | </div> |
| ... | @@ -337,7 +337,7 @@ import { useRoute, useRouter } from 'vue-router' | ... | @@ -337,7 +337,7 @@ import { useRoute, useRouter } from 'vue-router' |
| 337 | import { useCart } from '@/contexts/cart' | 337 | import { useCart } from '@/contexts/cart' |
| 338 | import { useAuth } from '@/contexts/auth' | 338 | import { useAuth } from '@/contexts/auth' |
| 339 | import { useTitle } from '@vueuse/core'; | 339 | import { useTitle } from '@vueuse/core'; |
| 340 | -import { showToast, showDialog } from 'vant'; | 340 | +import { showToast, showDialog, showImagePreview } from 'vant'; |
| 341 | import { formatDate } from '@/utils/tools' | 341 | import { formatDate } from '@/utils/tools' |
| 342 | 342 | ||
| 343 | import AppLayout from '@/components/layout/AppLayout.vue' | 343 | import AppLayout from '@/components/layout/AppLayout.vue' |
| ... | @@ -367,6 +367,22 @@ const isPurchased = ref(false) | ... | @@ -367,6 +367,22 @@ const isPurchased = ref(false) |
| 367 | const isReviewed = ref(false) | 367 | const isReviewed = ref(false) |
| 368 | const showReviewPopup = ref(false) | 368 | const showReviewPopup = ref(false) |
| 369 | 369 | ||
| 370 | +// 处理富文本点击事件,实现图片预览 | ||
| 371 | +const handleIntroduceClick = (event) => { | ||
| 372 | + const target = event.target; | ||
| 373 | + if (target.tagName === 'IMG') { | ||
| 374 | + // 阻止默认行为(如果需要) | ||
| 375 | + event.preventDefault(); | ||
| 376 | + | ||
| 377 | + // 调用 vant 的图片预览 | ||
| 378 | + showImagePreview({ | ||
| 379 | + images: [target.src], | ||
| 380 | + closeable: true, | ||
| 381 | + showIndex: false, // 单张图片不显示索引 | ||
| 382 | + }); | ||
| 383 | + } | ||
| 384 | +}; | ||
| 385 | + | ||
| 370 | // 打卡相关状态 | 386 | // 打卡相关状态 |
| 371 | const task_list = ref([]) | 387 | const task_list = ref([]) |
| 372 | const timeout_task_list = ref([]) | 388 | const timeout_task_list = ref([]) | ... | ... |
-
Please register or login to post a comment