diff --git a/miniprogram/src/pages-extra/event-detail/index.jsx b/miniprogram/src/pages-extra/event-detail/index.jsx index 62c376a..f49be46 100644 --- a/miniprogram/src/pages-extra/event-detail/index.jsx +++ b/miniprogram/src/pages-extra/event-detail/index.jsx @@ -1,5 +1,5 @@ import { View, Text, Input, Textarea, Picker, Button, Image, RichText } from '@tarojs/components'; -import Taro from '@tarojs/taro'; +import Taro, { useDidShow } from '@tarojs/taro'; import { useState, useEffect } from 'react'; import { getEventDetail, submitBooking, getMyBookingForEvent, fmtEvt, fmtEvtRange, payBooking, bookingPayStatus, requestWxPay, priceText } from '@/utils/booking'; @@ -14,7 +14,7 @@ const sanitizeRichHtml = (html) => String(html || '') const clean = attrs.replace(/\swidth\s*=\s*"[^"]*"/i, '').replace(/\sheight\s*=\s*"[^"]*"/i, ''); return ``; }); -import { isAuthed, getUser, wxLogin, wxPhoneBind, phoneLogin, bindPhone, sendCode } from '@/utils/auth'; +import { isAuthed, getUser, wxLogin, wxPhoneBind, phoneLogin, bindPhone, sendCode, getMe } from '@/utils/auth'; import { useEventShare } from '@/utils/share'; import coverWide from '@/assets/huodong-wide.png'; import Skeleton from '@/components/skeleton'; @@ -128,6 +128,27 @@ export default function EventDetail() { } }, [id]); + /* 每次页面显示时同步登录态与手机号绑定状态(解决 tab 切换/页面返回后登录态不同步问题)。 + 已登录则调用 /auth/me 从服务端拉取最新资料(含 phoneBound),避免本地缓存过期; + 未登录则清空 phoneBound/myBook。鉴权失败(token 失效)静默处理,api.js 已清 token。 */ + useDidShow(() => { + const nowAuthed = isAuthed(); + setAuthed(nowAuthed); + if (nowAuthed) { + getMe().then((r) => { + if (r && r.ok && r.user) { + setPhoneBound(!!r.user.phoneBound); + } + }).catch(() => {}); + if (id) { + getMyBookingForEvent(id).then((d) => setMyBook(d || null)).catch(() => {}); + } + } else { + setPhoneBound(false); + setMyBook(null); + } + }); + const gateSend = async () => { if (!/^1\d{10}$/.test(gatePhone)) { setErr('请输入正确的 11 位手机号'); return; } setErr('');