Skip to content

Commit f5c8ddf

Browse files
committed
feat: 登录二次验证切换为 tianai
1 parent 9e40ab8 commit f5c8ddf

File tree

9 files changed

+356
-828
lines changed

9 files changed

+356
-828
lines changed

public/captcha-tianai.png

14.8 KB
Loading

src/components/Captcha/index.css

Lines changed: 58 additions & 297 deletions
Large diffs are not rendered by default.

src/components/Captcha/index.tsx

Lines changed: 260 additions & 339 deletions
Large diffs are not rendered by default.

src/components/Captcha/typings.ts

Lines changed: 1 addition & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,5 @@
11
export interface CaptchaProps {
22
isSlideShow: boolean;
33
close: () => void;
4-
success: (captchaVerification: string) => void;
4+
success: (params: Record<string, any>) => void;
55
}
6-
7-
export interface CaptchaState {
8-
mode: string;
9-
vSpace: number;
10-
imgSize: {
11-
width: number;
12-
height: number;
13-
};
14-
barSize: {
15-
width: number;
16-
height: number;
17-
};
18-
blockSize: {
19-
width: number;
20-
height: number;
21-
};
22-
setSize: {
23-
imgHeight: number;
24-
imgWidth: number;
25-
barHeight: number;
26-
barWidth: number;
27-
};
28-
// 验证码背景图片
29-
backImgBase: string;
30-
// 验证滑块的背景图片
31-
blockBackImgBase: string;
32-
// 后端返回的唯一token值
33-
backToken: string;
34-
// 移动开始的时间
35-
startMoveTime: number;
36-
// 移动结束的时间
37-
endMoveTime: number;
38-
// 提示词的背景颜色
39-
tipsBackColor: string;
40-
// 后端返回的加密秘钥 字段
41-
secretKey: string;
42-
captchaType: 'blockPuzzle' | 'clickWord';
43-
moveBlockBackgroundColor: string;
44-
leftBarBorderColor: string;
45-
iconColor: string;
46-
barAreaLeft: number;
47-
barAreaOffsetWidth: number;
48-
startLeft: number;
49-
moveBlockLeft: any;
50-
leftBarWidth: any;
51-
// 鼠标状态
52-
status: boolean;
53-
// 是够验证完成
54-
isEnd: boolean;
55-
passFlag: boolean;
56-
tipWords: string;
57-
text: string;
58-
finishText: string;
59-
transitionWidth?: string;
60-
transitionLeft?: string;
61-
iconClass: string;
62-
move: (e: any) => void;
63-
end: () => void;
64-
}
65-
66-
export const captchaStateInit: CaptchaState = {
67-
mode: 'fixed',
68-
vSpace: 5,
69-
imgSize: {
70-
width: 330,
71-
height: 155,
72-
},
73-
barSize: {
74-
width: 310,
75-
height: 40,
76-
},
77-
blockSize: {
78-
width: 50,
79-
height: 50,
80-
},
81-
setSize: {
82-
imgHeight: 155,
83-
imgWidth: 330,
84-
barHeight: 40,
85-
barWidth: 310,
86-
},
87-
// 验证码背景图片
88-
backImgBase: '',
89-
// 验证滑块的背景图片
90-
blockBackImgBase: '',
91-
// 后端返回的唯一token值
92-
backToken: '',
93-
// 移动开始的时间
94-
startMoveTime: 0,
95-
// 移动结束的时间
96-
endMoveTime: 0,
97-
// 提示词的背景颜色
98-
tipsBackColor: '',
99-
// 后端返回的加密秘钥 字段
100-
secretKey: '',
101-
captchaType: 'blockPuzzle',
102-
moveBlockBackgroundColor: 'rgb(255, 255, 255)',
103-
leftBarBorderColor: '',
104-
iconColor: '',
105-
barAreaLeft: 0,
106-
barAreaOffsetWidth: 0,
107-
startLeft: 0,
108-
moveBlockLeft: null,
109-
leftBarWidth: null,
110-
// 鼠标状态
111-
status: false,
112-
// 是够验证完成
113-
isEnd: false,
114-
passFlag: false,
115-
tipWords: '',
116-
finishText: '',
117-
iconClass: 'icon-right',
118-
text: '',
119-
move: () => {},
120-
end: () => {},
121-
};

