master
zhengpengju 3 years ago
parent 30e310a1f8
commit a45b26d862

@ -4,7 +4,7 @@ import React, { useState } from 'react';
import { ProFormCaptcha, ProFormCheckbox, ProFormText, LoginForm } from '@ant-design/pro-form'; import { ProFormCaptcha, ProFormCheckbox, ProFormText, LoginForm } from '@ant-design/pro-form';
import { useIntl, history, FormattedMessage, SelectLang, useModel } from 'umi'; import { useIntl, history, FormattedMessage, SelectLang, useModel } from 'umi';
import Footer from '@/components/Footer'; 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 { getFakeCaptcha } from '@/services/ant-design-pro/login';
import styles from './index.less'; import styles from './index.less';
@ -41,22 +41,26 @@ const Login: React.FC = () => {
const handleSubmit = async (values: API.LoginParams) => { const handleSubmit = async (values: API.LoginParams) => {
try { try {
// 登录 // 登录校验
const msg = await login({ ...values, type }); const {login_status} = await checkLogin({ ...values, type });
if (msg.success === true) { if(login_status === '1'){
const defaultLoginSuccessMessage = '登录成功!'; // 登录产生cookie
message.success(defaultLoginSuccessMessage); const msg = await login({ ...values, type });
await fetchUserInfo(); if (msg.success === true) {
/** 此方法会跳转到 redirect 参数所在的位置 */ const defaultLoginSuccessMessage = '登录成功!';
if (!history) return; message.success(defaultLoginSuccessMessage);
const { query } = history.location; await fetchUserInfo();
const { redirect } = query as { redirect: string }; /** 此方法会跳转到 redirect 参数所在的位置 */
history.push(redirect || '/'); if (!history) return;
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) { } catch (error) {
const defaultLoginFailureMessage = msg?.info; const defaultLoginFailureMessage = msg?.info;
message.error(defaultLoginFailureMessage); message.error(defaultLoginFailureMessage);

@ -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<API.LoginResult>('/dsideal_yy/checkLoginStatus', {
method: 'POST',
requestType: 'form',
data: body,
...(options || {}),
});
}
/** 登录接口 POST */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) { export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
return request<API.LoginResult>('/dsideal_yy/checkLoginStatus', { // /dsideal_yy/login/doLogin?login_type=1 return request<API.LoginResult>('/dsideal_yy/login/doLogin?login_type=1', {
method: 'POST', method: 'POST',
requestType: 'form', requestType: 'form',
data: body, data: body,

Loading…
Cancel
Save