mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-10 11:26:45 +08:00
下载失败数据和封装下载hooks
This commit is contained in:
@@ -130,6 +130,7 @@ import { Form, message } from "ant-design-vue";
|
||||
import axios from "axios";
|
||||
import Cookies from "vue-cookies";
|
||||
import { downloadErrorData } from '@/api/case'
|
||||
import useDownload from '@/hooks/useDownload'
|
||||
|
||||
defineProps({
|
||||
visible: {
|
||||
@@ -251,17 +252,13 @@ const handleSearch = () => {
|
||||
|
||||
//下载模版
|
||||
const downloadErrorInfo = () => {
|
||||
downloadErrorData({ importId: state.importId })
|
||||
// apiCase.exportCasesInfo(type).then(res => {
|
||||
// const link = document.createElement('a');// 创建a标签
|
||||
// let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' }); // 设置文件类型
|
||||
// link.style.display = "none";
|
||||
// link.href = URL.createObjectURL(blob); // 创建URL
|
||||
// link.setAttribute("download", "案例.xls");
|
||||
// document.body.appendChild(link);
|
||||
// link.click();
|
||||
// document.body.removeChild(link);
|
||||
// })
|
||||
// if (!state.importId) return
|
||||
downloadErrorData({ importId: state.importId }).then((res) => {
|
||||
if(res.status!=200) return
|
||||
useDownload(res,'失败数据.xsl')
|
||||
}).catch((error) => {
|
||||
console.log(error);
|
||||
})
|
||||
}
|
||||
|
||||
// 下一步
|
||||
|
||||
20
src/hooks/useDownload.js
Normal file
20
src/hooks/useDownload.js
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} data 文件流Blob对象
|
||||
* @param {*} mimeType 类型
|
||||
* @param {*} fileName 名字
|
||||
*/
|
||||
const useDownload = (data, fileName, mimeType = 'application/vnd.ms-excel;charset=UTF-8') => {
|
||||
const link = document.createElement('a');// 创建a标签
|
||||
let blob = new Blob([data], { type: mimeType }); // 设置文件类型
|
||||
link.style.display = "none";
|
||||
link.href = URL.createObjectURL(blob); // 创建URL
|
||||
link.setAttribute("download", fileName);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
URL.revokeObjectURL(link.href);
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
|
||||
export default useDownload
|
||||
Reference in New Issue
Block a user