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