fix: 切换用户登录系统跳转至/

This commit is contained in:
Captain.B 2021-05-28 18:02:00 +08:00 committed by 刘瑞斌
parent 16c1387b42
commit 929ca1e0a1
1 changed files with 11 additions and 5 deletions

View File

@ -1,12 +1,13 @@
import Vue from "vue";
import VueRouter from 'vue-router'
import VueRouter from 'vue-router';
import RouterSidebar from "./RouterSidebar";
import Setting from "@/business/components/settings/router";
import API from "@/business/components/api/router";
import Performance from "@/business/components/performance/router";
import Track from "@/business/components/track/router";
import {getCurrentUserId} from "@/common/js/utils";
const requireContext = require.context('@/business/components/xpack/', true, /router\.js$/)
const requireContext = require.context('@/business/components/xpack/', true, /router\.js$/);
const Report = requireContext.keys().map(key => requireContext(key).report);
const ReportObj = Report && Report != null && Report.length > 0 && Report[0] != undefined ? Report : [{path: "/sidebar"}];
@ -48,8 +49,8 @@ router.beforeEach((to, from, next) => {
//重复点击导航路由报错
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
return routerPush.call(this, location).catch(error => error)
}
return routerPush.call(this, location).catch(error => error);
};
// 登入后跳转至原路径
@ -57,6 +58,11 @@ function redirectLoginPath(originPath) {
let redirectUrl = sessionStorage.getItem('redirectUrl');
let loginSuccess = sessionStorage.getItem('loginSuccess');
sessionStorage.setItem('redirectUrl', originPath);
// 换一个用户登录同一个浏览器,跳转到 /
if (getCurrentUserId() !== sessionStorage.getItem('lastUser')) {
sessionStorage.setItem('lastUser', getCurrentUserId());
redirectUrl = '/';
}
if (redirectUrl && loginSuccess) {
sessionStorage.removeItem('loginSuccess');
router.push(redirectUrl);
@ -65,4 +71,4 @@ function redirectLoginPath(originPath) {
}
export default router
export default router;