import React, { useEffect } from 'react' import { View, Text, ScrollView } from '@tarojs/components' import Taro from '@tarojs/taro' definePageConfig({ navigationBarTitleText: '消息详情', }) const MessageDetailPage: React.FC = () => { const [message, setMessage] = useState({ id: 1, type: 1, title: '欢迎注册鑫龙家电', content: '感谢您注册鑫龙家电,让我们一起开启美好购物体验!\n\n在鑫龙家电,您可以:\n• 浏览精选商品\n• 享受会员专属优惠\n• 参与精彩活动\n• 获得积分奖励\n\n如有任何问题,欢迎联系客服。', time: '2026-05-12 10:30:00', isRead: true, }) // 模拟获取消息详情 useEffect(() => { const params = Taro.getCurrentInstance().router?.params if (params?.id) { // 这里应该调用API获取消息详情 console.log('消息ID:', params.id) // 标记为已读 Taro.showToast({ title: '已标记为已读', icon: 'none' }) } }, []) // 获取类型图标 const getTypeIcon = (type: number) => { const iconMap: Record = { 1: '🔔', 2: '📦', 3: '🎁', } return iconMap[type] || '📋' } // 获取类型名称 const getTypeName = (type: number) => { const nameMap: Record = { 1: '系统通知', 2: '订单通知', 3: '活动通知', } return nameMap[type] || '其他' } // 格式化时间 const formatTime = (timeStr: string) => { const date = new Date(timeStr) const year = date.getFullYear() const month = (date.getMonth() + 1).toString().padStart(2, '0') const day = date.getDate().toString().padStart(2, '0') const hour = date.getHours().toString().padStart(2, '0') const minute = date.getMinutes().toString().padStart(2, '0') return `${year}-${month}-${day} ${hour}:${minute}` } // 删除消息 const handleDelete = () => { Taro.showModal({ title: '提示', content: '确定删除该消息吗?', confirmColor: '#0e932e', success: (res) => { if (res.confirm) { Taro.showToast({ title: '删除成功', icon: 'success' }) setTimeout(() => { Taro.navigateBack() }, 1500) } } }) } return ( {/* 消息头部 */} {getTypeIcon(message.type)} {message.title} {formatTime(message.time)} {getTypeName(message.type)} {/* 消息内容 */} {message.content} {/* 相关操作 */} 相关操作 Taro.navigateTo({ url: '/pages/user/user' })} > 查看个人中心 Taro.switchTab({ url: '/pages/index/index' })} > 返回首页 删除此消息 ) } export default MessageDetailPage