订单,用户,商品导出

This commit is contained in:
faiz 2024-12-16 16:30:51 +08:00
parent 4145acebe6
commit 773faa40b9
3 changed files with 173 additions and 117 deletions

View File

@ -572,12 +572,14 @@ import { fromList } from "@/libs/constants.js";
import timeOptions from "@/utils/timeOptions"; import timeOptions from "@/utils/timeOptions";
import * as FileSaver from "file-saver"; import * as FileSaver from "file-saver";
import Worker from "worker-loader!@/worker/calcWorker.js"; import Worker from "worker-loader!@/worker/calcWorker.js";
import { roterPre } from "@/settings";
export default { export default {
components: { orderDetail, cardsData, userDetails }, components: { orderDetail, cardsData, userDetails },
data() { data() {
return { return {
pickerOptions: timeOptions, pickerOptions: timeOptions,
orderId: 0, orderId: 0,
roterPre: roterPre,
tableData: { tableData: {
data: [], data: [],
total: 0, total: 0,
@ -759,66 +761,68 @@ export default {
// document.body.removeChild(downloadLink); // document.body.removeChild(downloadLink);
// }, // },
async exports() { async exports() {
const loading = this.$loading({ // const loading = this.$loading({
lock: true, // lock: true,
text: "导出中...", // text: "...",
spinner: "el-icon-loading", // spinner: "el-icon-loading",
background: "hsla(0, 0%, 100%, .9)", // background: "hsla(0, 0%, 100%, .9)",
}); // });
let excelData = JSON.parse(JSON.stringify(this.tableFrom)), // let excelData = JSON.parse(JSON.stringify(this.tableFrom)),
data = []; // data = [];
excelData.page = 1; // excelData.page = 1;
excelData.limit = 200; // excelData.limit = 200;
let pageCount = 1; // let pageCount = 1;
let lebData = {}; // let lebData = {};
// let work; // // let work;
for (let i = 0; i < pageCount; i++) { // for (let i = 0; i < pageCount; i++) {
lebData = await this.downData(excelData); // lebData = await this.downData(excelData);
// if(work){ // // if(work){
// work.setContent(lebData.export) // // work.setContent(lebData.export)
// }else{ // // }else{
// work = createWorkBook(lebData.header, lebData.title, data, lebData.foot,lebData.filename); // // work = createWorkBook(lebData.header, lebData.title, data, lebData.foot,lebData.filename);
// } // // }
// // //
pageCount = Math.ceil(lebData.count / excelData.limit); // pageCount = Math.ceil(lebData.count / excelData.limit);
// // //
if (lebData.export.length) { // if (lebData.export.length) {
data = data.concat(lebData.export); // data = data.concat(lebData.export);
excelData.page++; // excelData.page++;
} // }
} // }
console.log("开始处理"); // console.log("");
// // //
let start = performance.now(); // let start = performance.now();
// 线 // // 线
let worker = new Worker(); // let worker = new Worker();
// 线postMessage // // 线postMessage
worker.postMessage({ // worker.postMessage({
header: lebData.header, // header: lebData.header,
title: lebData.title, // title: lebData.title,
data, // data,
foot: lebData.foot, // foot: lebData.foot,
filename: lebData.filename, // filename: lebData.filename,
}); // });
// message // // message
worker.addEventListener("message", (e) => { // worker.addEventListener("message", (e) => {
// 线 // // 线
worker.terminate(); // worker.terminate();
// // //
let end = performance.now(); // let end = performance.now();
// // //
let durationTime = end - start; // let durationTime = end - start;
console.log("计算结果:", e.data); // console.log(":", e.data);
let { blob, filename } = e.data; // let { blob, filename } = e.data;
FileSaver.saveAs(blob, filename + ".xlsx"); // FileSaver.saveAs(blob, filename + ".xlsx");
loading.close(); // loading.close();
console.log(`代码执行了 ${durationTime} 毫秒`); // console.log(` ${durationTime} `);
}); // });
// this.exportCsv(lebData.header,data,lebData.filename) // // this.exportCsv(lebData.header,data,lebData.filename)
// createWorkBook(lebData.header, lebData.title, data, lebData.foot,lebData.filename) // // createWorkBook(lebData.header, lebData.title, data, lebData.foot,lebData.filename)
// work.saveAndDowloade(lebData.filename) // // work.saveAndDowloade(lebData.filename)
return; // return;
let excelData = JSON.parse(JSON.stringify(this.tableFrom));
this.exportRecord(excelData);
}, },
/**订单列表 */ /**订单列表 */
downData(excelData) { downData(excelData) {
@ -828,9 +832,9 @@ export default {
}); });
}); });
}, },
//
exportRecord() { exportRecord(excelData) {
exportOrderApi(this.tableFrom) exportOrderApi(excelData)
.then((res) => { .then((res) => {
const h = this.$createElement; const h = this.$createElement;
this.$msgbox({ this.$msgbox({
@ -841,7 +845,9 @@ export default {
h("span", null, '"查看~ '), h("span", null, '"查看~ '),
]), ]),
confirmButtonText: "我知道了", confirmButtonText: "我知道了",
}).then((action) => {}); }).then((action) => {
this.$router.push({ path: this.roterPre + "/group/exportList" });
});
}) })
.catch((res) => { .catch((res) => {
this.$message.error(res.message); this.$message.error(res.message);

View File

@ -1157,37 +1157,63 @@ export default {
this.$refs.editAttr.getAttrDetail(row.product_id); this.$refs.editAttr.getAttrDetail(row.product_id);
}, },
async exports() { async exports() {
let excelData = JSON.parse(JSON.stringify(this.tableFrom)), let excelData = JSON.parse(JSON.stringify(this.tableFrom));
data = []; this.exportRecord(excelData);
excelData.page = 1; // data = [];
excelData.limit = 200; // excelData.page = 1;
let pageCount = 1; // excelData.limit = 200;
let lebData = {}; // let pageCount = 1;
for (let i = 0; i < pageCount; i++) { // let lebData = {};
lebData = await this.downData(excelData); // for (let i = 0; i < pageCount; i++) {
pageCount = Math.ceil(lebData.count / excelData.limit); // lebData = await this.downData(excelData);
if (lebData.export.length) { // pageCount = Math.ceil(lebData.count / excelData.limit);
data = data.concat(lebData.export); // if (lebData.export.length) {
excelData.page++; // data = data.concat(lebData.export);
} // excelData.page++;
} // }
createWorkBook( // }
lebData.header, // createWorkBook(
lebData.title, // lebData.header,
data, // lebData.title,
lebData.foot, // data,
lebData.filename // lebData.foot,
); // lebData.filename
return; // );
// return;
}, },
/**订单列表 */ /**订单列表 */
downData(excelData) { downData(excelData) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
exportProductApi(excelData).then((res) => { exportProductApi(excelData)
return resolve(res.data); .then((res) => {
}); return resolve(res.data);
})
.catch((err) => {
this.$message.error(err);
});
}); });
}, },
//
exportRecord() {
exportProductApi(this.tableFrom)
.then((res) => {
const h = this.$createElement;
this.$msgbox({
title: "提示",
message: h("p", null, [
h("span", null, '文件正在生成中,请稍后点击"'),
h("span", { style: "color: teal" }, "导出记录"),
h("span", null, '"查看~ '),
]),
confirmButtonText: "我知道了",
}).then((action) => {
this.$router.push({ path: this.roterPre + "/group/exportList" });
});
})
.catch((res) => {
this.$message.error(res.message);
});
},
// //
onchangeTime(e) { onchangeTime(e) {
this.timeVal = e; this.timeVal = e;

View File

@ -641,6 +641,7 @@ import newsCategory from "@/components/newsCategory/index.vue";
import userDetail from "./userDetails"; import userDetail from "./userDetails";
import userCreate from "./userCreate"; import userCreate from "./userCreate";
import couponList from "./couponList"; import couponList from "./couponList";
import { roterPre } from "@/settings";
import createWorkBook from "@/utils/newToExcel.js"; import createWorkBook from "@/utils/newToExcel.js";
const checkMobile = (rule, value, cb) => { const checkMobile = (rule, value, cb) => {
const regMobile = /^[1][3,4,5,6,7,8,9][0-9]{9}$/; const regMobile = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
@ -775,6 +776,7 @@ export default {
total: 0, total: 0,
}, },
uid: "", uid: "",
roterPre: roterPre,
listLoading: true, listLoading: true,
multipleSelection: [], multipleSelection: [],
ids: "", ids: "",
@ -1024,35 +1026,37 @@ export default {
}, },
// //
async exportList() { async exportList() {
const loading = this.$loading({ // const loading = this.$loading({
lock: true, // lock: true,
text: "正在拼命导出中,请耐心等待...", // text: "...",
spinner: "el-icon-loading", // spinner: "el-icon-loading",
background: "hsla(0, 0%, 100%, .9)", // background: "hsla(0, 0%, 100%, .9)",
}); // });
let excelData = JSON.parse(JSON.stringify(this.userFrom)), // let excelData = JSON.parse(JSON.stringify(this.userFrom)),
data = []; // data = [];
excelData.page = 1; // excelData.page = 1;
excelData.limit = 500; // excelData.limit = 500;
let pageCount = 1; // let pageCount = 1;
let lebData = {}; // let lebData = {};
for (let i = 0; i < pageCount; i++) { // for (let i = 0; i < pageCount; i++) {
lebData = await this.downData(excelData); // lebData = await this.downData(excelData);
pageCount = Math.ceil(lebData.count / excelData.limit); // pageCount = Math.ceil(lebData.count / excelData.limit);
if (lebData.export.length) { // if (lebData.export.length) {
data = data.concat(lebData.export); // data = data.concat(lebData.export);
excelData.page++; // excelData.page++;
} // }
} // }
createWorkBook( // createWorkBook(
lebData.header, // lebData.header,
lebData.title, // lebData.title,
data, // data,
lebData.foot, // lebData.foot,
lebData.filename // lebData.filename
); // );
loading.close(); // loading.close();
return; // return;
let excelData = JSON.parse(JSON.stringify(this.userFrom));
this.exportRecord(excelData);
}, },
/**导出用户列表 */ /**导出用户列表 */
downData(excelData) { downData(excelData) {
@ -1062,6 +1066,26 @@ export default {
}); });
}); });
}, },
exportRecord(excelData) {
exportUserApi(excelData)
.then((res) => {
const h = this.$createElement;
this.$msgbox({
title: "提示",
message: h("p", null, [
h("span", null, '文件正在生成中,请稍后点击"'),
h("span", { style: "color: teal" }, "导出记录"),
h("span", null, '"查看~ '),
]),
confirmButtonText: "我知道了",
}).then((action) => {
this.$router.push({ path: this.roterPre + "/group/exportList" });
});
})
.catch((res) => {
this.$message.error(res.message);
});
},
sendSuccess() { sendSuccess() {
this.visibleCoupon = false; this.visibleCoupon = false;
}, },