import request from './request';
import defaultSetting from '../../config/defaultSettings';

export async function doFetch({ url, params }) {
  if (!url) {
    return;
  }
  if (url.indexOf('token') != -1) {
    return request(url, {
      method: 'post',
      data: params,
    });
  } else {
    return request(defaultSetting.proxypath + url, {
      method: 'post',
      data: params,
    });
  }
}

export async function postFetch({ url, params }) {
  return request(url, {
    method: 'post',
    data: params,
  });
}

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

export async function formFetch({ url, params }) {
  return request(url, {
    method: 'post',
    data: params,
    type: 'form',
  });
}
