feat: add user profile & logout...

This commit is contained in:
chenos 2020-12-07 17:23:05 +08:00
parent fb7706094b
commit efc51355dd

View File

@ -1,10 +1,26 @@
import React from 'react';
import { Layout, Menu } from 'antd';
import { Link } from 'umi';
import { Layout, Menu, Dropdown, Avatar } from 'antd';
import './style.less';
import { history, Link, request, useModel } from 'umi';
import { UserOutlined } from '@ant-design/icons';
const overlay = (
<Menu>
<Menu.Item disabled></Menu.Item>
<Menu.Divider></Menu.Divider>
<Menu.Item onClick={async () => {
await request('/users:logout');
localStorage.removeItem('NOCOBASE_TOKEN');
(window as any).routesReload();
history.push('/login');;
// window.location.href = '/login';
}}>退</Menu.Item>
</Menu>
);
export function TopMenuLayout(props: any) {
const { menu = [] } = props.page;
const { initialState = {}, loading, error, refresh, setInitialState } = useModel('@@initialState');
return (
<Layout style={{ height: '100vh' }}>
<Layout.Header style={{height: 48, lineHeight: '48px', padding: 0}} className="nb-header">
@ -16,6 +32,13 @@ export function TopMenuLayout(props: any) {
</Menu.Item>
))}
</Menu>
<div className={'noco-user'} style={{position: 'absolute', right: 24, color: 'rgba(255, 255, 255, 0.65)'}}>
<Dropdown overlay={overlay} placement="bottomRight">
<span className="nbui-dropdown-link" onClick={e => e.preventDefault()}>
<Avatar size={'small'} icon={<UserOutlined/>} style={{marginRight: 5}}/> {initialState.currentUser.nickname}
</span>
</Dropdown>
</div>
</Layout.Header>
<Layout.Content>
{props.children}