fix: table export 时忽略未知的列

This commit is contained in:
就眠儀式 2022-04-16 16:54:14 +08:00
parent f1d36edec0
commit d76f9962a8
2 changed files with 13 additions and 9 deletions

View File

@ -117,20 +117,24 @@ const print = function () {
document.body.innerHTML = oldContent; document.body.innerHTML = oldContent;
}; };
// table
const exportData = () => { const exportData = () => {
const head = []; const head = [];
const body = []; const body = [];
tableColumns.value.forEach((item) => { tableColumns.value.forEach((item) => {
head.push(item.title); try {
tableDataSource.value.forEach((dataItem) => {
if (dataItem[item.key] != undefined) {
head.push(item.title);
throw new Error("exception");
}
});
} catch (e) {}
}); });
tableDataSource.value.forEach((item) => { tableDataSource.value.forEach((item) => {
let obj = []; let obj = [];
tableColumns.value.forEach((tableColumn) => { tableColumns.value.forEach((tableColumn) => {
// @ts-ignore
Object.keys(item).forEach((name) => { Object.keys(item).forEach((name) => {
if (tableColumn.key === name) { if (tableColumn.key === name) {
// @ts-ignore
obj.push(item[name]); obj.push(item[name]);
} }
}); });

View File

@ -260,17 +260,17 @@ export default {
customSlot:"password", customSlot:"password",
key:"password", key:"password",
align: "center" align: "center"
},{
title:"操作",
width: "180px",
customSlot:"operator",
key:"operator"
},{ },{
title:"年龄", title:"年龄",
width: "180px", width: "180px",
key:"age", key:"age",
sort: true, sort: true,
align: "right" align: "right"
},{
title:"操作",
width: "180px",
customSlot:"operator",
key:"operator"
} }
] ]