修改pc 移动端跳转切换
This commit is contained in:
parent
2198380c9f
commit
50684e42b9
27
src/App.vue
27
src/App.vue
@ -5,24 +5,19 @@
|
||||
<script setup>
|
||||
import { onMounted } from 'vue'
|
||||
|
||||
// 检测是否是移动端
|
||||
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
|
||||
}
|
||||
const MOBILE_URL = 'https://bsh.yw.m.hnzhwlkj.cn'
|
||||
|
||||
// 全局移动端检测和跳转
|
||||
onMounted(() => {
|
||||
if (isMobile()) {
|
||||
// 如果是移动端,跳转到移动端地址
|
||||
window.location.href = 'https://bsh.yw.m.hnzhwlkj.cn/'
|
||||
// 1. 检查 URL 参数(有参数 = 从另一个端跳转过来 = 停止检测)
|
||||
if (window.location.search.includes('from_mobile=1')) {
|
||||
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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user