import React, { useState, useEffect } from 'react'; 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 { encryptWithRsa } from '@/utils/encryptWithRsa' import Password from 'antd/lib/input/Password'; const { TabPane } = Tabs; const LoginPage: React.FC = () => { const [activeKey, setActiveKey] = useState('supplier'); const [form] = Form.useForm(); const [loading, setLoading] = useState(false); const [captchaImg, setCaptchaImg] = useState(''); const [captchaKey, setCaptchaKey] = useState(''); const intl = useIntl(); useEffect(() => { fetchCaptcha(); }, [activeKey]); const onFinish = async (values: any) => { setLoading(true); try { const params = { ...values, password: encryptWithRsa(values.password, false), encryptValue: encryptWithRsa(values.identifying) }; const loginRes = await supplierLogin(params); if (loginRes.code === 200) { sessionStorage.setItem('token', loginRes.data.token); sessionStorage.setItem('currentUser', JSON.stringify(loginRes.data)); sessionStorage.setItem('userId', loginRes.data.supplierUser.userId); message.success('登录成功'); history.push('/index'); } else { message.error(loginRes.message || '登录失败'); } } finally { setLoading(false); } }; const fetchCaptcha = async () => { const res = await getCaptcha(); if (res.code === 200) { setCaptchaImg(res.data.base64Image); setCaptchaKey(res.data.code); } }; const handleTabChange = (key: string) => { setActiveKey(key); form.resetFields(); }; // 根据当前选中的Tab决定跳转到哪个注册页面 const handleRegister = () => { switch(activeKey) { case 'supplier': history.push('/register/supplier'); break; case 'expert': history.push('/register/expert'); break; default: // 招标代理不提供注册功能 break; } }; // 渲染注册链接(只在供应商和专家Tab下显示) const renderRegisterLink = () => { if (activeKey === 'agent') { return null; // 招标代理不显示注册链接 } return (
{intl.formatMessage({ id: 'login.register.tip' })} {intl.formatMessage({ id: 'login.register.action' })}
); }; return (
{/*
history.push('/index')}> {intl.formatMessage({ id: 'login.back.home' })}
*/}
{intl.formatMessage({ id: 'login.title' })}
{/*
*/}
} placeholder={intl.formatMessage({ id: 'login.username.placeholder' })} size="large" /> } placeholder={intl.formatMessage({ id: 'login.password.placeholder' })} iconRender={visible => (visible ? : )} size="large" /> } />
{intl.formatMessage({ id: 'login.remember' })} {intl.formatMessage({ id: 'login.forgot' })}
{renderRegisterLink()}
); }; export default LoginPage;