login page

This commit is contained in:
lix
2025-07-08 14:59:01 +08:00
parent 1e940183cd
commit f4f1f51393
3 changed files with 45 additions and 12 deletions

View File

@ -74,7 +74,19 @@ const Loading: React.FC<{}> = () => {
// return;
// }
// } else {
setUserData(userData, userData.authorityList[0].roleCode, userData.authorityList[0]);
let role = userData.authorityList[0].roleCode;
let roleData = userData.authorityList[0];
const loginType = localStorage.getItem('loginType');
if (loginType) {
const roleCode = `ebtp-${loginType}`
const targetRole = userData.authorityList.find((ite: any) => ite.roleCode == roleCode);
if (targetRole) {
role = targetRole.roleCode;
roleData = targetRole;
}
}
setUserData(userData, role, roleData);
// }
// await setDict();//存字典
setTimeout(() => {
@ -255,7 +267,10 @@ const Loading: React.FC<{}> = () => {
await redirect(res, url, extra);
} else {
if (status == 0) {
await refreshUserData(res?.userType, token, url, extra);
// await refreshUserData(res?.userType, token, url, extra);
message.error("角色身份信息不存在").then(() => {
history.replace('/login');
});
} else {
error('401');
}

View File

@ -1,7 +1,7 @@
import React, { useEffect, useRef, useState } from 'react';
import { Form, Input, Button, Checkbox, Card, Typography } from 'antd';
import { UserOutlined, LockOutlined, EyeInvisibleOutlined, EyeTwoTone } from '@ant-design/icons';
import { history } from '@umijs/max';
import { history, Helmet } from '@umijs/max';
import cookie from 'react-cookies';
import CaptchaInput from '@/components/CaptchaInput';
import styles from './internal.less';
@ -29,13 +29,21 @@ const InternalLogin: React.FC = () => {
account: values.username,
password: values.password,
captcha: values.captcha,
remember: values.remember,
}
try {
setLoading(true);
const res = await internalUserLogin(params);
setLoading(false);
if (res?.code === 200) {
sessionStorage.setItem('Authorization', res?.data?.token || '');
if (values.remember) {
localStorage.setItem('remember_user', JSON.stringify({
username: values.username,
password: values.password,
}));
} else {
localStorage.removeItem('remember_user');
}
history.push('/redirect');
} else {
captchaRef.current?.refresh();
@ -48,8 +56,6 @@ const InternalLogin: React.FC = () => {
}
} catch (error) {
console.error('登录失败:', error);
} finally {
setLoading(false);
}
};
@ -137,6 +143,9 @@ const InternalLogin: React.FC = () => {
return (
<div className={styles.loginContainer}>
<Helmet>
<title></title>
</Helmet>
<Card className={styles.loginCard}>
<Title level={2} style={{ textAlign: 'center', lineHeight: '80px', fontSize: 32, fontWeight: 700, marginBottom: 0 }}>

View File

@ -1,7 +1,7 @@
import React, { useEffect, useRef, useState } from 'react';
import { Form, Input, Button, Checkbox, Card, Typography, Tabs } from 'antd';
import { UserOutlined, LockOutlined, EyeInvisibleOutlined, EyeTwoTone } from '@ant-design/icons';
import { history } from 'umi';
import { history, Helmet } from '@umijs/max';
import cookie from 'react-cookies';
import CaptchaInput from '@/components/CaptchaInput';
import styles from './internal.less';
@ -35,21 +35,29 @@ const Login: React.FC = () => {
const [form] = Form.useForm();
const [loading, setLoading] = useState(false);
const [activeTab, setActiveTab] = useState<UserType>('supplier');
const captchaRef = useRef<any>(null);
const captchaRef = useRef<any>(null);
const onFinish = async (values: LoginFormValues) => {
const params = {
account: values.username,
password: values.password,
captcha: values.captcha,
remember: values.remember,
}
try {
setLoading(true);
const res = await userLogin(params, activeTab);
setLoading(false);
if (res?.code === 200) {
sessionStorage.setItem('Authorization', res?.data?.token || '');
localStorage.setItem('loginType', activeTab);
if (values.remember) {
localStorage.setItem('remember_user', JSON.stringify({
username: values.username,
password: values.password,
}));
} else {
localStorage.removeItem('remember_user');
}
history.push('/redirect');
} else {
captchaRef.current?.refresh();
@ -62,8 +70,6 @@ const Login: React.FC = () => {
}
} catch (error) {
console.error('登录失败:', error);
} finally {
setLoading(false);
}
};
@ -170,6 +176,9 @@ const Login: React.FC = () => {
return (
<div className={styles.loginContainer}>
<Helmet>
<title></title>
</Helmet>
<Card className={styles.loginCard}>
<Title level={2} style={{ textAlign: 'center', lineHeight: '80px', fontSize: 32, fontWeight: 700, marginBottom: 0 }}>