diff --git a/src/components/Header/HeaderUserInfo.tsx b/src/components/Header/HeaderUserInfo.tsx index cbd8145..a3de38e 100644 --- a/src/components/Header/HeaderUserInfo.tsx +++ b/src/components/Header/HeaderUserInfo.tsx @@ -1,12 +1,33 @@ import { DownOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons'; -import { Avatar, Button, Dropdown, Popconfirm, Space } from 'antd'; +import { App, Avatar, Button, Dropdown, Popconfirm, Space } from 'antd'; import { navigate } from '@/router/routerUtils'; +import { AdminServices } from '@/services/AdminServices'; import { useUserStore } from '@/store/UserStore'; import { imgWithPrefix } from '@/utils/common'; +import { useRequest } from '@/utils/useRequest'; import { GapBox } from '../GapBox'; export const HeaderUserInfo: React.FC = () => { - const userInfo = useUserStore().user; + const user = useUserStore(); + const userInfo = user.user; + const { notification } = App.useApp(); + + const { request: logoutRequest } = useRequest(AdminServices.logout, { + onSuccess: (res) => { + if (res.err_code == 0) { + notification.success({ title: '退出登录成功' }); + user.updateUser({}); + // updateCompany({erp_name: DefaultERPName}) + // const hash = window.location.hash; + // const end = hash.indexOf('?') > 1 ? hash.indexOf('?') : hash.length; + // const pathname = hash.substring(1, end); + // if (!pathname.includes('/login')) { + // localStorage.setItem(`u${user.user.user_id}_c${company.company_id}_lastRouter`, pathname); + // } + navigate('/login'); + } + }, + }); return ( @@ -34,7 +55,7 @@ export const HeaderUserInfo: React.FC = () => { size={40} src={`${imgWithPrefix(userInfo.avatar)}?v=${encodeURIComponent(userInfo.update_date)}`} icon={} - style={{ marginBottom: 4 }} // 👈 控制头像和名字的间距 + style={{ marginBottom: 4 }} // 控制头像和名字的间距 /> { { - location.hash = '#/login'; + new Promise((resolve, reject) => { + logoutRequest().then((res) => { + if (res?.err_code == 0) { + resolve(); + } else { + reject(); + } + }); + }).catch(() => {}); + // location.hash = '#/login'; }} >