From d0d240c08678872b802e49c63dff6f4e54508f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=81=E4=B8=87=E6=88=90?= Date: Mon, 11 Nov 2024 09:22:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E8=A1=A8=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/backend/report/MulipleReport.vue | 40 +++++++++++++++---- .../views/backend/report/RunningReport.vue | 25 +++++++++++- .../src/views/backend/report/SingleReport.vue | 33 ++++++++++++--- 3 files changed, 85 insertions(+), 13 deletions(-) diff --git a/ui/dasadmin/src/views/backend/report/MulipleReport.vue b/ui/dasadmin/src/views/backend/report/MulipleReport.vue index 5afde476..9a8831e4 100644 --- a/ui/dasadmin/src/views/backend/report/MulipleReport.vue +++ b/ui/dasadmin/src/views/backend/report/MulipleReport.vue @@ -54,7 +54,7 @@
查询 - 导出 + 导出 保存为模板
@@ -69,7 +69,7 @@ > @@ -143,7 +143,10 @@ import { useI18n } from 'vue-i18n' import { shortUuid } from '/@/utils/random' const { t } = useI18n() import { useAdminInfo } from '/@/stores/adminInfo' +import { cloneDeep } from 'lodash-es' const adminInfo = useAdminInfo() +import { useEnumStore } from '/@/stores/enums' +const enumStore = useEnumStore() const shortcuts = [ { text: '今天', @@ -233,6 +236,28 @@ const getReportTemplateList = () => { } }) } +const exportCsv = () => { + const exportColumnLabel = [{ prop: 'deviceId', label: '风机' }, { prop: 'time', label: '时间' }, ...reportTableColumn.value] + const itemsRest = cloneDeep(reportTableData.value).map((item: any) => { + if (item.deviceId) { + item.deviceId = windBlowerList.value.find((val: any) => val.irn == item.deviceId)?.name + } + const { id, ...rest } = item + return rest + }) + const csvContent = [ + exportColumnLabel.map((header: any) => header.label).join(', '), + ...itemsRest.map((row: any) => exportColumnLabel.map((header) => row[header.prop] ?? '-').join(', ')), + ].join('\n') + const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }) + const link = document.createElement('a') + link.href = URL.createObjectURL(blob) + link.download = Date.now() + '.csv' + link.style.display = 'none' + document.body.appendChild(link) + link.click() + document.body.removeChild(link) +} const addReportTemplate = () => { ElMessageBox.prompt('请输入模板名称', '添加模板', { confirmButtonText: '提交', @@ -336,7 +361,7 @@ const addColumn = () => { const addRow = () => {} const removeColumn = (val: any) => { const columnName = val.column.property - reportTableColumn.value = reportTableColumn.value.filter((val:any) => val.prop !== columnName) + reportTableColumn.value = reportTableColumn.value.filter((val: any) => val.prop !== columnName) } const handleSelections = (value: any) => { currentChooseRows.value = JSON.parse(JSON.stringify(value)) @@ -424,7 +449,7 @@ const queryHistoryData = () => { if (!windBlowerValue.value.length) return ElMessage.warning('请选择风机!') if (!timeRange.value.length) return ElMessage.warning('请选择时间!') if (!interval.value) return ElMessage.warning('请选择间隔!') - const attributeCodes = reportTableColumn.value.map((val:any) => val.prop).filter((item:any) => item != null && item !== '') + const attributeCodes = reportTableColumn.value.map((val: any) => val.prop).filter((item: any) => item != null && item !== '') if (!attributeCodes.length) return ElMessage.warning('请添加测点!') reportLoading.value = true // idCounter.value = 0 @@ -450,7 +475,7 @@ const queryHistoryData = () => { if (realResult) { let tableData = [] as any - attributeCodes.forEach((item:any) => { + attributeCodes.forEach((item: any) => { if (Object.keys(realResult).includes(item)) { tableData.push({ name: item, @@ -467,7 +492,8 @@ const queryHistoryData = () => { if (!processedData.has(time)) { processedData.set(time, { id: shortUuid(), time: timestampToTime(time), deviceId }) } - processedData.get(time)[name] = value[index] + const values = value[index] + processedData.get(time)[name] = enumStore.keys.includes(name) ? enumStore.data?.[name]?.[values] : values }) }) } @@ -526,7 +552,7 @@ const generateMissingData = (data: any, deviceIds: any) => { time: item.time, deviceId: deviceId, } as any - allKeys.forEach((key: any) => { + allKeys.forEach((key: string) => { if (!['id', 'time', 'deviceId'].includes(key)) { generatedItem[key] = '-' } diff --git a/ui/dasadmin/src/views/backend/report/RunningReport.vue b/ui/dasadmin/src/views/backend/report/RunningReport.vue index 9d7c9f7c..d9d163fc 100644 --- a/ui/dasadmin/src/views/backend/report/RunningReport.vue +++ b/ui/dasadmin/src/views/backend/report/RunningReport.vue @@ -16,7 +16,7 @@
查询 - 导出 + 导出
@@ -74,6 +74,7 @@ import { queryWindTurbinesPages, historyReq } from '/@/api/backend/statAnalysis/ import { shortUuid } from '/@/utils/random' import { useI18n } from 'vue-i18n' const { t } = useI18n() +import { cloneDeep } from 'lodash-es' const selectedIndex = ref(0) const buttons = ['日报', '月报'] const attributeCodes = ref(['iKWhThisDay', 'iOperationHoursDay', 'iWindSpeed']) @@ -186,6 +187,8 @@ const queryHistoryData = () => { requestData.startTime = new Date(getFirstAndLastDate(timeValue.value)[0] + ' 00:00:00').getTime() requestData.endTime = new Date(getFirstAndLastDate(timeValue.value)[1] + ' 23:59:59').getTime() } + console.log(requestData, 7777) + reportLoading.value = true historyReq(requestData).then((res) => { @@ -256,6 +259,26 @@ const queryHistoryData = () => { }) } +const exportCsv = () => { + const exportColumnLabel = [{ prop: 'time', label: '时间' }, ...reportTableColumn.value] + const itemsRest = cloneDeep(reportTableData.value).map((item: any) => { + const { id, deviceId, prop, ...rest } = item + return rest + }) + const csvContent = [ + exportColumnLabel.map((header: any) => header.label).join(', '), + ...itemsRest.map((row: any) => exportColumnLabel.map((header) => row[header.prop] ?? '-').join(', ')), + ].join('\n') + const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }) + const link = document.createElement('a') + link.href = URL.createObjectURL(blob) + link.download = Date.now() + '.csv' + link.style.display = 'none' + document.body.appendChild(link) + link.click() + document.body.removeChild(link) +} + // 时间转换 const timestampToTime = (timestamp: any) => { let timestamps = timestamp ? timestamp : null diff --git a/ui/dasadmin/src/views/backend/report/SingleReport.vue b/ui/dasadmin/src/views/backend/report/SingleReport.vue index 1c1e3176..8f17d6ba 100644 --- a/ui/dasadmin/src/views/backend/report/SingleReport.vue +++ b/ui/dasadmin/src/views/backend/report/SingleReport.vue @@ -58,7 +58,7 @@
查询 - 导出 + 导出 保存为模板
@@ -139,7 +139,10 @@ import Measurement from './measureList.vue' import { useI18n } from 'vue-i18n' const { t } = useI18n() import { useAdminInfo } from '/@/stores/adminInfo' +import { cloneDeep } from 'lodash-es' const adminInfo = useAdminInfo() +import { useEnumStore } from '/@/stores/enums' +const enumStore = useEnumStore() const shortcuts = [ { text: '今天', @@ -229,6 +232,25 @@ const getReportTemplateList = () => { } }) } +const exportCsv = () => { + const exportColumnLabel = [{ prop: 'time', label: '时间' }, ...reportTableColumn.value] + const itemsRest = cloneDeep(reportTableData.value).map((item: any) => { + const { id, ...rest } = item + return rest + }) + const csvContent = [ + exportColumnLabel.map((header: any) => header.label).join(', '), + ...itemsRest.map((row: any) => exportColumnLabel.map((header) => row[header.prop] ?? '-').join(', ')), + ].join('\n') + const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }) + const link = document.createElement('a') + link.href = URL.createObjectURL(blob) + link.download = Date.now() + '.csv' + link.style.display = 'none' + document.body.appendChild(link) + link.click() + document.body.removeChild(link) +} const addReportTemplate = () => { ElMessageBox.prompt('请输入模板名称', '添加模板', { confirmButtonText: '提交', @@ -314,7 +336,7 @@ const chooseMeasurePoint = () => { } const removeColumn = (val: any) => { const columnName = val.column.property - reportTableColumn.value = reportTableColumn.value.filter((val:any) => val.prop !== columnName) + reportTableColumn.value = reportTableColumn.value.filter((val: any) => val.prop !== columnName) } const handleSelections = (value: any) => { @@ -403,7 +425,7 @@ const queryHistoryData = () => { if (!windBlowerValue.value) return ElMessage.warning('请选择风机!') if (!timeRange.value.length) return ElMessage.warning('请选择时间!') if (!interval.value) return ElMessage.warning('请选择间隔!') - const attributeCodes = reportTableColumn.value.map((val:any) => val.prop).filter((item:any) => item != null && item !== '') + const attributeCodes = reportTableColumn.value.map((val: any) => val.prop).filter((item: any) => item != null && item !== '') if (!attributeCodes.length) return ElMessage.warning('请添加测点!') reportLoading.value = true const requestData = { @@ -423,7 +445,7 @@ const queryHistoryData = () => { if (Object.keys(result)?.length) { const realResult = result[windBlowerValue.value] let tableData = [] as any - attributeCodes.forEach((item:any) => { + attributeCodes.forEach((item: any) => { if (Object.keys(realResult).includes(item)) { tableData.push({ name: item, @@ -440,7 +462,8 @@ const queryHistoryData = () => { if (!processedData.has(time)) { processedData.set(time, { id: idCounter.value++, time: timestampToTime(time) }) } - processedData.get(time)[name] = value[index] + const values = value[index] + processedData.get(time)[name] = enumStore.keys.includes(name) ? enumStore.data?.[name]?.[values] : values }) }) }