Skip to content

Commit

Permalink
pref(user): 添加获取用户信息 (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
am6737 authored Jun 3, 2024
1 parent 82f62d6 commit 59faa35
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
26 changes: 24 additions & 2 deletions src/components/layout/layout-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { $t } from '@/i18n'
import { generateUserInfo } from '@/mock/data'
import { SettingOutlined, UserOutlined, UsergroupAddOutlined } from '@ant-design/icons'
import { Avatar, Drawer, DrawerProps, Flex, Divider, Typography, Switch, Button } from 'antd'
import { useMemo, useState } from 'react'
import { useEffect, useMemo, useState } from 'react'
import CustomIcon from '@/components/icon'
import Modal from '@/components/modal'
import { LightIcon, DarkIcon } from '@/components/icon/icon'
Expand All @@ -17,6 +17,7 @@ import useMobile from '@/hooks/useMobile'
import useUserStore from '@/stores/user'
import { useNavigate } from 'react-router'
import { createFingerprint } from '@/utils/fingerprint'
import { getUserInfoApi } from '@/api/user'

interface Menus {
icon: React.ForwardRefExoticComponent<any>
Expand All @@ -28,7 +29,7 @@ interface LayoutDrawerProps extends DrawerProps {
setOpen?: React.Dispatch<React.SetStateAction<boolean>>
}

const userInfo = generateUserInfo()
const mockUserInfo = generateUserInfo()

const drawerStyles: DrawerStyles = {
body: {
Expand All @@ -44,6 +45,27 @@ const LayoutDrawer: React.FC<Partial<LayoutDrawerProps>> = (props) => {
const commonStore = useCommonStore()
const { width } = useMobile()

useEffect(() => {
if (userStore.userId) {
getUserInfoApi({ id: userStore.userId })
.then((res) => {
console.log('获取用户信息成功: ', res)
userStore.update({
userInfo: res.data
})
})
.catch((error) => {
console.log('获取用户信息失败: ', error)
})
}
}, [userStore.userId])

const userInfo = {
avatar: userStore.userInfo?.avatar || mockUserInfo.avatar,
nickname: userStore.userInfo?.nickname || mockUserInfo.nickname,
email: userStore.userInfo?.email || mockUserInfo.email
}

const isLight = useMemo(() => commonStore.theme === THEME.LIGHT, [commonStore.theme])

const menus = useMemo<Menus[]>(
Expand Down
8 changes: 5 additions & 3 deletions src/pages/account/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ const Login: React.FC = () => {
})
return
}
navigate('/dashboard', {
replace: true
})
// 暂时注释
// 跳转在 src/hooks/useLogin.ts 做处理了
// navigate('/dashboard', {
// replace: true
// })
} catch (error: any) {
messageApi.open({
type: 'error',
Expand Down

0 comments on commit 59faa35

Please sign in to comment.