From 49cebcc7ce61ef42b3f66c0023bf194d5f2e2719 Mon Sep 17 00:00:00 2001 From: oustr <111119927+oustr@users.noreply.github.com> Date: Thu, 30 Mar 2023 00:31:58 +1100 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=8A=9F=E8=83=BD=20(#18)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 初步实现微信登录接口和基本流程 * feat: 实现登陆失败跳转回登录页面 * feat: 实现微信登录 * feat: 实现微信登录与账号密码登录并列 --- package.json | 1 + src/pages/Login/index.less | 41 ++++++++ src/pages/Login/index.tsx | 190 ++++++++++++++++++++++--------------- src/services/auth.ts | 26 ++++- src/services/index.ts | 4 +- 5 files changed, 182 insertions(+), 80 deletions(-) diff --git a/package.json b/package.json index 22d1ae0..c579601 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "lint-staged": "^10.0.0", "mockjs": "^1.1.0", "prettier": "^2.7.1", + "query-string": "^8.1.0", "release-it": "^15.6.0", "swagger-ui-dist": "^4.14.2", "typescript": "^4.8.4", diff --git a/src/pages/Login/index.less b/src/pages/Login/index.less index 40cda55..7502a1f 100644 --- a/src/pages/Login/index.less +++ b/src/pages/Login/index.less @@ -41,3 +41,44 @@ color: @primary-color; } } + +.main { + display: flex; + flex-direction: column; + align-items: center; + margin: 0 auto; + margin-top: 6vh; + + .title { + display: flex; + align-items: center; + font-weight: bold; + font-size: 32px; + transform: translateX(-6px); + + img { + width: 60px; + height: 60px; + margin-right: 8px; + border-radius: 30px; + } + } + + .weixinLoginFrame { + box-sizing: border-box; + width: 390px; + text-align: center; + + .link { + line-height: 40px; + } + } +} + +.center { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; +} diff --git a/src/pages/Login/index.tsx b/src/pages/Login/index.tsx index f9c88a6..cc6837e 100644 --- a/src/pages/Login/index.tsx +++ b/src/pages/Login/index.tsx @@ -1,15 +1,15 @@ import Footer from '@/components/Footer'; -import { login } from '@/services/auth'; +import { weixinLogin, accountLogin } from '@/services/auth'; import { LockOutlined, UserOutlined } from '@ant-design/icons'; import { LoginForm, ProFormCheckbox, ProFormText } from '@ant-design/pro-components'; import { history, useModel } from '@umijs/max'; import { message, Tabs } from 'antd'; import { flushSync } from 'react-dom'; +import queryString from 'query-string'; import styles from './index.less'; const Login: React.FC = () => { const { initialState, setInitialState } = useModel('@@initialState'); - const fetchUserInfo = async () => { const userInfo = await initialState?.fetchUserInfo?.(); if (userInfo) { @@ -21,12 +21,20 @@ const Login: React.FC = () => { }); } }; - - const handleSubmit = async (values: API.LoginParams) => { + const handleSubmit = async (type: string, data: any) => { try { // 登录 - const msg = await login({ ...values }); + let msg; + if (type === 'weixin') { + msg = await weixinLogin(data); + } else if (type === 'account') { + msg = await accountLogin(data); + } else { + return; + } + // @ts-ignore if (msg.code === 0) { + // @ts-ignore localStorage.setItem('accessToken', `${msg.accessToken}`); const defaultLoginSuccessMessage = '登录成功!'; message.success(defaultLoginSuccessMessage); @@ -35,84 +43,116 @@ const Login: React.FC = () => { history.push(urlParams.get('redirect') || '/'); return; } - console.log(msg); } catch (error) { const defaultLoginFailureMessage = '登录失败,请重试!'; - console.log(error); message.error(defaultLoginFailureMessage); + history.replace({ + pathname: '/', + }); } }; - return ( -