export const path = `${location.origin}/service`
// get方法
export function get(url, data = {}) {
  url = path + url;
  return new Promise((resolve, reject) => {
    uni.request({
      url,
      data,
      header: {
        'Cache-Control': 'no-cache'
      },
      success(res) {
        if(res.statusCode === 200){
          resolve(res.data);
        }else{
          reject();
          uni.showToast({
            icon: 'none',
            title: '请求数据失败!'
          });
        }
      },
      fail(err) {
        reject();
        uni.showToast({
          icon: 'none',
          title: '请求数据失败!'
        });
      }
    })
  });
}
// post方法
export function post(url, data = {}) {
  url = path + url;
  return new Promise((resolve, reject) => {
    uni.request({
      method: 'POST',
      url,
      data,
      header: {
        'Cache-Control': 'no-cache'
      },
      success(res) {
        if(res.statusCode === 200){
          resolve(res.data);
        }else{
          reject();
          uni.showToast({
            icon: 'none',
            title: '请求数据失败!'
          });
        }
      },
      fail(err) {
        reject();
        uni.showToast({
          icon: 'none',
          title: '请求数据失败!'
        });
      }
    })
  });
}