修改pc 移动端跳转切换

This commit is contained in:
浅念
2026-02-09 13:50:38 +08:00
parent 2198380c9f
commit 50684e42b9
+11 -16
View File
@@ -5,24 +5,19 @@
<script setup> <script setup>
import { onMounted } from 'vue' import { onMounted } from 'vue'
// 检测是否是移动端 const MOBILE_URL = 'https://bsh.yw.m.hnzhwlkj.cn'
function isMobile() {
// 方法1: 检测用户代理
const userAgent = navigator.userAgent || navigator.vendor || window.opera
const mobileRegex = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i
const isMobileByUA = mobileRegex.test(userAgent.toLowerCase())
// 方法2: 检测屏幕宽度
const isMobileByWidth = window.innerWidth <= 768
return isMobileByUA || isMobileByWidth
}
// 全局移动端检测和跳转
onMounted(() => { onMounted(() => {
if (isMobile()) { // 1. 检查 URL 参数(有参数 = 从另一个端跳转过来 = 停止检测)
// 如果是移动端,跳转到移动端地址 if (window.location.search.includes('from_mobile=1')) {
window.location.href = 'https://bsh.yw.m.hnzhwlkj.cn/' return // 不清理 URL,让它一直作为保护
}
// 2. 移动设备检测 + 跳转
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
if (isMobile) {
window.location.replace(`${MOBILE_URL}?from_pc=1`)
} }
}) })
</script> </script>