system-copyright-react/src/layout/head/Head.tsx

212 lines
8.3 KiB
TypeScript
Raw Normal View History

2024-03-11 19:13:42 +08:00
import './head.css'
2024-03-11 23:33:03 +08:00
import BalanceHead from '../../components/balance/BalanceHead.tsx';
import RechargeHead from '../../components/recharge/RechargeHead.tsx';
2024-04-29 17:22:26 +08:00
import { Dropdown, MenuProps, message, Modal, Space, Spin } from "antd";
import { DownOutlined, UserOutlined, KeyOutlined, LogoutOutlined, AccountBookOutlined } from "@ant-design/icons";
import { useContext, useEffect, useState } from "react";
import { put } from "../../util/AjaxUtils.ts";
import { GlobalContext, GlobalDispatchContext, reloadUser } from "../../context/GlobalContext.ts";
2024-04-02 18:45:46 +08:00
import UserEdit from "../../components/user/UserEdit.tsx";
import PasswordChange from "../../components/password/PasswordChange.tsx";
2024-04-29 17:22:26 +08:00
// import headRightBg from '../../assets/head-right-bg.png';
2024-04-02 18:45:46 +08:00
import InvoiceList from "../../components/invoice/InvoiceList.tsx";
2024-04-29 17:22:26 +08:00
import logoImg from '../../static/head/logo.png'
2024-05-23 14:57:22 +08:00
import userImg from '../../static/homeimg/userimg.png'
2024-05-28 18:00:42 +08:00
import { reMenuActive } from '../../util/cache';
2024-03-11 19:13:42 +08:00
export default function Head() {
2024-03-26 21:09:41 +08:00
const globalContext = useContext(GlobalContext);
const globalDispatchContext = useContext(GlobalDispatchContext);
const [messageApi, contextHolder] = message.useMessage();
const [modal, modalHolder] = Modal.useModal();
const [loading, setLoading] = useState<boolean>(false);
const [isSelfModalOpen, setIsSelfModalOpen] = useState(false);
2024-03-27 11:04:38 +08:00
const [isPasswordModalOpen, setIsPasswordModalOpen] = useState(false);
2024-04-07 17:37:09 +08:00
const [isInvoiceModalOpen, setIsInvoiceModalOpen] = useState(false);
2024-03-26 21:09:41 +08:00
useEffect(() => {
2024-04-02 18:45:46 +08:00
reloadUser(messageApi, globalDispatchContext).then((data) => {
if (!data.hasUserInfo) {
setIsSelfModalOpen(true);
2024-03-26 21:09:41 +08:00
}
2024-04-02 18:45:46 +08:00
});
2024-03-26 21:09:41 +08:00
}, [globalContext.user]);
2024-03-16 23:12:49 +08:00
const items: MenuProps['items'] = [
{
key: 'userinfo',
label: (
<div className="dropdown-item">
2024-04-29 17:22:26 +08:00
<UserOutlined />
2024-03-16 23:12:49 +08:00
<span className="title"></span>
</div>
),
2024-03-26 21:09:41 +08:00
onClick: () => {
setIsSelfModalOpen(true);
}
2024-03-16 23:12:49 +08:00
},
{
key: 'changePass',
label: (
<div className="dropdown-item">
2024-04-29 17:22:26 +08:00
<KeyOutlined />
2024-03-16 23:12:49 +08:00
<span className="title"></span>
</div>
),
2024-03-27 11:04:38 +08:00
onClick: () => {
setIsPasswordModalOpen(true);
}
2024-03-16 23:12:49 +08:00
},
2024-04-02 18:45:46 +08:00
{
key: 'invoice',
label: (
<div className="dropdown-item">
<AccountBookOutlined />
<span className="title"></span>
</div>
),
onClick: () => {
2024-04-07 17:37:09 +08:00
setIsInvoiceModalOpen(true);
2024-04-02 18:45:46 +08:00
}
},
2024-03-16 23:12:49 +08:00
{
key: 'logout',
label: (
<div className="dropdown-item">
2024-04-29 17:22:26 +08:00
<LogoutOutlined />
2024-03-16 23:12:49 +08:00
<span className="title">退</span>
</div>
),
2024-04-12 14:12:38 +08:00
onClick: () => {
2024-05-28 18:00:42 +08:00
reMenuActive()
2024-04-12 14:12:38 +08:00
window.location.href = '/copyright/logout'
}
2024-03-16 23:12:49 +08:00
},
]
2024-03-11 19:13:42 +08:00
return (
2024-03-26 21:09:41 +08:00
<>
<div className="head">
<div className="center">
<div className="left">
2024-04-29 17:22:26 +08:00
{/* <span className="sys-title">AI</span>
2024-03-26 21:09:41 +08:00
<Divider type="vertical"/>
2024-04-29 17:22:26 +08:00
<span className="sys-title-sub"></span> */}
<img src={logoImg} alt="" />
2024-03-26 21:09:41 +08:00
</div>
2024-04-29 17:22:26 +08:00
{/* <div className="right" style={{backgroundImage: `url(${headRightBg})`}}> */}
<div className="right">
<BalanceHead />
<RechargeHead />
2024-03-26 21:09:41 +08:00
{/*<MessageHead/>*/}
2024-04-29 17:22:26 +08:00
<div style={{ display: 'flex', alignContent: 'center', padding: '0 10px', cursor: 'pointer' }}>
2024-05-23 14:57:22 +08:00
<div style={{ width: '50px', height: '50px', borderRadius: '25px', marginLeft: '20px', marginRight: '10px' }} >
<img src={userImg} alt="" width={50} height={50}/>
</div>
2024-03-26 21:09:41 +08:00
<Dropdown menu={{
items: items
}}>
<Space>
2024-04-29 17:22:26 +08:00
{/* 您好:{globalContext.user.nickname} */}
<DownOutlined />
2024-03-26 21:09:41 +08:00
</Space>
</Dropdown>
</div>
2024-03-16 23:12:49 +08:00
</div>
2024-03-11 19:13:42 +08:00
</div>
</div>
2024-03-26 21:09:41 +08:00
<Modal open={isSelfModalOpen}
2024-04-29 17:22:26 +08:00
title="个人信息"
footer={false}
onCancel={() => {
if (!globalContext.user.hasUserInfo) {
messageApi.info('请完善个人信息');
return;
}
setIsSelfModalOpen(false)
}}>
2024-03-26 21:09:41 +08:00
<UserEdit handleConfirm={(data) => {
modal.confirm({
2024-03-27 11:04:38 +08:00
title: '提示',
2024-03-26 21:09:41 +08:00
content: '确定保存吗?',
okText: '确认',
cancelText: '取消',
okButtonProps: {
style: {
backgroundColor: 'var(--color-primary)'
}
},
onOk: () => {
setIsSelfModalOpen(false);
put({
messageApi,
url: '/api/user-info/update-self',
body: data,
onBefore() {
setLoading(true);
},
onSuccess() {
messageApi.success('修改成功');
},
onFinally() {
setLoading(false);
}
})
2024-03-27 11:04:38 +08:00
}
});
2024-04-29 17:22:26 +08:00
}} />
2024-03-27 11:04:38 +08:00
</Modal>
<Modal open={isPasswordModalOpen}
2024-04-29 17:22:26 +08:00
title="修改密码"
footer={false}
onCancel={() => {
setIsPasswordModalOpen(false)
}}>
2024-03-27 11:04:38 +08:00
<PasswordChange handleConfirm={(data) => {
modal.confirm({
title: '提示',
content: '确定修改吗?',
okText: '确认',
cancelText: '取消',
okButtonProps: {
style: {
backgroundColor: 'var(--color-primary)'
}
},
onOk: () => {
put({
messageApi,
url: '/api/user/update-password',
body: data,
onBefore() {
setLoading(true);
},
onSuccess() {
setIsPasswordModalOpen(false);
messageApi.success('修改成功,重新登录生效');
},
onFinally() {
setLoading(false);
}
})
2024-03-26 21:09:41 +08:00
}
});
2024-04-29 17:22:26 +08:00
}} />
2024-03-26 21:09:41 +08:00
</Modal>
2024-04-07 17:37:09 +08:00
<Modal open={isInvoiceModalOpen}
2024-04-29 17:22:26 +08:00
title="发票管理"
width={1100}
footer={false}
onCancel={() => setIsInvoiceModalOpen(false)}
2024-04-01 20:39:22 +08:00
>
2024-04-29 17:22:26 +08:00
<InvoiceList />
2024-04-01 20:39:22 +08:00
</Modal>
2024-04-29 17:22:26 +08:00
<Spin tip="正在提交..." spinning={loading} fullscreen />
2024-03-26 21:09:41 +08:00
{contextHolder}
{modalHolder}
</>
2024-03-11 19:13:42 +08:00
)
}