function fetch (method, url, data, loading){
  return new Promise((resolve, reject) => {
      //显示加载动画
      if (loading) uni.showLoading({title: '数据加载中...',mask: true});
      // let URL = 'http://localhost:9529' + url
      // let URL = 'https://xcx.sgjyun.com' + url
      let URL = 'https://xcx.kuyicloud.com' + url
      //获取token
      // let token = wx.getStorageSync("token")
      
      // let obj = { token, }
      //添加token
      // Object.assign(data,obj)
	  let header = {"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"}
      //发起请求
      uni.request({
		  url: URL,
		  method: method,
		  header: header,
		  data: data || {},
		  success: res => {
			  let code = res.data.code
			  let message = res.data.message
			  
			  resolve(res);
		  },
		  fail: err => {
			  uni.hideLoading();
			  // console.log(err)
			  reject(err)
		  },
		  complete: () => {
			uni.hideLoading(); 
		  }
      });
  })
}

export default {
  get: function (url, params, loading){
      return fetch('GET', url, params, loading)
  },
  post: function (url, params, loading){
      return fetch('POST', url, params, loading)
  },
  put: function (url, params, loading){
      return fetch('PUT', url, params, loading)
  },
  delete: function (url, params, loading){
      return fetch('DELETE', url, params, loading)
  }
}