From 6febfae1f39d1b793aa4c54c195f0c2c5d262edb Mon Sep 17 00:00:00 2001 From: mac Date: Tue, 9 Jul 2024 20:20:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=B7=BB=E5=8A=A0=E8=B0=B7?= =?UTF-8?q?=E6=AD=8C=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.ts | 3 ++ src/pages/login/index.tsx | 62 +++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 2ab7fed..0ac0afd 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -158,5 +158,8 @@ export default { bind_googleCode(data: object) { return $axios.post('/admin/bindAuthenticator', data) }, + verify_googleCode(data: object) { + return $axios.post('/admin/verifyAuthenticator', data) + }, } diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 1929c31..ad9dd9b 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -1,7 +1,7 @@ import React, { useEffect, FC, useMemo, useState, useRef } from 'react' import { useHistory } from 'react-router-dom' import { LockOutlined, UserOutlined } from '@ant-design/icons' -import { Form, Input, Button, Select, Cascader, Space, Row } from 'antd' +import { Form, Input, Button, Select, Cascader, Space, Row, Modal } from 'antd' import ReactCanvasNest from 'react-canvas-nest' import './login.less' import Logo from '@/assets/img/logo.png' @@ -9,6 +9,7 @@ import { setUserInfo } from '@/assets/js/publicFunc' import { connect } from 'react-redux' import * as actions from '@/store/actions' import common from '@/api' +import api from '@/api' interface Props extends ReduxProps { } @@ -18,9 +19,12 @@ const LoginForm: FC = ({ }) => { const history = useHistory() + const [form] = Form.useForm() + const nameRef = useRef('') const [codeUrl, setCodeUrl] = useState('') const codeId = useRef('') + const [visible, setVisible] = useState(false) useEffect(() => { const { token } = userInfo @@ -48,17 +52,24 @@ const LoginForm: FC = ({ const onFinish = (values: CommonObjectType): void => { const { username } = values; common.login({ ...values, id: codeId.current }).then((res: any) => { - // 登录后返回的数据,包括权限 - const resData = { - userName: username, - token: res.data.token, - permission: res.data.c || [] + console.log(res); + if (res.code === 0 && !res.data.google) { + // 登录后返回的数据,包括权限 + const resData = { + userName: username, + token: res.data.token, + permission: res.data.c || [] + } + setUserInfo(resData, setStoreData) + history.push('/') + } else { + nameRef.current = username + setVisible(true) } - setUserInfo(resData, setStoreData) - history.push('/') + }) } - + // verify_googleCode const FormView = (
= ({ ) + const onVerifyFinish = async (values) => { + const res: any = await api.verify_googleCode({ + code: Number(values.code) + }) + if (res.code === 0) { + // 登录后返回的数据,包括权限 + const resData = { + userName: nameRef.current, + token: res.data.token, + permission: res.data.c || [] + } + setUserInfo(resData, setStoreData) + history.push('/') + } + } + const floatColor = theme === 'default' ? '24,144,255' : '110,65,255' return (
+ + setVisible(false)} + title="谷歌验证码" + footer={() => null} + > +
+ + + + + + + +
+