微信授权逻辑修改
This commit is contained in:
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import TabMainHeader from '../components/TabMainHeader';
|
||||
import AppImage from '@dukang/shared-ui/AppImage';
|
||||
import { request } from '../lib/api';
|
||||
import { request, type UserProfile } from '../lib/api';
|
||||
import { useUserSession } from '../contexts/UserSessionContext';
|
||||
import ContactCustomerSheet from '../components/ContactCustomerSheet';
|
||||
|
||||
@@ -29,10 +29,8 @@ function formatMoney(amount: number) {
|
||||
|
||||
export default function MinePage() {
|
||||
const navigate = useNavigate();
|
||||
const { profile: sessionProfile, resetSession } = useUserSession();
|
||||
const [profile, setProfile] = useState<Record<string, unknown> | null>(
|
||||
sessionProfile as Record<string, unknown> | null,
|
||||
);
|
||||
const { profile: sessionProfile, refreshProfile, resetSession } = useUserSession();
|
||||
const [profile, setProfile] = useState<UserProfile | null>(sessionProfile);
|
||||
const [benefitBalance, setBenefitBalance] = useState(0);
|
||||
const [orderCounts, setOrderCounts] = useState<Record<string, number>>({});
|
||||
const [toast, setToast] = useState('');
|
||||
@@ -40,7 +38,7 @@ export default function MinePage() {
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([
|
||||
request<Record<string, unknown>>('USER_H5', '/auth/me'),
|
||||
request<UserProfile>('USER_H5', '/auth/me'),
|
||||
request<Array<Record<string, unknown>>>('USER_H5', '/benefit/coupons'),
|
||||
...ORDER_SHORTCUTS.map((s) =>
|
||||
request<{ total: number }>('USER_H5', `/trade/orders?tab=${s.tab}&pageSize=1`),
|
||||
@@ -48,6 +46,7 @@ export default function MinePage() {
|
||||
])
|
||||
.then(([me, coupons, ...totals]) => {
|
||||
setProfile(me);
|
||||
void refreshProfile();
|
||||
const balance = coupons.reduce((sum, c) => {
|
||||
if (String(c.status) === 'ACTIVE') return sum + Number(c.balance || 0);
|
||||
return sum;
|
||||
@@ -60,7 +59,7 @@ export default function MinePage() {
|
||||
setOrderCounts(counts);
|
||||
})
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
}, [refreshProfile]);
|
||||
|
||||
function showToast(msg: string) {
|
||||
setToast(msg);
|
||||
@@ -77,9 +76,10 @@ export default function MinePage() {
|
||||
void resetSession().then(() => navigate('/'));
|
||||
}
|
||||
|
||||
const nickname = String(profile?.nickname || '用户');
|
||||
const userNo = String(profile?.userNo || '');
|
||||
const avatar = String(profile?.avatarUrl || DEFAULT_AVATAR);
|
||||
const nickname = profile?.nickname || '用户';
|
||||
const userNo = profile?.userNo || '';
|
||||
const avatar = profile?.avatarUrl || DEFAULT_AVATAR;
|
||||
const hasWechat = !!profile?.hasWechat;
|
||||
|
||||
return (
|
||||
<div className="mine-page">
|
||||
@@ -89,12 +89,17 @@ export default function MinePage() {
|
||||
<div className="mine-profile">
|
||||
<div className="mine-avatar-wrap">
|
||||
<AppImage src={avatar} alt="" wrapperClassName="mine-avatar app-image--fill" />
|
||||
{hasWechat && (
|
||||
<span className="mine-wechat-badge" title="已绑定微信">
|
||||
<span className="material-symbols-outlined">chat</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="mine-profile-info">
|
||||
<h1 className="mine-profile-name">{nickname}</h1>
|
||||
<div className="mine-profile-meta">
|
||||
{userNo && <span className="mine-profile-id">ID: {userNo}</span>}
|
||||
<span className="mine-member-tag">好客会员</span>
|
||||
<span className="mine-member-tag">{hasWechat ? '微信会员' : '好客会员'}</span>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user