2025-07-09 14:01:45 +08:00
|
|
|
|
import React, { useState, useEffect } from 'react';
|
2025-06-17 14:20:06 +08:00
|
|
|
|
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';
|
2025-07-15 09:07:43 +08:00
|
|
|
|
import { getCaptcha, supplierLogin, expertLogin, accountLogin, getUserinfo, findMenuList } from '@/servers/api/login';
|
2025-07-09 14:01:45 +08:00
|
|
|
|
|
|
|
|
|
import { encryptWithRsa } from '@/utils/encryptWithRsa'
|
|
|
|
|
import Password from 'antd/lib/input/Password';
|
2025-06-17 14:20:06 +08:00
|
|
|
|
|
|
|
|
|
const { TabPane } = Tabs;
|
|
|
|
|
|
|
|
|
|
const LoginPage: React.FC = () => {
|
2025-07-11 08:33:29 +08:00
|
|
|
|
const [activeKey, setActiveKey] = useState('supplierLogin');
|
2025-06-17 14:20:06 +08:00
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
2025-07-09 14:01:45 +08:00
|
|
|
|
const [captchaImg, setCaptchaImg] = useState<string>('');
|
|
|
|
|
const [captchaKey, setCaptchaKey] = useState<string>('');
|
2025-07-11 08:33:29 +08:00
|
|
|
|
//切换后 走不同接口
|
|
|
|
|
const loginApiMap: { [key: string]: (params: any) => Promise<any> } = {
|
|
|
|
|
supplierLogin,
|
|
|
|
|
expertLogin,
|
|
|
|
|
accountLogin
|
|
|
|
|
};
|
2025-07-09 14:01:45 +08:00
|
|
|
|
|
2025-06-17 14:20:06 +08:00
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
2025-07-09 14:01:45 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchCaptcha();
|
|
|
|
|
}, [activeKey]);
|
|
|
|
|
|
|
|
|
|
const onFinish = async (values: any) => {
|
2025-06-17 14:20:06 +08:00
|
|
|
|
setLoading(true);
|
2025-07-09 14:01:45 +08:00
|
|
|
|
try {
|
|
|
|
|
const params = {
|
|
|
|
|
...values,
|
|
|
|
|
password: encryptWithRsa(values.password, false),
|
|
|
|
|
encryptValue: encryptWithRsa(values.identifying)
|
|
|
|
|
};
|
2025-07-11 08:33:29 +08:00
|
|
|
|
const loginRes = await loginApiMap[activeKey](params);
|
2025-07-09 14:01:45 +08:00
|
|
|
|
if (loginRes.code === 200) {
|
|
|
|
|
sessionStorage.setItem('token', loginRes.data.token);
|
2025-07-11 08:33:29 +08:00
|
|
|
|
//存入供应商用户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
|
2025-07-15 16:10:33 +08:00
|
|
|
|
sessionStorage.setItem('userId', loginRes.data.user.userId);
|
2025-07-11 08:33:29 +08:00
|
|
|
|
}
|
2025-07-09 14:01:45 +08:00
|
|
|
|
sessionStorage.setItem('currentUser', JSON.stringify(loginRes.data));
|
2025-07-15 09:07:43 +08:00
|
|
|
|
|
|
|
|
|
getUserinfo().then( async (res) => {
|
|
|
|
|
// if(res.code == 200) {
|
|
|
|
|
const roleIdList = res.authorityList.map((item:any) => {
|
|
|
|
|
return item.roleId
|
|
|
|
|
})
|
|
|
|
|
console.log(roleIdList,'roleIdList');
|
|
|
|
|
|
|
|
|
|
const menuList = await findMenuList({ roleIdList });
|
|
|
|
|
sessionStorage.setItem('menuList', JSON.stringify(menuList.data));
|
|
|
|
|
// }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
2025-07-09 14:01:45 +08:00
|
|
|
|
message.success('登录成功');
|
|
|
|
|
history.push('/index');
|
|
|
|
|
} else {
|
|
|
|
|
message.error(loginRes.message || '登录失败');
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
2025-06-17 14:20:06 +08:00
|
|
|
|
setLoading(false);
|
2025-07-09 14:01:45 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fetchCaptcha = async () => {
|
|
|
|
|
const res = await getCaptcha();
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
setCaptchaImg(res.data.base64Image);
|
|
|
|
|
setCaptchaKey(res.data.code);
|
|
|
|
|
}
|
2025-06-17 14:20:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleTabChange = (key: string) => {
|
|
|
|
|
setActiveKey(key);
|
|
|
|
|
form.resetFields();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 根据当前选中的Tab决定跳转到哪个注册页面
|
|
|
|
|
const handleRegister = () => {
|
|
|
|
|
switch(activeKey) {
|
2025-07-11 08:33:29 +08:00
|
|
|
|
case 'supplierLogin':
|
2025-06-17 14:20:06 +08:00
|
|
|
|
history.push('/register/supplier');
|
|
|
|
|
break;
|
2025-07-11 08:33:29 +08:00
|
|
|
|
case 'expertLogin':
|
2025-06-17 14:20:06 +08:00
|
|
|
|
history.push('/register/expert');
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// 招标代理不提供注册功能
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 渲染注册链接(只在供应商和专家Tab下显示)
|
|
|
|
|
const renderRegisterLink = () => {
|
|
|
|
|
if (activeKey === 'agent') {
|
|
|
|
|
return null; // 招标代理不显示注册链接
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="register-link">
|
|
|
|
|
{intl.formatMessage({ id: 'login.register.tip' })}
|
|
|
|
|
<a onClick={handleRegister}>
|
|
|
|
|
{intl.formatMessage({ id: 'login.register.action' })}
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className='login-page'>
|
|
|
|
|
<div className='login-container'>
|
2025-07-09 14:01:45 +08:00
|
|
|
|
{/* <div className='back-home'>
|
2025-06-17 14:20:06 +08:00
|
|
|
|
<a onClick={() => history.push('/index')}>
|
|
|
|
|
<HomeOutlined /> {intl.formatMessage({ id: 'login.back.home' })}
|
|
|
|
|
</a>
|
2025-07-09 14:01:45 +08:00
|
|
|
|
</div> */}
|
2025-06-17 14:20:06 +08:00
|
|
|
|
|
|
|
|
|
<div className='login-title'>{intl.formatMessage({ id: 'login.title' })}</div>
|
|
|
|
|
|
2025-07-11 08:33:29 +08:00
|
|
|
|
<div className="login-tab-container">
|
2025-06-17 14:20:06 +08:00
|
|
|
|
<Tabs activeKey={activeKey} onChange={handleTabChange} className='login-tabs'>
|
2025-07-11 08:33:29 +08:00
|
|
|
|
<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" />
|
2025-06-17 14:20:06 +08:00
|
|
|
|
</Tabs>
|
2025-07-11 08:33:29 +08:00
|
|
|
|
</div>
|
2025-06-17 14:20:06 +08:00
|
|
|
|
|
|
|
|
|
<Form
|
|
|
|
|
form={form}
|
|
|
|
|
name="login"
|
|
|
|
|
className='login-form'
|
|
|
|
|
initialValues={{ remember: false }}
|
|
|
|
|
onFinish={onFinish}
|
|
|
|
|
>
|
|
|
|
|
<Form.Item
|
2025-07-09 14:01:45 +08:00
|
|
|
|
name="account"
|
2025-06-17 14:20:06 +08:00
|
|
|
|
rules={[{ required: true, message: intl.formatMessage({ id: 'login.username.placeholder' }) + '!' }]}
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
prefix={<UserOutlined className="site-form-item-icon" />}
|
|
|
|
|
placeholder={intl.formatMessage({ id: 'login.username.placeholder' })}
|
|
|
|
|
size="large"
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Form.Item
|
|
|
|
|
name="password"
|
|
|
|
|
rules={[{ required: true, message: intl.formatMessage({ id: 'login.password.placeholder' }) + '!' }]}
|
|
|
|
|
>
|
|
|
|
|
<Input.Password
|
|
|
|
|
prefix={<LockOutlined className="site-form-item-icon" />}
|
|
|
|
|
placeholder={intl.formatMessage({ id: 'login.password.placeholder' })}
|
|
|
|
|
iconRender={visible => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
|
|
|
|
|
size="large"
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
2025-07-09 14:01:45 +08:00
|
|
|
|
<Form.Item
|
|
|
|
|
name="identifying"
|
|
|
|
|
rules={[{ required: true, message: intl.formatMessage({ id: 'login.captcha.placeholder' }) + '!' }]}
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder={intl.formatMessage({ id: 'login.captcha.placeholder' })}
|
|
|
|
|
size="large"
|
|
|
|
|
maxLength={6}
|
|
|
|
|
autoComplete="off"
|
|
|
|
|
prefix={null}
|
|
|
|
|
suffix={
|
|
|
|
|
<img
|
|
|
|
|
src={`data:image/png;base64,${captchaImg}`}
|
|
|
|
|
alt="验证码"
|
|
|
|
|
style={{ cursor: 'pointer', height: 32, verticalAlign: 'middle' }}
|
|
|
|
|
onClick={fetchCaptcha}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
2025-06-17 14:20:06 +08:00
|
|
|
|
|
|
|
|
|
<Form.Item>
|
|
|
|
|
<div className='login-options'>
|
|
|
|
|
<Form.Item name="remember" valuePropName="checked" noStyle>
|
|
|
|
|
<Checkbox>{intl.formatMessage({ id: 'login.remember' })}</Checkbox>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<a className="login-form-forgot" href="">
|
|
|
|
|
{intl.formatMessage({ id: 'login.forgot' })}
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Form.Item>
|
|
|
|
|
<Button type="primary" htmlType="submit" className="login-form-button" loading={loading} size="large">
|
|
|
|
|
{intl.formatMessage({ id: 'login.button' })}
|
|
|
|
|
</Button>
|
2025-07-11 08:33:29 +08:00
|
|
|
|
{activeKey !== 'accountLogin' && renderRegisterLink()}
|
2025-06-17 14:20:06 +08:00
|
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default LoginPage;
|