| | |
| | | <view class="share-content"> |
| | | <view class="share-title">分享到</view> |
| | | <view class="share-options"> |
| | | <button class="share-item" open-type="share" @click="handleShare('wechat')"> |
| | | <!-- 分享给好友 --> |
| | | <button class="share-item" open-type="share"> |
| | | <image src="/static/common/wechat.png" class="share-icon" /> |
| | | <text>微信好友</text> |
| | | </button> |
| | | <button class="share-item" open-type="share" @click="handleShare('moments')"> |
| | | <!-- 分享到朋友圈 --> |
| | | <view class="share-item" @click="handleShareTimeline"> |
| | | <image src="/static/common/wechat-moments.png" class="share-icon" /> |
| | | <text>朋友圈</text> |
| | | </button> |
| | | </view> |
| | | <view class="share-item" @click="handleCopyLink"> |
| | | <image src="/static/common/link.png" class="share-icon" /> |
| | | <text>复制链接</text> |
| | |
| | | emit('update:show', false) |
| | | } |
| | | |
| | | // 处理分享 |
| | | const handleShare = (type: 'wechat' | 'moments') => { |
| | | // 小程序分享通过页面配置和按钮的 open-type="share" 实现 |
| | | // 分享内容在页面的 onShareAppMessage 中配置 |
| | | // 处理分享到朋友圈 |
| | | const handleShareTimeline = () => { |
| | | // #ifdef MP-WEIXIN |
| | | // 使用微信原生朋友圈分享 |
| | | wx.openChannelsActivity({ |
| | | finderUserName: '', // 视频号用户名,可选 |
| | | success: (res) => { |
| | | console.log('打开朋友圈成功', res) |
| | | uni.showToast({ |
| | | title: '已打开朋友圈', |
| | | icon: 'success' |
| | | }) |
| | | }, |
| | | fail: (err) => { |
| | | console.error('打开朋友圈失败', err) |
| | | // 如果打开失败,尝试使用小程序分享 |
| | | uni.showModal({ |
| | | title: '提示', |
| | | content: '无法直接打开朋友圈,请点击右上角分享到朋友圈', |
| | | showCancel: false |
| | | }) |
| | | } |
| | | }) |
| | | // #endif |
| | | |
| | | // #ifndef MP-WEIXIN |
| | | // 非微信小程序环境 |
| | | uni.showToast({ |
| | | title: '请点击右上角分享到朋友圈', |
| | | icon: 'none', |
| | | duration: 2000 |
| | | }) |
| | | // #endif |
| | | |
| | | closePopup() |
| | | } |
| | | |