src/pages/user/Login/index.tsx

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import VerifySlide from '@/components/Captcha';
2+
import type { LoginParams } from '@/services/ballcat/login';
3+
import { login } from '@/services/ballcat/login';
4+
import { User, Token } from '@/utils/Ballcat';
5+
import { settings } from '@/utils/ConfigUtils';
6+
import { pwd } from '@/utils/Encrypt';
7+
import I18n from '@/utils/I18nUtils';
18
import {
29
AlipayCircleOutlined,
310
LockOutlined,
@@ -6,21 +13,14 @@ import {
613
UserOutlined,
714
WeiboCircleOutlined,
815
} from '@ant-design/icons';
9-
import { Alert, message, Space, Tabs } from 'antd';
10-
import React, { useState } from 'react';
1116
import ProForm, { ProFormCaptcha, ProFormCheckbox, ProFormText } from '@ant-design/pro-form';
17+
import { Alert, message, Space, Tabs, Modal } from 'antd';
18+
import React, { useState } from 'react';
19+
import { useAliveController } from 'react-activation';
1220
import { history, Link, SelectLang, useIntl, useModel } from 'umi';
13-
import type { LoginParams } from '@/services/ballcat/login';
14-
import { login } from '@/services/ballcat/login';
15-
import { pwd } from '@/utils/Encrypt';
16-
import VerifySlide from '@/components/Captcha';
17-
import { User, Token } from '@/utils/Ballcat';
18-
import { settings } from '@/utils/ConfigUtils';
19-
import I18n from '@/utils/I18nUtils';
2021

2122
// @ts-ignore
2223
import styles from './index.less';
23-
import { useAliveController } from 'react-activation';
2424

2525
const LoginMessage: React.FC<{
2626
content: string;
@@ -46,7 +46,7 @@ const Login: React.FC = () => {
4646
const [type, setType] = useState<string>('account');
4747
// 是否使用登录验证码
4848
const [captcha] = useState<boolean>(true);
49-
const [captchaSow, setCaptchaSow] = useState<boolean>(false);
49+
const [captchaShow, setCaptchaShow] = useState<boolean>(false);
5050
const [loginParams, setLoginParams] = useState<LoginParams>({});
5151
const [vs, setVs] = useState<VerifySlide | null>(null);
5252

@@ -95,7 +95,7 @@ const Login: React.FC = () => {
9595
return;
9696
}
9797
// 弹出验证码框
98-
setCaptchaSow(true);
98+
setCaptchaShow(true);
9999
vs.refresh();
100100
} else {
101101
await loginHandler(values);
@@ -109,20 +109,27 @@ const Login: React.FC = () => {
109109
<div hidden={!settings.i18n} className={styles.lang} data-lang>
110110
{SelectLang && <SelectLang />}
111111
</div>
112-
{captcha && (
112+
113+
<Modal
114+
closable={false}
115+
visible={captcha && captchaShow}
116+
forceRender={true}
117+
footer={false}
118+
onCancel={() => setCaptchaShow(false)}
119+
width={278}
120+
bodyStyle={{ padding: 0 }}
121+
>
113122
<VerifySlide
114-
ref={(ref) => {
115-
setVs(ref);
116-
}}
117-
isSlideShow={captchaSow}
123+
ref={setVs}
124+
isSlideShow={captchaShow}
118125
close={() => {
119-
setCaptchaSow(false);
126+
setCaptchaShow(false);
120127
}}
121-
success={async (captchaVerification) => {
122-
loginHandler({ ...loginParams, captchaVerification });
128+
success={async (params) => {
129+
loginHandler({ ...loginParams, ...params });
123130
}}
124131
/>
125-
)}
132+
</Modal>
126133
<div className={styles.content}>
127134
<div className={styles.top}>
128135
<div className={styles.header}>

src/services/ballcat/login/typings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export type LoginParams = {
55
type?: string;
66
grant_type?: string;
77
captchaVerification?: string;
8+
captchaId?: string;
89
};

src/services/captcha/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ import { request } from 'umi';
33
/**
44
* 获取验证码
55
*/
6-
export async function get(body: CAPTCHA.GetParams) {
7-
return request<CAPTCHA.Info>('captcha/get', {
8-
method: 'POST',
9-
data: body,
6+
export async function captchaGet(body: any) {
7+
return request<any>('captcha/tianai/gen', {
8+
method: 'GET',
9+
params: body,
1010
});
1111
}
1212

1313
/**
1414
* 校验
1515
*/
16-
export async function valid(body: CAPTCHA.ValidParams) {
17-
return request<CAPTCHA.ValidRes>('captcha/check', {
16+
export async function captchaValid(params: any, body: any) {
17+
return request<any>('captcha/tianai/check', {
1818
method: 'POST',
19+
params,
1920
data: body,
2021
});
2122
}

src/services/captcha/typings.d.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/utils/RequestConfig.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const customerResponseInterceptor: ResponseInterceptor = async (res, option) =>
5353

5454
if (option.url) {
5555
// 部分接口特殊处理
56-
if (option.url === 'captcha/get' || option.url === 'captcha/check') {
56+
if (option.url.startsWith('captcha/')) {
5757
return response;
5858
}
5959
}

0 commit comments

Comments
 (0)