|
@@ -15,7 +15,7 @@ import { OAUTH2_THIRD_LOGIN_TENANT_ID } from '/@/enums/cacheEnum';
|
|
|
import { useGlobSetting } from '/@/hooks/setting';
|
|
|
|
|
|
import _ from 'lodash';
|
|
|
-import { AUTO_LOGIN_URL_QUERY, MOCK_LOGIN_URL_QUERY, SKIP_SSO_URL_QUERY } from '../constant';
|
|
|
+import { AUTO_LOGIN_URL_QUERY, SKIP_SSO_URL_QUERY } from '../constant';
|
|
|
import { useSso } from '/@/hooks/web/useSso';
|
|
|
import { useAutoLogin } from '/@/hooks/vent/useAutoLogin';
|
|
|
|
|
@@ -43,13 +43,12 @@ export function createPermissionGuard(router: Router) {
|
|
|
const permissionStore = usePermissionStoreWithOut();
|
|
|
const { doAutoLogin } = useAutoLogin();
|
|
|
|
|
|
- router.beforeEach(async (to, from) => {
|
|
|
+ router.beforeEach(async (to, from, next) => {
|
|
|
RootRoute.redirect = glob.homePath || PageEnum.BASE_HOME;
|
|
|
|
|
|
if (_.isEmpty(history.state.current)) {
|
|
|
_.assign(history.state, { current: from.fullPath });
|
|
|
}
|
|
|
-
|
|
|
if (
|
|
|
from.path === ROOT_PATH &&
|
|
|
to.path === (glob.homePath || PageEnum.BASE_HOME) &&
|
|
@@ -57,15 +56,16 @@ export function createPermissionGuard(router: Router) {
|
|
|
userStore.getUserInfo.homePath !== (glob.homePath || PageEnum.BASE_HOME)
|
|
|
) {
|
|
|
// mountMicroApp(userStore.getUserInfo.homePath);
|
|
|
+ next(userStore.getUserInfo.homePath);
|
|
|
document.title = '首页';
|
|
|
- return userStore.getUserInfo.homePath;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
// 如果符合自动登录的相关条件则直接执行自动登录,覆盖原有的登录信息
|
|
|
- const logged = await doAutoLogin(to);
|
|
|
- if (logged) {
|
|
|
+ if (to.query[AUTO_LOGIN_URL_QUERY.key] === AUTO_LOGIN_URL_QUERY.val) {
|
|
|
+ await doAutoLogin(to);
|
|
|
// 自动登录后会动态添加路由,此处应当重定向到fullPath,否则会加载404页面内容
|
|
|
- return { path: to.fullPath, replace: true, query: to.query };
|
|
|
+ return next({ path: to.fullPath, replace: true });
|
|
|
}
|
|
|
|
|
|
const token = userStore.getToken;
|
|
@@ -82,8 +82,9 @@ export function createPermissionGuard(router: Router) {
|
|
|
|
|
|
try {
|
|
|
if (!isSessionTimeout) {
|
|
|
+ next((to.query?.redirect as string) || '/');
|
|
|
document.title = '';
|
|
|
- return (to.query?.redirect as string) || '/';
|
|
|
+ return;
|
|
|
}
|
|
|
} catch {}
|
|
|
//update-begin---author:wangshuai ---date:20220629 for:[issues/I5BG1I]vue3不支持auth2登录------------
|
|
@@ -94,23 +95,27 @@ export function createPermissionGuard(router: Router) {
|
|
|
// if (to.query.tenantId) {
|
|
|
// setAuthCache(OAUTH2_THIRD_LOGIN_TENANT_ID, to.query.tenantId);
|
|
|
// }
|
|
|
+ next({ path: OAUTH2_LOGIN_PAGE_PATH });
|
|
|
document.title = '登录';
|
|
|
- return { path: OAUTH2_LOGIN_PAGE_PATH };
|
|
|
///
|
|
|
|
|
|
//update-end---author:wangshuai ---date:20230224 for:[QQYUN-3440]新建企业微信和钉钉配置表,通过租户模式隔离------------
|
|
|
+ return;
|
|
|
//update-end---author:wangshuai ---date:20220629 for:[issues/I5BG1I]vue3不支持auth2登录------------
|
|
|
}
|
|
|
+ next();
|
|
|
+
|
|
|
document.title = to.meta.title;
|
|
|
- return true;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
// token does not exist
|
|
|
if (!token) {
|
|
|
// You can access without permission. You need to set the routing meta.ignoreAuth to true
|
|
|
if (to.meta.ignoreAuth) {
|
|
|
+ next();
|
|
|
document.title = to.meta.title;
|
|
|
- return true;
|
|
|
+ return;
|
|
|
}
|
|
|
// query如果没有明确要求跳过sso则执行sso登录
|
|
|
if (to.query[SKIP_SSO_URL_QUERY.key] !== SKIP_SSO_URL_QUERY.val) {
|
|
@@ -119,15 +124,15 @@ export function createPermissionGuard(router: Router) {
|
|
|
if (redirectSso) return;
|
|
|
}
|
|
|
// query中要求自动登录的执行自动登录
|
|
|
- if (to.query[MOCK_LOGIN_URL_QUERY.key] === MOCK_LOGIN_URL_QUERY.val) {
|
|
|
+ if (to.query[AUTO_LOGIN_URL_QUERY.key] === AUTO_LOGIN_URL_QUERY.val) {
|
|
|
const userStore = useUserStoreWithOut();
|
|
|
await userStore.mockLogin({
|
|
|
goHome: false,
|
|
|
});
|
|
|
- return {
|
|
|
+ return next({
|
|
|
path: to.path,
|
|
|
query: to.query,
|
|
|
- };
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
//update-begin---author:wangshuai ---date:20220629 for:[issues/I5BG1I]vue3 Auth2未实现------------
|
|
@@ -135,13 +140,13 @@ export function createPermissionGuard(router: Router) {
|
|
|
if (whitePathList.includes(to.path as PageEnum)) {
|
|
|
// 在免登录白名单,如果进入的页面是login页面并且当前是OAuth2app环境,就进入OAuth2登录页面
|
|
|
if (to.path === LOGIN_PATH && isOAuth2AppEnv()) {
|
|
|
+ next({ path: OAUTH2_LOGIN_PAGE_PATH });
|
|
|
document.title = '登录';
|
|
|
- return { path: OAUTH2_LOGIN_PAGE_PATH };
|
|
|
} else {
|
|
|
//在免登录白名单,直接进入
|
|
|
// mountMicroApp(to.path);
|
|
|
+ next();
|
|
|
document.title = to.meta.title;
|
|
|
- return true;
|
|
|
}
|
|
|
} else {
|
|
|
//update-begin---author:wangshuai ---date:20230302 for:只有首次登陆并且是企业微信或者钉钉的情况下才会调用------------
|
|
@@ -192,14 +197,16 @@ export function createPermissionGuard(router: Router) {
|
|
|
};
|
|
|
}
|
|
|
// mountMicroApp(redirectData.path);
|
|
|
+ next(redirectData);
|
|
|
document.title = '';
|
|
|
- return redirectData;
|
|
|
+ return;
|
|
|
}
|
|
|
//==============================【首次登录并且是企业微信或者钉钉的情况下才会调用】==================
|
|
|
//判断是免登录页面,如果页面包含/tenantId/,那么就直接前往主页
|
|
|
if (isOAuth2AppEnv() && to.path.indexOf('/tenantId/') != -1) {
|
|
|
+ next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
|
|
|
document.title = '首页';
|
|
|
- return userStore.getUserInfo.homePath || PageEnum.BASE_HOME;
|
|
|
+ return;
|
|
|
}
|
|
|
//==============================【首次登录并且是企业微信或者钉钉的情况下才会调用】==================
|
|
|
|
|
@@ -210,8 +217,9 @@ export function createPermissionGuard(router: Router) {
|
|
|
to.fullPath !== (userStore.getUserInfo.homePath || glob.homePath || PageEnum.BASE_HOME)
|
|
|
) {
|
|
|
// mountMicroApp(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
|
|
|
+ next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
|
|
|
document.title = '首页';
|
|
|
- return userStore.getUserInfo.homePath || PageEnum.BASE_HOME;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
// get userinfo while last fetch time is empty
|
|
@@ -221,17 +229,17 @@ export function createPermissionGuard(router: Router) {
|
|
|
} catch (err) {
|
|
|
console.info(err);
|
|
|
// mountMicroApp(to.path);
|
|
|
+ next();
|
|
|
document.title = to.meta.title;
|
|
|
- return true;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
if (permissionStore.getIsDynamicAddedRoute) {
|
|
|
+ // mountMicroApp(to.path);
|
|
|
+ next();
|
|
|
document.title = to.meta.title;
|
|
|
- return true;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- // 如果没有在登录时正确的添加动态路由,则在守卫里添加下
|
|
|
const routes = await permissionStore.buildRoutesAction();
|
|
|
|
|
|
routes.forEach((route) => {
|
|
@@ -244,15 +252,15 @@ export function createPermissionGuard(router: Router) {
|
|
|
permissionStore.setDynamicAddedRoute(true);
|
|
|
|
|
|
if (to.name === PAGE_NOT_FOUND_ROUTE.name) {
|
|
|
- // mountMicroApp(to.path);
|
|
|
// 动态添加路由后,此处应当重定向到fullPath,否则会加载404页面内容
|
|
|
- return { path: to.fullPath, replace: true, query: to.query };
|
|
|
+ next({ path: to.fullPath, replace: true, query: to.query });
|
|
|
} else {
|
|
|
const redirectPath = (from.query.redirect || to.path) as string;
|
|
|
const redirect = decodeURIComponent(redirectPath);
|
|
|
- // mountMicroApp(return Data.path);
|
|
|
+ const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect };
|
|
|
+ // mountMicroApp(nextData.path);
|
|
|
+ next(nextData);
|
|
|
document.title = '';
|
|
|
- return to.path === redirect ? { ...to, replace: true } : { path: redirect };
|
|
|
}
|
|
|
});
|
|
|
}
|