callAppBox.vue 3.18 KB
<template>
    <div class="call-app-box" v-if="callApps">

		<!-- Android WeChat内无法唤起APP,提示用浏览器打开蒙层 -->
		<mask-layer ref="maskLayer"
			:maskLayers="maskLayers">
		</mask-layer>
		
		<div class="box">
			<div class="logo-box">
				<img src="static/img/call_app_logo.png" class="img" />
			</div>
			<div class="buttons-box">
				<div class="btn btn-default" @click="callApp">打开APP</div>
			</div>
		</div>
    </div>
</template>

<script>

// 导入跳转方法组件
import openAppOld from "@/common/openAppOld.js";
import maskLayer from "@/components/maskLayer/maskLayer";

export default {
  data: function () {
    return {
      maskLayers: null,				// 蒙层对象
      downLoadBtnData: {
        data: "",
        source: "",
        channelName: this.$route.query.channelName,		//频道名称
        title: "下载好家园,观看更多优质内容",
      }
    }
  },
  props: ["callApps"],
  components: {
    maskLayer
  },
  methods: {

    /**
     * H5唤起App按钮事件
     */
    callApp () {

      /**
       * 走openinstall拉起下载APP
       * 通过分享页面下载完可以拉起到指定页面
       */
      if (typeof this.callApps.funcs === "object") {

        // 拼接参数字符串,根据分享参数拼接
        let shareString = "shop_shop_type=" + this.callApps.funcs.callAppParams.shop_shop_type + "&shop_to=" + this.callApps.funcs.callAppParams.shop_to + "&shop_type=" + this.callApps.funcs.callAppParams.shop_type + "&share_mold=" + this.callApps.funcs.callAppParams.share_mold;

        // 临时 硬加参数
        if (this.isAndroid.value && this.$router && this.$router.history.current.name == 'labourUnion2') {

          // 设置请求参数,添加shop_extra=1
          shareString += "&shop_extra=1";
        } else 

        // 判断是否有扩展参数,如果有,拼接扩展参数到原始字符串
        if (this.callApps.funcs.callAppParams.shop_ext) {

          // 拼接扩展参数到原始字符串
          shareString += "&shop_extra=" + this.callApps.funcs.callAppParams.shop_ext;
        }

        // Base64位编码加密
        const CryptoJS = require("crypto-js");
        const wordArray = CryptoJS.enc.Utf8.parse(shareString);
        let shopData = encodeURIComponent(CryptoJS.enc.Base64.stringify(wordArray));

        // 设置下载参数
        this.$set(this.downLoadBtnData, 'data', 'channel_id=' + (this.mode === 'prod' ? 'cnlive_mall' : 'cnlive_mall_test') + '&type=shop' + '&shopData=' + shopData);

        if (this.isiPhone.value || this.isiPad.value) {
          openAppOld.submitFn.call(this, this.downLoadBtnData);
        } else if (this.isAndroid.value) {
          if (this.isWeChat.value) {

            // 设置蒙层图片
            this.$set(this, "maskLayers", {
              img: "static/img/mask_layer_browser.png",
            });

            // 显示蒙层
            this.$refs.maskLayer.showLayer();
          } else {
            openAppOld.submitFn.call(this, this.downLoadBtnData);
          }
        }
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style rel="stylesheet/less" lang="less">
@import './callAppBox';
</style>