import React from 'react' import { View, Text } from '@tarojs/components' import { Popup } from '@nutui/nutui-react-taro' import { Share, Link, Close } from '@nutui/icons-react-taro' import Taro from '@tarojs/taro' export interface CouponShareProps { /** 是否显示分享弹窗 */ visible: boolean /** 优惠券信息 */ coupon: { id: number name: string type: number amount: string minAmount?: string description?: string } /** 关闭回调 */ onClose: () => void } const CouponShare: React.FC = ({ visible, coupon, onClose }) => { // 生成分享文案 const generateShareText = () => { const typeText = coupon.type === 10 ? '满减券' : coupon.type === 20 ? '折扣券' : '免费券' const amountText = coupon.type === 10 ? `¥${coupon.amount}` : coupon.type === 20 ? `${coupon.amount}折` : '免费' const conditionText = coupon.minAmount ? `满${coupon.minAmount}元可用` : '无门槛' return `🎁 ${coupon.name}\n💰 ${amountText} ${typeText}\n📋 ${conditionText}\n快来领取吧!` } // 生成分享链接 const generateShareUrl = () => { // 这里应该是实际的分享链接,包含优惠券ID等参数 return `https://your-domain.com/coupon/share?id=${coupon.id}` } // 微信分享 const handleWechatShare = () => { Taro.showShareMenu({ withShareTicket: true, success: () => { Taro.showToast({ title: '分享成功', icon: 'success' }) onClose() }, fail: () => { Taro.showToast({ title: '分享失败', icon: 'error' }) } }) } // 复制链接 const handleCopyLink = () => { const shareUrl = generateShareUrl() const shareText = generateShareText() const fullText = `${shareText}\n\n${shareUrl}` Taro.setClipboardData({ data: fullText, success: () => { Taro.showToast({ title: '已复制到剪贴板', icon: 'success' }) onClose() }, fail: () => { Taro.showToast({ title: '复制失败', icon: 'error' }) } }) } // 保存图片分享 const handleSaveImage = async () => { try { // 这里可以生成优惠券图片并保存到相册 // 实际实现需要canvas绘制优惠券图片 Taro.showToast({ title: '功能开发中', icon: 'none' }) } catch (error) { Taro.showToast({ title: '保存失败', icon: 'error' }) } } const shareOptions = [ { icon: , label: '微信好友', onClick: handleWechatShare }, { icon: , label: '复制链接', onClick: handleCopyLink }, { icon: , label: '保存图片', onClick: handleSaveImage } ] return ( {/* 头部 */} 分享优惠券 {/* 优惠券预览 */} {coupon.name} {coupon.type === 10 ? `¥${coupon.amount}` : coupon.type === 20 ? `${coupon.amount}折` : '免费'} {coupon.minAmount ? `满${coupon.minAmount}元可用` : '无门槛使用'} {/* 分享选项 */} {shareOptions.map((option, index) => ( {option.icon} {option.label} ))} {/* 分享文案预览 */} 分享文案预览: {generateShareText()} ) } export default CouponShare