|
|
|
|
@ -206,6 +206,12 @@
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</xy-selectors>
|
|
|
|
|
<Button
|
|
|
|
|
style="margin-left: 10px"
|
|
|
|
|
type="primary"
|
|
|
|
|
@click="exportExcel(new Date().getTime().toString())"
|
|
|
|
|
>导出</Button
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<template #create>
|
|
|
|
|
@ -222,13 +228,6 @@
|
|
|
|
|
>导入</Button
|
|
|
|
|
>
|
|
|
|
|
</template>
|
|
|
|
|
<template #export>
|
|
|
|
|
<Button
|
|
|
|
|
type="primary"
|
|
|
|
|
@click="exportExcel(new Date().getTime().toString())"
|
|
|
|
|
>导出</Button
|
|
|
|
|
>
|
|
|
|
|
</template>
|
|
|
|
|
</header-content>
|
|
|
|
|
</slot>
|
|
|
|
|
</LxHeader>
|
|
|
|
|
@ -325,18 +324,59 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async exportExcel(sheetName) {
|
|
|
|
|
let filterTableColumns = this.$refs['xyTable']?.tableFormat || []
|
|
|
|
|
const res = await index(
|
|
|
|
|
Object.assign(this.select, { page: 1, page_size: 9999 })
|
|
|
|
|
);
|
|
|
|
|
if (res.data) {
|
|
|
|
|
let headers = this.form.map((i) => {
|
|
|
|
|
let headers = filterTableColumns.filter(i => !!i.prop).map((i) => {
|
|
|
|
|
return {
|
|
|
|
|
key: i.field,
|
|
|
|
|
title: i.name,
|
|
|
|
|
key: i.prop,
|
|
|
|
|
title: i.label,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
const data = res.data.map((row) =>
|
|
|
|
|
headers.map((header) => row[header.key])
|
|
|
|
|
const data = res.data.map((row, rindex) =>
|
|
|
|
|
headers.map((header) => {
|
|
|
|
|
const i = this.form.find(i => i.field === header.key)
|
|
|
|
|
// 处理选择项(select_item)
|
|
|
|
|
if (
|
|
|
|
|
i &&
|
|
|
|
|
i.select_item &&
|
|
|
|
|
typeof i.select_item === "object" &&
|
|
|
|
|
!(i.select_item instanceof Array)
|
|
|
|
|
) {
|
|
|
|
|
let keys = Object.keys(i.select_item);
|
|
|
|
|
let paramMap = new Map();
|
|
|
|
|
keys.forEach((key) => {
|
|
|
|
|
paramMap.set(i.select_item[key], key);
|
|
|
|
|
});
|
|
|
|
|
return paramMap.get(row[i.field]?.toString()) || row[i.field];
|
|
|
|
|
}
|
|
|
|
|
// 处理关联数据(_relations)
|
|
|
|
|
if (i && i._relations) {
|
|
|
|
|
let { link_relation, foreign_key, link_with_name } = i._relations;
|
|
|
|
|
if (link_relation === "newHasOne" || link_relation === "hasOne") {
|
|
|
|
|
return row[link_with_name]?.original_name || row[link_with_name]?.name ||
|
|
|
|
|
row[link_with_name]?.no ||
|
|
|
|
|
row[link_with_name]?.value || ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (link_relation === "hasMany" || link_relation === "newHasMany") {
|
|
|
|
|
return row[link_with_name]?.map((o) => (
|
|
|
|
|
o?.name ||
|
|
|
|
|
o?.no ||
|
|
|
|
|
o?.value ||
|
|
|
|
|
o?.biaoti ||
|
|
|
|
|
o?.mingcheng
|
|
|
|
|
)).join(', ') || ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 处理格式化器(formatter)
|
|
|
|
|
if (this.table.find(i => i.prop === header.key)?.formatter) {
|
|
|
|
|
return this.table.find(i => i.prop === header.key).formatter(row, {}, row[header.key], rindex)
|
|
|
|
|
}
|
|
|
|
|
return row[header.key] || ''
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
data.unshift(headers.map((header) => header.title));
|
|
|
|
|
const wb = XLSX.utils.book_new();
|
|
|
|
|
@ -349,7 +389,7 @@ export default {
|
|
|
|
|
});
|
|
|
|
|
saveAs(
|
|
|
|
|
new Blob([wbout], { type: "application/octet-stream" }),
|
|
|
|
|
`${sheetName}.xlsx`
|
|
|
|
|
`租赁合同变更记录_${sheetName}.xlsx`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|