Files
fe_service_ebtp_frontend/src/components/GlobalHeader/RightContent.tsx

157 lines
5.9 KiB
TypeScript
Raw Normal View History

import { Avatar, Dropdown, Menu, message, Modal } from 'antd';
import { DownOutlined, UserOutlined, UserSwitchOutlined, CarryOutOutlined, HomeOutlined, ImportOutlined } from '@ant-design/icons';
2023-02-15 09:38:59 +08:00
import React, { useEffect, useRef } from 'react';
2022-03-10 14:24:13 +08:00
import moment from 'moment'
2025-07-07 16:40:14 +08:00
import { connect, history, KeepAliveContext } from '@umijs/max';
2020-12-23 11:14:35 +08:00
import { ConnectState } from '@/models/connect';
2025-07-04 10:03:42 +08:00
import logo from '@/assets/logo.svg';
2022-03-10 14:24:13 +08:00
import './index.less';
import { getMenu, getLogout } from './services'
2025-07-04 10:03:42 +08:00
import { getSessionUserData, getSessionRoleData } from "@/utils/session";
2023-02-15 09:38:59 +08:00
import { getToSecondUrl } from '@/pages/LoadingPage/service';
2025-06-12 17:19:52 +08:00
import userIcon from '@/assets/user.svg';
import homeIcon from '@/assets/home.svg';
import shutdownIcon from '@/assets/shutdown.svg';
import { logout } from './services';
import cookie from 'react-cookies';
2025-07-04 10:03:42 +08:00
import divider from '@/assets/divider.png';
2025-07-07 16:40:14 +08:00
import useGoHome from '@/utils/useGoHome';
2025-07-04 10:03:42 +08:00
const theme = JSON.parse(PROJECT_THEME);
2020-12-23 11:14:35 +08:00
2022-03-10 14:24:13 +08:00
const GlobalHeaderRight: React.FC<{}> = (props) => {
// let className = styles.right;
2025-06-12 17:19:52 +08:00
const data = getSessionUserData();
2025-07-04 10:03:42 +08:00
const roleData = getSessionRoleData();
2022-03-10 14:24:13 +08:00
const [dataMenu, setDataMenu] = React.useState<any>([]);
2023-02-15 09:38:59 +08:00
const urlRef = useRef(null);
2025-07-07 16:40:14 +08:00
const goHome = useGoHome()
const handelRole = (item: any) => {
2022-03-10 14:24:13 +08:00
sessionStorage.setItem('roleData', JSON.stringify(item));
sessionStorage.setItem('roleAuthority', JSON.stringify([item.roleCode]));
2025-06-12 17:19:52 +08:00
const params = {
roleIdList: [item.roleId]
2022-03-10 14:24:13 +08:00
}
history.push('/Dashboard')
window.location.reload()
2025-06-12 17:19:52 +08:00
// getMenu(params).then(res => {
// if (res?.code == 1) {
// setDataMenu(res?.data)
// } else {
// message.error("数据错误请联系管理员")
// }
// })
2020-12-23 11:14:35 +08:00
}
//角色退出登录
const toLogout = () => {
2023-02-21 11:08:04 +08:00
// let _data = {
// mall3_token: sessionStorage.getItem('Authorization')
// }
Modal.info({
title: '请确认是否退出?',
content: false,
onOk() {
2025-06-12 17:19:52 +08:00
logout().then((res) => {
if (res?.success) {
2025-06-12 17:19:52 +08:00
// if (data?.userType == "0") {//联通智慧门户
// window.close();
// } else if (data?.userType == "1") {//合作方
// window.close();
// } else if (data?.userType == "2") {//专家
// window.location.href = "/userformal/login"
// }
message.success('退出登录成功');
sessionStorage.clear();
cookie.remove('mall3_token');
setTimeout(() => {
2025-07-24 08:46:25 +08:00
history.push('/login');
2025-06-12 17:19:52 +08:00
}, 1000);
}
})
},
closable: true,
centered: true,
okText: "确认退出",
className: "layout-modal-logout",
});
2022-03-10 14:24:13 +08:00
}
const droMenu = (
<Menu style={{ top: "17px" }}>
2022-03-10 14:24:13 +08:00
{data?.authorityList != undefined ?
2025-06-12 17:19:52 +08:00
data?.authorityList?.map((item: any) => (
<Menu.Item key={item.roleId}>
<a target="_blank" rel="noopener noreferrer" onClick={() => handelRole(item)}>{item.roleName}</a>
</Menu.Item>
2022-03-10 14:24:13 +08:00
)) : null}
2025-06-12 17:19:52 +08:00
{/* <>
2022-03-10 14:24:13 +08:00
<Menu.Divider />
<Menu.Item key="exit">
<a key="1" onClick={() => toLogout()}>退</a>
2022-03-10 14:24:13 +08:00
</Menu.Item>
2025-06-12 17:19:52 +08:00
</> */}
2022-03-10 14:24:13 +08:00
</Menu>
);
2020-12-23 11:14:35 +08:00
2023-02-15 09:38:59 +08:00
useEffect(() => {
const getUrl = async () => {
const response = await getToSecondUrl();
if (response?.success) {
urlRef.current = response?.data;
}
}
getUrl();
}, [])
2020-12-23 11:14:35 +08:00
return (
2025-07-04 10:03:42 +08:00
<div className="top-menu" style={{ height: 56 }}>
2022-03-10 14:24:13 +08:00
<div className="left-logo">
2025-06-12 17:19:52 +08:00
<div className="logo-container" style={{ display: 'flex', alignItems: 'center' }}>
<div className="logo-img">
2025-07-04 10:03:42 +08:00
<img src={logo} alt="" style={{ width: '66.89px', height: '42.49px' }}/>
2025-06-12 17:19:52 +08:00
</div>
2025-07-04 10:03:42 +08:00
<div className="logo-text" style={{ display: 'flex', flexDirection: 'column', gap: '0' }}>
<span style={{ fontSize: '24px', lineHeight: '24px', fontWeight: 700, letterSpacing: '2.5px' }}></span>
<span style={{ lineHeight: 'normal', fontSize: '12px', fontWeight: 400 }}>COSCO SHIPPING Group Procurement Information System</span>
</div>
<div style={{ margin: '0 9px' }}>
<img src={divider} alt="" style={{ width: '1px', height: '100%', margin: 0 }}/>
</div>
<div className="logo-text" style={{ display: 'flex', flexDirection: 'column', gap: '0' }}>
<span style={{ fontSize: '24px', lineHeight: '24px', fontWeight: 700, letterSpacing: '2.5px' }}>{roleData?.roleName}</span>
<span style={{ lineHeight: 'normal', fontSize: '12px', fontWeight: 400 }}>{roleData?.roleCode}</span>
2025-06-12 17:19:52 +08:00
</div>
</div>
2022-03-10 14:24:13 +08:00
</div>
<ul className="right-btns">
2025-06-12 17:19:52 +08:00
{/* <li><ImportOutlined /><a onClick={() => { urlRef.current && window.open(urlRef.current); }}>交易平台2.0</a></li> */}
2022-03-10 14:24:13 +08:00
<li>
2025-06-12 17:19:52 +08:00
<Avatar size="small" src={userIcon} style={{ width: '30px' }} />
2022-03-10 14:24:13 +08:00
<Dropdown overlay={droMenu}>
2025-07-04 10:03:42 +08:00
<a className="antd-dropdown-link" style={{ color: theme['text-color'], verticalAlign: '-2px' }}>
{data?.fullName} <DownOutlined />
2022-03-10 14:24:13 +08:00
</a>
</Dropdown>
</li>
2025-06-12 17:19:52 +08:00
<li>
2025-07-07 16:40:14 +08:00
<img src={homeIcon} style={{width: 13, cursor: 'pointer'}} alt="dashboard" onClick={() => {
goHome()
}} />
2025-06-12 17:19:52 +08:00
</li>
2025-07-04 10:03:42 +08:00
<li style={{ paddingRight: 16 }}>
<img src={shutdownIcon} style={{width: 14, cursor: 'pointer' }} alt="shutdown" onClick={() => toLogout()}/>
2025-06-12 17:19:52 +08:00
</li>
{/* <li><CarryOutOutlined />{moment().format("YYYY-MM-DD")}</li> */}
{/* {data?.organizationName == null ? null : (<li><UserSwitchOutlined />{data?.organizationName}</li>)} */}
2022-03-10 14:24:13 +08:00
</ul>
2020-12-23 11:14:35 +08:00
</div>
);
};
export default connect(({ settings }: ConnectState) => ({
theme: settings.navTheme,
layout: settings.layout,
}))(GlobalHeaderRight);