Files
websopy-taro/src/components/GiftCardShare.tsx
赵忠林 07f5c92f4b feat(add): 新增多页面新增和编辑表单功能
- 添加编辑和新增收货地址页面,支持表单数据加载和提交
- 新增应用密钥凭证、新增应用操作动态、新增应用成员、新增应用版本页面配置
- 实现文章新增及编辑页面,包含图片上传及多种文章属性配置
- 增加注册会员页面,支持头像上传、手机号获取和邀请人关系处理
- 引入统一表单提交成功和失败处理,支持编辑模式数据回显
- 配置统一eslint和editorconfig规则,增强代码规范和编辑体验
- 新增.gitignore规则,屏蔽无关文件和目录,优化版本管理
2026-04-11 12:22:29 +08:00

228 lines
5.9 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from 'react'
import { View, Text } from '@tarojs/components'
import { Popup } from '@nutui/nutui-react-taro'
import { Share, Link, Close, Gift } from '@nutui/icons-react-taro'
import Taro from '@tarojs/taro'
export interface GiftCardShareProps {
/** 是否显示分享弹窗 */
visible: boolean
/** 礼品卡信息 */
giftCard: {
id: number
name: string
type: number
faceValue: string
code?: string
description?: string
}
/** 关闭回调 */
onClose: () => void
}
const GiftCardShare: React.FC<GiftCardShareProps> = ({
visible,
giftCard,
onClose
}) => {
// 获取礼品卡类型文本
const getTypeText = () => {
switch (giftCard.type) {
case 10: return '礼品劵'
case 20: return '虚拟礼品卡'
case 30: return '服务礼品卡'
default: return '水票'
}
}
// 生成分享文案
const generateShareText = () => {
const typeText = getTypeText()
const valueText = `¥${giftCard.faceValue}`
return `🎁 ${giftCard.name}\n💰 面值 ${valueText}\n🏷 ${typeText}\n${giftCard.description ? `📝 ${giftCard.description}\n` : ''}快来领取这份礼品卡吧!`
}
// 生成分享链接
const generateShareUrl = () => {
// 这里应该是实际的分享链接包含礼品卡ID等参数
return `https://your-domain.com/gift/share?id=${giftCard.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 handleCopyCode = () => {
if (!giftCard.code) {
Taro.showToast({
title: '暂无兑换码',
icon: 'none'
})
return
}
Taro.setClipboardData({
data: giftCard.code,
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: <Share size="32" className="text-green-500" />,
label: '微信好友',
onClick: handleWechatShare
},
{
icon: <Link size="32" className="text-blue-500" />,
label: '复制链接',
onClick: handleCopyLink
},
{
icon: <Gift size="32" className="text-purple-500" />,
label: '复制兑换码',
onClick: handleCopyCode,
disabled: !giftCard.code
},
{
icon: <Share size="32" className="text-orange-500" />,
label: '保存图片',
onClick: handleSaveImage
}
]
return (
<Popup
visible={visible}
position="bottom"
style={{ height: 'auto' }}
round
>
<View className="p-6">
{/* 头部 */}
<View className="flex items-center justify-between mb-6">
<Text className="text-lg font-semibold"></Text>
<View onClick={onClose}>
<Close size="20" className="text-gray-500" />
</View>
</View>
{/* 礼品卡预览 */}
<View className="rounded-xl p-4 mb-6 text-white" style={{backgroundColor: '#fbbf24'}}>
<Text className="text-xl font-bold mb-2">{giftCard.name}</Text>
<View className="flex items-center justify-between">
<View>
<Text className="text-2xl font-bold">¥{giftCard.faceValue}</Text>
<Text className="text-sm opacity-90">{getTypeText()}</Text>
</View>
<Gift size="24" />
</View>
{giftCard.code && (
<View className="mt-3 p-2 bg-white bg-opacity-20 rounded">
<Text className="text-xs opacity-80"></Text>
<Text className="font-mono font-bold">{giftCard.code}</Text>
</View>
)}
</View>
{/* 分享选项 */}
<View className="flex justify-between mb-4" style={{gap: '16px'}}>
{shareOptions.map((option, index) => (
<View
key={index}
className={`flex-1 flex flex-col items-center py-4 bg-gray-50 rounded-lg ${
option.disabled ? 'opacity-50' : ''
}`}
onClick={option.disabled ? undefined : option.onClick}
>
<View className="mb-2">{option.icon}</View>
<Text className="text-sm text-gray-700">{option.label}</Text>
</View>
))}
</View>
{/* 分享文案预览 */}
<View className="bg-gray-50 rounded-lg p-3">
<Text className="text-xs text-gray-500 mb-2"></Text>
<Text className="text-sm text-gray-700 leading-relaxed">
{generateShareText()}
</Text>
</View>
</View>
</Popup>
)
}
export default GiftCardShare