import request from '@/utils/request'
import { parseStrEmpty } from "@/utils/ruoyi";
// import { previewFile } from '@/utils/prevDown'
import { download, previewFile } from '@/utils/request'
// 查询仓库树形列表
export function getFileList(query) {
	return request({
		url: '/system/file/list',
		method: 'get',
		params: query
	})
}
// 查询单个文件的信息
export function getFileById(fileId) {
	return request({
		url: '/system/file/'+fileId,
		method: 'get'
	})
}
// 下载文件
// export function downLoadFile(query) {
// 	return request({
// 		url: '/system/file/download',
// 		method: 'get',
// 		params: query
// 	})
// }
export function downLoadFile(data) {
    download('/system/file/download?url='+data.url, data, data.fileName)
}
// 修改文件名
export function delFile(fileId) {
  return request({
    url: '/system/file/' + fileId,
    method: 'delete'
  })
}
// 回收文件到垃圾桶
export function recycleFile(fileId) {
  return request({
    url: '/system/file/recycle/' + fileId,
    method: 'delete'
  })
}
// 彻底删除文件
export function editFile(data) {
	return request({
	  url: '/system/file',
	  method: 'put',
	  data: data
	})
}
// 新建文件夹
export function addFolder(data) {
	return request({
	  url: '/system/file/folder',
	  method: 'post',
	  data: data
	})
}
// 上传文件
export function uploadFile(data) {
    return request({
		url: '/system/file/fileupload',
		method: 'post',
		data: data
	})
}
// 预览文件
export function prevFile(data) {
    return previewFile('/system/file/download?url='+data.url, data)
}
export function transformPdf(data) {
    previewFile('/system/file/convert?type=pdf&fileId='+data.fileId, data);
}
const S4 = function(){
	return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
// 生成唯一标识
export function guid() {
    return (S4() + S4() +'-'+ S4() +'-'+ S4() +'-'+ S4() +'-'+ S4() + S4() + S4())
}