Skip to content
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

Closed
noahge opened this issue Jun 11, 2021 · 2 comments
Closed

🐛[BUG]antd pro v5退出登录按钮,按了没有反应。 #8598

noahge opened this issue Jun 11, 2021 · 2 comments

Comments

@noahge
Copy link

noahge commented Jun 11, 2021

🐛 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;
};

/**

  • 退出登录,并且将当前的 url 保存
    */
    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;
}

  history.push(`/account/${key}`);
},
[initialState, setInitialState],

);

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 />} */}

  <Menu.Item key="logout">
    <LogoutOutlined />
    退出登录
  </Menu.Item>
</Menu>

);
return (

<span className={${styles.action} ${styles.account}}>

<span className={${styles.name} anticon}>{currentUser.user_name}


);
};

export default AvatarDropdown;

© 版本信息

  • Ant Design Pro 版本: [e.g. 4.0.0]
  • umi 版本
  • 浏览器环境
  • 开发环境 [e.g. mac OS]

🚑 其他信息

@github-actions
Copy link

以下的 Issues 可能会帮助到你 / The following issues may help you

@noahge
Copy link
Author

noahge commented Jun 11, 2021

问题已解决。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant