fix(模块): 修复了一些 bug
This commit is contained in:
parent
55d599824e
commit
6a7a8985ce
@ -14,11 +14,8 @@ export default {
|
||||
],
|
||||
routes: [
|
||||
{
|
||||
id: 1,
|
||||
key: '1',
|
||||
path: '/',
|
||||
redirect: '',
|
||||
name: '首页'
|
||||
component: '@/layouts/index',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
@ -117,6 +114,14 @@ export default {
|
||||
name: '(404)学生',
|
||||
path: '/student',
|
||||
redirect: '',
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
key: '5',
|
||||
path: '/user/login',
|
||||
redirect: '',
|
||||
name: '登录',
|
||||
component: "@/pages/user/login",
|
||||
},
|
||||
]
|
||||
};
|
||||
|
||||
@ -107,8 +107,17 @@ const UserModel: UserModelType = {
|
||||
},
|
||||
effects: {
|
||||
//登录
|
||||
*login({ payload }, { call, put }) {
|
||||
console.log('payload', payload);
|
||||
*login({ payload }, { call, put, select }) {
|
||||
// 检查当前是否已经在登录状态
|
||||
const { isLogin } = yield select((state) => state.user);
|
||||
if (isLogin) {
|
||||
return { code: 1, message: '您已经登录' };
|
||||
}
|
||||
|
||||
// 检查是否有payload,防止自动触发
|
||||
if (!payload) {
|
||||
return { code: 1, message: '登录参数无效' };
|
||||
}
|
||||
|
||||
yield put({
|
||||
type: 'save',
|
||||
@ -117,10 +126,9 @@ const UserModel: UserModelType = {
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
const res: API.LoginResponse = yield call(userLogin, payload);
|
||||
console.log('res', res);
|
||||
|
||||
//登录成功之后设置token并获取用户信息等数据
|
||||
if (!res.code) {
|
||||
localStorage.setItem('Authorization', res.data.token);
|
||||
|
||||
@ -130,6 +138,7 @@ const UserModel: UserModelType = {
|
||||
type: 'concurrent',
|
||||
},
|
||||
});
|
||||
return res;
|
||||
} else {
|
||||
yield put({
|
||||
type: 'save',
|
||||
@ -137,12 +146,34 @@ const UserModel: UserModelType = {
|
||||
loginBtnLoading: false,
|
||||
},
|
||||
});
|
||||
return res;
|
||||
}
|
||||
} catch (error) {
|
||||
yield put({
|
||||
type: 'save',
|
||||
payload: {
|
||||
loginBtnLoading: false,
|
||||
},
|
||||
});
|
||||
return { code: 1, message: '登录失败,请稍后重试' };
|
||||
}
|
||||
},
|
||||
//获取用户信息和权限以及菜单
|
||||
*getUserInfoAuthorityMenu({ payload }, { call, put }) {
|
||||
const { type }: { type: ReqOrder } = payload;
|
||||
|
||||
// 如果当前在登录页面,且不是通过登录操作触发,则不执行后续操作
|
||||
if (window.location.pathname === '/user/login' && type !== 'concurrent') {
|
||||
yield put({
|
||||
type: 'save',
|
||||
payload: {
|
||||
layoutWrapperLoading: false,
|
||||
isLogin: false // 确保在登录页面时重置登录状态
|
||||
},
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
let userInfoRes: API.UserInfoResponse = {
|
||||
data: {},
|
||||
code: 0,
|
||||
@ -182,6 +213,13 @@ const UserModel: UserModelType = {
|
||||
},
|
||||
});
|
||||
|
||||
// 只有在非登录页面时才执行重定向
|
||||
if (window.location.pathname !== '/user/login') {
|
||||
yield put({
|
||||
type: 'resetLoginStatus',
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -245,14 +283,11 @@ const UserModel: UserModelType = {
|
||||
},
|
||||
});
|
||||
|
||||
//当前页面不是登录页, 且没有redirect参数的时候再设置redirect参数
|
||||
//而且这个redirect参数要包含url pathname和查询字符串参数, 即pathname及其后面的所有字符
|
||||
//当前页面不是登录页时,才进行重定向
|
||||
if (window.location.pathname !== '/user/login') {
|
||||
if (!/redirect=/.test(window.location.search)) {
|
||||
const redirectValue = `${window.location.pathname}${window.location.search}`;
|
||||
history.push(`/user/login?redirect=${encodeURIComponent(redirectValue)}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
reducers: {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
|
||||
const authority: PageAuthority = {
|
||||
'/user/login': [], // 登录页面不需要权限验证
|
||||
'/': [
|
||||
'/',
|
||||
],
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import type { FC } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { Col, Divider, Row, Space, Typography } from 'antd';
|
||||
import { Col, Divider, Row, Space, Typography, message } from 'antd';
|
||||
import { connect, Link } from 'umi';
|
||||
import { LockFilled, UserOutlined } from '@ant-design/icons';
|
||||
import { ProFormText, LoginForm } from '@ant-design/pro-components';
|
||||
@ -8,20 +8,29 @@ import Footer from '@/components/Footer';
|
||||
import { retrieveCaptcha } from '@/services/user';
|
||||
import type { UserConnectedProps } from '@/models/user';
|
||||
import styles from './index.less';
|
||||
const logo = '@/assets/logo.svg'
|
||||
const loginBg = '@/assets/login-bg.png'
|
||||
// import logo from '@/assets/logo.svg'
|
||||
// import loginBg from '@/assets/login-bg.png'
|
||||
import logo from '@/assets/logo.svg';
|
||||
import loginBg from '@/assets/login-bg.png';
|
||||
|
||||
const Index: FC<UserConnectedProps> = (props) => {
|
||||
const [type, setType] = useState<string>('account');
|
||||
const { user, dispatch } = props;
|
||||
|
||||
const handleSubmit = async (values: API.LoginParams) => {
|
||||
dispatch?.({
|
||||
try {
|
||||
const response = await dispatch?.({
|
||||
type: 'user/login',
|
||||
payload: values,
|
||||
});
|
||||
|
||||
if (response?.code) {
|
||||
message.error(response.message || '登录失败,请检查账号密码');
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Login failed:', error);
|
||||
message.error('登录失败,请稍后重试');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user