import Axios from 'axios'
/**
 * 上传文件
 *
 * @param file
 */
export async function uploadFileApi(file) {
  const formData = new FormData()
  formData.append('file', file)
  const axios = Axios.create({
    baseURL: '/files',
    withCredentials: true
  })
  const token = localStorage.getItem('token')
  const apiToken = localStorage.getItem('apiToken')
  if (token) axios.defaults.headers.common['token'] = token
  if (apiToken) axios.defaults.headers.common['api-token'] = apiToken
  return await axios.request({
    url: '/web/template/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
