layout-link.vue 1.06 KB
<template>
  <a href="javascript:;" class="layout-link" @click="jumpTo">
    <slot></slot>
  </a>
</template>

<script>
import { mapGetters } from 'vuex';
import queryString from 'querystring'

export default {
  name: 'LayoutLink',
  props: {
    href: String,
    report: {
      type: Object,
    },
    reportEvent: String,
  },
  computed: {
    ...mapGetters(['getLogin'])
  },
  watch: {
    report: function(newVal) {
    },
  },
  methods: {
    jumpTo() {

      if (!this.href) {
        return;
      }
      // 资源位跳转 领券等需判断是否登录
      // 判断条件为查询参数 isNeedLogin
      const qsParams = queryString.parse(this.href.split('?')[1]);
      if(!this.getLogin && +qsParams.isNeedLogin === 1) {
        this.$yoho.auth();
        return;
      }

      this.$xianyu.goXianyuNewPage({
        url: this.href
      });

      if (this.reportEvent) {
        this.$store.dispatch('reportYas', {
          params: {
            appop: this.reportEvent,
            param: this.report
          }
        });
      }
    }
  }
};
</script>