diff --git a/src/components/drawers/InitiateRecommend.vue b/src/components/drawers/InitiateRecommend.vue index 6d4fa556..e15611c3 100644 --- a/src/components/drawers/InitiateRecommend.vue +++ b/src/components/drawers/InitiateRecommend.vue @@ -129,7 +129,8 @@ import { reactive, onMounted, ref, watch } from 'vue'; import { Form, message } from "ant-design-vue"; import axios from "axios"; import Cookies from "vue-cookies"; -import { downloadErrorData } from '@/api/case' +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); + }) } // 下一步 diff --git a/src/hooks/useDownload.js b/src/hooks/useDownload.js new file mode 100644 index 00000000..cef1c4d5 --- /dev/null +++ b/src/hooks/useDownload.js @@ -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 \ No newline at end of file