export default async function (params) {
  const app = getApp().globalData

  uni.showLoading({
    mask: true
  })

  const url = `${app.env.baseUrl}/admin-api/infra/file/upload`
  const token = uni.getStorageSync('token')
  const {
    file
  } = params

  return await uni.uploadFile({
    url,
    file,
    name: 'file',
    header: {
      // "Content-Type": "multipart/form-data",
      'X-Access-Token': token,
      'Authorization': `Bearer ${token}`
    },
  }).then(res => {
    uni.hideLoading()
    return JSON.parse(res.data)
  })
    .catch(async err => {
      uni.hideLoading()
      await uni.showToast({
        title: '上传图片失败',
        mask: true
      })
    })
}