Merge branch '20230331-生产合作方运维登录短信验证码接口改造' into 'release_20230331'

3.31 生产合作方运维登录短信验证码接口改造

See merge request eshop/fe_service_ebtp_frontend!199
This commit is contained in:
jl-zhoujl2
2023-03-31 13:56:31 +00:00
3 changed files with 27 additions and 16 deletions

View File

@ -75,13 +75,12 @@ const LoginItem: React.FC<LoginItemProps> = (props) => {
...restProps ...restProps
} = props; } = props;
const onGetCaptcha = useCallback(async (mobile: string) => { const onGetCaptcha = useCallback(async (values: any) => {
const result = await getFakeCaptcha(mobile); const result = await getFakeCaptcha(values);
if (result === false) { if (result?.success) {
return;
}
message.success('获取验证码成功!'); message.success('获取验证码成功!');
setTiming(true); setTiming(true);
}
}, []); }, []);
useEffect(() => { useEffect(() => {
@ -127,8 +126,8 @@ const LoginItem: React.FC<LoginItemProps> = (props) => {
className={styles.getCaptcha} className={styles.getCaptcha}
size="large" size="large"
onClick={() => { onClick={() => {
validateFields(['mobile']).then(values => { validateFields(['mobile', 'code', 'tmpToken']).then(values => {
const value = values?.mobile; const value = { strmobileNumber: values?.mobile, code: values?.code, codeKey: values?.tmpToken };
onGetCaptcha(value); onGetCaptcha(value);
}) })
}} }}

View File

@ -35,8 +35,9 @@ const Login: React.FC<LoginProps> = (props) => {
const [type, setType] = useState<string>('account'); const [type, setType] = useState<string>('account');
const [dis, disSet] = useState<boolean>(false); const [dis, disSet] = useState<boolean>(false);
const [imgUrl, setImgUrl] = useState<any>(''); const [imgUrl, setImgUrl] = useState<any>('');
const [tmpToken, setTmpToken] = useState<any>(''); // const [tmpToken, setTmpToken] = useState<any>('');
const remainingTime = 3 //刷新token的剩余时间单位小时 const remainingTime = 3 //刷新token的剩余时间单位小时
const [form] = Form.useForm();
const genRandomString = (len: number) => { const genRandomString = (len: number) => {
const text = 'abcdefghijklmnopqrstuvwxyz0123456789'; const text = 'abcdefghijklmnopqrstuvwxyz0123456789';
@ -48,7 +49,7 @@ const Login: React.FC<LoginProps> = (props) => {
const changeCaptcha = () => { const changeCaptcha = () => {
let tmpToken = genRandomString(16); let tmpToken = genRandomString(16);
let url = '/api/auth/captcha?token=' + tmpToken; let url = '/api/auth/captcha?token=' + tmpToken;
setTmpToken(tmpToken); form.setFieldsValue({ tmpToken });
setImgUrl(url); setImgUrl(url);
}; };
useEffect(() => { useEffect(() => {
@ -109,7 +110,7 @@ const Login: React.FC<LoginProps> = (props) => {
}) })
} else { } else {
disSet(true); disSet(true);
await CooperfakeAccountLogin({ ...values, tmpToken }).then((res) => { await CooperfakeAccountLogin({ ...values }).then((res) => {
if (res?.success) { if (res?.success) {
if (moment(res?.data?.expiration).diff(moment(), 'hours') < remainingTime) { if (moment(res?.data?.expiration).diff(moment(), 'hours') < remainingTime) {
refreshToken(res?.data) refreshToken(res?.data)
@ -137,7 +138,7 @@ const Login: React.FC<LoginProps> = (props) => {
/> />
</div> </div>
<LoginForm activeKey={type} onTabChange={setType} onSubmit={handleSubmit}> <LoginForm activeKey={type} onTabChange={setType} onSubmit={handleSubmit} from={form}>
<Tab key="account" tab="账号密码登录"> <Tab key="account" tab="账号密码登录">
{status === 'error' && loginType === 'account' && !submitting && ( {status === 'error' && loginType === 'account' && !submitting && (
<LoginMessage content="账号或密码错误" /> <LoginMessage content="账号或密码错误" />
@ -172,8 +173,21 @@ const Login: React.FC<LoginProps> = (props) => {
}, },
]} ]}
/> />
<Form.Item name="tmpToken" hidden>
<Input />
</Form.Item>
{START_ENV == 'sim' || START_ENV == 'PROD' ? ( {START_ENV == 'sim' || START_ENV == 'PROD' ? (
<> <>
<Row>
<Col span={12}>
<Form.Item name="code" rules={[{ required: true, message: '请输入验证码' }]}>
<Input size='large' placeholder="验证码" />
</Form.Item>
</Col>
<Col span={12} style={{ lineHeight: '33.11px' }}>
<Image src={imgUrl} preview={false} onClick={() => changeCaptcha()} />
</Col>
</Row>
<Mobile <Mobile
name="mobile" name="mobile"
placeholder="手机号" placeholder="手机号"
@ -191,7 +205,7 @@ const Login: React.FC<LoginProps> = (props) => {
<Captcha <Captcha
name="captcha" name="captcha"
placeholder="验证码" placeholder="验证码"
countDown={60} countDown={30}
getCaptchaButtonText="" getCaptchaButtonText=""
getCaptchaSecondText="秒" getCaptchaSecondText="秒"
rules={[ rules={[

View File

@ -118,9 +118,7 @@ export async function getPassword(params: any) { // 获取后台验证码接口
export async function getFakeCaptcha(params: any) { export async function getFakeCaptcha(params: any) {
return request('/api/notification/v1/notification/savaSmsByPhoneNew', { return request('/api/notification/v1/notification/savaSmsByPhoneNew', {
method: 'POST', method: 'POST',
data: { data: { ...params },
strmobileNumber: params
},
requestType: 'json', requestType: 'json',
}); });
} }