flat: 对接爱山东登录
This commit is contained in:
@@ -217,9 +217,12 @@ export async function render(oldRender: () => void) {
|
|||||||
const checkRegion = 5 * 60 * 1000;
|
const checkRegion = 5 * 60 * 1000;
|
||||||
export const request = {
|
export const request = {
|
||||||
...errorConfig,
|
...errorConfig,
|
||||||
baseURL: process.env.NODE_ENV === 'development' ? '' : 'https://qd.zhaopinzao8dian.com/api',
|
// baseURL: process.env.NODE_ENV === 'development' ? '' : 'https://qd.zhaopinzao8dian.com/api',
|
||||||
// baseURL: 'http://39.98.44.136:8080',
|
// baseURL: 'http://39.98.44.136:8080',
|
||||||
// baseURL: process.env.NODE_ENV === 'development' ? '' : 'http://10.213.6.207:19010/api',
|
baseURL:
|
||||||
|
process.env.NODE_ENV === 'development'
|
||||||
|
? 'http://10.213.6.207:19010'
|
||||||
|
: 'http://10.213.6.207:19010/api',
|
||||||
requestInterceptors: [
|
requestInterceptors: [
|
||||||
(url: any, options: { headers: any }) => {
|
(url: any, options: { headers: any }) => {
|
||||||
const headers = options.headers ? options.headers : [];
|
const headers = options.headers ? options.headers : [];
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Footer from '@/components/Footer';
|
import Footer from '@/components/Footer';
|
||||||
import { getCaptchaImg, login } from '@/services/system/auth';
|
import { getCaptchaImg, login } from '@/services/system/auth';
|
||||||
import { getFakeCaptcha } from '@/services/ant-design-pro/login';
|
import { getFakeCaptcha, sancGenerateQrcode, sancAuthCheck } from '@/services/ant-design-pro/login';
|
||||||
import {
|
import {
|
||||||
AlipayCircleOutlined,
|
AlipayCircleOutlined,
|
||||||
LockOutlined,
|
LockOutlined,
|
||||||
@@ -25,7 +25,9 @@ import { flushSync } from 'react-dom';
|
|||||||
import { clearSessionToken, setSessionToken } from '@/access';
|
import { clearSessionToken, setSessionToken } from '@/access';
|
||||||
import logoImg from '@/assets/logo.svg';
|
import logoImg from '@/assets/logo.svg';
|
||||||
import login_imge2b033b1 from '@/assets/login_img.e2b033b1.png';
|
import login_imge2b033b1 from '@/assets/login_img.e2b033b1.png';
|
||||||
|
import { use } from 'echarts';
|
||||||
|
|
||||||
|
let timer: any = null;
|
||||||
const ActionIcons = () => {
|
const ActionIcons = () => {
|
||||||
const langClassName = useEmotionCss(({ token }) => {
|
const langClassName = useEmotionCss(({ token }) => {
|
||||||
return {
|
return {
|
||||||
@@ -93,7 +95,9 @@ const Login: React.FC = () => {
|
|||||||
const { initialState, setInitialState } = useModel('@@initialState');
|
const { initialState, setInitialState } = useModel('@@initialState');
|
||||||
const [captchaCode, setCaptchaCode] = useState<string>('');
|
const [captchaCode, setCaptchaCode] = useState<string>('');
|
||||||
const [uuid, setUuid] = useState<string>('');
|
const [uuid, setUuid] = useState<string>('');
|
||||||
const [qrcodeVal, setQrcodeVal] = useState<string>('7655212');
|
const [qrcodeVal, setQrcodeVal] = useState<string>('');
|
||||||
|
const [qrcodeTime, setQrcodeTime] = useState<string>('');
|
||||||
|
const [qrcodeStatus, setQrcodeStatus] = useState<string>('loading');
|
||||||
|
|
||||||
const containerClassName = useEmotionCss(() => {
|
const containerClassName = useEmotionCss(() => {
|
||||||
return {
|
return {
|
||||||
@@ -155,15 +159,81 @@ const Login: React.FC = () => {
|
|||||||
getCaptchaCode();
|
getCaptchaCode();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// message.error(response.msg);
|
|
||||||
const defaultLoginFailureMessage = intl.formatMessage({
|
const defaultLoginFailureMessage = intl.formatMessage({
|
||||||
id: 'pages.login.failure',
|
id: 'pages.login.failure',
|
||||||
defaultMessage: '登录失败,请重试!',
|
defaultMessage: '登录失败,请重试!',
|
||||||
});
|
});
|
||||||
// console.log(error);
|
|
||||||
message.error(defaultLoginFailureMessage);
|
message.error(defaultLoginFailureMessage);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const generateQrcode = async () => {
|
||||||
|
setQrcodeStatus('loading');
|
||||||
|
const response = await sancGenerateQrcode();
|
||||||
|
if (response.code === 200) {
|
||||||
|
const { qrCode, validDate } = response.data;
|
||||||
|
setQrcodeStatus('active');
|
||||||
|
setQrcodeVal(qrCode);
|
||||||
|
setQrcodeTime(validDate);
|
||||||
|
if (timer) {
|
||||||
|
clearInterval(timer);
|
||||||
|
}
|
||||||
|
timer = setInterval(() => {
|
||||||
|
const timeDiff = getTimeDiff(validDate);
|
||||||
|
if (timeDiff > 0) {
|
||||||
|
clearInterval(timer);
|
||||||
|
setQrcodeStatus('expired');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
checkQrcode(qrCode as string);
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkQrcode = async (text: string) => {
|
||||||
|
const response = await sancAuthCheck(text);
|
||||||
|
if (response.code === 200) {
|
||||||
|
const { authStatus } = response.data;
|
||||||
|
switch (authStatus) {
|
||||||
|
case 'success':
|
||||||
|
setQrcodeStatus('scanned');
|
||||||
|
message.success('扫码成功');
|
||||||
|
const defaultLoginSuccessMessage = intl.formatMessage({
|
||||||
|
id: 'pages.login.success',
|
||||||
|
defaultMessage: '登录成功!',
|
||||||
|
});
|
||||||
|
const current = new Date();
|
||||||
|
const expireTime = current.setTime(current.getTime() + 1000 * 12 * 60 * 60);
|
||||||
|
setSessionToken(response.data?.token, response.data?.token, expireTime);
|
||||||
|
message.success(defaultLoginSuccessMessage);
|
||||||
|
await fetchUserInfo();
|
||||||
|
const urlParams = new URL(window.location.href).searchParams;
|
||||||
|
history.push(urlParams.get('redirect') || '/');
|
||||||
|
setTimeout(() => history.go(0), 0);
|
||||||
|
break;
|
||||||
|
case 'failed':
|
||||||
|
setQrcodeStatus('expired');
|
||||||
|
message.error(response.data.errCode + ':' + response.data.errMsg);
|
||||||
|
break;
|
||||||
|
case 'pending':
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
clearInterval(timer);
|
||||||
|
setQrcodeStatus('expired');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function getTimeDiff(validTimeStr: string): number {
|
||||||
|
const now = new Date();
|
||||||
|
const [h, m, s] = validTimeStr.split(':').map(Number);
|
||||||
|
|
||||||
|
const target = new Date();
|
||||||
|
target.setHours(h, m, s, 0);
|
||||||
|
|
||||||
|
return now.getTime() - target.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
const { code } = userLoginState;
|
const { code } = userLoginState;
|
||||||
const loginType = type;
|
const loginType = type;
|
||||||
|
|
||||||
@@ -215,7 +285,15 @@ const Login: React.FC = () => {
|
|||||||
>
|
>
|
||||||
<Tabs
|
<Tabs
|
||||||
activeKey={type}
|
activeKey={type}
|
||||||
onChange={setType}
|
onChange={(type) => {
|
||||||
|
setType(type);
|
||||||
|
if (timer) {
|
||||||
|
clearInterval(timer);
|
||||||
|
}
|
||||||
|
if (type === 'scanQode') {
|
||||||
|
generateQrcode();
|
||||||
|
}
|
||||||
|
}}
|
||||||
centered
|
centered
|
||||||
items={[
|
items={[
|
||||||
{
|
{
|
||||||
@@ -256,7 +334,9 @@ const Login: React.FC = () => {
|
|||||||
errorLevel="H"
|
errorLevel="H"
|
||||||
size={300}
|
size={300}
|
||||||
iconSize={300 / 5}
|
iconSize={300 / 5}
|
||||||
value="https://ant.design/"
|
status={qrcodeStatus}
|
||||||
|
onRefresh={() => generateQrcode()}
|
||||||
|
value={qrcodeVal}
|
||||||
icon={login_imge2b033b1}
|
icon={login_imge2b033b1}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
@@ -36,3 +36,20 @@ export async function outLogin(options?: { [key: string]: any }) {
|
|||||||
...(options || {}),
|
...(options || {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** 登录接口 POST /api/login/outLogin */
|
||||||
|
export async function sancGenerateQrcode() {
|
||||||
|
return request<Record<string, any>>('/api/essc/generateQrcode', {
|
||||||
|
method: 'POST',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function sancAuthCheck(qrCode: string) {
|
||||||
|
return request<Record<string, any>>('/api/essc/authCheck', {
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
qrCode
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user