update:新增网页中转和二维码跳转微信小程序

This commit is contained in:
lihaoyuan 2025-12-25 16:25:38 +08:00
parent 31ee325d93
commit edf1359dc4
3 changed files with 56 additions and 31 deletions

View File

@ -3,13 +3,9 @@
*/
import http from '../utils/http'
export function GetScheme (){
return new Promise((resolve, reject) => {
http({
url:'/api//admin/shop/wxqrcode/gen/common/wxurlscheme',
method:'post',
}).then(res=>{
resolve(res)
}).catch(e => reject(console.warn(e)))
export function GetScheme() {
return http({
url: '/api/admin/shop/wxqrcode/common/wxurlscheme',
method: 'post',
})
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

View File

@ -1,48 +1,72 @@
<template>
<div class="wrapper">
<p>正在打开小程序请稍候</p>
<button id="openBtn" class="btn" @click="forceOpen">
<div>
<img
src="@/assets/image/indexQRcode.png"
alt="小程序二维码"
class="qr-img"
style="width: 300px; height: 300px; margin-bottom: 20px;"
>
</div>
<p style="font-size: 30px;">小发同城和您一起享受本地生活服务</p>
<button id="openBtn" class="btn" @click="go">
立即打开
</button>
<button class="btn" @click="handleScheme">
测试获取
</button>
</div>
</template>
<script setup>
import { onMounted } from 'vue'
import {GetScheme} from '@/api/scheme.js'
// 1. URL Scheme
const scheme = 'weixin://dl/business/?t=9FVo0FY1jLk'
import { ref, onMounted } from 'vue'
import { GetScheme } from '@/api/scheme.js'
import { ElMessage } from 'element-plus'
// 2.
const scheme = ref('weixin://dl/business/?t=RNOoY1cRSDv')
//
const isWechat = /MicroMessenger/i.test(navigator.userAgent)
// 3. JSSDK
// JSSDK
function wxJump() {
if (!isWechat) return false
if (!window.wx) return false
wx.miniProgram.navigateTo({ url: 'pages/index/index' })
if (!window.wx) {
ElMessage.warning('微信JSSDK未加载将使用Scheme跳转')
return false
}
wx.miniProgram.navigateTo({ url: '/pages/index/index' }) // 路径补全/避免报错
return true
}
function handleScheme(){
let res=GetScheme();
console.log("数据",res);
// Scheme
async function handleScheme() {
try {
const res = await GetScheme()
if (res.code === 0 && res.data?.openlink) {
scheme.value = res.data.openlink // Scheme
} else {
ElMessage.error('获取Scheme失败' + (res.msg || '无有效链接'))
}
} catch (err) {
console.error('接口请求异常:', err)
ElMessage.error('网络异常,请重试!')
}
}
// 4. URL Scheme
function schemeJump() {
location.href = scheme
if (!scheme.value) {
ElMessage.warning('Scheme为空无法跳转')
return
}
location.href = scheme.value
}
// 5.
//
function go() {
if (!wxJump()) schemeJump()
}
// 6.
onMounted(() => {
//Scheme
onMounted(async () => {
await handleScheme() // Scheme
go()
})
</script>
@ -55,6 +79,7 @@ onMounted(() => {
justify-content: center;
height: 100vh;
font-size: 16px;
margin: 0; /* 清除默认边距 */
}
.btn {
margin-top: 30px;
@ -64,5 +89,9 @@ onMounted(() => {
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
}
.btn:hover {
background: #06b058;
}
</style>