61 lines
1.1 KiB
Vue
61 lines
1.1 KiB
Vue
<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> |