ykzz-web/src/components/DashboardLayout/HeaderUser.tsx

159 lines
4.7 KiB
TypeScript
Raw Normal View History

2024-12-10 10:28:55 +08:00
import { RollbackOutlined, LogoutOutlined } from '@ant-design/icons';
import { Avatar, Menu, Typography, Modal, Form, Input, Button, message } from 'antd';
2024-12-19 18:00:13 +08:00
import { useDispatch, useSelector } from "react-redux";
2024-12-10 10:28:55 +08:00
import { useNavigate } from "react-router";
import { LoginUser, removeLoginInfo } from "../../models/auth/_";
import { RootState } from "../../models/store";
import React, { useState } from "react";
2024-12-19 18:00:13 +08:00
import { divIcon } from "leaflet";
2024-12-10 10:28:55 +08:00
import { httppost2 } from '../../utils/request';
import apiurl from '../../service/apiurl';
import CryptoJS from 'crypto-js';
2024-12-19 18:00:13 +08:00
import { createCrudService } from '../../components/crud/_';
2024-12-10 10:28:55 +08:00
const { SubMenu } = Menu;
const HeaderUser: React.FC<{
user: LoginUser | null
}> = ({ user }) => {
const navigate = useNavigate();
const dispatch = useDispatch();
2024-12-19 18:00:13 +08:00
const [open, setOpen] = useState(false)
2024-12-10 10:28:55 +08:00
const logout = () => {
removeLoginInfo();
navigate('/login');
dispatch.runtime.setHasAlertBox(false);
dispatch.runtime.setAlarmActive(false);
window.location.reload();
};
2024-12-19 18:00:13 +08:00
//AES加密
const encryptData = (data: any) => {
const encryptedData = CryptoJS.MD5(data).toString();
return encryptedData;
2024-12-10 10:28:55 +08:00
}
2024-12-19 18:00:13 +08:00
const onFinish = async (val: any) => {
const path = `${apiurl.systemM.userM.updatePassword}?oldPassword=${val.oldPassword}&newPassword=${val.newPassword}`;
createCrudService(path).userEdit().then((result) => {
if (result?.code === 200) {
message.success('修改成功,即将重新登录')
setOpen(false)
setTimeout(() => {
logout()
}, 1500);
}
})
// if(val.newSecretKey!==val.secondSecretKey){
// message.error('确认密码错误')
// return
// }
// const params = {
// oldSecretKey:encryptData(val.oldSecretKey),
// newSecretKey:encryptData(val.newSecretKey),
// secondSecretKey:encryptData(val.secondSecretKey),
// userId: localStorage.getItem('userId')
// }
// const res = await httppost2(apiurl.setPassword,params)
// if(res.code===200){
// message.success('修改成功')
// setTimeout(() => {
// logout()
// }, 1500);
// }else{
// message.error(res.description)
// }
}
2024-12-10 10:28:55 +08:00
return (
<div className="clearFloat">
2024-12-19 18:00:13 +08:00
<div className="lf">
<Menu
mode="horizontal"
theme="dark"
style={{ width: "130px", color: "#fff" }}
>
{/*icon={<Avatar><UserOutlined /></Avatar>}*/}
<SubMenu key="pm" icon={<div className="user topMenuIcon1"></div>} title={
<span style={{ fontSize: "12px" }}>
{localStorage.getItem('userName') ?? '-'}
{/* 咸丰测试 */}
</span>} >
<Menu.Item key="logout2" onClick={() => setOpen(true)} className="userBox"></Menu.Item>
<Menu.Item icon={<LogoutOutlined />} key="logout" onClick={logout} className="userBox2"></Menu.Item>
</SubMenu>
</Menu>
</div>
2024-12-10 10:28:55 +08:00
{
2024-12-19 18:00:13 +08:00
localStorage.getItem('getInfoAdcd') === "420000000000000" ?
<div className="lf" style={{ width: "30px", height: "30px", lineHeight: "32px", background: "#fff", borderRadius: "50%", textAlign: "center", marginTop: "17px" }}>
<a href="http://223.75.53.141:8000/home" target="_self" style={{ color: "#4677FF" }}>
<RollbackOutlined style={{ fontSize: "18px" }} />
2024-12-10 10:28:55 +08:00
</a>
2024-12-19 18:00:13 +08:00
</div> : null
2024-12-10 10:28:55 +08:00
}
2024-12-19 18:00:13 +08:00
<Modal
title="修改密码"
open={open}
onOk={() => setOpen(false)}
onCancel={() => setOpen(false)}
footer={null}
destroyOnClose
>
2024-12-10 10:28:55 +08:00
<Form
name="basic"
2024-12-19 18:00:13 +08:00
labelCol={{ span: 5 }}
wrapperCol={{ span: 18 }}
initialValues={{ remember: true }}
2024-12-10 10:28:55 +08:00
onFinish={onFinish}
autoComplete="off"
>
<Form.Item
label="原密码"
2024-12-19 18:00:13 +08:00
name="oldPassword"
rules={[{ required: true }]}>
2024-12-10 10:28:55 +08:00
<Input.Password />
</Form.Item>
<Form.Item
label="新密码"
2024-12-19 18:00:13 +08:00
name="newPassword"
rules={[{ required: true }]}>
2024-12-10 10:28:55 +08:00
<Input.Password />
</Form.Item>
2024-12-19 18:00:13 +08:00
{/* <Form.Item
2024-12-10 10:28:55 +08:00
label="确认密码"
name="secondSecretKey"
rules={[{required: true}]}>
<Input.Password />
2024-12-19 18:00:13 +08:00
</Form.Item> */}
2024-12-10 10:28:55 +08:00
<Form.Item
wrapperCol={{
offset: 20,
span: 4,
}}
>
<Button type="primary" htmlType="submit">
</Button>
</Form.Item>
</Form>
</Modal>
</div>
);
};
export default HeaderUser