Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Fedex
/
EcomWeb
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
zhanbo.xu
2026-01-28 17:22:07 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9de8413f1ab1e0b375c78046f049a76cdc06222b
9de8413f
1 parent
b9caf032
优化导出并修改代码
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
133 additions
and
7 deletions
src/api/exportList-api.js
src/utils/request.js
src/utils/zipdownload.js
src/views/exportListQuery/index.vue
src/api/exportList-api.js
View file @
9de8413
...
...
@@ -64,3 +64,29 @@ export function getCustomizeExcel(data) {
data
:
data
,
});
}
// 查询导出的任务ID
// POST
// /exportList/submitExportTask
export
function
getSubmitExportTask
(
data
)
{
return
request
({
url
:
"/bus-customer/exportList/submitExportTask"
,
method
:
"post"
,
data
:
data
,
});
}
// /asyncExport/taskStatus/{taskId}
export
function
getTaskStatus
(
data
)
{
return
request
({
url
:
"/bus-customer/asyncExport/taskStatus/"
+
data
.
taskId
,
method
:
"get"
,
});
}
// /asyncExport/download/{taskId}
export
function
getDownload
(
data
)
{
return
request
({
url
:
"/bus-customer/asyncExport/download/"
+
data
.
taskId
,
method
:
"get"
,
});
}
...
...
src/utils/request.js
View file @
9de8413
This diff is collapsed. Click to expand it.
src/utils/zipdownload.js
View file @
9de8413
...
...
@@ -20,6 +20,8 @@ const apiUrl = {
declareDataModel
:
"/bus-customer/declareData/downloadTemplate"
,
// 清单查询下载
listExport
:
"/bus-customer/exportList/listExport"
,
// 根据id导出
customDownloadXls
:
"/bus-customer/asyncExport/download"
,
};
const
baseUrl
=
process
.
env
.
VUE_APP_BASE_API
;
...
...
@@ -31,6 +33,8 @@ export function downLoadZip(urlStatus, str, filename, type, method, data) {
url
=
baseUrl
+
apiUrl
[
str
];
}
else
if
(
urlStatus
==
"res"
)
{
url
=
str
;
}
else
if
(
urlStatus
==
"task"
)
{
url
=
baseUrl
+
apiUrl
[
str
]
+
"/"
+
data
.
taskId
;
}
console
.
log
(
url
);
...
...
src/views/exportListQuery/index.vue
View file @
9de8413
...
...
@@ -215,6 +215,7 @@
size="small"
icon="el-icon-download"
@click="downloadData"
:loading="isPolling || exportLoading"
>
导出
</el-button>
...
...
@@ -282,7 +283,12 @@
</template>
<script>
import { getAllexportList, getListReceiptData } from "@/api/exportList-api.js";
import {
getAllexportList,
getListReceiptData,
getSubmitExportTask,
getTaskStatus,
} from "@/api/exportList-api.js";
import CustomDialog from "./custom-dialog.vue";
import { formatDateNew } from "../../utils";
...
...
@@ -415,6 +421,11 @@ export default {
formItemconsignmentHeadCode: false,
},
tableMaxheight: null,
exportLoading: false,
pollTimer: null, // 定时器实例
pollInterval: 5000, // 轮询间隔(5秒)
isPolling: false, // 轮询状态标识
currentTaskId: null,
};
},
created() {
...
...
@@ -423,9 +434,13 @@ export default {
mounted() {
this.tableMaxheight = window.innerHeight - 360;
},
beforeDestroy() {
this.stopPolling(); // 组件销毁前清理定时器
},
watch: {
$route() {
this.popoverClose();
this.stopPolling(); // 组件销毁前清理定时器
},
},
methods: {
...
...
@@ -496,6 +511,68 @@ export default {
summaryApplicationStatus: "",
};
},
// 查询成功后调用的其他接口
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;
});
} catch (error) {
console.error("后续接口调用失败:", error);
}
},
// 轮询查询状态
async pollStatus() {
try {
const result = await getTaskStatus({ taskId: this.currentTaskId });
if (+result.code === 200) {
// PENDING, PROCESSING, COMPLETED, FAILED
if (result.data.status === "COMPLETED") {
this.stopPolling(); // 停止轮询
await this.callOtherApi(); // 调用其他接口
} else if (result.data.status === "FAILED") {
this.stopPolling();
this.handleFailure();
this.alertWarningMsg(result.data.errorMessage);
} else {
this.startPolling(); // 启动轮询
}
} else {
this.stopPolling();
this.handleFailure();
}
// 其他状态继续轮询
} catch (error) {
console.error("轮询查询失败:", error);
this.stopPolling();
}
},
// 启动轮询
startPolling() {
if (this.isPolling) return;
this.isPolling = true;
this.pollTimer = setInterval(() => {
this.pollStatus();
}, this.pollInterval);
},
// 停止轮询
stopPolling() {
if (this.pollTimer) {
clearInterval(this.pollTimer);
this.pollTimer = null;
}
this.isPolling = false;
this.exportLoading = false;
},
//导出
downloadData() {
let obj = { ...this.sreachFormData };
...
...
@@ -527,13 +604,32 @@ export default {
// // 2. 清单查询
// console.log(res);
// });
const fileName = `${formatDateNew(new Date())}.xlsx`;
this.fileDownload
.downLoadZip("api", "listExport", fileName, "xlsx", "post", {
...obj,
this.exportLoading = true;
this.$confirm(`正在导出中,请稍候!`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
getSubmitExportTask(obj).then((res) => {
if (+res.code === 200) {
console.log(res);
this.currentTaskId = res.data;
this.startPolling();
}
});
// this.fileDownload
// .downLoadZip("api", "listExport", fileName, "xlsx", "post", {
// ...obj,
// })
// .finally(() => {
// // this.cancelDownload();
// this.exportLoading = false;
// });
})
.
finally
(() => {
this.
cancelDownload()
;
.
catch
(() => {
this.
exportLoading = false
;
});
},
//查询详情
...
...
Please
register
or
login
to post a comment