feat(auth): 添加统一认证工具和优化登录流程

- 新增 auth 工具模块,包含 isLoggedIn、goToRegister、ensureLoggedIn 方法
- 将硬编码的服务器URL更新为 glt-server 域名
- 重构多个页面的登录检查逻辑,使用统一的认证工具
- 在用户注册/登录流程中集成邀请关系处理
- 更新注册页面配置和实现,支持跳转参数传递
- 优化分销商二维码页面的加载状态和错误处理
- 在水票使用页面添加无票时的购买引导
- 统一文件上传和API请求的服务器地址
- 添加加密库类型定义文件
This commit is contained in:
2026-02-13 21:30:58 +08:00
parent 52ef8d4199
commit e22cfe4646
23 changed files with 712 additions and 154 deletions

View File

@@ -14,6 +14,7 @@ import {ArrowLeft, Del} from '@nutui/icons-react-taro';
import {View} from '@tarojs/components';
import {CartItem, useCart} from "@/hooks/useCart";
import './cart.scss';
import { ensureLoggedIn } from '@/utils/auth'
function Cart() {
const [statusBarHeight, setStatusBarHeight] = useState<number>(0);
@@ -150,6 +151,9 @@ function Cart() {
// 将选中的商品信息存储到本地,供结算页面使用
Taro.setStorageSync('checkout_items', JSON.stringify(selectedCartItems));
// 未登录则引导去注册/登录;登录后回到购物车结算页
if (!ensureLoggedIn('/shop/orderConfirmCart/index')) return
// 跳转到购物车结算页面
Taro.navigateTo({
url: '/shop/orderConfirmCart/index'

View File

@@ -9,6 +9,7 @@ import { checkAndHandleInviteRelation, hasPendingInvite } from '@/utils/invite'
import { pageShopGoods } from '@/api/shop/shopGoods'
import type { ShopGoods, ShopGoodsParam } from '@/api/shop/shopGoods/model'
import { getMyGltUserTicketTotal } from '@/api/glt/gltUserTicket'
import { ensureLoggedIn } from '@/utils/auth'
import './index.scss'
function Home() {
@@ -201,19 +202,28 @@ function Home() {
key: 'ticket',
title: '我的水票',
icon: <Ticket size={30} />,
onClick: () => Taro.navigateTo({ url: '/user/ticket/index' }),
onClick: () => {
if (!ensureLoggedIn('/user/ticket/index')) return
Taro.navigateTo({ url: '/user/ticket/index' })
},
},
{
key: 'order',
title: '立即送水',
icon: <Cart size={30} />,
onClick: () => Taro.navigateTo({ url: '/user/ticket/use?goodsId=10074' }),
onClick: () => {
if (!ensureLoggedIn('/user/ticket/use?goodsId=10074')) return
Taro.navigateTo({ url: '/user/ticket/use?goodsId=10074' })
},
},
{
key: 'invite',
title: '邀请有礼',
icon: <Gift size={30} />,
onClick: () => Taro.navigateTo({ url: '/dealer/qrcode/index' }),
onClick: () => {
if (!ensureLoggedIn('/dealer/qrcode/index')) return
Taro.navigateTo({ url: '/dealer/qrcode/index' })
},
},
// {
// key: 'coupon',
@@ -313,7 +323,10 @@ function Home() {
<View className="goods-card__actions">
<View
className="goods-card__btn goods-card__btn--ghost"
onClick={() => Taro.navigateTo({ url: '/shop/orderConfirm/index?goodsId=10074' })}
onClick={() => {
if (!ensureLoggedIn('/shop/orderConfirm/index?goodsId=10074')) return
Taro.navigateTo({ url: '/shop/orderConfirm/index?goodsId=10074' })
}}
>
<Text className="goods-card__btnText"></Text>
</View>

View File

@@ -8,7 +8,7 @@ import navTo from "@/utils/common";
import {TenantId} from "@/config/app";
import {useUser} from "@/hooks/useUser";
import {useUserData} from "@/hooks/useUserData";
import {getStoredInviteParams} from "@/utils/invite";
import {checkAndHandleInviteRelation, getStoredInviteParams, hasPendingInvite} from "@/utils/invite";
import UnifiedQRButton from "@/components/UnifiedQRButton";
import {useThemeStyles} from "@/hooks/useTheme";
import {getRootDomain} from "@/utils/domain";
@@ -206,6 +206,13 @@ const UserCard = forwardRef<any, any>((_, ref) => {
// 登录态已就绪后刷新卡片统计(余额/积分/券/水票)
refresh().then()
reloadTicketTotal()
// 登录成功后(可能是新注册用户),检查是否存在待处理的邀请关系并尝试绑定
if (hasPendingInvite()) {
checkAndHandleInviteRelation().catch((e) => {
console.error('个人中心登录后处理邀请关系失败:', e)
})
}
}
})
} else {