From 775486340228f0b11dfa6e48b453380fa112074c Mon Sep 17 00:00:00 2001 From: admin <417727563@qq.com> Date: Mon, 19 May 2025 18:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE0519-2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4c05e9d..a137e0f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -50,14 +50,20 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) { // 初始化主题 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 +} + +