合并zcwy-dev

This commit is contained in:
nisen
2023-08-01 18:03:29 +08:00
parent 89cb4c8d28
commit 19c8dee418
12 changed files with 2145 additions and 30 deletions

33
src/hooks/useDownload.js Normal file
View File

@@ -0,0 +1,33 @@
import http from "@/api/configSys";
/**
* @param {String} url [请求的url地址]
* @param {Object} params [参数]
* @param {String} fileName [导出文件名称] 默认值 导出文件
* @param {String} fileType [导出文件类型] 默认值 xls
* @param {string} mimeType [导出文件类型]
*/
const useDownload = (url, params = {}, fileName = '导出文件', fileType = 'xls', mimeType = 'application/vnd.ms-excel;charset=UTF-8') => {
return new Promise((resolve, reject) => {
http.post(url, params, { responseType: 'blob' })
.then(res => {
resolve(res.data);
if (!res.data) {
return
}
const link = document.createElement('a');// 创建a标签
let blob = new Blob([res.data], { type: mimeType }); // 设置文件类型
link.style.display = "none";
link.href = URL.createObjectURL(blob); // 创建URL
link.setAttribute("download", `${fileName}.${fileType}`);
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href);
document.body.removeChild(link);
})
.catch(err => {
reject(err.data);
})
});
}
export default useDownload