<template>
<view class="content">
<image class="top-desc" src="../../.png">
</image>
<view class="goToDownLoad" @click="goDownload()">前往APP</view>
</view>
</template>
<script>
export default {
data() {
return {
neizhi: '',
iosLinkUrl: "itms-apps://itunes.apple.com/app/",
androidLinkurl: "",
huaweiUrl: '',
oppoUrl: "",
vivoUrl: "",
xiaomiUrl: ''
}
},
onLoad() {
uni.hideNavigationBarLoading(),
this.neizhi = this.is_neizhi(),
},
methods: {
is_neizhi() {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return "weixin";
} else if (ua.match(/QQ/i) == "qq") {
return "QQ";
} else if (ua.match(/Alipay/i) == "alipay" && payway == 2) {
return "alipay";
}
return false;
},
verifyBrand() {
const userAgent = navigator.userAgent.toLowerCase();
const isIphone = userAgent.match(/(iphone|ipad|ipod)/i);
const isHuawei = userAgent.match(/huawei/i);
const isHonor = userAgent.match(/honor/i);
const isOppo = userAgent.match(/oppo/i);
const isOppoR15 = userAgent.match(/PACM00/i);
const isVivo = userAgent.match(/vivo/i);
const isXiaomi = userAgent.match(/mi\s/i);
const isXIAOMI = userAgent.match(/xiaomi/i);
const isXiaomi2s = userAgent.match(/mix\s/i);
const isRedmi = userAgent.match(/redmi/i);
if (isIphone) {
return 'iphone'
} else if (isHuawei) {
return 'huawei';
} else if (isOppo || isOppoR15) {
return 'oppo';
} else if (isVivo) {
return 'vivo';
} else if (isXiaomi || isRedmi || isXiaomi2s || isXIAOMI) {
return 'xiaomi';
} else {
return 'other'
}
},
goDownload() {
if (this.neizhi) {
//内置浏览器 可加提示使其打开手机自带浏览器
uni.showToast({
title: "请使用手机自带浏览器打开",
duration: 2000
})
return;
}
const brand = this.verifyBrand()
console.log("brand",brand)
switch (brand) {
case 'iphone':
console.log("iosLinkUrl",this.iosLinkUrl)
window.location.href = this.iosLinkUrl;
break;
case 'xiaomi':
window.location.href = this.xiaomiUrl;
break;
case 'huawei':
window.location.href = this.huaweiUrl;
break;
case 'vivo':
window.location.href = this.vivoUrl;
break;
case 'oppo':
window.location.href = this.oppoUrl;
break;
default:
this.downloadFile(this.androidLinkurl,"hyt_prd.apk")
break;
}
},
downloadFile(url, fileName) {
fetch(url)
.then(response => response.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
})
.catch(error => console.error('Error downloading the file:', error));
}
}
}
</script>
<style>
.content {
width: 100%;
height: 100%;
background-color: #fff;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 100;
}
.top-desc {
width: 100vw;
height: 100vh;
}
.goToDownLoad {
margin-left: 20rpx;
position: fixed;
background-color: #5779FA;
color: white;
bottom: 100rpx;
border-radius: 15rpx;
height: 80rpx;
width: calc(100vw - 40rpx);
box-sizing: border-box;
padding: 20rpx;
text-align: center;
}
</style>