Commit 296d31f0 by yancanhua

fix: 页面路由优化

1 parent 7113ab52
...@@ -156,6 +156,51 @@ export default class App extends Vue { ...@@ -156,6 +156,51 @@ export default class App extends Vue {
this.loginUserName = this.$auth.getAuthentication().fullName; this.loginUserName = this.$auth.getAuthentication().fullName;
// 底部菜单权限 // 底部菜单权限
this.privileges = this.getPrivileges; this.privileges = this.getPrivileges;
// 初始化菜单选中状态
this.initMenuSelected();
}
mounted(): void {
// 监听路由变化
this.$router.afterEach(() => {
this.initMenuSelected();
});
}
/**
* 初始化菜单选中状态
*/
initMenuSelected(): void {
const currentPath = this.$route.path;
const menuKey = this.findMenuKeyByPath(this.privileges, currentPath);
if (menuKey) {
this.selectedKeys = [menuKey];
} else if (currentPath === '/dashboard') {
this.selectedKeys = ['dashboard'];
} else if (currentPath === '/security/profile') {
this.selectedKeys = ['profile'];
}
}
/**
* 根据路由路径查找对应的菜单键
* @param privileges 权限菜单列表
* @param path 当前路由路径
* @returns 对应的菜单键
*/
findMenuKeyByPath(privileges: any[], path: string): string | null {
for (const item of privileges) {
if (item.value === path) {
return item.code;
}
if (item.children && item.children.length > 0) {
const foundKey = this.findMenuKeyByPath(item.children, path);
if (foundKey) {
return foundKey;
}
}
}
return null;
} }
logout() { logout() {
......
...@@ -67,16 +67,16 @@ export class CustomTokenInterceptor { ...@@ -67,16 +67,16 @@ export class CustomTokenInterceptor {
if (error) { if (error) {
// 请求已发出,但是不在2xx的范围 // 请求已发出,但是不在2xx的范围
this.handleError(error); this.handleError(error);
if(error?.config?.url == 'security/getUserAuthentication'){ if (error?.config?.url == 'security/getUserAuthentication') {
console.log('token过期了重新登录',error); console.log('token过期了重新登录', error);
//获取报错端口 //获取报错端口
const windowOrigin = window.location.origin; const windowOrigin = window.location.origin;
if(windowOrigin == "https://aus.test.glsx.com.cn"){ if (windowOrigin == "https://aus.test.glsx.com.cn") {
window.location.href = "https://aus.test.glsx.com.cn/admin/login"; window.location.href = "https://aus.test.glsx.com.cn/admin/login";
} else if(windowOrigin == "https://aus.glsx.com.cn"){ } else if (windowOrigin == "https://aus.glsx.com.cn") {
window.location.href = "https://aus.glsx.com.cn/admin/login"; window.location.href = "https://aus.glsx.com.cn/admin/login";
} else { } else {
console.log('windowOrigin',windowOrigin); console.log('windowOrigin', windowOrigin);
} }
} }
return Promise.reject(error.response); return Promise.reject(error.response);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!