Showing
4 changed files
with
133 additions
and
7 deletions
| ... | @@ -64,3 +64,29 @@ export function getCustomizeExcel(data) { | ... | @@ -64,3 +64,29 @@ export function getCustomizeExcel(data) { |
| 64 | data: data, | 64 | data: data, |
| 65 | }); | 65 | }); |
| 66 | } | 66 | } |
| 67 | + | ||
| 68 | +// 查询导出的任务ID | ||
| 69 | + | ||
| 70 | +// POST | ||
| 71 | +// /exportList/submitExportTask | ||
| 72 | +export function getSubmitExportTask(data) { | ||
| 73 | + return request({ | ||
| 74 | + url: "/bus-customer/exportList/submitExportTask", | ||
| 75 | + method: "post", | ||
| 76 | + data: data, | ||
| 77 | + }); | ||
| 78 | +} | ||
| 79 | +// /asyncExport/taskStatus/{taskId} | ||
| 80 | +export function getTaskStatus(data) { | ||
| 81 | + return request({ | ||
| 82 | + url: "/bus-customer/asyncExport/taskStatus/" + data.taskId, | ||
| 83 | + method: "get", | ||
| 84 | + }); | ||
| 85 | +} | ||
| 86 | +// /asyncExport/download/{taskId} | ||
| 87 | +export function getDownload(data) { | ||
| 88 | + return request({ | ||
| 89 | + url: "/bus-customer/asyncExport/download/" + data.taskId, | ||
| 90 | + method: "get", | ||
| 91 | + }); | ||
| 92 | +} | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -20,6 +20,8 @@ const apiUrl = { | ... | @@ -20,6 +20,8 @@ const apiUrl = { |
| 20 | declareDataModel: "/bus-customer/declareData/downloadTemplate", | 20 | declareDataModel: "/bus-customer/declareData/downloadTemplate", |
| 21 | // 清单查询下载 | 21 | // 清单查询下载 |
| 22 | listExport: "/bus-customer/exportList/listExport", | 22 | listExport: "/bus-customer/exportList/listExport", |
| 23 | + // 根据id导出 | ||
| 24 | + customDownloadXls: "/bus-customer/asyncExport/download", | ||
| 23 | }; | 25 | }; |
| 24 | 26 | ||
| 25 | const baseUrl = process.env.VUE_APP_BASE_API; | 27 | const baseUrl = process.env.VUE_APP_BASE_API; |
| ... | @@ -31,6 +33,8 @@ export function downLoadZip(urlStatus, str, filename, type, method, data) { | ... | @@ -31,6 +33,8 @@ export function downLoadZip(urlStatus, str, filename, type, method, data) { |
| 31 | url = baseUrl + apiUrl[str]; | 33 | url = baseUrl + apiUrl[str]; |
| 32 | } else if (urlStatus == "res") { | 34 | } else if (urlStatus == "res") { |
| 33 | url = str; | 35 | url = str; |
| 36 | + } else if (urlStatus == "task") { | ||
| 37 | + url = baseUrl + apiUrl[str] + "/" + data.taskId; | ||
| 34 | } | 38 | } |
| 35 | console.log(url); | 39 | console.log(url); |
| 36 | 40 | ... | ... |
| ... | @@ -215,6 +215,7 @@ | ... | @@ -215,6 +215,7 @@ |
| 215 | size="small" | 215 | size="small" |
| 216 | icon="el-icon-download" | 216 | icon="el-icon-download" |
| 217 | @click="downloadData" | 217 | @click="downloadData" |
| 218 | + :loading="isPolling || exportLoading" | ||
| 218 | > | 219 | > |
| 219 | 导出 | 220 | 导出 |
| 220 | </el-button> | 221 | </el-button> |
| ... | @@ -282,7 +283,12 @@ | ... | @@ -282,7 +283,12 @@ |
| 282 | </template> | 283 | </template> |
| 283 | 284 | ||
| 284 | <script> | 285 | <script> |
| 285 | -import { getAllexportList, getListReceiptData } from "@/api/exportList-api.js"; | 286 | +import { |
| 287 | + getAllexportList, | ||
| 288 | + getListReceiptData, | ||
| 289 | + getSubmitExportTask, | ||
| 290 | + getTaskStatus, | ||
| 291 | +} from "@/api/exportList-api.js"; | ||
| 286 | import CustomDialog from "./custom-dialog.vue"; | 292 | import CustomDialog from "./custom-dialog.vue"; |
| 287 | import { formatDateNew } from "../../utils"; | 293 | import { formatDateNew } from "../../utils"; |
| 288 | 294 | ||
| ... | @@ -415,6 +421,11 @@ export default { | ... | @@ -415,6 +421,11 @@ export default { |
| 415 | formItemconsignmentHeadCode: false, | 421 | formItemconsignmentHeadCode: false, |
| 416 | }, | 422 | }, |
| 417 | tableMaxheight: null, | 423 | tableMaxheight: null, |
| 424 | + exportLoading: false, | ||
| 425 | + pollTimer: null, // 定时器实例 | ||
| 426 | + pollInterval: 5000, // 轮询间隔(5秒) | ||
| 427 | + isPolling: false, // 轮询状态标识 | ||
| 428 | + currentTaskId: null, | ||
| 418 | }; | 429 | }; |
| 419 | }, | 430 | }, |
| 420 | created() { | 431 | created() { |
| ... | @@ -423,9 +434,13 @@ export default { | ... | @@ -423,9 +434,13 @@ export default { |
| 423 | mounted() { | 434 | mounted() { |
| 424 | this.tableMaxheight = window.innerHeight - 360; | 435 | this.tableMaxheight = window.innerHeight - 360; |
| 425 | }, | 436 | }, |
| 437 | + beforeDestroy() { | ||
| 438 | + this.stopPolling(); // 组件销毁前清理定时器 | ||
| 439 | + }, | ||
| 426 | watch: { | 440 | watch: { |
| 427 | $route() { | 441 | $route() { |
| 428 | this.popoverClose(); | 442 | this.popoverClose(); |
| 443 | + this.stopPolling(); // 组件销毁前清理定时器 | ||
| 429 | }, | 444 | }, |
| 430 | }, | 445 | }, |
| 431 | methods: { | 446 | methods: { |
| ... | @@ -496,6 +511,68 @@ export default { | ... | @@ -496,6 +511,68 @@ export default { |
| 496 | summaryApplicationStatus: "", | 511 | summaryApplicationStatus: "", |
| 497 | }; | 512 | }; |
| 498 | }, | 513 | }, |
| 514 | + | ||
| 515 | + // 查询成功后调用的其他接口 | ||
| 516 | + async callOtherApi() { | ||
| 517 | + try { | ||
| 518 | + const fileName = `${formatDateNew(new Date())}.xlsx`; | ||
| 519 | + this.fileDownload | ||
| 520 | + .downLoadZip("task", "customDownloadXls", fileName, "xlsx", "get", { | ||
| 521 | + taskId: this.currentTaskId, | ||
| 522 | + }) | ||
| 523 | + .finally(() => { | ||
| 524 | + // this.cancelDownload(); | ||
| 525 | + this.exportLoading = false; | ||
| 526 | + }); | ||
| 527 | + } catch (error) { | ||
| 528 | + console.error("后续接口调用失败:", error); | ||
| 529 | + } | ||
| 530 | + }, | ||
| 531 | + // 轮询查询状态 | ||
| 532 | + async pollStatus() { | ||
| 533 | + try { | ||
| 534 | + const result = await getTaskStatus({ taskId: this.currentTaskId }); | ||
| 535 | + | ||
| 536 | + if (+result.code === 200) { | ||
| 537 | + // PENDING, PROCESSING, COMPLETED, FAILED | ||
| 538 | + if (result.data.status === "COMPLETED") { | ||
| 539 | + this.stopPolling(); // 停止轮询 | ||
| 540 | + await this.callOtherApi(); // 调用其他接口 | ||
| 541 | + } else if (result.data.status === "FAILED") { | ||
| 542 | + this.stopPolling(); | ||
| 543 | + this.handleFailure(); | ||
| 544 | + this.alertWarningMsg(result.data.errorMessage); | ||
| 545 | + } else { | ||
| 546 | + this.startPolling(); // 启动轮询 | ||
| 547 | + } | ||
| 548 | + } else { | ||
| 549 | + this.stopPolling(); | ||
| 550 | + this.handleFailure(); | ||
| 551 | + } | ||
| 552 | + // 其他状态继续轮询 | ||
| 553 | + } catch (error) { | ||
| 554 | + console.error("轮询查询失败:", error); | ||
| 555 | + this.stopPolling(); | ||
| 556 | + } | ||
| 557 | + }, | ||
| 558 | + // 启动轮询 | ||
| 559 | + startPolling() { | ||
| 560 | + if (this.isPolling) return; | ||
| 561 | + | ||
| 562 | + this.isPolling = true; | ||
| 563 | + this.pollTimer = setInterval(() => { | ||
| 564 | + this.pollStatus(); | ||
| 565 | + }, this.pollInterval); | ||
| 566 | + }, | ||
| 567 | + // 停止轮询 | ||
| 568 | + stopPolling() { | ||
| 569 | + if (this.pollTimer) { | ||
| 570 | + clearInterval(this.pollTimer); | ||
| 571 | + this.pollTimer = null; | ||
| 572 | + } | ||
| 573 | + this.isPolling = false; | ||
| 574 | + this.exportLoading = false; | ||
| 575 | + }, | ||
| 499 | //导出 | 576 | //导出 |
| 500 | downloadData() { | 577 | downloadData() { |
| 501 | let obj = { ...this.sreachFormData }; | 578 | let obj = { ...this.sreachFormData }; |
| ... | @@ -527,13 +604,32 @@ export default { | ... | @@ -527,13 +604,32 @@ export default { |
| 527 | // // 2. 清单查询 | 604 | // // 2. 清单查询 |
| 528 | // console.log(res); | 605 | // console.log(res); |
| 529 | // }); | 606 | // }); |
| 530 | - const fileName = `${formatDateNew(new Date())}.xlsx`; | 607 | + this.exportLoading = true; |
| 531 | - this.fileDownload | 608 | + |
| 532 | - .downLoadZip("api", "listExport", fileName, "xlsx", "post", { | 609 | + this.$confirm(`正在导出中,请稍候!`, "提示", { |
| 533 | - ...obj, | 610 | + confirmButtonText: "确定", |
| 611 | + cancelButtonText: "取消", | ||
| 612 | + type: "warning", | ||
| 613 | + }) | ||
| 614 | + .then(() => { | ||
| 615 | + getSubmitExportTask(obj).then((res) => { | ||
| 616 | + if (+res.code === 200) { | ||
| 617 | + console.log(res); | ||
| 618 | + this.currentTaskId = res.data; | ||
| 619 | + this.startPolling(); | ||
| 620 | + } | ||
| 621 | + }); | ||
| 622 | + // this.fileDownload | ||
| 623 | + // .downLoadZip("api", "listExport", fileName, "xlsx", "post", { | ||
| 624 | + // ...obj, | ||
| 625 | + // }) | ||
| 626 | + // .finally(() => { | ||
| 627 | + // // this.cancelDownload(); | ||
| 628 | + // this.exportLoading = false; | ||
| 629 | + // }); | ||
| 534 | }) | 630 | }) |
| 535 | - .finally(() => { | 631 | + .catch(() => { |
| 536 | - this.cancelDownload(); | 632 | + this.exportLoading = false; |
| 537 | }); | 633 | }); |
| 538 | }, | 634 | }, |
| 539 | //查询详情 | 635 | //查询详情 | ... | ... |
-
Please register or login to post a comment