|
@@ -79,6 +79,7 @@ import api from '/@/api/device'
|
|
import * as echarts from 'echarts'
|
|
import * as echarts from 'echarts'
|
|
import dayjs from 'dayjs'
|
|
import dayjs from 'dayjs'
|
|
import { Download, FullScreen } from '@element-plus/icons-vue'
|
|
import { Download, FullScreen } from '@element-plus/icons-vue'
|
|
|
|
+import downloadFile from '/@/utils/download'
|
|
|
|
|
|
const data = ref({ name: '', key: '', unit: '' })
|
|
const data = ref({ name: '', key: '', unit: '' })
|
|
const historyDateRangeType = ref('1')
|
|
const historyDateRangeType = ref('1')
|
|
@@ -264,40 +265,8 @@ const handleCurrentChange = (page: number) => {
|
|
|
|
|
|
// 导出数据
|
|
// 导出数据
|
|
const exportData = () => {
|
|
const exportData = () => {
|
|
- const historyParams = {
|
|
|
|
- ...params,
|
|
|
|
- pageNum: currentPage.value,
|
|
|
|
- pageSize: pageSize.value,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- api.device.getDeviceAttributesHistoryList(historyParams).then((res: any) => {
|
|
|
|
- // 创建CSV内容
|
|
|
|
- let csvContent = '时间,属性值'
|
|
|
|
- if (data.value.unit) {
|
|
|
|
- csvContent += ',数据单位'
|
|
|
|
- }
|
|
|
|
- csvContent += '\n'
|
|
|
|
-
|
|
|
|
- res.List.forEach((item: any) => {
|
|
|
|
- csvContent += `${item.ts},${item.value}`
|
|
|
|
- if (data.value.unit) {
|
|
|
|
- csvContent += `,${data.value.unit}`
|
|
|
|
- }
|
|
|
|
- csvContent += '\n'
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- // 创建Blob对象
|
|
|
|
- const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' })
|
|
|
|
- const url = URL.createObjectURL(blob)
|
|
|
|
-
|
|
|
|
- // 创建下载链接
|
|
|
|
- const link = document.createElement('a')
|
|
|
|
- link.setAttribute('href', url)
|
|
|
|
- link.setAttribute('download', `${data.value.name}_历史数据_${dayjs().format('YYYYMMDD_HHmmss')}.csv`)
|
|
|
|
- link.style.visibility = 'hidden'
|
|
|
|
- document.body.appendChild(link)
|
|
|
|
- link.click()
|
|
|
|
- document.body.removeChild(link)
|
|
|
|
|
|
+ api.device.getDeviceAttributesHistoryListExport(params).then((res: any) => {
|
|
|
|
+ downloadFile(res, `${data.value.name}(${data.value.key}) 历史数据导出.xlsx`)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|