ShortLinkModal.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <script setup lang="ts">
  2. // 监听showModal变化,当弹窗显示时自动获取分享短链
  3. import { watch } from 'vue'
  4. import { useCouponShare } from '../hooks/useCouponShare'
  5. // 定义props
  6. const props = defineProps<{
  7. couponId?: string // 优惠券ID,从父组件传入
  8. showModal?: boolean // 控制弹窗显示/隐藏的prop
  9. }>()
  10. // 定义emit
  11. const emit = defineEmits<{
  12. // 弹窗关闭时触发
  13. (e: 'close'): void
  14. // 用于v-model的update事件
  15. (e: 'update:showModal', value: boolean): void
  16. }>()
  17. const { shareLink, copySuccess, shareLoading, shareCoupon, copyShareLink } = useCouponShare()
  18. watch(() => props.showModal, (newVal) => {
  19. console.log('showModal', newVal)
  20. if (newVal && props.couponId) {
  21. shareCoupon(props.couponId)
  22. }
  23. })
  24. // 弹窗关闭时触发事件
  25. function handleClose() {
  26. emit('update:showModal', false)
  27. emit('close')
  28. }
  29. </script>
  30. <template>
  31. <!-- 分享弹窗 - 使用uview-plus的Modal组件 -->
  32. <!-- <up-modal :show="props.showModal" title="分享优惠券" :show-cancel-button="false" confirm-text="关闭" :border-radius="16"
  33. width="600rpx" @confirm="handleClose">
  34. <view class="share-modal-content">
  35. <view class="share-link-container">
  36. <text class="share-link">{{ shareLink }}</text>
  37. <button class="copy-btn" @click="copyShareLink">
  38. 复制
  39. </button>
  40. </view>
  41. <view v-if="copySuccess" class="copy-success">
  42. 复制成功!
  43. </view>
  44. </view>
  45. </up-modal> -->
  46. <up-modal title="分享优惠券" style="z-index: 1000;" :show="props.showModal" :show-confirm-button="false">
  47. <view class="share-modal-content">
  48. <view class="share-link-container">
  49. <text class="share-link">{{ shareLink }}</text>
  50. <button class="copy-btn" @click="copyShareLink">
  51. 复制
  52. </button>
  53. </view>
  54. <view v-if="copySuccess" class="copy-success">
  55. 复制成功!
  56. </view>
  57. </view>
  58. <template #popupBottom>
  59. <view class="rounded" style="margin-top: 20px;" @click="handleClose">
  60. <up-icon name="close-circle" size="50rpx" color="#fff" />
  61. </view>
  62. </template>
  63. </up-modal>
  64. </template>
  65. <style scoped>
  66. .share-modal-content {
  67. margin: 20rpx 0;
  68. }
  69. .share-link-container {
  70. display: flex;
  71. align-items: center;
  72. justify-content: space-between;
  73. padding: 20rpx;
  74. background-color: #f5f5f5;
  75. border-radius: 8rpx;
  76. margin-bottom: 20rpx;
  77. }
  78. .share-link {
  79. flex: 1;
  80. font-size: 28rpx;
  81. color: #333;
  82. overflow: hidden;
  83. text-overflow: ellipsis;
  84. white-space: nowrap;
  85. margin-right: 20rpx;
  86. }
  87. .copy-btn {
  88. padding: 10rpx 20rpx;
  89. font-size: 28rpx;
  90. color: #007aff;
  91. background-color: transparent;
  92. border: 1px solid #007aff;
  93. border-radius: 8rpx;
  94. }
  95. .copy-success {
  96. text-align: center;
  97. font-size: 28rpx;
  98. color: #07c160;
  99. }
  100. </style>