登录
This commit is contained in:
@ -3,7 +3,7 @@ import { Form, Input, Button, Checkbox, Tabs, message } from 'antd';
|
||||
import { UserOutlined, LockOutlined, EyeInvisibleOutlined, EyeTwoTone, HomeOutlined } from '@ant-design/icons';
|
||||
import { history, useIntl } from 'umi';
|
||||
import './login.less';
|
||||
import { getCaptcha, supplierLogin } from '@/servers/api/login';
|
||||
import { getCaptcha, supplierLogin, expertLogin, accountLogin } from '@/servers/api/login';
|
||||
|
||||
import { encryptWithRsa } from '@/utils/encryptWithRsa'
|
||||
import Password from 'antd/lib/input/Password';
|
||||
@ -11,11 +11,17 @@ import Password from 'antd/lib/input/Password';
|
||||
const { TabPane } = Tabs;
|
||||
|
||||
const LoginPage: React.FC = () => {
|
||||
const [activeKey, setActiveKey] = useState('supplier');
|
||||
const [activeKey, setActiveKey] = useState('supplierLogin');
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [captchaImg, setCaptchaImg] = useState<string>('');
|
||||
const [captchaKey, setCaptchaKey] = useState<string>('');
|
||||
//切换后 走不同接口
|
||||
const loginApiMap: { [key: string]: (params: any) => Promise<any> } = {
|
||||
supplierLogin,
|
||||
expertLogin,
|
||||
accountLogin
|
||||
};
|
||||
|
||||
const intl = useIntl();
|
||||
|
||||
@ -31,11 +37,20 @@ const LoginPage: React.FC = () => {
|
||||
password: encryptWithRsa(values.password, false),
|
||||
encryptValue: encryptWithRsa(values.identifying)
|
||||
};
|
||||
const loginRes = await supplierLogin(params);
|
||||
const loginRes = await loginApiMap[activeKey](params);
|
||||
if (loginRes.code === 200) {
|
||||
sessionStorage.setItem('token', loginRes.data.token);
|
||||
//存入供应商用户id
|
||||
if(activeKey === 'supplierLogin') {
|
||||
sessionStorage.setItem('userId', loginRes.data.supplierUser.userId);
|
||||
} else if(activeKey === 'expertLogin') {
|
||||
//存入专家用户id
|
||||
// sessionStorage.setItem('userId', loginRes.data.expertUser.userId);
|
||||
} else if(activeKey === 'accountLogin') {
|
||||
//存入招标代理用户id
|
||||
// sessionStorage.setItem('userId', loginRes.data.supplierUser.userId);
|
||||
}
|
||||
sessionStorage.setItem('currentUser', JSON.stringify(loginRes.data));
|
||||
sessionStorage.setItem('userId', loginRes.data.supplierUser.userId);
|
||||
message.success('登录成功');
|
||||
history.push('/index');
|
||||
} else {
|
||||
@ -63,10 +78,10 @@ const LoginPage: React.FC = () => {
|
||||
// 根据当前选中的Tab决定跳转到哪个注册页面
|
||||
const handleRegister = () => {
|
||||
switch(activeKey) {
|
||||
case 'supplier':
|
||||
case 'supplierLogin':
|
||||
history.push('/register/supplier');
|
||||
break;
|
||||
case 'expert':
|
||||
case 'expertLogin':
|
||||
history.push('/register/expert');
|
||||
break;
|
||||
default:
|
||||
@ -102,13 +117,13 @@ const LoginPage: React.FC = () => {
|
||||
|
||||
<div className='login-title'>{intl.formatMessage({ id: 'login.title' })}</div>
|
||||
|
||||
{/* <div className="login-tab-container">
|
||||
<div className="login-tab-container">
|
||||
<Tabs activeKey={activeKey} onChange={handleTabChange} className='login-tabs'>
|
||||
<TabPane tab={intl.formatMessage({ id: 'login.tab.supplier' })} key="supplier" />
|
||||
<TabPane tab={intl.formatMessage({ id: 'login.tab.expert' })} key="expert" />
|
||||
<TabPane tab={intl.formatMessage({ id: 'login.tab.agent' })} key="agent" />
|
||||
<TabPane tab={intl.formatMessage({ id: 'login.tab.supplier' })} key="supplierLogin" />
|
||||
<TabPane tab={intl.formatMessage({ id: 'login.tab.expert' })} key="expertLogin" />
|
||||
<TabPane tab={intl.formatMessage({ id: 'login.tab.agent' })} key="accountLogin" />
|
||||
</Tabs>
|
||||
</div> */}
|
||||
</div>
|
||||
|
||||
<Form
|
||||
form={form}
|
||||
@ -175,7 +190,7 @@ const LoginPage: React.FC = () => {
|
||||
<Button type="primary" htmlType="submit" className="login-form-button" loading={loading} size="large">
|
||||
{intl.formatMessage({ id: 'login.button' })}
|
||||
</Button>
|
||||
{renderRegisterLink()}
|
||||
{activeKey !== 'accountLogin' && renderRegisterLink()}
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user