chore: 移除 xlsx 依赖, 重构 table 导出

This commit is contained in:
就眠儀式 2022-04-16 14:03:15 +08:00
parent 7f03d84e25
commit 817793be6e

View File

@ -121,9 +121,9 @@ const print = function () {
const exportData = () => { const exportData = () => {
const head = []; const head = [];
const body = []; const body = [];
tableColumns.value.forEach(item => { tableColumns.value.forEach((item) => {
head.push(item.title); head.push(item.title);
}) });
tableDataSource.value.forEach((item) => { tableDataSource.value.forEach((item) => {
let obj = []; let obj = [];
tableColumns.value.forEach((tableColumn) => { tableColumns.value.forEach((tableColumn) => {
@ -137,19 +137,19 @@ const exportData = () => {
}); });
body.push(obj); body.push(obj);
}); });
exportToExcel(head, body) exportToExcel(head, body);
return; return;
}; };
function exportToExcel(headerList, bodyList){ function exportToExcel(headerList, bodyList) {
let excelList = []; let excelList = [];
excelList.push(headerList.join("\t,")); excelList.push(headerList.join("\t,"));
excelList.push("\n"); excelList.push("\n");
bodyList.forEach(item=>{ bodyList.forEach((item) => {
excelList.push(item.join("\t,")); excelList.push(item.join("\t,"));
excelList.push("\n"); excelList.push("\n");
}) });
var merged = excelList .join(""); var merged = excelList.join("");
let link = document.createElement("a"); let link = document.createElement("a");
link.href = "data:text/xls;charset=utf-8,\ufeff" + encodeURIComponent(merged); link.href = "data:text/xls;charset=utf-8,\ufeff" + encodeURIComponent(merged);
link.download = `table.xls`; link.download = `table.xls`;