登录
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>
|
||||
|
@ -56,8 +56,8 @@ const ExpertRegister: React.FC = () => {
|
||||
<div className="register-page">
|
||||
<div className="register-container">
|
||||
<div className="back-home">
|
||||
<a onClick={() => history.push('/index')}>
|
||||
<HomeOutlined /> {intl.formatMessage({ id: 'login.back.home' })}
|
||||
<a onClick={() => history.push('/login')}>
|
||||
<HomeOutlined /> 返回
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
@ -128,8 +128,8 @@ const SupplierRegister: React.FC<supplierWithInputProps> = (props) => {
|
||||
{!supplierWithInput && (
|
||||
<>
|
||||
<div className="back-home">
|
||||
<a onClick={() => history.push('/index')}>
|
||||
<HomeOutlined /> {intl.formatMessage({ id: 'login.back.home' })}
|
||||
<a onClick={() => history.push('/login')}>
|
||||
<HomeOutlined /> 返回
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
@ -136,27 +136,27 @@ const CategoryAddModal: React.FC<Props> = ({ visible, onCancel, onSuccess }) =>
|
||||
const handleTreeCheck = (checkedKeysValue: any) => {
|
||||
const onlyOneEachLevel = checkedKeysValue;
|
||||
|
||||
console.log(onlyOneEachLevel,'onlyOneEachLevel');
|
||||
|
||||
console.log(onlyOneEachLevel, 'onlyOneEachLevel');
|
||||
|
||||
setCheckedKeys(onlyOneEachLevel);
|
||||
form.setFieldsValue({ categoryKeys: onlyOneEachLevel });
|
||||
};
|
||||
// 从树中获取所有选中节点及其父级节点
|
||||
const collectCheckedWithParents = (nodes: TreeNodeType[], checked: string[]): string[] => {
|
||||
const result = new Set<string>();
|
||||
const collectCheckedWithParents = (nodes: TreeNodeType[], checked: string[]): string[] => {
|
||||
const result = new Set<string>();
|
||||
|
||||
const dfs = (node: TreeNodeType, parents: string[]) => {
|
||||
if (checked.includes(node.key)) {
|
||||
result.add(node.key);
|
||||
parents.forEach(pid => result.add(pid)); // 加入所有父级
|
||||
}
|
||||
node.children?.forEach(child => dfs(child, [...parents, node.key]));
|
||||
const dfs = (node: TreeNodeType, parents: string[]) => {
|
||||
if (checked.includes(node.key)) {
|
||||
result.add(node.key);
|
||||
parents.forEach(pid => result.add(pid)); // 加入所有父级
|
||||
}
|
||||
node.children?.forEach(child => dfs(child, [...parents, node.key]));
|
||||
};
|
||||
|
||||
nodes.forEach(root => dfs(root, []));
|
||||
return Array.from(result);
|
||||
};
|
||||
|
||||
nodes.forEach(root => dfs(root, []));
|
||||
return Array.from(result);
|
||||
};
|
||||
|
||||
// 提交校验
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
@ -248,15 +248,17 @@ const collectCheckedWithParents = (nodes: TreeNodeType[], checked: string[]): st
|
||||
required
|
||||
rules={[{ required: true, message: '请选择品类' }]}
|
||||
>
|
||||
<Tree
|
||||
checkable
|
||||
selectable={false}
|
||||
treeData={treeData}
|
||||
checkedKeys={checkedKeys}
|
||||
expandedKeys={expandedKeys}
|
||||
onExpand={setExpandedKeys as any}
|
||||
onCheck={handleTreeCheck}
|
||||
/>
|
||||
<div style={{ maxHeight: 200, overflow: 'auto', border: '1px solid #f0f0f0', borderRadius: 4, padding: 8 }}>
|
||||
<Tree
|
||||
checkable
|
||||
selectable={false}
|
||||
treeData={treeData}
|
||||
checkedKeys={checkedKeys}
|
||||
expandedKeys={expandedKeys}
|
||||
onExpand={setExpandedKeys as any}
|
||||
onCheck={handleTreeCheck}
|
||||
/>
|
||||
</div>
|
||||
<span style={{ color: '#888', marginLeft: 4, fontWeight: 400, fontSize: 12 }}>
|
||||
(注:同一级品类不可多选)
|
||||
</span>
|
||||
|
@ -229,11 +229,11 @@ const CategoryLibraryManage: React.FC = () => {
|
||||
<Button className="buttonReset" icon={<DeleteOutlined />} onClick={handleReset} >重置</Button>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item style={{ marginLeft: 'auto' }}>
|
||||
{/* <Form.Item style={{ marginLeft: 'auto' }}>
|
||||
<Button className="buttonFunctionBlock" type="primary" onClick={() => setAddVisible(true)} >
|
||||
新增
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form.Item> */}
|
||||
|
||||
</Form>
|
||||
</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) {
|
||||
return request('/v1/login/accountLogin/supplier', {
|
||||
|
Reference in New Issue
Block a user