download.js 1.28 KB
const serverDownloadMixin = {
  methods: {
    async isDownloadBarHide() {
      return true;
    },

    async isMiniapp() {
      return false;
    },

    openByBrowser() {

    }

  }
};

const clientDownloadMixin = {
  methods: {
    async isDownloadBarHide() {
      let isMiniapp = await this.isMiniapp();

      if (isMiniapp) {
        return true;
      }

      return document.getElementById('no-download');
    },

    isMiniapp() {
      /* eslint-disable-next-line */
      return this.$store.$context.env.isMiniApp;
    },

    sleep(ns) {
      return new Promise(resolve => {
        setTimeout(resolve, ns);
      });
    },

    openByBrowser() {
      let appPathUrl = window.location.pathname;

      const query = Object.assign({}, this.$route.query, {
        headerid: -1,
        toplayoutByH5: 'Y'
      });

      const openBy = {
        action: 'go.h5',
        params: {
          url: 'http://m.yohobuy.com' + appPathUrl,
          param: JSON.stringify(query)
        }
      };

      this.$router.push({
        name: 'openByBrowser',
        query: {
          'openby:yohobuy': encodeURIComponent(JSON.stringify(openBy)),
          share: false
        }
      });
    }
  }
};

export default process.env.VUE_ENV === 'server' ?
  serverDownloadMixin :
  clientDownloadMixin;