website/src/views/wxJump/WxJump.vue
2025-07-18 11:52:38 +08:00

61 lines
1.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="wrapper">
<p>正在打开小程序请稍候</p>
<button id="openBtn" class="btn" @click="forceOpen">
立即打开
</button>
</div>
</template>
<script setup>
import { onMounted } from 'vue'
// 1. 微信 URL Scheme替换为你自己的
const scheme = 'weixin://dl/business/?t=9FVo0FY1jLk'
// 2. 判断是否在微信内
const isWechat = /MicroMessenger/i.test(navigator.userAgent)
// 3. 微信内:优先用 JSSDK
function wxJump() {
if (!isWechat) return false
if (!window.wx) return false
wx.miniProgram.navigateTo({ url: 'pages/index/index' })
return true
}
// 4. 兜底URL Scheme
function schemeJump() {
location.href = scheme
}
// 5. 统一入口
function go() {
if (!wxJump()) schemeJump()
}
// 6. 页面加载后自动尝试
onMounted(() => {
go()
})
</script>
<style scoped>
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
font-size: 16px;
}
.btn {
margin-top: 30px;
padding: 12px 28px;
background: #07c160;
color: #fff;
border: none;
border-radius: 4px;
font-size: 16px;
}
</style>