Files
xinlong-shop-taro/src_bak/pages/points/signin.tsx
赵忠林 1fa58040f3 feat(user): 新增收货地址管理及售后申请页面
- 新增地址类型定义,增强前端地址数据结构
- 新增地址编辑页面,支持地址智能识别和定位选点功能
- 地址编辑支持省市区选择及默认地址设置
- 新增地址列表页面,支持地址展示、删除、编辑和选择功能
- 实现售后申请页面,支持选择售后类型和退款原因
- 售后申请支持商品选择、退款金额计算和凭证上传
- 新增售后详情页面,支持售后状态展示及申请取消
- 优化页面加载和用户交互体验,增加错误提示和权限处理
2026-07-01 12:11:56 +08:00

150 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

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, { useState, useEffect } from 'react'
import { View, Text } from '@tarojs/components'
import Taro from '@tarojs/taro'
import { useUser } from '@/hooks/useUser'
import { listShopSigninRecord, addShopSigninRecord } from '@/api/shop/shopSigninRecord'
definePageConfig({
navigationBarTitleText: '每日签到',
})
const SigninPage: React.FC = () => {
const { user, isLoggedIn } = useUser()
const [signedDates, setSignedDates] = useState<string[]>([])
const [todaySigned, setTodaySigned] = useState(false)
const [loading, setLoading] = useState(false)
const today = new Date()
const todayStr = today.toISOString().split('T')[0] // YYYY-MM-DD
// 获取当月已签到日期
useEffect(() => {
if (!isLoggedIn) {
Taro.navigateTo({ url: '/passport/login' })
return
}
loadSignedRecords()
}, [isLoggedIn])
const loadSignedRecords = async () => {
try {
const year = today.getFullYear()
const month = today.getMonth() + 1
const data = await listShopSigninRecord({
userId: (user as any)?.userId,
year,
month,
})
if (data && Array.isArray(data)) {
const dates = data.map((record: any) => record.signinDate)
setSignedDates(dates)
setTodaySigned(dates.includes(todayStr))
}
} catch (err) {
console.error('加载签到记录失败', err)
}
}
const handleSignin = async () => {
if (todaySigned) {
Taro.showToast({ title: '今日已签到', icon: 'none' })
return
}
if (loading) return
setLoading(true)
try {
await addShopSigninRecord({
userId: (user as any)?.userId,
signinDate: todayStr,
})
Taro.showToast({ title: '签到成功 +5积分', icon: 'success' })
setTodaySigned(true)
setSignedDates(prev => [...prev, todayStr])
} catch (err: any) {
console.error('签到失败', err)
Taro.showToast({ title: err.message || '签到失败', icon: 'none' })
} finally {
setLoading(false)
}
}
// 生成本周日期列表用于UI显示
const getWeekDates = () => {
const dates = []
for (let i = 6; i >= 0; i--) {
const d = new Date(today)
d.setDate(d.getDate() - i)
dates.push(d)
}
return dates
}
const weekDates = getWeekDates()
const getDayOfWeek = (date: Date) => {
const days = ['日', '一', '二', '三', '四', '五', '六']
return days[date.getDay()]
}
return (
<View className='min-h-screen bg-gray-50 p-4'>
{/* 签到卡片 */}
<View className='bg-white rounded-xl p-6 text-center'>
<Text className='text-lg font-bold text-gray-800 block mb-1'></Text>
<Text className='text-sm text-gray-500 block mb-4'></Text>
{/* 本周签到 */}
<View className='grid grid-cols-7 gap-1 mb-4'>
{weekDates.map((date, idx) => {
const dateStr = date.toISOString().split('T')[0]
const dayOfWeek = getDayOfWeek(date)
const isSigned = signedDates.includes(dateStr)
const isToday = dateStr === todayStr
return (
<View key={idx} className='flex flex-col items-center py-2'>
<Text className='text-xs text-gray-400 mb-1'>{dayOfWeek}</Text>
<View
className={`w-8 h-8 rounded-full flex items-center justify-center ${
isSigned
? 'bg-green-500'
: isToday
? 'bg-green-50 border border-green-500'
: 'bg-gray-50'
}`}
>
<Text className={`text-xs ${isSigned ? 'text-white' : isToday ? 'text-green-600' : 'text-gray-400'}`}>
{date.getDate()}
</Text>
</View>
</View>
)
})}
</View>
<View
className='py-2 rounded-full'
style={{ backgroundColor: todaySigned ? '#ccc' : '#0e932e' }}
onClick={handleSignin}
>
<Text className='text-white font-medium text-sm'>
{loading ? '签到中...' : todaySigned ? '已签到' : '立即签到'}
</Text>
</View>
</View>
{/* 签到规则 */}
<View className='bg-white rounded-xl p-4 mt-4'>
<Text className='text-sm font-medium text-gray-800 mb-2'></Text>
<View className='text-xs text-gray-500 leading-6'>
<Text className='block'>1. 5 </Text>
<Text className='block'>2. 7 20 </Text>
<Text className='block'>3. 30 100 </Text>
<Text className='block'>4. </Text>
</View>
</View>
</View>
)
}
export default SigninPage