```
feat(registration): 优化经销商注册流程并增加地址定位功能 - 修改导航栏标题从“邀请注册”为“注册成为会员” - 修复重复提交问题并移除不必要的submitting状态 - 增加昵称和头像的必填验证提示 - 添加用户角色缺失时的默认角色写入机制 - 集成地图选点功能,支持经纬度获取和地址解析 - 实现微信地址导入功能,自动填充基本信息 - 增加定位权限检查和错误处理机制 - 添加.gitignore规则忽略备份文件夹src__bak - 移除已废弃的银行卡和客户管理页面代码 - 优化表单验证规则和错误提示信息 - 实现经销商注册成功后自动跳转到“我的”页面 - 添加用户信息缓存刷新机制确保角色信息同步 ```
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import {pageShopUserCoupon} from "@/api/shop/shopUserCoupon";
|
||||
import {pageShopGift} from "@/api/shop/shopGift";
|
||||
import Taro from '@tarojs/taro'
|
||||
import {getUserInfo} from "@/api/layout";
|
||||
import {useUser} from "@/hooks/useUser";
|
||||
import Taro from '@tarojs/taro'
|
||||
import { getUserCardStats } from '@/api/user'
|
||||
|
||||
interface UserData {
|
||||
balance: number
|
||||
balance: string
|
||||
points: number
|
||||
coupons: number
|
||||
giftCards: number
|
||||
@@ -24,7 +22,7 @@ interface UseUserDataReturn {
|
||||
loading: boolean
|
||||
error: string | null
|
||||
refresh: () => Promise<void>
|
||||
updateBalance: (newBalance: number) => void
|
||||
updateBalance: (newBalance: string) => void
|
||||
updatePoints: (newPoints: number) => void
|
||||
}
|
||||
|
||||
@@ -35,30 +33,22 @@ export const useUserData = (): UseUserDataReturn => {
|
||||
|
||||
// 获取用户数据
|
||||
const fetchUserData = useCallback(async () => {
|
||||
// 检查用户ID是否存在(更直接的登录状态检查)
|
||||
const userId = Taro.getStorageSync('UserId')
|
||||
if (!userId) {
|
||||
setLoading(false)
|
||||
setData(null)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
|
||||
// 并发请求所有数据
|
||||
const [userDataRes, couponsRes, giftCardsRes] = await Promise.all([
|
||||
getUserInfo(),
|
||||
pageShopUserCoupon({ page: 1, limit: 1, userId, status: 0}),
|
||||
pageShopGift({ page: 1, limit: 1, userId, status: 0})
|
||||
])
|
||||
if(!Taro.getStorageSync('UserId')){
|
||||
return;
|
||||
}
|
||||
|
||||
// 聚合接口:一次请求返回余额/积分/优惠券/礼品卡统计(后端可按用户做缓存)
|
||||
const stats = await getUserCardStats()
|
||||
|
||||
const newData: UserData = {
|
||||
balance: userDataRes?.balance || 0.00,
|
||||
points: userDataRes?.points || 0,
|
||||
coupons: couponsRes?.count || 0,
|
||||
giftCards: giftCardsRes?.count || 0,
|
||||
balance: stats?.balance || '0.00',
|
||||
points: stats?.points || 0,
|
||||
coupons: stats?.coupons || 0,
|
||||
giftCards: stats?.giftCards || 0,
|
||||
orders: {
|
||||
pending: 0,
|
||||
paid: 0,
|
||||
@@ -82,7 +72,7 @@ export const useUserData = (): UseUserDataReturn => {
|
||||
}, [fetchUserData])
|
||||
|
||||
// 更新余额(本地更新,避免频繁请求)
|
||||
const updateBalance = useCallback((newBalance: number) => {
|
||||
const updateBalance = useCallback((newBalance: string) => {
|
||||
setData(prev => prev ? { ...prev, balance: newBalance } : null)
|
||||
}, [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user