Commit c09a8dd5 authored by 张伯涛's avatar 张伯涛

动态路由相关问题修改

parent 589f06b7
......@@ -2,7 +2,7 @@ export enum PageEnum {
// basic login path
BASE_LOGIN = '/login',
// basic home path
BASE_HOME = '/system/user',
BASE_HOME = '/dashboard',
// error page path
ERROR_PAGE = '/exception',
// error log page path
......
......@@ -7,17 +7,18 @@ import { useUserStoreWithOut } from '@/store/modules/user';
import { PAGE_NOT_FOUND_ROUTE } from '@/router/routes/basic';
import { RootRoute } from '@/router/routes';
// import { RootRoute } from '@/router/routes';
const LOGIN_PATH = PageEnum.BASE_LOGIN;
const ROOT_PATH = RootRoute.path;
// const ROOT_PATH = RootRoute.path;
const whitePathList: PageEnum[] = [LOGIN_PATH];
export function createPermissionGuard(router: Router) {
const userStore = useUserStoreWithOut();
const permissionStore = usePermissionStoreWithOut();
const ROOT_PATH = userStore.getUserInfo.homePath;
router.beforeEach(async (to, from, next) => {
if (
from.path === ROOT_PATH &&
......
......@@ -20,14 +20,14 @@ Object.keys(modules).forEach((key) => {
export const asyncRoutes = [PAGE_NOT_FOUND_ROUTE, ...routeModuleList];
// 根路由
export const RootRoute: AppRouteRecordRaw = {
path: '/',
name: 'Root',
redirect: PageEnum.BASE_HOME,
meta: {
title: 'Root',
},
};
// export const RootRoute: AppRouteRecordRaw = {
// path: '/',
// name: 'Root',
// redirect: PageEnum.BASE_HOME,
// meta: {
// title: 'Root',
// },
// };
export const LoginRoute: AppRouteRecordRaw = {
path: '/login',
......@@ -42,7 +42,7 @@ export const LoginRoute: AppRouteRecordRaw = {
// 未经许可的基本路由
export const basicRoutes = [
LoginRoute,
RootRoute,
// RootRoute,
...mainOutRoutes,
REDIRECT_ROUTE,
PAGE_NOT_FOUND_ROUTE,
......
......@@ -242,9 +242,18 @@ export const usePermissionStore = defineStore({
// } catch (error) {
// console.error(error);
// }
console.log('userStore.getUserInfo.data.menus',userStore.getUserInfo.data.menus)
routeList = userStore.getUserInfo.data.menus
routeList = userStore.getUserInfo.menus
const rootPath = {
path: '/',
name: 'Root',
redirect: userStore.getUserInfo.homePath,
meta: {
title: 'Root',
},
}
routeList.push(rootPath)
console.log('routeList',routeList)
// Dynamically introduce components
// 动态引入组件
routeList = transformObjToRoute(routeList);
......
......@@ -134,9 +134,21 @@ export const useUserStore = defineStore({
} else {
this.setRoleList(['ROLE_DEFAULT']);
}
// 获取动态路由下的第一个菜单路径
const firstChild = await this.getFirstChild(userInfo.data.menus[0])
// 登陆后进入的第一个页面
userInfo.data.homePath = firstChild
// 设置用户信息,并存储本地缓存
this.setUserInfo(userInfo);
return userInfo;
this.setUserInfo(userInfo.data);
return userInfo.data;
},
/** 获取动态路由下的第一个菜单路径*/
getFirstChild(item): Promise<any> {
if (item.children && item.children.length > 0) {
return this.getFirstChild(item.children[0])
} else {
return item.path
}
},
/**
* @description: logout
......
......@@ -119,7 +119,7 @@
const rememberMe = ref(false);
const formData = reactive({
account: 'vben',
account: 'guanliyuan',
password: '123456',
});
......@@ -139,11 +139,10 @@
username: data.account,
mode: 'none', //不要默认的错误提示
});
console.log('11111111111111',userInfo)
if (userInfo) {
notification.success({
message: t('sys.login.loginSuccessTitle'),
description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.data.user.name}`,
description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.user.name}`,
duration: 3,
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment