doFetch.js 1009 Bytes
Newer Older
wuhao's avatar
wuhao committed
1
import request from './request';
wuhao's avatar
wuhao committed
2
import defaultSetting from '../../config/defaultSettings';
wuhao's avatar
wuhao committed
3 4 5 6 7

export async function doFetch({ url, params }) {
  if (!url) {
    return;
  }
wuhao's avatar
wuhao committed
8 9 10 11 12 13 14 15 16 17 18
  if (url.indexOf('token') != -1) {
    return request(url, {
      method: 'post',
      data: params,
    });
  } else {
    return request(defaultSetting.proxypath + url, {
      method: 'post',
      data: params,
    });
  }
wuhao's avatar
wuhao committed
19 20 21
}

export async function postFetch({ url, params }) {
22 23 24 25 26 27 28
  return request(defaultSetting.proxypath + url, {
    method: 'post',
    data: params,
  });
}
export async function exportFetch({ url, params }) {
  return request(defaultSetting.proxypath + url, {
wuhao's avatar
wuhao committed
29 30
    method: 'post',
    data: params,
31
    responseType: 'blob'
wuhao's avatar
wuhao committed
32 33 34 35 36 37 38 39 40 41 42
  });
}

export async function getFetch({ url, params }) {
  return request(url, {
    method: 'get',
    params,
  });
}

export async function formFetch({ url, params }) {
43
  return request(defaultSetting.proxypath + url, {
wuhao's avatar
wuhao committed
44 45 46 47 48
    method: 'post',
    data: params,
    type: 'form',
  });
}