场景:微信扫描二维码跳转下载页面下载apk失败,提示浏览器打开下载。
实现思路:添加下载页面及路由,将该路由地址生成二维码,判断是否是微信扫描,如果是,给这个下载页面添加一个遮罩层并提示使用浏览器打开。(http协议下,浏览器扫描可直接下载)
实现步骤:
1、配置路由和添加下载 页面
路由配置
{
path: "/appDownload",
name: "appDownload",
component: () => import("@/views/app/app.vue"),
},
下载页面
<template>
<div class="background">
<div class="downBtn">
<a :href="url1">
<el-button type="primary" class="pdaButton">WMS(PDA)应用下载</el-button></a>
<a :href="url2">
<el-button type="primary" class="pdaButton">WMS(领用)应用下载</el-button>
</a>
<p>安卓需 Android6.0以上操作系统</p>
<p>不支持IOS下载</p>
</div>
//遮罩层
<div v-if="isWeixin" class="appDialog">
<img src="../../assets/images/appDialog.png" alt="">
</div>
</div>
</template>
<script>
import api from "@/api";
const { getApp } = api.app;
export default {
data() {
return {
isWeixin: false,
url1: '',
url2: ''
}
},
created() {
//判断是否微信扫描
let ua = navigator.userAgent;
this.isWeixin = !!/MicroMessenger/i.test(ua);
this.download('app包名1')
this.download('app包名2')
},
methods: {
download(data) {
getApp(data).then(res => {
if (data === 'app包名1') {
this.url1 = res.data
}
this.url2 = res.data
})
}
}
}
</script>
<style scoped>
.background {
background-image: url(../../assets/images/appDownloadImage.png);
background-size: 100% 100%;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
position: relative;
}
.downBtn {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 60%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.downBtn p {
font-size: 12px;
color: #8E8E8E;
}
.pdaButton {
width: 250px;
margin: 20px;
border-radius: 200px;
}
.appDialog {
height: 100%;
width: 100%;
position: fixed;
background: rgba(0, 0, 0, 0.6);
padding: 20px;
padding-top: 50px;
}
.appDialog img {
width: 100%;
}
</style>
2、网址生成二维码
3、效果
微信扫描的结果
右上角浏览器打开