From ab61aa9ee09b191138a5cd4c15e019553b0a31bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Sat, 28 Feb 2026 20:28:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(user):=20=E4=BF=AE=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=A1=B5=E9=9D=A2=E7=BB=84=E4=BB=B6=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=92=8C=E6=B0=B4=E7=A5=A8=E4=BD=99=E9=A2=9D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在订单确认页面添加水票模板购买数量限制逻辑 - 为用户页面添加dealerViewKey状态确保子组件正确刷新 - 交换用户卡片中水票和余额的位置显示正确数据 - 移除自动跳转邀请注册页面逻辑改用显式跳转 - 添加预期失败场景的日志过滤避免不必要的错误输出 --- src/hooks/useUser.ts | 21 ++++++++++----------- src/pages/user/components/UserCard.tsx | 20 ++++++++++---------- src/pages/user/user.tsx | 8 ++++++-- src/shop/orderConfirm/index.tsx | 25 ++++++++++++++----------- 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/hooks/useUser.ts b/src/hooks/useUser.ts index 4ad2069..df5c040 100644 --- a/src/hooks/useUser.ts +++ b/src/hooks/useUser.ts @@ -3,7 +3,7 @@ import Taro from '@tarojs/taro'; import { User } from '@/api/system/user/model'; import { getUserInfo, updateUserInfo, loginByOpenId } from '@/api/layout'; import { TenantId } from '@/config/app'; -import {getStoredInviteParams, handleInviteRelation} from '@/utils/invite'; +import { handleInviteRelation } from '@/utils/invite'; // 用户Hook export const useUser = () => { @@ -44,15 +44,10 @@ export const useUser = () => { reject(new Error('自动登录失败')); } }).catch(_ => { - // 首次注册,跳转到邀请注册页面 - const pages = Taro.getCurrentPages(); - const currentPage = pages[pages.length - 1]; - const inviteParams = getStoredInviteParams() - if (currentPage?.route !== 'dealer/apply/add' && inviteParams?.inviter) { - return Taro.navigateTo({ - url: '/dealer/apply/add' - }); - } + // 登录失败(通常是新用户尚未注册/未绑定手机号等)。 + // 这里不做任何“自动跳转”,避免用户点击「我的」时被强制带到分销/申请页,体验割裂。 + // 需要登录的页面请使用 utils/auth 的 ensureLoggedIn / goToRegister 做显式跳转。 + reject(new Error('autoLoginByOpenId failed')); }); }, fail: reject @@ -60,7 +55,11 @@ export const useUser = () => { }); return res; } catch (error) { - console.error('自动登录失败:', error); + const msg = error instanceof Error ? error.message : String(error); + // 新用户首次进入、未绑定手机号等场景属于“预期失败”,避免刷屏报错。 + if (msg !== 'autoLoginByOpenId failed') { + console.error('自动登录失败:', error); + } return null; } }; diff --git a/src/pages/user/components/UserCard.tsx b/src/pages/user/components/UserCard.tsx index 7ec508d..93c76b4 100644 --- a/src/pages/user/components/UserCard.tsx +++ b/src/pages/user/components/UserCard.tsx @@ -335,13 +335,9 @@ const UserCard = forwardRef((_, ref) => { navTo('/user/wallet/wallet', true)}> - 余额 - {data?.balance || '0.00'} - - - 积分 - {data?.points || 0} + onClick={() => navTo('/user/ticket/index', true)}> + 水票 + {ticketTotal} navTo('/user/coupon/index', true)}> @@ -349,9 +345,13 @@ const UserCard = forwardRef((_, ref) => { {data?.coupons || 0} navTo('/user/ticket/index', true)}> - 水票 - {ticketTotal} + onClick={() => navTo('/user/wallet/wallet', true)}> + 余额 + {data?.balance || '0.00'} + + + 积分 + {data?.points || 0} diff --git a/src/pages/user/user.tsx b/src/pages/user/user.tsx index f97724c..d9ff840 100644 --- a/src/pages/user/user.tsx +++ b/src/pages/user/user.tsx @@ -1,4 +1,4 @@ -import {useEffect, useRef} from 'react' +import {useEffect, useRef, useState} from 'react' import {PullToRefresh} from '@nutui/nutui-react-taro' import UserCard from "./components/UserCard"; import UserOrder from "./components/UserOrder"; @@ -14,12 +14,15 @@ function User() { const userCardRef = useRef() const themeStyles = useThemeStyles(); + // TabBar 页在小程序里通常不会销毁;从“注册/申请”页返回时需要触发子组件重新初始化/拉取最新状态。 + const [dealerViewKey, setDealerViewKey] = useState(0) // 下拉刷新处理 const handleRefresh = async () => { if (userCardRef.current?.handleRefresh) { await userCardRef.current.handleRefresh() } + setDealerViewKey(v => v + 1) } useEffect(() => { @@ -30,6 +33,7 @@ function User() { userCardRef.current?.reloadStats?.() // 个人资料(头像/昵称)可能在其它页面被修改,这里确保返回时立刻刷新 userCardRef.current?.reloadUserInfo?.() + setDealerViewKey(v => v + 1) }) return ( @@ -58,7 +62,7 @@ function User() { - + diff --git a/src/shop/orderConfirm/index.tsx b/src/shop/orderConfirm/index.tsx index d9360fb..7eee474 100644 --- a/src/shop/orderConfirm/index.tsx +++ b/src/shop/orderConfirm/index.tsx @@ -853,17 +853,20 @@ const OrderConfirm = () => { ¥{goods.price} - - - + + + {goods.stock !== undefined && ( 库存 {goods.stock} 件