import { request } from 'umi';
import { getApiUrl } from '@/global_data';

export default {
  myrequst(option, methods = 'GET') {
    let { url, data, contentType } = option;

    const newurl = getApiUrl() + url;
    console.log('我是请求',newurl);
    if (methods == 'GET') {
      return request(newurl, {
        method: methods,
        timeout: 5000,
        skipErrorHandler: true,
      });
    } else if (methods == 'POST') {
      return request(newurl, {
        method: methods,
        timeout: 5000,
        data: data,
        skipErrorHandler: true,
      });
    }
    return '';
  },
  get(url, data = '') {
    let option = { url, data };
    return this.myrequst(option);
  },
  post: function (url, data) {
    let option = { url, data };
    return this.myrequst(option, 'POST');
  },
};
