cloudroam
7 天以前 c31a8def0ac90d86b8e8e345441bd28002a9ef2f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<template>
  <view class="share-popup" v-if="show">
    <view class="share-mask" @click="closePopup"></view>
    <view class="share-content">
      <view class="share-title">分享到</view>
      <view class="share-options">
        <button class="share-item" open-type="share" @click="handleShare('wechat')">
          <image src="/static/common/wechat.png" class="share-icon" />
          <text>微信好友</text>
        </button>
        <button class="share-item" open-type="share" @click="handleShare('moments')">
          <image src="/static/common/wechat-moments.png" class="share-icon" />
          <text>朋友圈</text>
        </button>
        <view class="share-item" @click="handleCopyLink">
          <image src="/static/common/link.png" class="share-icon" />
          <text>复制链接</text>
        </view>
      </view>
      <view class="share-cancel" @click="closePopup">取消</view>
    </view>
  </view>
</template>
 
<script setup lang="ts">
import { ref, defineProps, defineEmits } from 'vue'
 
const props = defineProps({
  show: {
    type: Boolean,
    default: false
  },
  shareData: {
    type: Object,
    default: () => ({
      title: '',
      desc: '',
      image: '',
      url: ''
    })
  }
})
 
const emit = defineEmits(['update:show'])
 
// 关闭弹窗
const closePopup = () => {
  emit('update:show', false)
}
 
// 处理分享
const handleShare = (type: 'wechat' | 'moments') => {
  // 小程序分享通过页面配置和按钮的 open-type="share" 实现
  // 分享内容在页面的 onShareAppMessage 中配置
  closePopup()
}
 
// 复制链接
const handleCopyLink = () => {
  uni.setClipboardData({
    data: props.shareData.url,
    success: () => {
      uni.showToast({
        title: '链接已复制',
        icon: 'success'
      })
      closePopup()
    }
  })
}
</script>
 
<style lang="scss" scoped>
.share-popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
 
  .share-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
  }
 
  .share-content {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-radius: 20rpx 20rpx 0 0;
    padding: 30rpx;
    transform: translateY(0);
    transition: transform 0.3s ease-out;
 
    .share-title {
      text-align: center;
      font-size: 32rpx;
      color: #333;
      margin-bottom: 30rpx;
    }
 
    .share-options {
      display: flex;
      justify-content: space-around;
      padding: 20rpx 0;
 
      .share-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 120rpx;
        background: none;
        border: none;
        padding: 0;
        margin: 0;
        line-height: normal;
 
        &::after {
          border: none;
        }
 
        .share-icon {
          width: 80rpx;
          height: 80rpx;
          margin-bottom: 10rpx;
        }
 
        text {
          font-size: 24rpx;
          color: #666;
        }
      }
    }
 
    .share-cancel {
      text-align: center;
      color: #888;
      font-size: 28rpx;
      padding: 20rpx 0;
      border-top: 1px solid #eee;
      margin-top: 20rpx;
    }
  }
}
</style>