import request from '@/utils/request'
import qs from 'qs'
export function initData(url, data) {
  return request({
    url,
    method: 'post',
    // data: qs.stringify(data, { indices: false })
    data,
  })
}

export function download(data) {
  return request({
    url: 'file/downloadFile',
    method: 'post',
    data,
    timeout: 300000,
  })
}

export function importData(url, data) {
  return request({
    url: url,
    method: 'post',
    data,
    timeout: 3600000,
  })
}

export function exportData(url, data) {
  return request({
    url: url,
    method: 'post',
    data,
    timeout: 3600000,
  })
}
/**
 * 文件上传统一接口
 * @param {*} fileList
 * @param {*} fileModule (1: 头像, 2: 新闻图片, 10: 导入的文件, 20: 报警图片, 30: 通用附件, 31: 巡检附件, 40: 模型文件, 41: 模型缩略图文件)
 * @returns
 */
export function uploadFiles(fileList = [], fileModule = 30) {
  let param = {
    fileModule,
    fileList,
  }
  return request({
    url: 'file/uploadFiles',
    method: 'post',
    data: qs.stringify(param, { arrayFormat: 'indices', allowDots: true }),
  })
}

export function deleteFile(data) {
  return request({
    url: 'file/deleteFile',
    method: 'post',
    data: qs.stringify(data),
  })
}

export function uploadBase64(data) {
  let param = {
    fileModule: 1,
    data,
  }
  return request({
    url: 'file/uploadBase64',
    method: 'post',
    data: param,
  })
}
