import axios from "axios";

//全局配置
// axios.defaults.baseURL = "http://139.159.228.85:8080"
// axios.defaults.timeout = 5000

// //拦截器
// axios.interceptors.request.use(config => {
//   return config
// }, error => {
//   return Promise.error(error)
// })
// axios.interceptors.response.use(response => {
//   return response.data
// }, error => {
//   return Promise.error(error)
// })

export function request(url = '', params = {}, type = 'POST') {
  //设置 url params type 的默认值
  return new Promise((resolve, reject) => {
    let promise
    if (type.toUpperCase() === 'GET') {
      promise = axios({
        url,
        params
      })
    } else if (type.toUpperCase() === 'POST') {
      promise = axios({
        method: 'POST',
        url,
        data: params
      })
    }
    //处理返回
    promise.then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}