|
|
@@ -9,10 +9,11 @@ import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
|
|
|
|
|
|
import { RootRoute } from '/@/router/routes';
|
|
|
|
|
|
-import {isOAuth2AppEnv, isOAuth2DingAppEnv} from '/@/views/sys/login/useLogin';
|
|
|
-import { OAUTH2_THIRD_LOGIN_TENANT_ID } from "/@/enums/cacheEnum";
|
|
|
-import { setAuthCache } from "/@/utils/auth";
|
|
|
+import { isOAuth2AppEnv, isOAuth2DingAppEnv } from '/@/views/sys/login/useLogin';
|
|
|
+import { OAUTH2_THIRD_LOGIN_TENANT_ID } from '/@/enums/cacheEnum';
|
|
|
+import { setAuthCache } from '/@/utils/auth';
|
|
|
import { PAGE_NOT_FOUND_NAME_404 } from '/@/router/constant';
|
|
|
+import { useAutoLogin } from '/@/hooks/system/useAutoLogin';
|
|
|
|
|
|
const LOGIN_PATH = PageEnum.BASE_LOGIN;
|
|
|
//auth2登录路由
|
|
|
@@ -27,11 +28,12 @@ const TOKEN_LOGIN = PageEnum.TOKEN_LOGIN;
|
|
|
const ROOT_PATH = RootRoute.path;
|
|
|
|
|
|
// 代码逻辑说明: [VUEN-2472]分享免登录------------
|
|
|
-const whitePathList: PageEnum[] = [LOGIN_PATH, OAUTH2_LOGIN_PAGE_PATH,SYS_FILES_PATH, TOKEN_LOGIN ];
|
|
|
+const whitePathList: PageEnum[] = [LOGIN_PATH, OAUTH2_LOGIN_PAGE_PATH, SYS_FILES_PATH, TOKEN_LOGIN];
|
|
|
|
|
|
export function createPermissionGuard(router: Router) {
|
|
|
const userStore = useUserStoreWithOut();
|
|
|
const permissionStore = usePermissionStoreWithOut();
|
|
|
+ const { validateRoute, doAutoLogin } = useAutoLogin();
|
|
|
|
|
|
// 自定义首页跳转次数
|
|
|
let homePathJumpCount = 0;
|
|
|
@@ -50,16 +52,24 @@ export function createPermissionGuard(router: Router) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // 如果符合自动登录的相关条件则直接执行自动登录,覆盖原有的登录信息
|
|
|
+ if (validateRoute(to)) {
|
|
|
+ await doAutoLogin(to);
|
|
|
+ // 自动登录后会动态添加路由,此处应当重定向到fullPath,否则会加载404页面内容
|
|
|
+ next({ path: to.fullPath, replace: true, query: to.query });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
const token = userStore.getToken;
|
|
|
|
|
|
// Whitelist can be directly entered
|
|
|
if (whitePathList.includes(to.path as PageEnum)) {
|
|
|
if (to.path === LOGIN_PATH && token) {
|
|
|
const isSessionTimeout = userStore.getSessionTimeout;
|
|
|
-
|
|
|
+
|
|
|
//TODO vben默认写法,暂时不知目的,有问题暂时先注释掉
|
|
|
//await userStore.afterLoginAction();
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
if (!isSessionTimeout) {
|
|
|
next((to.query?.redirect as string) || '/');
|
|
|
@@ -71,8 +81,8 @@ export function createPermissionGuard(router: Router) {
|
|
|
//退出登录进入此逻辑
|
|
|
//如果进入的页面是login页面并且当前是OAuth2app环境,并且token为空,就进入OAuth2登录页面
|
|
|
// 代码逻辑说明: [QQYUN-3440]新建企业微信和钉钉配置表,通过租户模式隔离------------
|
|
|
- if(to.query.tenantId){
|
|
|
- setAuthCache(OAUTH2_THIRD_LOGIN_TENANT_ID,to.query.tenantId)
|
|
|
+ if (to.query.tenantId) {
|
|
|
+ setAuthCache(OAUTH2_THIRD_LOGIN_TENANT_ID, to.query.tenantId);
|
|
|
}
|
|
|
next({ path: OAUTH2_LOGIN_PAGE_PATH });
|
|
|
return;
|
|
|
@@ -104,11 +114,11 @@ export function createPermissionGuard(router: Router) {
|
|
|
//只有首次登陆并且是企业微信或者钉钉的情况下才会调用
|
|
|
const href = window.location.href;
|
|
|
//判断当前是auth2页面,并且是钉钉/企业微信,并且包含tenantId参数
|
|
|
- if(isOAuth2AppEnv() && href.indexOf("/tenantId/")!= -1){
|
|
|
+ if (isOAuth2AppEnv() && href.indexOf('/tenantId/') != -1) {
|
|
|
const params = to.params;
|
|
|
- if(params && params.path && params.path.length>0){
|
|
|
+ if (params && params.path && params.path.length > 0) {
|
|
|
//直接获取参数最后一位
|
|
|
- setAuthCache(OAUTH2_THIRD_LOGIN_TENANT_ID,params.path[params.path.length-1])
|
|
|
+ setAuthCache(OAUTH2_THIRD_LOGIN_TENANT_ID, params.path[params.path.length - 1]);
|
|
|
}
|
|
|
}
|
|
|
//---------【首次登陆并且是企业微信或者钉钉的情况下才会调用】------------------------------------------------
|
|
|
@@ -124,19 +134,24 @@ export function createPermissionGuard(router: Router) {
|
|
|
|
|
|
// 代码逻辑说明: 【QQYUN-4713】登录代码调整逻辑有问题,改造待观察--
|
|
|
if (to.fullPath) {
|
|
|
- console.log("to.fullPath 1",to.fullPath)
|
|
|
- console.log("to.path 2",to.path)
|
|
|
-
|
|
|
+ console.log('to.fullPath 1', to.fullPath);
|
|
|
+ console.log('to.path 2', to.path);
|
|
|
+
|
|
|
const getFullPath = to.fullPath;
|
|
|
- if(getFullPath=='/' || getFullPath=='/500' || getFullPath=='/400' || getFullPath=='/login?redirect=/' || getFullPath=='/login?redirect=/login?redirect=/'){
|
|
|
+ if (
|
|
|
+ getFullPath == '/' ||
|
|
|
+ getFullPath == '/500' ||
|
|
|
+ getFullPath == '/400' ||
|
|
|
+ getFullPath == '/login?redirect=/' ||
|
|
|
+ getFullPath == '/login?redirect=/login?redirect=/'
|
|
|
+ ) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
redirectData.query = {
|
|
|
...redirectData.query,
|
|
|
// 代码逻辑说明: 修复登录成功后,没有正确重定向的问题
|
|
|
redirect: to.fullPath,
|
|
|
-
|
|
|
};
|
|
|
}
|
|
|
next(redirectData);
|
|
|
@@ -145,7 +160,7 @@ export function createPermissionGuard(router: Router) {
|
|
|
|
|
|
//==============================【首次登录并且是企业微信或者钉钉的情况下才会调用】==================
|
|
|
//判断是免登录页面,如果页面包含/tenantId/,那么就直接前往主页
|
|
|
- if(isOAuth2AppEnv() && to.path.indexOf("/tenantId/") != -1){
|
|
|
+ if (isOAuth2AppEnv() && to.path.indexOf('/tenantId/') != -1) {
|
|
|
// 代码逻辑说明: 【TV360X-2958】钉钉登录后打开了敲敲云,换其他账号登录后,再打开敲敲云显示的是原来账号的应用---
|
|
|
if (isOAuth2DingAppEnv()) {
|
|
|
next(OAUTH2_LOGIN_PAGE_PATH);
|