From b59dce220fafbe5f980cc4ecfea97a47a5a11f35 Mon Sep 17 00:00:00 2001 From: JayChou Date: Mon, 19 May 2025 09:18:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=BF=E9=97=AE=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=BE=AA=E7=8E=AF=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.ts b/src/main.ts index cbd63a1..b219fd7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -52,11 +52,15 @@ const useThemeStore = themeStore() useThemeStore.initTheme() const ua = navigator.userAgent.toLowerCase() const isMobile = /iphone|android|ipad|mobile/.test(ua) -if (isMobile) { - console.log('手机端') - // location.href = import.meta.env.VITE_APP_MOBILE_URL -} else if (!isMobile) { - console.log('电脑端') - // location.href = import.meta.env.VITE_APP_PC_URL - -} \ No newline at end of file + +const currentHost = location.host +const mobileHost = new URL(import.meta.env.VITE_APP_MOBILE_URL).host +const pcHost = new URL(import.meta.env.VITE_APP_PC_URL).host + +if (isMobile && currentHost !== mobileHost) { + console.log('手机端,跳转到移动站') + location.href = import.meta.env.VITE_APP_MOBILE_URL +} else if (!isMobile && currentHost !== pcHost) { + console.log('电脑端,跳转到 PC 站') + location.href = import.meta.env.VITE_APP_PC_URL +}