mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-11 03:46:45 +08:00
下载失败数据和封装下载hooks
This commit is contained in:
@@ -129,7 +129,8 @@ import { reactive, onMounted, ref, watch } from 'vue';
|
|||||||
import { Form, message } from "ant-design-vue";
|
import { Form, message } from "ant-design-vue";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import Cookies from "vue-cookies";
|
import Cookies from "vue-cookies";
|
||||||
import { downloadErrorData } from '@/api/case'
|
import { downloadErrorData } from '@/api/case'
|
||||||
|
import useDownload from '@/hooks/useDownload'
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
visible: {
|
visible: {
|
||||||
@@ -251,17 +252,13 @@ const handleSearch = () => {
|
|||||||
|
|
||||||
//下载模版
|
//下载模版
|
||||||
const downloadErrorInfo = () => {
|
const downloadErrorInfo = () => {
|
||||||
downloadErrorData({ importId: state.importId })
|
// if (!state.importId) return
|
||||||
// apiCase.exportCasesInfo(type).then(res => {
|
downloadErrorData({ importId: state.importId }).then((res) => {
|
||||||
// const link = document.createElement('a');// 创建a标签
|
if(res.status!=200) return
|
||||||
// let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' }); // 设置文件类型
|
useDownload(res,'失败数据.xsl')
|
||||||
// link.style.display = "none";
|
}).catch((error) => {
|
||||||
// link.href = URL.createObjectURL(blob); // 创建URL
|
console.log(error);
|
||||||
// link.setAttribute("download", "案例.xls");
|
})
|
||||||
// document.body.appendChild(link);
|
|
||||||
// link.click();
|
|
||||||
// document.body.removeChild(link);
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下一步
|
// 下一步
|
||||||
|
|||||||
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