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

动态路由相关问题修改

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