From 7c699671486dad7a013dd3c9e3548676ee5bf464 Mon Sep 17 00:00:00 2001 From: lai <371757574@qq.com> Date: Tue, 26 Dec 2023 10:03:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=BC=E5=87=BA=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E5=8F=AF=E6=8E=92=E5=BA=8F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/execl-utils.ts | 18 +++++-- src/views/faultManage/active-alarm/index.vue | 38 ++++++++++++++- src/views/faultManage/history-alarm/index.vue | 47 ++++++++++++++++++- src/views/index.vue | 9 ++-- 4 files changed, 102 insertions(+), 10 deletions(-) diff --git a/src/utils/execl-utils.ts b/src/utils/execl-utils.ts index fe57d798..9578360e 100644 --- a/src/utils/execl-utils.ts +++ b/src/utils/execl-utils.ts @@ -1,4 +1,4 @@ -import { read, utils, write } from 'xlsx'; +import { JSON2SheetOpts, read, utils, write } from 'xlsx'; // 静态资源路径 const baseUrl = import.meta.env.VITE_HISTORY_BASE_URL; @@ -19,7 +19,10 @@ export const xlsxUrl = `${ * console.log(res) * }); */ -export async function readLoalXlsx(lang:string,id: string): Promise[]> { +export async function readLoalXlsx( + lang: string, + id: string +): Promise[]> { let result = await fetch(`${xlsxUrl}/${lang}/${id}.xlsx`); let fileBuffer = await result.arrayBuffer(); // 判断是否xlsx文件 @@ -62,11 +65,18 @@ export async function readSheet( * ); * */ -export async function writeSheet(data: any[], sheetName: string) { +export async function writeSheet( + data: any[], + sheetName: string, + opts?: JSON2SheetOpts + ) { if (data.length === 0) { return new Blob([], { type: 'application/octet-stream' }); } - const workSheet = utils.json_to_sheet(data); + + const workSheet = utils.json_to_sheet(data, opts); + console.log(workSheet); + // 设置列宽度,单位厘米 workSheet['!cols'] = Object.keys(data[0]).map(() => { return { wch: 20 }; diff --git a/src/views/faultManage/active-alarm/index.vue b/src/views/faultManage/active-alarm/index.vue index d11e6bc2..984f890f 100644 --- a/src/views/faultManage/active-alarm/index.vue +++ b/src/views/faultManage/active-alarm/index.vue @@ -630,6 +630,42 @@ function fnExportAll() { onOk() { const key = 'exportAlarm'; message.loading({ content: t('common.loading'), key }); + // 排序字段 + const sortData = { + header: [ + 'id', + 'neId', + 'neName', + 'neType', + 'ackState', + 'ackTime', + 'ackUser', + 'addInfo', + 'alarmCode', + 'alarmId', + 'alarmSeq', + 'alarmStatus', + 'alarmTitle', + 'alarmType', + 'clearTime', + 'clearType', + 'clearUser', + 'counter', + 'eventTime', + 'latestEventTime', + 'locationInfo', + 'objectName', + 'objectType', + 'objectUid', + 'origSeverity', + 'perceivedSeverity', + 'province', + 'pvFlag', + 'specificProblem', + 'specificProblemId', + 'timestamp', + ], + }; exportAll(queryParams).then(res => { if (res.code === RESULT_CODE_SUCCESS) { message.success({ @@ -637,7 +673,7 @@ function fnExportAll() { key, duration: 3, }); - writeSheet(res.data, 'alarm').then(fileBlob => + writeSheet(res.data, 'alarm', sortData).then(fileBlob => saveAs(fileBlob, `alarm_${Date.now()}.xlsx`) ); } else { diff --git a/src/views/faultManage/history-alarm/index.vue b/src/views/faultManage/history-alarm/index.vue index 52ca2d6a..19609729 100644 --- a/src/views/faultManage/history-alarm/index.vue +++ b/src/views/faultManage/history-alarm/index.vue @@ -39,6 +39,9 @@ let dict: { /**记录开始结束时间 */ let queryRangePicker = ref<[string, string]>(['', '']); +/**表格字段列排序 */ +let tableColumnsDnd = ref([]); + /**查询参数 */ let queryParams = reactive({ /**告警设备类型 */ @@ -431,6 +434,42 @@ function fnExportAll() { onOk() { const key = 'exportAlarmHis'; message.loading({ content: t('common.loading'), key }); + // 排序字段 + const sortData = { + header: [ + 'id', + 'neId', + 'neName', + 'neType', + 'ackState', + 'ackTime', + 'ackUser', + 'addInfo', + 'alarmCode', + 'alarmId', + 'alarmSeq', + 'alarmStatus', + 'alarmTitle', + 'alarmType', + 'clearTime', + 'clearType', + 'clearUser', + 'counter', + 'eventTime', + 'latestEventTime', + 'locationInfo', + 'objectName', + 'objectType', + 'objectUid', + 'origSeverity', + 'perceivedSeverity', + 'province', + 'pvFlag', + 'specificProblem', + 'specificProblemId', + 'timestamp', + ], + }; exportAll(queryParams).then(res => { if (res.code === RESULT_CODE_SUCCESS) { message.success({ @@ -438,7 +477,7 @@ function fnExportAll() { key, duration: 3, }); - writeSheet(res.data, 'alarm').then(fileBlob => + writeSheet(res.data, 'alarm',sortData).then(fileBlob => saveAs(fileBlob, `history-alarm_${Date.now()}.xlsx`) ); } else { @@ -707,6 +746,10 @@ onMounted(() => { + @@ -714,7 +757,7 @@ onMounted(() => { { nfInfo.obj }}