-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛[BUG]antd pro v5退出登录按钮,按了没有反应。 #8598
Comments
以下的 Issues 可能会帮助到你 / The following issues may help you
|
问题已解决。 |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🐛 bug 描述
用户登出,点退出登录没有反应,用console.log测试,点了按钮后,并没有进入到onMenuClick方法里,实在找不到问题所在了,请帮忙看下,谢谢。
📷 复现步骤
🏞 期望结果
💻 复现代码
import React, { useCallback } from 'react';
import { LogoutOutlined } from '@ant-design/icons';
import { Avatar, Menu, Spin } from 'antd';
import { history, useModel } from 'umi';
import { stringify } from 'querystring';
import HeaderDropdown from '../HeaderDropdown';
import styles from './index.less';
// import { outLogin } from '@/services/ant-design-pro/api';
export type GlobalHeaderRightProps = {
menu?: boolean;
};
/**
*/
const loginOut = async () => {
// await outLogin();
const { query = {}, pathname } = history.location;
const { redirect } = query;
localStorage.removeItem('user');
localStorage.removeItem('token');
// Note: There may be security issues, please note
if (window.location.pathname !== '/login' && !redirect) {
history.replace({
pathname: '/login',
search: stringify({
redirect: pathname,
}),
});
}
};
const AvatarDropdown: React.FC = () => {
const { initialState, setInitialState } = useModel('@@initialstate');
const onMenuClick = useCallback(
(event: {
key: React.Key;
keyPath: React.Key[];
item: React.ReactInstance;
domEvent: React.MouseEvent;
}) => {
const { key } = event;
if (key === 'logout' && initialState) {
setInitialState({ ...initialState, currentUser: undefined });
loginOut();
return;
}
);
const loading = (
<span className={
${styles.action} ${styles.account}
}><Spin
size="small"
style={{
marginLeft: 8,
marginRight: 8,
}}
/>
);
if (!initialState) {
return loading;
}
const { currentUser } = initialState;
if (!currentUser || !currentUser.user_name) {
return loading;
}
const menuHeaderDropdown = (
<Menu className={styles.menu} selectedKeys={[]} onClick={() => onMenuClick}>
{/* {menu && (
<Menu.Item key="center">
个人中心
</Menu.Item>
)}
{menu && (
<Menu.Item key="settings">
个人设置
</Menu.Item>
)}
{menu && <Menu.Divider />} */}
);
return (
<span className={
${styles.action} ${styles.account}
}><span className={
${styles.name} anticon
}>{currentUser.user_name});
};
export default AvatarDropdown;
© 版本信息
🚑 其他信息
The text was updated successfully, but these errors were encountered: