登录
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 { UserOutlined, LockOutlined, EyeInvisibleOutlined, EyeTwoTone, HomeOutlined } from '@ant-design/icons';
|
||||||
import { history, useIntl } from 'umi';
|
import { history, useIntl } from 'umi';
|
||||||
import './login.less';
|
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 { encryptWithRsa } from '@/utils/encryptWithRsa'
|
||||||
import Password from 'antd/lib/input/Password';
|
import Password from 'antd/lib/input/Password';
|
||||||
@ -11,11 +11,17 @@ import Password from 'antd/lib/input/Password';
|
|||||||
const { TabPane } = Tabs;
|
const { TabPane } = Tabs;
|
||||||
|
|
||||||
const LoginPage: React.FC = () => {
|
const LoginPage: React.FC = () => {
|
||||||
const [activeKey, setActiveKey] = useState('supplier');
|
const [activeKey, setActiveKey] = useState('supplierLogin');
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [captchaImg, setCaptchaImg] = useState<string>('');
|
const [captchaImg, setCaptchaImg] = useState<string>('');
|
||||||
const [captchaKey, setCaptchaKey] = useState<string>('');
|
const [captchaKey, setCaptchaKey] = useState<string>('');
|
||||||
|
//切换后 走不同接口
|
||||||
|
const loginApiMap: { [key: string]: (params: any) => Promise<any> } = {
|
||||||
|
supplierLogin,
|
||||||
|
expertLogin,
|
||||||
|
accountLogin
|
||||||
|
};
|
||||||
|
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
@ -31,11 +37,20 @@ const LoginPage: React.FC = () => {
|
|||||||
password: encryptWithRsa(values.password, false),
|
password: encryptWithRsa(values.password, false),
|
||||||
encryptValue: encryptWithRsa(values.identifying)
|
encryptValue: encryptWithRsa(values.identifying)
|
||||||
};
|
};
|
||||||
const loginRes = await supplierLogin(params);
|
const loginRes = await loginApiMap[activeKey](params);
|
||||||
if (loginRes.code === 200) {
|
if (loginRes.code === 200) {
|
||||||
sessionStorage.setItem('token', loginRes.data.token);
|
sessionStorage.setItem('token', loginRes.data.token);
|
||||||
sessionStorage.setItem('currentUser', JSON.stringify(loginRes.data));
|
//存入供应商用户id
|
||||||
|
if(activeKey === 'supplierLogin') {
|
||||||
sessionStorage.setItem('userId', loginRes.data.supplierUser.userId);
|
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));
|
||||||
message.success('登录成功');
|
message.success('登录成功');
|
||||||
history.push('/index');
|
history.push('/index');
|
||||||
} else {
|
} else {
|
||||||
@ -63,10 +78,10 @@ const LoginPage: React.FC = () => {
|
|||||||
// 根据当前选中的Tab决定跳转到哪个注册页面
|
// 根据当前选中的Tab决定跳转到哪个注册页面
|
||||||
const handleRegister = () => {
|
const handleRegister = () => {
|
||||||
switch(activeKey) {
|
switch(activeKey) {
|
||||||
case 'supplier':
|
case 'supplierLogin':
|
||||||
history.push('/register/supplier');
|
history.push('/register/supplier');
|
||||||
break;
|
break;
|
||||||
case 'expert':
|
case 'expertLogin':
|
||||||
history.push('/register/expert');
|
history.push('/register/expert');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -102,13 +117,13 @@ const LoginPage: React.FC = () => {
|
|||||||
|
|
||||||
<div className='login-title'>{intl.formatMessage({ id: 'login.title' })}</div>
|
<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'>
|
<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.supplier' })} key="supplierLogin" />
|
||||||
<TabPane tab={intl.formatMessage({ id: 'login.tab.expert' })} key="expert" />
|
<TabPane tab={intl.formatMessage({ id: 'login.tab.expert' })} key="expertLogin" />
|
||||||
<TabPane tab={intl.formatMessage({ id: 'login.tab.agent' })} key="agent" />
|
<TabPane tab={intl.formatMessage({ id: 'login.tab.agent' })} key="accountLogin" />
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</div> */}
|
</div>
|
||||||
|
|
||||||
<Form
|
<Form
|
||||||
form={form}
|
form={form}
|
||||||
@ -175,7 +190,7 @@ const LoginPage: React.FC = () => {
|
|||||||
<Button type="primary" htmlType="submit" className="login-form-button" loading={loading} size="large">
|
<Button type="primary" htmlType="submit" className="login-form-button" loading={loading} size="large">
|
||||||
{intl.formatMessage({ id: 'login.button' })}
|
{intl.formatMessage({ id: 'login.button' })}
|
||||||
</Button>
|
</Button>
|
||||||
{renderRegisterLink()}
|
{activeKey !== 'accountLogin' && renderRegisterLink()}
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -56,8 +56,8 @@ const ExpertRegister: React.FC = () => {
|
|||||||
<div className="register-page">
|
<div className="register-page">
|
||||||
<div className="register-container">
|
<div className="register-container">
|
||||||
<div className="back-home">
|
<div className="back-home">
|
||||||
<a onClick={() => history.push('/index')}>
|
<a onClick={() => history.push('/login')}>
|
||||||
<HomeOutlined /> {intl.formatMessage({ id: 'login.back.home' })}
|
<HomeOutlined /> 返回
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -128,8 +128,8 @@ const SupplierRegister: React.FC<supplierWithInputProps> = (props) => {
|
|||||||
{!supplierWithInput && (
|
{!supplierWithInput && (
|
||||||
<>
|
<>
|
||||||
<div className="back-home">
|
<div className="back-home">
|
||||||
<a onClick={() => history.push('/index')}>
|
<a onClick={() => history.push('/login')}>
|
||||||
<HomeOutlined /> {intl.formatMessage({ id: 'login.back.home' })}
|
<HomeOutlined /> 返回
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -136,13 +136,13 @@ const CategoryAddModal: React.FC<Props> = ({ visible, onCancel, onSuccess }) =>
|
|||||||
const handleTreeCheck = (checkedKeysValue: any) => {
|
const handleTreeCheck = (checkedKeysValue: any) => {
|
||||||
const onlyOneEachLevel = checkedKeysValue;
|
const onlyOneEachLevel = checkedKeysValue;
|
||||||
|
|
||||||
console.log(onlyOneEachLevel,'onlyOneEachLevel');
|
console.log(onlyOneEachLevel, 'onlyOneEachLevel');
|
||||||
|
|
||||||
setCheckedKeys(onlyOneEachLevel);
|
setCheckedKeys(onlyOneEachLevel);
|
||||||
form.setFieldsValue({ categoryKeys: onlyOneEachLevel });
|
form.setFieldsValue({ categoryKeys: onlyOneEachLevel });
|
||||||
};
|
};
|
||||||
// 从树中获取所有选中节点及其父级节点
|
// 从树中获取所有选中节点及其父级节点
|
||||||
const collectCheckedWithParents = (nodes: TreeNodeType[], checked: string[]): string[] => {
|
const collectCheckedWithParents = (nodes: TreeNodeType[], checked: string[]): string[] => {
|
||||||
const result = new Set<string>();
|
const result = new Set<string>();
|
||||||
|
|
||||||
const dfs = (node: TreeNodeType, parents: string[]) => {
|
const dfs = (node: TreeNodeType, parents: string[]) => {
|
||||||
@ -155,7 +155,7 @@ const collectCheckedWithParents = (nodes: TreeNodeType[], checked: string[]): st
|
|||||||
|
|
||||||
nodes.forEach(root => dfs(root, []));
|
nodes.forEach(root => dfs(root, []));
|
||||||
return Array.from(result);
|
return Array.from(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 提交校验
|
// 提交校验
|
||||||
const handleOk = async () => {
|
const handleOk = async () => {
|
||||||
@ -248,6 +248,7 @@ const collectCheckedWithParents = (nodes: TreeNodeType[], checked: string[]): st
|
|||||||
required
|
required
|
||||||
rules={[{ required: true, message: '请选择品类' }]}
|
rules={[{ required: true, message: '请选择品类' }]}
|
||||||
>
|
>
|
||||||
|
<div style={{ maxHeight: 200, overflow: 'auto', border: '1px solid #f0f0f0', borderRadius: 4, padding: 8 }}>
|
||||||
<Tree
|
<Tree
|
||||||
checkable
|
checkable
|
||||||
selectable={false}
|
selectable={false}
|
||||||
@ -257,6 +258,7 @@ const collectCheckedWithParents = (nodes: TreeNodeType[], checked: string[]): st
|
|||||||
onExpand={setExpandedKeys as any}
|
onExpand={setExpandedKeys as any}
|
||||||
onCheck={handleTreeCheck}
|
onCheck={handleTreeCheck}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
<span style={{ color: '#888', marginLeft: 4, fontWeight: 400, fontSize: 12 }}>
|
<span style={{ color: '#888', marginLeft: 4, fontWeight: 400, fontSize: 12 }}>
|
||||||
(注:同一级品类不可多选)
|
(注:同一级品类不可多选)
|
||||||
</span>
|
</span>
|
||||||
|
@ -229,11 +229,11 @@ const CategoryLibraryManage: React.FC = () => {
|
|||||||
<Button className="buttonReset" icon={<DeleteOutlined />} onClick={handleReset} >重置</Button>
|
<Button className="buttonReset" icon={<DeleteOutlined />} onClick={handleReset} >重置</Button>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item style={{ marginLeft: 'auto' }}>
|
{/* <Form.Item style={{ marginLeft: 'auto' }}>
|
||||||
<Button className="buttonFunctionBlock" type="primary" onClick={() => setAddVisible(true)} >
|
<Button className="buttonFunctionBlock" type="primary" onClick={() => setAddVisible(true)} >
|
||||||
新增
|
新增
|
||||||
</Button>
|
</Button>
|
||||||
</Form.Item>
|
</Form.Item> */}
|
||||||
|
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,7 +10,26 @@ export async function getCaptcha() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 招标代理
|
||||||
|
*/
|
||||||
|
export async function accountLogin (data: API.LoginSupplier) {
|
||||||
|
return request('/v1/login/accountLogin', {
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 专家
|
||||||
|
*/
|
||||||
|
export async function expertLogin (data: API.LoginSupplier) {
|
||||||
|
return request('/v1/login/expertLogin', {
|
||||||
|
method: 'POST',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 供应商
|
||||||
*/
|
*/
|
||||||
export async function supplierLogin (data: API.LoginSupplier) {
|
export async function supplierLogin (data: API.LoginSupplier) {
|
||||||
return request('/v1/login/accountLogin/supplier', {
|
return request('/v1/login/accountLogin/supplier', {
|
||||||
|
Reference in New Issue
Block a user