提交 9ca48c36 作者: 龚洪江

功能:首页二维码登录

上级 ae75f6b0
......@@ -26,10 +26,6 @@ body {
top:50%;
left: 50%;
transform: translate(-50%, -50%);
img{
width: 200px;
height: 200px;
}
}
}
.login-content {
......
import { Button, Checkbox, Form, Image, Input, message } from 'antd';
import { Button, Checkbox, Form, Image, Input, message, QRCode } from 'antd';
import { useEffect, useState } from 'react';
import { LockOutlined, UserOutlined } from '@ant-design/icons';
import { useNavigate } from 'react-router-dom';
......@@ -14,9 +14,11 @@ import qrCodeIcon from '~/assets/image/qr-code-icon.svg';
// 请求的类型
type ReqType = InterReqType<BackEndLoginType>;
//定时器暂存
let time: NodeJS.Timer;
function LoginView() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/ban-ts-comment
// @ts-ignore
const navigate = useNavigate();
// redux
const dispatch = useDispatch();
......@@ -28,8 +30,6 @@ function LoginView() {
const [randomLoginCode] = useState<string>(parseInt(String(Math.random() * 10001), 10) + '');
//小程序二维码地址
const [qrCodeUrl, setQrCodeUrl] = useState<string>('');
//定时器暂存
const [time, setTime] = useState<NodeJS.Timer>();
// 提交数据
const onFinish = async (values: ReqType) => {
......@@ -38,6 +38,7 @@ function LoginView() {
passWord: values?.passWord,
});
if (res && res.code === '200') {
message.success('登录成功');
const { token } = res.result;
await Cookies.set('SHAREFLY-TOKEN', token);
// 记住密码
......@@ -67,28 +68,40 @@ function LoginView() {
scene: `randomLoginCode=${randomLoginCode}&port=1`,
}).then(({ result }) => {
setQrCodeUrl(result ? `data:image/png;base64,${result}` : '');
setTime(
setInterval(() => {
getLoginInfo();
}, 1000),
);
time = setInterval(() => {
getLoginInfo();
}, 1000);
});
} else if (!isLoginCode && qrCodeUrl) {
setTime(
setInterval(() => {
getLoginInfo();
}, 1000),
);
time = setInterval(() => {
getLoginInfo();
}, 1000);
} else {
if (time) {
clearInterval(time);
}
}
setIsLoginCode(!isLoginCode);
};
//二维码登录
const getLoginInfo = () => {
CommonAPI.getLoginInfo({ randomLoginCode }).then(({ result }) => {});
CommonAPI.getLoginInfo({ randomLoginCode }).then(async ({ result, code }) => {
if (code === '200') {
clearInterval(time);
message.success('登录成功');
const { token } = result;
await Cookies.set('SHAREFLY-TOKEN', token);
dispatch(SET_USERINFO(result));
localStorage.setItem('roleId', result.roleInfo.id.toString());
authRouterList().then((value: any) => {
if (value.length) {
navigate({ pathname: value[0].children.find((v: any) => !v.meta.hidden)?.path });
} else {
message.warning('请先配置权限');
}
});
}
});
};
// componentDidMount
useEffect(() => {
......@@ -102,18 +115,25 @@ function LoginView() {
remember: Boolean(Cookies.get('remember')),
});
}, []);
return (
<div className='login-warp'>
<div className='login-view'>
<div className='login-flex login-content'>
<div className='login-title'>欢迎来到</div>
<div className='login-title'></div>
<div className='login-text'>云享飞管理平台</div>
<div className='login-detail'>让天空为世界所用</div>
</div>
<div className='login-flex login-form'>
{isLoginCode ? (
<div className='qr-code-wrap'>{<img src={qrCodeUrl} alt='' />}</div>
<div className='qr-code-wrap'>
{qrCodeUrl ? (
<Image src={qrCodeUrl} alt='' width={200} height={200} preview={false} />
) : (
<QRCode value='https://ant.design/' status='loading' />
)}
</div>
) : (
<>
<div className='login-image' />
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论