feat(mine): 个人中心改为展示登录返回的真实用户信息,移除 mock 数据源

This commit is contained in:
ozh 2026-09-16 17:13:58 +08:00
parent 86234d4f1f
commit b1a9bef903
3 changed files with 16 additions and 43 deletions

View File

@ -1,24 +0,0 @@
import { request } from '@/http'
const USE_MOCK = true
export interface UserInfo {
id: string
name: string
avatar: string
mobile: string
loginType: 'mobile' | 'wechat'
}
export function getUserInfo(): Promise<UserInfo> {
if (USE_MOCK) {
return Promise.resolve({
id: 'u-001',
name: '张大爷',
avatar: '',
mobile: '',
loginType: 'mobile'
})
}
return request.get<UserInfo>('/user/info')
}

View File

@ -10,7 +10,7 @@
align-items: center; align-items: center;
} }
// 白底绿字头像:与渐变头形成对比 // 白底绿字头像:与渐变头形成对比(有微信头像时直接展示图片,复用同尺寸)
.avatar { .avatar {
width: 132px; width: 132px;
height: 132px; height: 132px;
@ -20,6 +20,7 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
margin-right: 32px; margin-right: 32px;
overflow: hidden;
} }
.avatarText { .avatarText {

View File

@ -1,24 +1,18 @@
import { useEffect, useState } from 'react' import { useDispatch } from 'react-redux'
import { View, Text } from '@tarojs/components' import { View, Text, Image } from '@tarojs/components'
import { useAppDispatch } from '@/store/hooks'
import { clearAuth } from '@/store/authSlice' import { clearAuth } from '@/store/authSlice'
import { Navbar } from '@/components/navbar' import { Navbar } from '@/components/navbar'
import { ListRow, ListRowGroup } from '@/components/list-row' import { ListRow, ListRowGroup } from '@/components/list-row'
import { getUserInfo, type UserInfo } from '@/api/user' import { useAppSelector } from '@/store/hooks'
import { useToast } from '@/hooks/useToast' import { useToast } from '@/hooks/useToast'
import { reLaunch, navigateTo } from '@/utils/navigation' import { reLaunch, navigateTo } from '@/utils/navigation'
import { ROUTES } from '@/constants/routes' import { ROUTES } from '@/constants/routes'
import styles from './index.module.scss' import styles from './index.module.scss'
export default function Mine() { export default function Mine() {
const dispatch = useAppDispatch() const dispatch = useDispatch()
const toast = useToast() const toast = useToast()
const [user, setUser] = useState<UserInfo | null>(null) const user = useAppSelector((s) => s.auth.userInfo)
useEffect(() => {
getUserInfo().then(setUser).catch(() => toast.error('加载用户失败'))
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
const logout = () => { const logout = () => {
dispatch(clearAuth()) dispatch(clearAuth())
@ -30,14 +24,16 @@ export default function Mine() {
<View className={styles.page}> <View className={styles.page}>
<Navbar title="个人中心" autoBack={false} variant="hero" /> <Navbar title="个人中心" autoBack={false} variant="hero" />
<View className={styles.header}> <View className={styles.header}>
<View className={styles.avatar}> {user?.avatar ? (
<Text className={styles.avatarText}>{user?.name?.[0] ?? '?'}</Text> <Image className={styles.avatar} src={user.avatar} mode="aspectFill" />
</View> ) : (
<View className={styles.avatar}>
<Text className={styles.avatarText}>{user?.nickName?.[0] ?? '?'}</Text>
</View>
)}
<View className={styles.headerInfo}> <View className={styles.headerInfo}>
<Text className={styles.name}>{user?.name ?? '加载中...'}</Text> <Text className={styles.name}>{user?.nickName ?? '未登录'}</Text>
<Text className={styles.uid}> <Text className={styles.uid}>微信登录</Text>
{user?.loginType === 'mobile' ? '手机号验证码登录' : '微信登录'}
</Text>
</View> </View>
</View> </View>