Showing
2 changed files
with
77 additions
and
12 deletions
| ... | @@ -69,6 +69,7 @@ export function downLoadZip(urlStatus, str, filename, type, method, data) { | ... | @@ -69,6 +69,7 @@ export function downLoadZip(urlStatus, str, filename, type, method, data) { |
| 69 | }, | 69 | }, |
| 70 | }) | 70 | }) |
| 71 | .then((res) => { | 71 | .then((res) => { |
| 72 | + console.log(res); | ||
| 72 | if (filename == null) { | 73 | if (filename == null) { |
| 73 | if (res.headers["content-disposition"]) { | 74 | if (res.headers["content-disposition"]) { |
| 74 | var patt = new RegExp("filename=([^;]+\\.[^\\.;]+);*"); | 75 | var patt = new RegExp("filename=([^;]+\\.[^\\.;]+);*"); |
| ... | @@ -84,8 +85,9 @@ export function downLoadZip(urlStatus, str, filename, type, method, data) { | ... | @@ -84,8 +85,9 @@ export function downLoadZip(urlStatus, str, filename, type, method, data) { |
| 84 | resolveBlob(res, mimeMap[type], filename); | 85 | resolveBlob(res, mimeMap[type], filename); |
| 85 | resolve(); | 86 | resolve(); |
| 86 | }) | 87 | }) |
| 87 | - .catch(() => { | 88 | + .catch((err) => { |
| 88 | - reject(); | 89 | + debugger; |
| 90 | + reject(err); | ||
| 89 | }); | 91 | }); |
| 90 | }); | 92 | }); |
| 91 | } | 93 | } | ... | ... |
| ... | @@ -291,6 +291,8 @@ import { | ... | @@ -291,6 +291,8 @@ import { |
| 291 | } from "@/api/exportList-api.js"; | 291 | } from "@/api/exportList-api.js"; |
| 292 | import CustomDialog from "./custom-dialog.vue"; | 292 | import CustomDialog from "./custom-dialog.vue"; |
| 293 | import { formatDateNew } from "../../utils"; | 293 | import { formatDateNew } from "../../utils"; |
| 294 | +import axios from "axios"; | ||
| 295 | +import { getToken } from "@/utils/auth"; | ||
| 294 | 296 | ||
| 295 | export default { | 297 | export default { |
| 296 | name: "ExportListQuery", | 298 | name: "ExportListQuery", |
| ... | @@ -512,18 +514,80 @@ export default { | ... | @@ -512,18 +514,80 @@ export default { |
| 512 | }; | 514 | }; |
| 513 | }, | 515 | }, |
| 514 | 516 | ||
| 517 | + downLoadZip() { | ||
| 518 | + const baseUrl = process.env.VUE_APP_BASE_API; | ||
| 519 | + console.log(this.currentTaskId); | ||
| 520 | + axios({ | ||
| 521 | + method: "get", | ||
| 522 | + url: `${baseUrl}/bus-customer/asyncExport/download/${this.currentTaskId}`, | ||
| 523 | + responseType: "blob", | ||
| 524 | + headers: { | ||
| 525 | + Authorization: "Bearer " + getToken(), | ||
| 526 | + Ver: process.env.VUE_APP_APIVERSION, | ||
| 527 | + }, | ||
| 528 | + }) | ||
| 529 | + .then((res) => { | ||
| 530 | + debugger; | ||
| 531 | + console.log(res); | ||
| 532 | + const mimeType = | ||
| 533 | + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; | ||
| 534 | + | ||
| 535 | + const aLink = document.createElement("a"); | ||
| 536 | + var blob = new Blob([res.data], { type: mimeType }); | ||
| 537 | + if (blob.size < 500) { | ||
| 538 | + var reader = new FileReader(); | ||
| 539 | + reader.readAsText(blob, "utf-8"); | ||
| 540 | + reader.onloadend = () => { | ||
| 541 | + // 获取文本内容并将其转换为JSON格式 | ||
| 542 | + if ( | ||
| 543 | + reader.result && | ||
| 544 | + reader.result != null && | ||
| 545 | + reader.result != "" | ||
| 546 | + ) { | ||
| 547 | + if (JSON.parse(reader.result)) { | ||
| 548 | + debugger; | ||
| 549 | + let jsonData = JSON.parse(reader.result); | ||
| 550 | + if (jsonData.code == "10103") { | ||
| 551 | + this.startPolling(); | ||
| 552 | + return; | ||
| 553 | + } | ||
| 554 | + this.alertWarningMsg(jsonData.message); | ||
| 555 | + } else { | ||
| 556 | + this.alertWarningMsg("文件无法下载,请重新生成后再试!"); | ||
| 557 | + } | ||
| 558 | + } else { | ||
| 559 | + this.alertWarningMsg("文件无法下载,请重新生成后再试!"); | ||
| 560 | + } | ||
| 561 | + }; | ||
| 562 | + } else { | ||
| 563 | + const fileName = `${formatDateNew(new Date())}.xlsx`; | ||
| 564 | + aLink.href = URL.createObjectURL(blob); | ||
| 565 | + aLink.setAttribute("download", fileName); // 设置下载文件名称 | ||
| 566 | + document.body.appendChild(aLink); | ||
| 567 | + aLink.click(); | ||
| 568 | + document.body.removeChild(aLink); | ||
| 569 | + this.exportLoading = false; | ||
| 570 | + } | ||
| 571 | + }) | ||
| 572 | + .catch((error) => { | ||
| 573 | + console.log("失败", error); | ||
| 574 | + this.exportLoading = false; | ||
| 575 | + }); | ||
| 576 | + }, | ||
| 577 | + | ||
| 515 | // 查询成功后调用的其他接口 | 578 | // 查询成功后调用的其他接口 |
| 516 | async callOtherApi() { | 579 | async callOtherApi() { |
| 517 | try { | 580 | try { |
| 518 | - const fileName = `${formatDateNew(new Date())}.xlsx`; | 581 | + this.downLoadZip(); |
| 519 | - this.fileDownload | 582 | + // const fileName = `${formatDateNew(new Date())}.xlsx`; |
| 520 | - .downLoadZip("task", "customDownloadXls", fileName, "xlsx", "get", { | 583 | + // this.fileDownload |
| 521 | - taskId: this.currentTaskId, | 584 | + // .downLoadZip("task", "customDownloadXls", fileName, "xlsx", "get", { |
| 522 | - }) | 585 | + // taskId: this.currentTaskId, |
| 523 | - .finally(() => { | 586 | + // }) |
| 524 | - // this.cancelDownload(); | 587 | + // .finally(() => { |
| 525 | - this.exportLoading = false; | 588 | + // // this.cancelDownload(); |
| 526 | - }); | 589 | + // this.exportLoading = false; |
| 590 | + // }); | ||
| 527 | } catch (error) { | 591 | } catch (error) { |
| 528 | console.error("后续接口调用失败:", error); | 592 | console.error("后续接口调用失败:", error); |
| 529 | } | 593 | } |
| ... | @@ -532,7 +596,6 @@ export default { | ... | @@ -532,7 +596,6 @@ export default { |
| 532 | async pollStatus() { | 596 | async pollStatus() { |
| 533 | try { | 597 | try { |
| 534 | const result = await getTaskStatus({ taskId: this.currentTaskId }); | 598 | const result = await getTaskStatus({ taskId: this.currentTaskId }); |
| 535 | - | ||
| 536 | if (+result.code === 200) { | 599 | if (+result.code === 200) { |
| 537 | // PENDING, PROCESSING, COMPLETED, FAILED | 600 | // PENDING, PROCESSING, COMPLETED, FAILED |
| 538 | if (result.data.status === "COMPLETED") { | 601 | if (result.data.status === "COMPLETED") { | ... | ... |
-
Please register or login to post a comment