前往AP...">
美文网首页
点击扫描二维码, 跳转首页,点击按钮进行app的下载

点击扫描二维码, 跳转首页,点击按钮进行app的下载

作者: 可乐小子 | 来源:发表于2024-08-13 13:45 被阅读0次

<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>

相关文章

网友评论

      本文标题:点击扫描二维码, 跳转首页,点击按钮进行app的下载

      本文链接:https://www.haomeiwen.com/subject/umkjkjtx.html