From 5c43f6d742f86ecbbea3e2a5cfbc7c16cd785ff2 Mon Sep 17 00:00:00 2001 From: Pine Date: Wed, 9 Sep 2026 22:59:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B4=BB=E5=8A=A8=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E5=A2=9E=E5=8A=A0useDidShow=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=80=81=E4=B8=8E=E6=89=8B=E6=9C=BA=E5=8F=B7?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E7=8A=B6=E6=80=81=EF=BC=8C=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83=E7=99=BB=E5=BD=95=E5=90=8E?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E9=A1=B5=E8=AF=86=E5=88=AB=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages-extra/event-detail/index.jsx | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) 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('');