uniapp H5唤起手机App 中间下载页

我这里直接是打开中间下载页,在下载页判断手机是否已存在App,有则唤起App,没有则可点击下载按钮下载app。

唤起App的关键语句是:window.location.href =  scheme 

Scheme链接格式样式:
[scheme]://[host]/[path]?[query]

直接放全部代码:

<template>
  <div class="page">
    <div class="container">
      <div class="img-box">
        <img src="@/static/img/logo.png">
      </div>
      <div class="title">xxxApp</div>
      <div v-show="browser.versions.android" class="button" @tap="downloadAndroid">点击下载</div>
      <div v-show="browser.versions.ios" class="button" @tap="downloadIOS">点击下载</div>
    </div>
    <div class="cover">
      <div class="cover-content">
        <div class="cover-text">
          <div>请点击右上角按钮</div>
          <div>选择“在浏览器打开”来下载</div>
        </div>
        <div class="cover-img">
          <img src="@/static/img/download.png" alt="">
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import config from "@/config/config"
export default {
  data(){
    return{
      config,
      cover: '',
      browser: '',
      id: ''
    }
  },
  onLoad(val){
    this.id = val.id
  },
  onShow(){
    this.init()
  },
  methods: {
    init(){
      this.$nextTick(()=>{
        this.cover = document.querySelector(".cover");
        this.isWeixin();
      });
      this.browser = {
        versions: (function () {
          var u = navigator.userAgent,
            app = navigator.appVersion;
          return {
            trident: u.indexOf("Trident") > -1, //IE内核
            presto: u.indexOf("Presto") > -1, //opera内核
            webKit: u.indexOf("AppleWebKit") > -1, //苹果、谷歌内核
            gecko: u.indexOf("Gecko") > -1 && u.indexOf("KHTML") == -1, //火狐内核
            mobile:
              !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
            android: u.indexOf("Android") > -1 || u.indexOf("Linux") > -1, //android终端或者uc浏览器
            iPhone: u.indexOf("iPhone") > -1 || u.indexOf("Mac") > -1, //是否为iPhone或者QQHD浏览器
            iPad: u.indexOf("iPad") > -1, //是否iPad
            webApp: u.indexOf("Safari") == -1, //是否web应该程序,没有头部与底部
            weixin: u.match(/(MicroMessenger)/i), // 是否微信内打开
          };
        })(),
      };
      // console.log('this.browser', this.browser);
      if (this.browser.versions.ios) {
        window.open(config.downloadIOSLink, "_blank");
      }
      this.openApp()
    },
    /**
     * 打开app 仅在h5生效 使用ifream唤醒app
     */
    openApp() {
      let t = `${config.schemeLink}`;
      if(this.id){  
        // 如果需要跳转到其他H5页面,可以在这里修改一下
        t = `${config.schemeLink}pages/mine/myContacts?id=${this.id}`
      }
      try {
        var e = navigator.userAgent.toLowerCase(),
          n = e.match(/cpu iphone os (.*?) like mac os/);
        if (
          ((n = null !== n ? n[1].replace(/_/g, ".") : 0), parseInt(n) >= 9)
        ) {
          window.location.href = t;
        } else {
          var r = document.createElement("iframe");
          (r.src = t), (r.style.display = "none"), document.body.appendChild(r);
        }
      } catch (e) {
        window.location.href = t;
      }
    },
    isWeixin() {
      if (this.browser.versions.weixin) {
        this.cover.style.display = "block";
        return;
      }
    },
    showOrHide() {
      this.cover.style.display = "none";
    },
    downloadAndroid(){
      this.isWeixin();
      window.open(config.downloadAndroidLink, "_blank")
    },
    downloadIOS(){
      this.isWeixin();
      window.open(config.downloadIOSLink, "_blank");
    },
  }
}
</script>

<style lang="scss" scoped>
uni-page-body{
  height: 100%;
}
.page{
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background-image: linear-gradient(180deg, #37A60A, #72CF2B);
  position: relative;
  overflow: hidden;
  .container{
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: absolute;
    bottom: 500rpx;
    .img-box{
      width: 260rpx;
      img{
        width: 100%;
      }
    }
    .title{
      font-weight: bold;
      font-size: 30px;
      color: #ffffff;
      margin: 40rpx 0 160rpx 0;
    }
    .button{
      width: calc(100% - 80rpx);
      height: 90rpx;
      margin: 20rpx 30rpx;
      border: none;
      outline: none;
      color: #37A60A;
      background-color: #fff;
      border-radius: 90rpx;
      line-height: 90rpx;
      font-size: 18px;
      text-align: center;
      &:hover, &:focus, &:active{
        box-shadow: 1px 3px 12px rgba(0, 0, 0, 0.3);
      }
    }
  }
  .cover{
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10;
    display: none;
    .cover-content {
      width: 100%;
      height: 70px;
      background-color: #eeeeee;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 15px;
      box-sizing: border-box;
      .cover-text{
        color: #5f5d5d;
        font-size: 14px;
      }
      .cover-img img{
        width: 40px;
        height: 40px;
      }
    }
  }
}
</style>

其中:

上述代码中的schemeLink:xxxApp://

Android和ios的下载链接:一个放的apk安装包,一个是跳转到AppStore的

效果如下: 

  

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-19 05:48:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-19 05:48:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-19 05:48:05       82 阅读
  4. Python语言-面向对象

    2024-02-19 05:48:05       91 阅读

热门阅读

  1. Swift 指北

    2024-02-19 05:48:05       51 阅读
  2. DP进阶之最长递增子序列

    2024-02-19 05:48:05       62 阅读
  3. 【npm】npm镜像源及命令

    2024-02-19 05:48:05       50 阅读
  4. opencv进行人脸识别

    2024-02-19 05:48:05       48 阅读
  5. 企业面临的网络安全风险及应对策略

    2024-02-19 05:48:05       44 阅读
  6. 洛谷 P8630 [蓝桥杯 2015 国 B] 密文搜索

    2024-02-19 05:48:05       43 阅读
  7. npm详解:掌握package.json配置

    2024-02-19 05:48:05       50 阅读
  8. js-后端返回参数前端动态切换样式

    2024-02-19 05:48:05       43 阅读
  9. Python函数——函数介绍

    2024-02-19 05:48:05       55 阅读
  10. 不同编程网站应当注意的点

    2024-02-19 05:48:05       52 阅读
  11. C++入门

    C++入门

    2024-02-19 05:48:05      44 阅读
  12. 从零开始学HCIA之广域网技术01

    2024-02-19 05:48:05       45 阅读
  13. Deep深度系统下载安装Beyond compare4

    2024-02-19 05:48:05       56 阅读