菜单与 审核按钮,登录新用户修改密码
This commit is contained in:
@ -3,7 +3,8 @@ import { Form, Input, Button, Checkbox, Tabs, message } from 'antd';
|
||||
import { UserOutlined, LockOutlined, EyeInvisibleOutlined, EyeTwoTone } from '@ant-design/icons';
|
||||
import { history, useIntl } from 'umi';
|
||||
import './login.less';
|
||||
import { getCaptcha, supplierLogin, expertLogin, accountLogin, getUserinfo, refreshDictCache, findMenuList } from '@/servers/api/login';
|
||||
import { getCaptcha, supplierLogin, expertLogin, accountLogin, getUserinfo, refreshDictCache, findMenuList, changePasswordOnFirstLogin } from '@/servers/api/login';
|
||||
import ChangePasswordModal from './components/ChangePasswordModal';
|
||||
|
||||
import { encryptWithRsa } from '@/utils/encryptWithRsa'
|
||||
|
||||
@ -14,6 +15,10 @@ const LoginPage: React.FC = () => {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [captchaImg, setCaptchaImg] = useState<string>('');
|
||||
const [userId, setUserId] = useState<string>('');
|
||||
// ======= 修改密码弹窗控制 =======
|
||||
const [showChangePwd, setShowChangePwd] = useState(false);
|
||||
|
||||
// const [captchaKey, setCaptchaKey] = useState<string>('');
|
||||
//切换后 走不同接口
|
||||
const loginApiMap: { [key: string]: (params: any) => Promise<any> } = {
|
||||
@ -51,6 +56,26 @@ const LoginPage: React.FC = () => {
|
||||
// });
|
||||
// }
|
||||
}, [form]);
|
||||
|
||||
// 修改密码确认回调
|
||||
const handleChangePwd = async (values: { userId: string; newPassword: string; confirmPassword: string; }) => {
|
||||
try {
|
||||
await changePasswordOnFirstLogin({
|
||||
userId: userId,
|
||||
newPassword: encryptWithRsa(values.newPassword, false),
|
||||
confirmPassword: encryptWithRsa(values.confirmPassword, false)
|
||||
}).then((res) => {
|
||||
if(res.data) {
|
||||
setShowChangePwd(false);
|
||||
message.success('修改成功,请重新登录');
|
||||
} else {
|
||||
message.success('修改密码失败');
|
||||
}
|
||||
})
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '修改密码失败');
|
||||
}
|
||||
};
|
||||
const onFinish = async (values: any) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
@ -92,11 +117,19 @@ const LoginPage: React.FC = () => {
|
||||
sessionStorage.setItem('currentUser', JSON.stringify(loginRes.data));
|
||||
await getUserinfo().then(async (res) => {
|
||||
const roleIdList = res.authorityList.map((item: any) => item.roleId);
|
||||
console.log(res);
|
||||
|
||||
setUserId(res.userId)
|
||||
sessionStorage.setItem('Userinfo', JSON.stringify(res));
|
||||
const menuList: any = await findMenuList({ roleIdList });
|
||||
sessionStorage.setItem('menuList', JSON.stringify(menuList.data));
|
||||
message.success('登录成功');
|
||||
history.push('/index');
|
||||
//新用户需要修改一次密码
|
||||
if (loginRes.data?.supplierUser?.firstLogin === 1) {
|
||||
setShowChangePwd(true);
|
||||
} else {
|
||||
message.success('登录成功');
|
||||
history.push('/index');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
message.error(loginRes.message || '登录失败');
|
||||
@ -157,6 +190,12 @@ const LoginPage: React.FC = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ChangePasswordModal
|
||||
visible={showChangePwd}
|
||||
onOk={handleChangePwd}
|
||||
/>
|
||||
|
||||
<div className='login-page'>
|
||||
<div className='login-container'>
|
||||
{/* <div className='back-home'>
|
||||
@ -245,6 +284,7 @@ const LoginPage: React.FC = () => {
|
||||
</Form>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user