报表导出
This commit is contained in:
parent
67674ac6de
commit
d0d240c086
@ -54,7 +54,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<el-button class="button" :icon="Search" @click="queryHistoryData" type="primary">查询</el-button>
|
<el-button class="button" :icon="Search" @click="queryHistoryData" type="primary">查询</el-button>
|
||||||
<el-button class="button" :icon="Upload" type="primary" plain>导出</el-button>
|
<el-button class="button" :icon="Upload" type="primary" plain @click="exportCsv">导出</el-button>
|
||||||
<el-button class="button" :icon="Notebook" type="primary" @click="addReportTemplate" plain>保存为模板</el-button>
|
<el-button class="button" :icon="Notebook" type="primary" @click="addReportTemplate" plain>保存为模板</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -69,7 +69,7 @@
|
|||||||
>
|
>
|
||||||
<el-table-column prop="deviceId" label="风机" fixed width="80px" align="center">
|
<el-table-column prop="deviceId" label="风机" fixed width="80px" align="center">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
{{ windBlowerList.find((val) => val.irn == scope.row.deviceId)!.name }}
|
{{ windBlowerList.find((val) => val.irn == scope.row.deviceId)?.name }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="time" label="时间" fixed width="180px" align="center"> </el-table-column>
|
<el-table-column prop="time" label="时间" fixed width="180px" align="center"> </el-table-column>
|
||||||
@ -143,7 +143,10 @@ import { useI18n } from 'vue-i18n'
|
|||||||
import { shortUuid } from '/@/utils/random'
|
import { shortUuid } from '/@/utils/random'
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
import { useAdminInfo } from '/@/stores/adminInfo'
|
import { useAdminInfo } from '/@/stores/adminInfo'
|
||||||
|
import { cloneDeep } from 'lodash-es'
|
||||||
const adminInfo = useAdminInfo()
|
const adminInfo = useAdminInfo()
|
||||||
|
import { useEnumStore } from '/@/stores/enums'
|
||||||
|
const enumStore = useEnumStore()
|
||||||
const shortcuts = [
|
const shortcuts = [
|
||||||
{
|
{
|
||||||
text: '今天',
|
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 = () => {
|
const addReportTemplate = () => {
|
||||||
ElMessageBox.prompt('请输入模板名称', '添加模板', {
|
ElMessageBox.prompt('请输入模板名称', '添加模板', {
|
||||||
confirmButtonText: '提交',
|
confirmButtonText: '提交',
|
||||||
@ -336,7 +361,7 @@ const addColumn = () => {
|
|||||||
const addRow = () => {}
|
const addRow = () => {}
|
||||||
const removeColumn = (val: any) => {
|
const removeColumn = (val: any) => {
|
||||||
const columnName = val.column.property
|
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) => {
|
const handleSelections = (value: any) => {
|
||||||
currentChooseRows.value = JSON.parse(JSON.stringify(value))
|
currentChooseRows.value = JSON.parse(JSON.stringify(value))
|
||||||
@ -424,7 +449,7 @@ const queryHistoryData = () => {
|
|||||||
if (!windBlowerValue.value.length) return ElMessage.warning('请选择风机!')
|
if (!windBlowerValue.value.length) return ElMessage.warning('请选择风机!')
|
||||||
if (!timeRange.value.length) return ElMessage.warning('请选择时间!')
|
if (!timeRange.value.length) return ElMessage.warning('请选择时间!')
|
||||||
if (!interval.value) 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('请添加测点!')
|
if (!attributeCodes.length) return ElMessage.warning('请添加测点!')
|
||||||
reportLoading.value = true
|
reportLoading.value = true
|
||||||
// idCounter.value = 0
|
// idCounter.value = 0
|
||||||
@ -450,7 +475,7 @@ const queryHistoryData = () => {
|
|||||||
|
|
||||||
if (realResult) {
|
if (realResult) {
|
||||||
let tableData = [] as any
|
let tableData = [] as any
|
||||||
attributeCodes.forEach((item:any) => {
|
attributeCodes.forEach((item: any) => {
|
||||||
if (Object.keys(realResult).includes(item)) {
|
if (Object.keys(realResult).includes(item)) {
|
||||||
tableData.push({
|
tableData.push({
|
||||||
name: item,
|
name: item,
|
||||||
@ -467,7 +492,8 @@ const queryHistoryData = () => {
|
|||||||
if (!processedData.has(time)) {
|
if (!processedData.has(time)) {
|
||||||
processedData.set(time, { id: shortUuid(), time: timestampToTime(time), deviceId })
|
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,
|
time: item.time,
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
} as any
|
} as any
|
||||||
allKeys.forEach((key: any) => {
|
allKeys.forEach((key: string) => {
|
||||||
if (!['id', 'time', 'deviceId'].includes(key)) {
|
if (!['id', 'time', 'deviceId'].includes(key)) {
|
||||||
generatedItem[key] = '-'
|
generatedItem[key] = '-'
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<div style="width: 20px"></div>
|
<div style="width: 20px"></div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<el-button class="button" :icon="Search" @click="queryHistoryData" type="primary">查询</el-button>
|
<el-button class="button" :icon="Search" @click="queryHistoryData" type="primary">查询</el-button>
|
||||||
<el-button class="button" :icon="Upload" type="primary" plain>导出</el-button>
|
<el-button class="button" :icon="Upload" type="primary" @click="exportCsv" plain>导出</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-space>
|
</el-space>
|
||||||
<div class="reportButtons">
|
<div class="reportButtons">
|
||||||
@ -74,6 +74,7 @@ import { queryWindTurbinesPages, historyReq } from '/@/api/backend/statAnalysis/
|
|||||||
import { shortUuid } from '/@/utils/random'
|
import { shortUuid } from '/@/utils/random'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
import { cloneDeep } from 'lodash-es'
|
||||||
const selectedIndex = ref(0)
|
const selectedIndex = ref(0)
|
||||||
const buttons = ['日报', '月报']
|
const buttons = ['日报', '月报']
|
||||||
const attributeCodes = ref(['iKWhThisDay', 'iOperationHoursDay', 'iWindSpeed'])
|
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.startTime = new Date(getFirstAndLastDate(timeValue.value)[0] + ' 00:00:00').getTime()
|
||||||
requestData.endTime = new Date(getFirstAndLastDate(timeValue.value)[1] + ' 23:59:59').getTime()
|
requestData.endTime = new Date(getFirstAndLastDate(timeValue.value)[1] + ' 23:59:59').getTime()
|
||||||
}
|
}
|
||||||
|
console.log(requestData, 7777)
|
||||||
|
|
||||||
reportLoading.value = true
|
reportLoading.value = true
|
||||||
|
|
||||||
historyReq(requestData).then((res) => {
|
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) => {
|
const timestampToTime = (timestamp: any) => {
|
||||||
let timestamps = timestamp ? timestamp : null
|
let timestamps = timestamp ? timestamp : null
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<el-button class="button" :icon="Search" @click="queryHistoryData" type="primary">查询</el-button>
|
<el-button class="button" :icon="Search" @click="queryHistoryData" type="primary">查询</el-button>
|
||||||
<el-button class="button" :icon="Upload" type="primary" plain>导出</el-button>
|
<el-button class="button" :icon="Upload" type="primary" plain @click="exportCsv">导出</el-button>
|
||||||
<el-button class="button" :icon="Notebook" type="primary" @click="addReportTemplate" plain>保存为模板</el-button>
|
<el-button class="button" :icon="Notebook" type="primary" @click="addReportTemplate" plain>保存为模板</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -139,7 +139,10 @@ import Measurement from './measureList.vue'
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
import { useAdminInfo } from '/@/stores/adminInfo'
|
import { useAdminInfo } from '/@/stores/adminInfo'
|
||||||
|
import { cloneDeep } from 'lodash-es'
|
||||||
const adminInfo = useAdminInfo()
|
const adminInfo = useAdminInfo()
|
||||||
|
import { useEnumStore } from '/@/stores/enums'
|
||||||
|
const enumStore = useEnumStore()
|
||||||
const shortcuts = [
|
const shortcuts = [
|
||||||
{
|
{
|
||||||
text: '今天',
|
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 = () => {
|
const addReportTemplate = () => {
|
||||||
ElMessageBox.prompt('请输入模板名称', '添加模板', {
|
ElMessageBox.prompt('请输入模板名称', '添加模板', {
|
||||||
confirmButtonText: '提交',
|
confirmButtonText: '提交',
|
||||||
@ -314,7 +336,7 @@ const chooseMeasurePoint = () => {
|
|||||||
}
|
}
|
||||||
const removeColumn = (val: any) => {
|
const removeColumn = (val: any) => {
|
||||||
const columnName = val.column.property
|
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) => {
|
const handleSelections = (value: any) => {
|
||||||
@ -403,7 +425,7 @@ const queryHistoryData = () => {
|
|||||||
if (!windBlowerValue.value) return ElMessage.warning('请选择风机!')
|
if (!windBlowerValue.value) return ElMessage.warning('请选择风机!')
|
||||||
if (!timeRange.value.length) return ElMessage.warning('请选择时间!')
|
if (!timeRange.value.length) return ElMessage.warning('请选择时间!')
|
||||||
if (!interval.value) 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('请添加测点!')
|
if (!attributeCodes.length) return ElMessage.warning('请添加测点!')
|
||||||
reportLoading.value = true
|
reportLoading.value = true
|
||||||
const requestData = {
|
const requestData = {
|
||||||
@ -423,7 +445,7 @@ const queryHistoryData = () => {
|
|||||||
if (Object.keys(result)?.length) {
|
if (Object.keys(result)?.length) {
|
||||||
const realResult = result[windBlowerValue.value]
|
const realResult = result[windBlowerValue.value]
|
||||||
let tableData = [] as any
|
let tableData = [] as any
|
||||||
attributeCodes.forEach((item:any) => {
|
attributeCodes.forEach((item: any) => {
|
||||||
if (Object.keys(realResult).includes(item)) {
|
if (Object.keys(realResult).includes(item)) {
|
||||||
tableData.push({
|
tableData.push({
|
||||||
name: item,
|
name: item,
|
||||||
@ -440,7 +462,8 @@ const queryHistoryData = () => {
|
|||||||
if (!processedData.has(time)) {
|
if (!processedData.has(time)) {
|
||||||
processedData.set(time, { id: idCounter.value++, time: timestampToTime(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
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user