import request from '@/https/request';
import AppHelper from '@/utils/AppHelper';
import {stringify} from 'qs';

export default {


  /**
   * 下载文件
   * @param url
   * @param params
   */
  downloadFile: (url, params) => {
    return request(url, {method: 'POST', data: {...params}}).then(res => {
      if (res.code === 200) {
        window.location.href = res.data;
      } else {
        AppHelper.showRespError(res);
      }
    });
  },

  /**
   * 直接下载文件
   * @param url
   * @param params
   */
  downloadByWindow: (url, params) => {
    let query = {token: sessionStorage.getItem('token'), ...params};
    window.location.href = url + '?' + stringify(query);
  },


};
