|
|
@@ -6,9 +6,10 @@ import { advertisementClient, wechatCouponStockClient } from '@/api'
|
|
|
import { Button } from '@/components/ui/button'
|
|
|
import { Card, CardContent, CardHeader } from '@/components/ui/card'
|
|
|
import { cn } from '@/utils/cn'
|
|
|
-import { receiveCoupon, getCurrentUserId, checkAuth, redirectToLogin } from '@/utils/coupon-api'
|
|
|
+import { receiveCoupon } from '@/utils/coupon-api'
|
|
|
import { Navbar } from '@/components/ui/navbar'
|
|
|
import { TabBarLayout } from '@/layouts/tab-bar-layout'
|
|
|
+import { useAuth } from '@/utils/auth'
|
|
|
|
|
|
interface Advertisement {
|
|
|
id: number
|
|
|
@@ -35,6 +36,7 @@ interface WechatCouponStock {
|
|
|
|
|
|
export default function IndexPage() {
|
|
|
const queryClient = useQueryClient()
|
|
|
+ const { user, isLoggedIn } = useAuth()
|
|
|
|
|
|
// 获取广告列表
|
|
|
const { data: advertisements, isLoading: adsLoading } = useQuery({
|
|
|
@@ -73,11 +75,10 @@ export default function IndexPage() {
|
|
|
// 领取代金券
|
|
|
const receiveMutation = useMutation({
|
|
|
mutationFn: async (stockId: number) => {
|
|
|
- const userId = getCurrentUserId()
|
|
|
- if (!userId) {
|
|
|
+ if (!user?.id) {
|
|
|
throw new Error('请先登录')
|
|
|
}
|
|
|
- const result = await receiveCoupon({ stockId, userId })
|
|
|
+ const result = await receiveCoupon({ stockId, userId: user.id })
|
|
|
if (!result.success) {
|
|
|
throw new Error(result.message)
|
|
|
}
|
|
|
@@ -97,7 +98,7 @@ export default function IndexPage() {
|
|
|
content: '请先登录后再领取优惠券',
|
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
- redirectToLogin()
|
|
|
+ Taro.navigateTo({ url: '/pages/login/index' })
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
@@ -111,13 +112,13 @@ export default function IndexPage() {
|
|
|
})
|
|
|
|
|
|
const handleReceiveCoupon = (stockId: number) => {
|
|
|
- if (!checkAuth()) {
|
|
|
+ if (!isLoggedIn) {
|
|
|
Taro.showModal({
|
|
|
title: '提示',
|
|
|
content: '请先登录后再领取优惠券',
|
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
- redirectToLogin()
|
|
|
+ Taro.navigateTo({ url: '/pages/login/index' })
|
|
|
}
|
|
|
}
|
|
|
})
|