告警根据中英文导出

This commit is contained in:
lai
2024-09-05 16:38:06 +08:00
parent e8ef2816df
commit 33f468209a
4 changed files with 102 additions and 59 deletions

View File

@@ -426,6 +426,17 @@ function fnCancelConfirm() {
});
}
// key替换中文title
function mapKeysWithReduce(data: any, titleMapping: any) {
return data.map((item:any) => {
return Object.keys(item).reduce((newItem:any, key:any) => {
const title = titleMapping[key] || key;
newItem[title] = item[key];
return newItem;
});
});
}
/**
* 导出全部
*/
@@ -437,12 +448,18 @@ function fnExportAll() {
const key = 'exportAlarmHis';
message.loading({ content: t('common.loading'), key });
let sortArr: any = [];
let writeSheetOpt: any = [];
let mappArr: any = {};
tableColumnsDnd.value.forEach((item: any) => {
if (item.dataIndex) sortArr.push(item.dataIndex);
if (item.dataIndex) {
sortArr.push(item.dataIndex);
writeSheetOpt.push(item.title);
mappArr[item.dataIndex] = item.title;
}
});
// 排序字段
//提供给writeSheet排序参数
const sortData = {
header: sortArr,
header: writeSheetOpt,
};
exportAll(queryParams).then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
@@ -470,14 +487,17 @@ function fnExportAll() {
return filteredObj;
});
message.success({
content: t('common.msgSuccess', { msg: t('common.export') }),
key,
duration: 3,
res.data = mapKeysWithReduce(res.data, mappArr);
writeSheet(res.data, 'alarm', sortData).then(fileBlob => {
saveAs(fileBlob, `history-alarm_${Date.now()}.xlsx`);
message.success({
content: t('common.msgSuccess', { msg: t('common.export') }),
key,
duration: 3,
});
});
writeSheet(res.data, 'alarm', sortData).then(fileBlob =>
saveAs(fileBlob, `history-alarm_${Date.now()}.xlsx`)
);
} else {
message.error({
content: `${res.msg}`,