

import axios from "axios";
import base from "../assets/js/base.js"



var qs = require("qs");
let message = base.message;

axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// axios.defaults.withCredentials = true;



// code  // 200成功
          // 700 重新登录
          // 401
          // 500

//请求响应拦截
axios.interceptors.response.use(function (response) {
    return response.data;

}, function (error) {
  return Promise.reject(error);
});




// objUrl,地址
// objMethods,提交方式
// objData, 提交的数据
// cb,回调函数

function axiosMethods(objMethods,objUrl,objData,cb,ip = base.ip) {
  // console.log(objUrl)
  axios.defaults.baseURL = ip;

  switch (objMethods){
    //get
    case "get":axios({
      url: objUrl,
      method: objMethods,
      params:objData
    }).then(function (response) {

      cb(response)
      // cb(JSON.parse(response.data))
    });
      break;

    // post
    case "post": axios({
      url: objUrl,
      method: objMethods,
      data: qs.stringify(objData),

    }).then((response) => {
      cb(response);
    });
      break;

  }
}


export default {
  AxiosMethods:axiosMethods
}
