<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>
|