Commit d431b5d6 authored by 涂伟's avatar 涂伟

feat: '运维登录新增验证码验证'

parent 3efe3026
Pipeline #93976 passed with stages
import React from 'react'; import React, { useState, useEffect } from 'react';
import { Form, Input } from 'antd'; import { Form, Input } from 'antd';
import { FieldNumberOutlined, ReloadOutlined } from '@ant-design/icons';
import LoginContext from './LoginContext'; import LoginContext from './LoginContext';
import ItemMap from './map'; import ItemMap from './map';
import styles from './index.less';
const FormItem = Form.Item; const FormItem = Form.Item;
...@@ -25,6 +27,52 @@ const getFormItemOptions = ({ ...@@ -25,6 +27,52 @@ const getFormItemOptions = ({
return options; return options;
}; };
const ValidateCode = props => {
const [count, setCount] = useState(0);
const codeUrl = '/PandaOMS/OMS/GetVerificationCode';
useEffect(() => {
window.myGlobalHandError = function() {
handError();
};
return () => {
delete window.myGlobalHandError;
};
}, []);
const handError = () => {
setCount(Date.now());
};
const handeRefresh = () => {
setCount(Date.now());
};
const handChange = value => {
props?.onChange?.(value);
};
return (
<div className={styles.validate_view}>
<Input
size={props.size || 'large'}
prefix={props?.prefix || <FieldNumberOutlined />}
className={styles.validate_input}
value={props.value || ''}
placeholder={props?.placeholder || '请输入验证码'}
onChange={handChange}
/>
<div className={styles.validate_img}>
<img src={`${codeUrl}?time=${count}`} alt="" />
<div className={styles.validate_refresh} onClick={handeRefresh}>
<ReloadOutlined />
</div>
</div>
</div>
);
};
const LoginItem = props => { const LoginItem = props => {
const { const {
onChange, onChange,
...@@ -36,6 +84,9 @@ const LoginItem = props => { ...@@ -36,6 +84,9 @@ const LoginItem = props => {
...restProps ...restProps
} = props; } = props;
console.log(type,name,'666666666666666666');
if (!name) { if (!name) {
return null; return null;
} }
...@@ -43,6 +94,14 @@ const LoginItem = props => { ...@@ -43,6 +94,14 @@ const LoginItem = props => {
const options = getFormItemOptions(props); const options = getFormItemOptions(props);
const otherProps = restProps || {}; const otherProps = restProps || {};
if (type === 'Validate') {
return (
<Form.Item name={name} {...options}>
<ValidateCode {...customProps} {...otherProps} />
</Form.Item>
);
}
return ( return (
<FormItem name={name} {...options}> <FormItem name={name} {...options}>
<Input {...customProps} {...otherProps} /> <Input {...customProps} {...otherProps} />
......
...@@ -41,5 +41,6 @@ Login.UserName = LoginItem.UserName; ...@@ -41,5 +41,6 @@ Login.UserName = LoginItem.UserName;
Login.Password = LoginItem.Password; Login.Password = LoginItem.Password;
Login.Mobile = LoginItem.Mobile; Login.Mobile = LoginItem.Mobile;
Login.Captcha = LoginItem.Captcha; Login.Captcha = LoginItem.Captcha;
Login.Validate = LoginItem.Validate;
export default Login; export default Login;
...@@ -46,4 +46,52 @@ ...@@ -46,4 +46,52 @@
width: 100%; width: 100%;
margin-top: 24px; margin-top: 24px;
} }
.validate_view {
display: flex;
align-items: center;
.validate_input {
flex: 1;
margin-right: 20px;
}
.validate_img {
width: 92px;
height: 40px;
flex: none;
position: relative;
cursor: pointer;
border: 1px solid #d9d9d9;
border-radius: 2px;
&:hover {
.validate_refresh {
opacity: 1;
background-color: rgba(238, 238, 238, 0.7);
}
}
img {
width: 100%;
height: 100%;
// object-fit: contain;
}
.validate_refresh {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
z-index: 1;
display: flex;
opacity: 0;
align-items: center;
justify-content: center;
cursor: pointer;
color: #666666;
}
}
}
} }
\ No newline at end of file
import React from 'react'; import React from 'react';
import { LockTwoTone, MailTwoTone, MobileTwoTone, UserOutlined } from '@ant-design/icons'; import {
LockTwoTone,
MailTwoTone,
MobileTwoTone,
UserOutlined,
FieldNumberOutlined,
} from '@ant-design/icons';
import styles from './index.less'; import styles from './index.less';
...@@ -71,4 +77,25 @@ export default { ...@@ -71,4 +77,25 @@ export default {
}, },
], ],
}, },
Validate: {
props: {
size: 'large',
id: 'validate',
prefix: (
<FieldNumberOutlined
style={{
color: '#1890ff',
}}
className={styles.prefixIcon}
/>
),
placeholder: '请输入验证码',
},
rules: [
{
required: true,
message: '请输入验证码!',
},
],
},
}; };
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Alert, notification } from 'antd'; import { Alert, notification } from 'antd';
import { OMSLogin } from '@/services/user/api'; import { OMSLogin, IsOpenVerificationCodeValidation } from '@/services/user/api';
import { gateWayConfig, GetGateWay } from '@/services/common/api'; import { gateWayConfig, GetGateWay } from '@/services/common/api';
import { AUTHORITY, USER_MODE } from '@/utils/constants'; import { AUTHORITY, USER_MODE } from '@/utils/constants';
import { appConnector } from '@/containers/App/store'; import { appConnector } from '@/containers/App/store';
...@@ -10,7 +10,7 @@ import LoginForm from './components/Login'; ...@@ -10,7 +10,7 @@ import LoginForm from './components/Login';
import styles from './style.less'; import styles from './style.less';
import { SysConfiguration } from '@/services/userManage/api'; import { SysConfiguration } from '@/services/userManage/api';
import { setAuthority } from '@/utils/authority'; import { setAuthority } from '@/utils/authority';
const { UserName, Password, Submit } = LoginForm; const { UserName, Password, Validate, Submit } = LoginForm;
const LoginMessage = ({ content }) => ( const LoginMessage = ({ content }) => (
<Alert <Alert
...@@ -31,8 +31,10 @@ const Login = props => { ...@@ -31,8 +31,10 @@ const Login = props => {
// const [autoLogin, setAutoLogin] = useState(true); // const [autoLogin, setAutoLogin] = useState(true);
const [type, setType] = useState('account'); const [type, setType] = useState('account');
const [pasType, setPasType] = useState(''); const [pasType, setPasType] = useState('');
const [showValidate, setShowValidate] = useState(false);
useEffect(() => { useEffect(() => {
isShowValidate();
passwordType(); passwordType();
}, []); }, []);
...@@ -43,12 +45,21 @@ const Login = props => { ...@@ -43,12 +45,21 @@ const Login = props => {
} }
}); });
}; };
const isShowValidate = () => {
IsOpenVerificationCodeValidation().then(res => {
if (res.code === 0) {
setShowValidate(res.data);
} else {
setShowValidate(false);
}
});
};
const handleSubmit = values => { const handleSubmit = values => {
/* eslint-disable no-console */ /* eslint-disable no-console */
console.log(values); // eg:{userName: "123", password: "123"} console.log(values); // eg:{userName: "123", password: "123"}
const { userName: loginName, password } = values; const { userName: loginName, password, validate } = values;
setLoading(true); setLoading(true);
OMSLogin(loginName, encipher(password, pasType ? pasType : '').toUpperCase(), 'CivManage') OMSLogin(loginName, encipher(password, pasType ? pasType : '').toUpperCase(), 'CivManage', validate)
.then(result => { .then(result => {
const { msg } = result; const { msg } = result;
...@@ -87,9 +98,11 @@ const Login = props => { ...@@ -87,9 +98,11 @@ const Login = props => {
message: msg || '没有权限!', message: msg || '没有权限!',
}); });
} }
window.myGlobalHandError();
setLoading(false); setLoading(false);
}) })
.catch(e => { .catch(e => {
window.myGlobalHandError();
setLoading(false); setLoading(false);
notification.error({ notification.error({
message: e.message || '没有权限!', message: e.message || '没有权限!',
...@@ -151,6 +164,18 @@ const Login = props => { ...@@ -151,6 +164,18 @@ const Login = props => {
}, },
]} ]}
/> />
{
showValidate && <Validate
name="validate"
placeholder="请输入验证码"
rules={[
{
required: true,
message: '请输入验证码!',
},
]}
/>
}
<div> <div>
{/* <Checkbox {/* <Checkbox
checked={autoLogin} checked={autoLogin}
......
...@@ -4,5 +4,7 @@ export const getUserInfo = param => get('/cityinterface/getUserinfo', param); ...@@ -4,5 +4,7 @@ export const getUserInfo = param => get('/cityinterface/getUserinfo', param);
export const login = param => get(`${CITY_SERVICE}/OMS.svc/L_GetCheckUser`, param); export const login = param => get(`${CITY_SERVICE}/OMS.svc/L_GetCheckUser`, param);
export const OMSLogin = (userName, password, systemType) => export const IsOpenVerificationCodeValidation = param => get(`${PUBLISH_SERVICE}/IsOpenVerificationCodeValidation`, param);
postForm(`${PUBLISH_SERVICE}/OMSLogin`, { userName, password, systemType });
export const OMSLogin = (userName, password, systemType, validate) =>
postForm(`${PUBLISH_SERVICE}/OMSLogin`, { userName, password, systemType, vcode: validate });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment