replace-to-home.vue 1.33 KB
<template>
  <a v-if="isShow"
      class="back-btn hover-opacity"
     :class="{'scroll-opacity': scrolling}"
     :href="toHomeHref || 'javascript:;'">
  </a>
</template>

<script>
import _ from 'lodash';
import qs from 'querystring';

export default {
  name: 'replace-to-home',
  props: {
    scrolling: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return {
      toHomeHref: '//m.yohobuy.com?openby:yohobuy= {"action":"go.guangchannel","params":{"index":"1"}}',
      hasBackToHome: 0,
      isShow: false
    };
  },
  mounted() {
    // 地址栏携带参数过来,并且当前页面不在app中
    const hasBackToHome = _.chain(window.location.href)
      .thru(n => n.split('?'))
      .get('[1]', '')
      .thru(qs.parse)
      .get('hasBackToHome', 0)
      .thru(JSON.parse)
      .thru(n => n === 1 ? 1 : 0)
      .value();

    // && this.$yoho.isApp;

    this.isShow = hasBackToHome === 1 && this.$yoho.isApp;
  }
};
</script>

<style scoped>
.back-btn {
  width: 260px;
  height: 80px;
  position: absolute;
  left: calc(50% - 130px);
  z-index: 999;
  display: flex;
  align-items: center;
  transition: all 600ms ease-in-out;
  background-image: url("~statics/image/article/back_zc@3x.png");
  background-size: contain;
  background-repeat: no-repeat;

  &.scroll-opacity {
    opacity: 0.3;
  }
}
</style>