修改pc 移动端跳转切换
This commit is contained in:
+10
-26
@@ -3,41 +3,25 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, onUnmounted } from 'vue'
|
||||
import { onMounted } from 'vue'
|
||||
|
||||
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(() => {
|
||||
redirectIfPc()
|
||||
if (typeof window !== 'undefined') {
|
||||
window.addEventListener('resize', handleResize)
|
||||
// 1. 检查 URL 参数(有参数 = 从另一个端跳转过来 = 停止检测)
|
||||
if (window.location.search.includes('from_pc=1')) {
|
||||
return // 不清理 URL,让它一直作为保护
|
||||
}
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.removeEventListener('resize', handleResize)
|
||||
// 2. PC 设备检测 + 跳转
|
||||
const isPC = !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
||||
|
||||
if (isPC) {
|
||||
window.location.replace(`${TARGET_URL}?from_mobile=1`)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
html,body,#app { height: 100%; margin: 0; }
|
||||
html, body, #app { height: 100%; margin: 0; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user