From 327637f94c196b3fbe125c59b9ae5677747fa607 Mon Sep 17 00:00:00 2001 From: v6ole Date: Fri, 26 Jun 2026 15:33:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E5=8A=A8=E7=AB=AF/=E6=A1=8C?= =?UTF-8?q?=E9=9D=A2=E7=AB=AF=E8=87=AA=E5=8A=A8=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - utils/index.ts: 新增 isMobile() 检测 user-agent - router: beforeEach 守卫中根据设备自动跳转 - 手机访问 / 桌面路由 → 自动跳 /m - 桌面访问 /m 移动路由 → 自动跳 / Co-Authored-By: Claude --- frontend/src/router/index.ts | 14 ++++++++++++++ frontend/src/utils/index.ts | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 2bdefa6..919b292 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -1,5 +1,6 @@ import { createRouter, createWebHistory } from 'vue-router' import { useAuthStore } from '@/stores/auth' +import { isMobile } from '@/utils' const router = createRouter({ history: createWebHistory(), @@ -73,6 +74,19 @@ router.beforeEach((to, _from, next) => { next('/login') return } + + // Auto-redirect to mobile layout for mobile devices accessing desktop routes + const onMobile = isMobile() + if (onMobile && to.path === '/' && !to.path.startsWith('/m')) { + next('/m') + return + } + // Desktop user accidentally on mobile route → redirect to desktop + if (!onMobile && to.path.startsWith('/m')) { + next('/') + return + } + next() }) diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 4778a14..291dd87 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -3,3 +3,9 @@ export function todayStr(): string { const d = new Date() return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}` } + +/** Detect if current device is mobile based on user-agent. */ +export function isMobile(): boolean { + const ua = navigator.userAgent || '' + return /Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i.test(ua) +}