修改pc 移动端跳转切换
This commit is contained in:
parent
2198380c9f
commit
50684e42b9
25
src/App.vue
25
src/App.vue
@ -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: 检测屏幕宽度
|
onMounted(() => {
|
||||||
const isMobileByWidth = window.innerWidth <= 768
|
// 1. 检查 URL 参数(有参数 = 从另一个端跳转过来 = 停止检测)
|
||||||
|
if (window.location.search.includes('from_mobile=1')) {
|
||||||
return isMobileByUA || isMobileByWidth
|
return // 不清理 URL,让它一直作为保护
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全局移动端检测和跳转
|
// 2. 移动设备检测 + 跳转
|
||||||
onMounted(() => {
|
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
||||||
if (isMobile()) {
|
|
||||||
// 如果是移动端,跳转到移动端地址
|
if (isMobile) {
|
||||||
window.location.href = 'https://bsh.yw.m.hnzhwlkj.cn/'
|
window.location.replace(`${MOBILE_URL}?from_pc=1`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user