import store from '@/store'
import { getAccessToken } from './auth';

function uploadFile(filePath) {
  uni.showLoading({
    title:"上传中..."
  })
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: 'https://test.api.chelvc.com/maintain/file', //仅为示例，非真实的接口地址
      filePath: filePath,
      name: 'file',
      header:{
        'Content-Type': 'multipart/form-data',
        platform: store.getters.app.system.osName.toUpperCase(),
        terminal: 'APPLET', // TODO:
        version: store.getters.app.system.appVersion.toUpperCase(),
        // scope: store.getters.scope,
        device: store.getters.app.system.deviceId,
        timestamp: new Date().getTime(),
        Authorization: `Bearer ${getAccessToken()}`
      },
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      },
      complete:()=>{
        uni.hideLoading()
      }
    });
  })

}

export {
  uploadFile
}
