<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">
|
<image src="/static/common/wechat.png" class="share-icon" />
|
<text>微信好友</text>
|
</button>
|
<!-- 分享到朋友圈 -->
|
<view class="share-item" @click="handleShareTimeline">
|
<image src="/static/common/wechat-moments.png" class="share-icon" />
|
<text>朋友圈</text>
|
</view>
|
<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 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()
|
}
|
|
// 复制链接
|
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>
|