import {
  baseURL
} from '../../config/api'
import {
  getToken
} from '../permission/login'
export function request({
  path,
  params,
  method
}) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseURL + path, //仅为示例，并非真实的接口地址
      data: params,
      header: {
        'content-type': 'application/json', // 默认值
        'X-API-TOKEN': getToken()
      },
      method: method,
      success(res) {
        console.log(res.data)
        resolve(res.data);
      },
      fail(res) {
        console.log(res);
        reject(res)
      }
    })
  })
}

export function uploadFile({
  path,
  url,
  data
}) {
  return new Promise((resolve, reject) => {
    wx.uploadFile({
      url: baseURL + path, //接口地址
      filePath: url,
      name: 'file',
      header: {
        "X-API-TOKEN": getToken()
      },
      formData: data,
      success: function (res) {
        console.log(res)
      },
      fail: function (res) {
        console.log(res);
      }
    })
  })
}