diff --git a/src/api/user.ts b/src/api/user.ts deleted file mode 100644 index 8018d2a..0000000 --- a/src/api/user.ts +++ /dev/null @@ -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 { - if (USE_MOCK) { - return Promise.resolve({ - id: 'u-001', - name: '张大爷', - avatar: '', - mobile: '', - loginType: 'mobile' - }) - } - return request.get('/user/info') -} diff --git a/src/pages/mine/index.module.scss b/src/pages/mine/index.module.scss index d2d1322..92f3599 100644 --- a/src/pages/mine/index.module.scss +++ b/src/pages/mine/index.module.scss @@ -10,7 +10,7 @@ align-items: center; } -// 白底绿字头像:与渐变头形成对比 +// 白底绿字头像:与渐变头形成对比(有微信头像时直接展示图片,复用同尺寸) .avatar { width: 132px; height: 132px; @@ -20,6 +20,7 @@ align-items: center; justify-content: center; margin-right: 32px; + overflow: hidden; } .avatarText { diff --git a/src/pages/mine/index.tsx b/src/pages/mine/index.tsx index 5376c08..47ee92c 100644 --- a/src/pages/mine/index.tsx +++ b/src/pages/mine/index.tsx @@ -1,24 +1,18 @@ -import { useEffect, useState } from 'react' -import { View, Text } from '@tarojs/components' -import { useAppDispatch } from '@/store/hooks' +import { useDispatch } from 'react-redux' +import { View, Text, Image } from '@tarojs/components' import { clearAuth } from '@/store/authSlice' import { Navbar } from '@/components/navbar' 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 { reLaunch, navigateTo } from '@/utils/navigation' import { ROUTES } from '@/constants/routes' import styles from './index.module.scss' export default function Mine() { - const dispatch = useAppDispatch() + const dispatch = useDispatch() const toast = useToast() - const [user, setUser] = useState(null) - - useEffect(() => { - getUserInfo().then(setUser).catch(() => toast.error('加载用户失败')) - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []) + const user = useAppSelector((s) => s.auth.userInfo) const logout = () => { dispatch(clearAuth()) @@ -30,14 +24,16 @@ export default function Mine() { - - {user?.name?.[0] ?? '?'} - + {user?.avatar ? ( + + ) : ( + + {user?.nickName?.[0] ?? '?'} + + )} - {user?.name ?? '加载中...'} - - {user?.loginType === 'mobile' ? '手机号验证码登录' : '微信登录'} - + {user?.nickName ?? '未登录'} + 微信登录