// 下载blob文件
import request from '@/utils/request'

export const downloadFile = ({ fileData, fileType, fileName }) => {
  const blob = new Blob([fileData], {
    type: fileType
  })
  const link = document.createElement('a')
  link.href = URL.createObjectURL(blob)
  link.download = fileName
  link.style.display = 'none'
  document.body.appendChild(link)
  link.click()
  URL.revokeObjectURL(link.href)
  document.body.removeChild(link)
}

// 通用a链接下载
export const downloadFileByUrl = (url) => {
  const link = document.createElement('a')
  link.href = url
  link.setAttribute('download', '')
  link.style.display = 'none'
  document.body.appendChild(link)
  link.click()
  URL.revokeObjectURL(link.href)
  document.body.removeChild(link)
}

export function delFileById(id){
  return request({
    url: '/system/select/' + id,
    method: 'delete'
  })
}
