样式优化
This commit is contained in:
@@ -25,15 +25,33 @@ const isMobile = (): boolean => {
|
||||
|
||||
// 标记是否已跳转到移动端路由,防止无限循环
|
||||
let hasRedirectedToMobile = false;
|
||||
|
||||
// 新增:标记是否已从/mobile跳转到/dashboard,防止无限循环
|
||||
let hasRedirectedToDashboard = false;
|
||||
// 优化后的移动端跳转守卫(登录优先)
|
||||
const MobileRedirectGuard: NavigationGuard = function (to, from, next) {
|
||||
// 1. 排除移动端路由和登录页,避免逻辑干扰
|
||||
const isMobileRoute = to.path === '/mobile';
|
||||
const isLoginRoute = to.path === '/login';
|
||||
// 新增:检测当前是否为非移动端设备
|
||||
const isNonMobile = !isMobile();
|
||||
|
||||
// 【新增核心逻辑】:当前路由是/mobile,但不是移动端设备,跳转到/dashboard
|
||||
if (isMobileRoute && isNonMobile) {
|
||||
if (!hasRedirectedToDashboard) {
|
||||
hasRedirectedToDashboard = true;
|
||||
// 重置移动端跳转标记,避免后续干扰
|
||||
hasRedirectedToMobile = false;
|
||||
next({ path: '/dashboard' });
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (isMobileRoute) {
|
||||
hasRedirectedToMobile = true;
|
||||
// 重置dashboard跳转标记,避免后续干扰
|
||||
hasRedirectedToDashboard = false;
|
||||
next();
|
||||
return;
|
||||
}
|
||||
@@ -41,6 +59,7 @@ const MobileRedirectGuard: NavigationGuard = function (to, from, next) {
|
||||
if (isLoginRoute) {
|
||||
// 登录页无需移动端跳转,直接放行
|
||||
hasRedirectedToMobile = false; // 重置标记,登录后可正常跳转移动端
|
||||
hasRedirectedToDashboard = false; // 重置dashboard跳转标记
|
||||
next();
|
||||
return;
|
||||
}
|
||||
@@ -55,30 +74,31 @@ const MobileRedirectGuard: NavigationGuard = function (to, from, next) {
|
||||
// 已登录:跳移动端(防止重复跳转)
|
||||
if (!hasRedirectedToMobile) {
|
||||
hasRedirectedToMobile = true;
|
||||
hasRedirectedToDashboard = false; // 重置dashboard跳转标记
|
||||
next({ path: '/mobile' });
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 非移动端:重置标记,不影响后续操作
|
||||
// 非移动端:重置所有标记,不影响后续操作
|
||||
hasRedirectedToMobile = false;
|
||||
hasRedirectedToDashboard = false;
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
// 原有守卫逻辑(无修改)
|
||||
const loginGuard: NavigationGuard = function (to, from, next) {
|
||||
if (!http.checkAuthorization() && !/^\/(init|login|home|mobile)?$/.test(to.fullPath)) {
|
||||
console.log(to.fullPath)
|
||||
const account = useAccountStore();
|
||||
account.setLogged(false);
|
||||
// 重置dashboard跳转标记
|
||||
hasRedirectedToDashboard = false;
|
||||
next('/login');
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
const dynamicinitRoute = {
|
||||
path: '/',
|
||||
name: 'login',
|
||||
@@ -154,11 +174,24 @@ const NotFoundGuard: NaviGuard = {
|
||||
|
||||
// 优化后的页面刷新移动端检测(登录优先)
|
||||
window.addEventListener('load', () => {
|
||||
if (isMobile() && window.location.pathname !== '/mobile') {
|
||||
const currentPath = window.location.pathname;
|
||||
const isNonMobile = !isMobile();
|
||||
|
||||
// 【新增】:刷新后如果是/mobile路由且非移动端,跳转到/dashboard
|
||||
if (currentPath === '/mobile' && isNonMobile) {
|
||||
router.push('/dashboard').catch(err => {
|
||||
if (!err.message.includes('NavigationDuplicated')) {
|
||||
console.error('刷新时从/mobile跳转到/dashboard失败:', err);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (isMobile() && currentPath !== '/mobile') {
|
||||
const isAuthorized = http.checkAuthorization();
|
||||
if (!isAuthorized) {
|
||||
// 未登录:跳登录(避免重复跳转)
|
||||
if (window.location.pathname !== '/login') {
|
||||
if (currentPath !== '/login') {
|
||||
router.push('/login').catch(err => {
|
||||
if (!err.message.includes('NavigationDuplicated')) {
|
||||
console.error('刷新时跳转登录页失败:', err);
|
||||
|
||||
Reference in New Issue
Block a user