修改pc 移动端跳转切换
This commit is contained in:
+9
-25
@@ -3,37 +3,21 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, onUnmounted } from 'vue'
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
const TARGET_URL = 'https://bsh.yw.hnzhwlkj.cn'
|
const TARGET_URL = 'https://bsh.yw.hnzhwlkj.cn'
|
||||||
|
|
||||||
const isPcDevice = () => {
|
|
||||||
if (typeof navigator === 'undefined') return false
|
|
||||||
const mobileRegex = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
|
|
||||||
return !mobileRegex.test(navigator.userAgent || '')
|
|
||||||
}
|
|
||||||
|
|
||||||
const redirectIfPc = () => {
|
|
||||||
if (typeof window === 'undefined') return
|
|
||||||
if (isPcDevice()) {
|
|
||||||
window.location.replace(TARGET_URL)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleResize = () => {
|
|
||||||
redirectIfPc()
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
redirectIfPc()
|
// 1. 检查 URL 参数(有参数 = 从另一个端跳转过来 = 停止检测)
|
||||||
if (typeof window !== 'undefined') {
|
if (window.location.search.includes('from_pc=1')) {
|
||||||
window.addEventListener('resize', handleResize)
|
return // 不清理 URL,让它一直作为保护
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
// 2. PC 设备检测 + 跳转
|
||||||
if (typeof window !== 'undefined') {
|
const isPC = !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
||||||
window.removeEventListener('resize', handleResize)
|
|
||||||
|
if (isPC) {
|
||||||
|
window.location.replace(`${TARGET_URL}?from_mobile=1`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user