同步导出,异步导出兼容

This commit is contained in:
faiz 2024-12-17 18:09:45 +08:00
parent d701c62d11
commit efc090f4c8
3 changed files with 119 additions and 4 deletions

View File

@ -835,7 +835,69 @@ export default {
exportRecord(excelData) { exportRecord(excelData) {
exportOrderApi(excelData) exportOrderApi(excelData)
.then((res) => { .then(async (res) => {
if (res.data.filename) {
const loading = this.$loading({
lock: true,
text: "导出中...",
spinner: "el-icon-loading",
background: "hsla(0, 0%, 100%, .9)",
});
let excelData = JSON.parse(JSON.stringify(this.tableFrom)),
data = [];
excelData.page = 1;
excelData.limit = 200;
let pageCount = 1;
let lebData = {};
// let work;
for (let i = 0; i < pageCount; i++) {
lebData = await this.downData(excelData);
// if(work){
// work.setContent(lebData.export)
// }else{
// work = createWorkBook(lebData.header, lebData.title, data, lebData.foot,lebData.filename);
// }
//
pageCount = Math.ceil(lebData.count / excelData.limit);
//
if (lebData.export.length) {
data = data.concat(lebData.export);
excelData.page++;
}
}
console.log("开始处理");
//
let start = performance.now();
// 线
let worker = new Worker();
// 线postMessage
worker.postMessage({
header: lebData.header,
title: lebData.title,
data,
foot: lebData.foot,
filename: lebData.filename,
});
// message
worker.addEventListener("message", (e) => {
// 线
worker.terminate();
//
let end = performance.now();
//
let durationTime = end - start;
console.log("计算结果:", e.data);
let { blob, filename } = e.data;
FileSaver.saveAs(blob, filename + ".xlsx");
loading.close();
console.log(`代码执行了 ${durationTime} 毫秒`);
});
// this.exportCsv(lebData.header,data,lebData.filename)
// createWorkBook(lebData.header, lebData.title, data, lebData.foot,lebData.filename)
// work.saveAndDowloade(lebData.filename)
return;
}
const h = this.$createElement; const h = this.$createElement;
this.$msgbox({ this.$msgbox({
title: "提示", title: "提示",

View File

@ -1203,9 +1203,32 @@ export default {
}); });
}, },
// //
exportRecord() { exportRecord(excelData) {
exportProductApi(this.tableFrom) exportProductApi(this.tableFrom)
.then((res) => { .then(async (res) => {
if (res.data.filename) {
let data = [];
excelData.page = 1;
excelData.limit = 200;
let pageCount = 1;
let lebData = {};
for (let i = 0; i < pageCount; i++) {
lebData = await this.downData(excelData);
pageCount = Math.ceil(lebData.count / excelData.limit);
if (lebData.export.length) {
data = data.concat(lebData.export);
excelData.page++;
}
}
createWorkBook(
lebData.header,
lebData.title,
data,
lebData.foot,
lebData.filename
);
return;
}
const h = this.$createElement; const h = this.$createElement;
this.$msgbox({ this.$msgbox({
title: "提示", title: "提示",

View File

@ -1077,7 +1077,37 @@ export default {
}, },
exportRecord(excelData) { exportRecord(excelData) {
exportUserApi(excelData) exportUserApi(excelData)
.then((res) => { .then(async (res) => {
if (res.data.filename) {
const loading = this.$loading({
lock: true,
text: "正在拼命导出中,请耐心等待...",
spinner: "el-icon-loading",
background: "hsla(0, 0%, 100%, .9)",
});
let data = [];
excelData.page = 1;
excelData.limit = 500;
let pageCount = 1;
let lebData = {};
for (let i = 0; i < pageCount; i++) {
lebData = await this.downData(excelData);
pageCount = Math.ceil(lebData.count / excelData.limit);
if (lebData.export.length) {
data = data.concat(lebData.export);
excelData.page++;
}
}
createWorkBook(
lebData.header,
lebData.title,
data,
lebData.foot,
lebData.filename
);
loading.close();
return;
}
const h = this.$createElement; const h = this.$createElement;
this.$msgbox({ this.$msgbox({
title: "提示", title: "提示",