vue H5 唤醒app

<template>
  <div>
    <div
      class="btn"
      @click="submitFn"
    >
      <div> 打开APP</div>
    </div>
    <div
      v-if="iosApp"
      id="guideZfbPayPage"
    >
      <div class="wx-open">
        <p>1.请点击右上角 • • •</p>
        <p>2.选择在浏览器中打开</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HomeView',
  data() {
    return {
      iosApp: false
    }
  },
  mounted() {
    if (this.isWeixin()) {
      this.iosApp = true
    } else {
      // 显示手动打开外置浏览器提示
      this.iosApp = false
      this.submitFn()
    }
  },
  methods: {
    isWeixin() {
      const u = navigator.userAgent.toLowerCase()
      return /micromessenger/i.test(u) || u.indexOf('weibo') > -1 || u.indexOf('qq') > -1 || u.indexOf('mqqbrowser') > -1
    },
    submitFn() {
      var t = 1000; var hasApp = true
      const u = navigator.userAgent
      const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1 // android终端或者uc浏览器
      setTimeout(function() {
        if (hasApp) {
          //    alert('安装了app');
          //    return false;
        } else {
          //    alert('未安装app');
          if (isAndroid) {
            window.location.href = 'https://......'// 下载网址
          } else {
            window.location.href = ''https://......'// 下载网址
          }
        }
        document.body.removeChild(ifr)
      }, 2000)

      var t1 = Date.now()
      var ifr = document.createElement('iframe')
      if (isAndroid) {
        ifr.setAttribute('src', '') // 安卓链接 不是https:
        ifr.setAttribute('style', 'display:none')
        document.body.appendChild(ifr)
      } else {
        window.location.href = '' // ios链接 不是https:
      }

      setTimeout(function() {
        var t2 = Date.now()
        if (!t1 || t2 - t1 < t + 100) {
          hasApp = false
        }
      }, t)
    }
  }
}
</script>

<style lang="scss" scoped>
/* 提示浏览器打开 */
#guideZfbPayPage {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    z-index: 777;
}
.btn{
  position: absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  >div{
    font-size: 0.27rem;
    font-family: PingFang SC-Semibold, PingFang SC;
    font-weight: 600;
    color: #6588D1;
    line-height: 0.41rem;
    padding: 0.2rem 0.41rem;
    background: #FFFFFF;
    border-radius: 0.14rem;
    border: 0.02rem solid #6588D1;
  }
}
.wx-open {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 888888;
}
.wx-open p {
    position: relative;
    top: 38%;
    margin-block-start: 0;
    color: white;
    font-size: 18px;
    line-height: 20px;
}
.wx-open img {
    width: 25%;
    border-style: none;
    position: absolute;
    transform: rotateZ(246deg);
    top: 6%;
    right: 28px;
}
</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值