Image.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <!-- 聊天消息内容的文本展示 -->
  3. <van-popover
  4. teleport="images"
  5. theme="dark"
  6. placement="bottom"
  7. actions-direction="horizontal"
  8. v-model:show="showPopover"
  9. @select="select"
  10. >
  11. <div class="flex my-16 mx-10">
  12. <div v-for="(item, index) in actions" :key="index" @click="" class="mx-10 text-center">
  13. <span :class="`iconfont ${item.icon} text-white mb-4`" style="font-size: 24px"></span>
  14. <p class="text-white text-base">{{ item.text }}</p>
  15. </div>
  16. </div>
  17. <template #reference>
  18. <img
  19. class="w-full images h-full object-contain"
  20. :src="itemData?.url"
  21. @touchstart="doTouchstart"
  22. alt=""
  23. />
  24. </template>
  25. </van-popover>
  26. </template>
  27. <script setup>
  28. import { useClipboard } from '@vueuse/core'
  29. const { copy, isSupported } = useClipboard()
  30. const showPopover = ref(false)
  31. defineProps({
  32. itemData: {
  33. type: String,
  34. default: ''
  35. }
  36. })
  37. defineEmits(['onDelete'])
  38. const actions = [
  39. { text: '引用', icon: 'icon-quote' },
  40. { text: '复制', icon: 'icon-copy' },
  41. { text: '删除', icon: 'icon-delete-three' }
  42. ]
  43. function doTouchstart() {
  44. showPopover.value = true
  45. }
  46. function select(action, index) {
  47. console.log(action, index)
  48. if (action.text == '复制') {
  49. copy(itemData.text)
  50. showToast('已复制')
  51. }
  52. if (action.text == '删除') {
  53. $emit('onDelete')
  54. showToast('已复制')
  55. }
  56. showPopover.value = false
  57. }
  58. </script>
  59. <style lang="scss" scoped></style>