From a45b26d86249bbc58bebeecdbd52d59a8cb00287 Mon Sep 17 00:00:00 2001 From: zhengpengju Date: Wed, 16 Mar 2022 11:34:09 +0800 Subject: [PATCH] fix login --- web/src/pages/user/Login/index.tsx | 34 ++++++++++++++------------ web/src/services/ant-design-pro/api.ts | 14 +++++++++-- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/web/src/pages/user/Login/index.tsx b/web/src/pages/user/Login/index.tsx index 7fc3245..1aaf553 100644 --- a/web/src/pages/user/Login/index.tsx +++ b/web/src/pages/user/Login/index.tsx @@ -4,7 +4,7 @@ import React, { useState } from 'react'; import { ProFormCaptcha, ProFormCheckbox, ProFormText, LoginForm } from '@ant-design/pro-form'; import { useIntl, history, FormattedMessage, SelectLang, useModel } from 'umi'; import Footer from '@/components/Footer'; -import { login } from '@/services/ant-design-pro/api'; +import { checkLogin, login } from '@/services/ant-design-pro/api'; import { getFakeCaptcha } from '@/services/ant-design-pro/login'; import styles from './index.less'; @@ -41,22 +41,26 @@ const Login: React.FC = () => { const handleSubmit = async (values: API.LoginParams) => { try { - // 登录 - const msg = await login({ ...values, type }); - if (msg.success === true) { - const defaultLoginSuccessMessage = '登录成功!'; - message.success(defaultLoginSuccessMessage); - await fetchUserInfo(); - /** 此方法会跳转到 redirect 参数所在的位置 */ - if (!history) return; - const { query } = history.location; - const { redirect } = query as { redirect: string }; - history.push(redirect || '/'); - return; + // 登录校验 + const {login_status} = await checkLogin({ ...values, type }); + if(login_status === '1'){ + // 登录产生cookie + const msg = await login({ ...values, type }); + if (msg.success === true) { + const defaultLoginSuccessMessage = '登录成功!'; + message.success(defaultLoginSuccessMessage); + await fetchUserInfo(); + /** 此方法会跳转到 redirect 参数所在的位置 */ + if (!history) return; + const { query } = history.location; + const { redirect } = query as { redirect: string }; + history.push(redirect || '/'); + return; + } + console.log('msg..', msg); } - console.log('msg..', msg); // 如果失败去设置用户错误信息 - setUserLoginState(msg); + //setUserLoginState(msg); } catch (error) { const defaultLoginFailureMessage = msg?.info; message.error(defaultLoginFailureMessage); diff --git a/web/src/services/ant-design-pro/api.ts b/web/src/services/ant-design-pro/api.ts index 4cbb6fc..1ec932e 100644 --- a/web/src/services/ant-design-pro/api.ts +++ b/web/src/services/ant-design-pro/api.ts @@ -36,9 +36,19 @@ export async function outLogin(options?: { [key: string]: any }) { }); } -/** 登录接口 POST /api/login/account */ +/** 登录校验接口 POST */ +export async function checkLogin(body: API.LoginParams, options?: { [key: string]: any }) { + return request('/dsideal_yy/checkLoginStatus', { + method: 'POST', + requestType: 'form', + data: body, + ...(options || {}), + }); +} + +/** 登录接口 POST */ export async function login(body: API.LoginParams, options?: { [key: string]: any }) { - return request('/dsideal_yy/checkLoginStatus', { // /dsideal_yy/login/doLogin?login_type=1 + return request('/dsideal_yy/login/doLogin?login_type=1', { method: 'POST', requestType: 'form', data: body,