Normalize legacy home redirects
This commit is contained in:
@@ -17,7 +17,7 @@ from core.menu.schema import MenuCreate, MenuUpdate
|
|||||||
menu_cache = CacheManager(prefix="menu:")
|
menu_cache = CacheManager(prefix="menu:")
|
||||||
|
|
||||||
# 缓存key
|
# 缓存key
|
||||||
AI_AGENT_ADMIN_MENU_CACHE_VERSION = "v4"
|
AI_AGENT_ADMIN_MENU_CACHE_VERSION = "v5"
|
||||||
MENU_TREE_CACHE_KEY = f"tree:ai_agent_admin:{AI_AGENT_ADMIN_MENU_CACHE_VERSION}"
|
MENU_TREE_CACHE_KEY = f"tree:ai_agent_admin:{AI_AGENT_ADMIN_MENU_CACHE_VERSION}"
|
||||||
USER_ROUTE_CACHE_PREFIX = f"user_route:ai_agent_admin:{AI_AGENT_ADMIN_MENU_CACHE_VERSION}:"
|
USER_ROUTE_CACHE_PREFIX = f"user_route:ai_agent_admin:{AI_AGENT_ADMIN_MENU_CACHE_VERSION}:"
|
||||||
|
|
||||||
|
|||||||
@@ -11744,7 +11744,7 @@
|
|||||||
"fields": {
|
"fields": {
|
||||||
"application_id": "23CFVEUHdZcOQyku1mbIO",
|
"application_id": "23CFVEUHdZcOQyku1mbIO",
|
||||||
"config_key": "frontend_preferences",
|
"config_key": "frontend_preferences",
|
||||||
"config_value": "{\"app\": {\"defaultHomePath\": \"/app/workflow_center/page-render/flow_index\"}}",
|
"config_value": "{\"app\": {\"defaultHomePath\": \"/control-center\"}}",
|
||||||
"config_type": "preferences",
|
"config_type": "preferences",
|
||||||
"description": "子应用UI偏好配置",
|
"description": "子应用UI偏好配置",
|
||||||
"status": true,
|
"status": true,
|
||||||
@@ -11764,7 +11764,7 @@
|
|||||||
"fields": {
|
"fields": {
|
||||||
"application_id": "uRFPsrZ0BSJodp-qesFq6",
|
"application_id": "uRFPsrZ0BSJodp-qesFq6",
|
||||||
"config_key": "frontend_preferences",
|
"config_key": "frontend_preferences",
|
||||||
"config_value": "{\"app\": {\"defaultHomePath\": \"/app/cheliangguanli/form-render/cheliangguanli\"}}",
|
"config_value": "{\"app\": {\"defaultHomePath\": \"/control-center\"}}",
|
||||||
"config_type": "preferences",
|
"config_type": "preferences",
|
||||||
"description": "子应用UI偏好配置",
|
"description": "子应用UI偏好配置",
|
||||||
"status": true,
|
"status": true,
|
||||||
|
|||||||
@@ -8,16 +8,10 @@ import { startProgress, stopProgress } from '@vben/utils';
|
|||||||
import { accessRoutes, coreRouteNames } from '#/router/routes';
|
import { accessRoutes, coreRouteNames } from '#/router/routes';
|
||||||
import { useAuthStore } from '#/store';
|
import { useAuthStore } from '#/store';
|
||||||
import { useAppContextStore } from '#/store/app-context';
|
import { useAppContextStore } from '#/store/app-context';
|
||||||
|
import { normalizeHomePath } from '#/utils/legacy-home';
|
||||||
|
|
||||||
import { generateAccess } from './access';
|
import { generateAccess } from './access';
|
||||||
|
|
||||||
function normalizeHomePath(path?: null | string) {
|
|
||||||
if (!path || path === '/page-render/main_home') {
|
|
||||||
return preferences.app.defaultHomePath;
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用守卫配置
|
* 通用守卫配置
|
||||||
* @param router
|
* @param router
|
||||||
@@ -118,9 +112,8 @@ function setupAccessGuard(router: Router) {
|
|||||||
// 基本路由,这些路由不需要进入权限拦截
|
// 基本路由,这些路由不需要进入权限拦截
|
||||||
if (coreRouteNames.includes(to.name as string)) {
|
if (coreRouteNames.includes(to.name as string)) {
|
||||||
if (to.path === LOGIN_PATH && accessStore.accessToken) {
|
if (to.path === LOGIN_PATH && accessStore.accessToken) {
|
||||||
return decodeURIComponent(
|
return normalizeHomePath(
|
||||||
(to.query?.redirect as string) ||
|
(to.query?.redirect as string) || userStore.userInfo?.homePath,
|
||||||
normalizeHomePath(userStore.userInfo?.homePath),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -211,13 +204,15 @@ function setupAccessGuard(router: Router) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 重定向逻辑
|
// 重定向逻辑
|
||||||
const redirectPath = (from.query.redirect ??
|
const redirectPath = normalizeHomePath(
|
||||||
|
(from.query.redirect ??
|
||||||
(to.path === preferences.app.defaultHomePath
|
(to.path === preferences.app.defaultHomePath
|
||||||
? normalizeHomePath(userInfo.homePath)
|
? userInfo.homePath
|
||||||
: to.fullPath)) as string;
|
: to.fullPath)) as string,
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...router.resolve(decodeURIComponent(redirectPath)),
|
...router.resolve(redirectPath),
|
||||||
replace: true,
|
replace: true,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { ref } from 'vue';
|
|||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { LOGIN_PATH } from '@vben/constants';
|
import { LOGIN_PATH } from '@vben/constants';
|
||||||
import { preferences } from '@vben/preferences';
|
|
||||||
import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
|
import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
|
||||||
|
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
@@ -12,13 +11,7 @@ import { defineStore } from 'pinia';
|
|||||||
import { getAccessCodesApi, loginApi, logoutApi } from '#/api/core/auth';
|
import { getAccessCodesApi, loginApi, logoutApi } from '#/api/core/auth';
|
||||||
import { getUserInfoApi } from '#/api/core/user';
|
import { getUserInfoApi } from '#/api/core/user';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
import { normalizeHomePath } from '#/utils/legacy-home';
|
||||||
function normalizeHomePath(path?: null | string) {
|
|
||||||
if (!path || path === '/page-render/main_home') {
|
|
||||||
return preferences.app.defaultHomePath;
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', () => {
|
export const useAuthStore = defineStore('auth', () => {
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { preferences } from '@vben/preferences';
|
||||||
|
|
||||||
|
const LEGACY_HOME_PATTERNS = [
|
||||||
|
/^\/app\/[^/]+\/(?:form-render|page-render)\//,
|
||||||
|
/^\/(?:form-render|page-render)\//,
|
||||||
|
/^\/online-dev(?:\/|$)/,
|
||||||
|
/^\/online-development(?:\/|$)/,
|
||||||
|
];
|
||||||
|
|
||||||
|
function decodePath(path: string) {
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(path);
|
||||||
|
} catch {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isLegacyHomePath(path: string) {
|
||||||
|
return LEGACY_HOME_PATTERNS.some((pattern) => pattern.test(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeHomePath(path?: null | string) {
|
||||||
|
if (!path) {
|
||||||
|
return preferences.app.defaultHomePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
const decodedPath = decodePath(path);
|
||||||
|
return isLegacyHomePath(decodedPath)
|
||||||
|
? preferences.app.defaultHomePath
|
||||||
|
: decodedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { normalizeHomePath };
|
||||||
@@ -10,8 +10,7 @@ import { $t } from '@vben/locales';
|
|||||||
|
|
||||||
import { getPreferencesConfigApi } from '#/api/core/ui-config';
|
import { getPreferencesConfigApi } from '#/api/core/ui-config';
|
||||||
import { useAuthStore } from '#/store';
|
import { useAuthStore } from '#/store';
|
||||||
|
import { normalizeHomePath } from '#/utils/legacy-home';
|
||||||
const LEGACY_HOME_PATH = '/page-render/main_home';
|
|
||||||
|
|
||||||
defineOptions({ name: 'Login' });
|
defineOptions({ name: 'Login' });
|
||||||
|
|
||||||
@@ -61,10 +60,6 @@ const getRedirectState = () => {
|
|||||||
return redirect ? JSON.stringify({ redirect }) : undefined;
|
return redirect ? JSON.stringify({ redirect }) : undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
function normalizeRedirectPath(path: string) {
|
|
||||||
return path === LEGACY_HOME_PATH ? '/' : path;
|
|
||||||
}
|
|
||||||
|
|
||||||
type OAuthProvider =
|
type OAuthProvider =
|
||||||
| 'dingtalk'
|
| 'dingtalk'
|
||||||
| 'feishu'
|
| 'feishu'
|
||||||
@@ -115,7 +110,7 @@ async function handleLogin(params: Record<string, any>) {
|
|||||||
if (redirect) {
|
if (redirect) {
|
||||||
// 有 redirect 参数时,登录成功后跳转到指定页面
|
// 有 redirect 参数时,登录成功后跳转到指定页面
|
||||||
await authStore.authLogin(params, async () => {
|
await authStore.authLogin(params, async () => {
|
||||||
const targetPath = normalizeRedirectPath(decodeURIComponent(redirect));
|
const targetPath = normalizeHomePath(redirect);
|
||||||
await router.push(targetPath);
|
await router.push(targetPath);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user