zhanbo.xu

feat: 优化导出配置10103的情况

......@@ -69,6 +69,7 @@ export function downLoadZip(urlStatus, str, filename, type, method, data) {
},
})
.then((res) => {
console.log(res);
if (filename == null) {
if (res.headers["content-disposition"]) {
var patt = new RegExp("filename=([^;]+\\.[^\\.;]+);*");
......@@ -84,8 +85,9 @@ export function downLoadZip(urlStatus, str, filename, type, method, data) {
resolveBlob(res, mimeMap[type], filename);
resolve();
})
.catch(() => {
reject();
.catch((err) => {
debugger;
reject(err);
});
});
}
......
......@@ -291,6 +291,8 @@ import {
} from "@/api/exportList-api.js";
import CustomDialog from "./custom-dialog.vue";
import { formatDateNew } from "../../utils";
import axios from "axios";
import { getToken } from "@/utils/auth";
export default {
name: "ExportListQuery",
......@@ -512,18 +514,80 @@ export default {
};
},
downLoadZip() {
const baseUrl = process.env.VUE_APP_BASE_API;
console.log(this.currentTaskId);
axios({
method: "get",
url: `${baseUrl}/bus-customer/asyncExport/download/${this.currentTaskId}`,
responseType: "blob",
headers: {
Authorization: "Bearer " + getToken(),
Ver: process.env.VUE_APP_APIVERSION,
},
})
.then((res) => {
debugger;
console.log(res);
const mimeType =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
const aLink = document.createElement("a");
var blob = new Blob([res.data], { type: mimeType });
if (blob.size < 500) {
var reader = new FileReader();
reader.readAsText(blob, "utf-8");
reader.onloadend = () => {
// 获取文本内容并将其转换为JSON格式
if (
reader.result &&
reader.result != null &&
reader.result != ""
) {
if (JSON.parse(reader.result)) {
debugger;
let jsonData = JSON.parse(reader.result);
if (jsonData.code == "10103") {
this.startPolling();
return;
}
this.alertWarningMsg(jsonData.message);
} else {
this.alertWarningMsg("文件无法下载,请重新生成后再试!");
}
} else {
this.alertWarningMsg("文件无法下载,请重新生成后再试!");
}
};
} else {
const fileName = `${formatDateNew(new Date())}.xlsx`;
aLink.href = URL.createObjectURL(blob);
aLink.setAttribute("download", fileName); // 设置下载文件名称
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink);
this.exportLoading = false;
}
})
.catch((error) => {
console.log("失败", error);
this.exportLoading = false;
});
},
// 查询成功后调用的其他接口
async callOtherApi() {
try {
const fileName = `${formatDateNew(new Date())}.xlsx`;
this.fileDownload
.downLoadZip("task", "customDownloadXls", fileName, "xlsx", "get", {
taskId: this.currentTaskId,
})
.finally(() => {
// this.cancelDownload();
this.exportLoading = false;
});
this.downLoadZip();
// const fileName = `${formatDateNew(new Date())}.xlsx`;
// this.fileDownload
// .downLoadZip("task", "customDownloadXls", fileName, "xlsx", "get", {
// taskId: this.currentTaskId,
// })
// .finally(() => {
// // this.cancelDownload();
// this.exportLoading = false;
// });
} catch (error) {
console.error("后续接口调用失败:", error);
}
......@@ -532,7 +596,6 @@ export default {
async pollStatus() {
try {
const result = await getTaskStatus({ taskId: this.currentTaskId });
if (+result.code === 200) {
// PENDING, PROCESSING, COMPLETED, FAILED
if (result.data.status === "COMPLETED") {
......