<template><el-table:data="tableData"style="width: 100%"><el-table-columnprop="title"label="设备名称"width="150"></el-table-column><el-table-columnlabel="温度"><templatev-for="i in tableColumns"><el-table-column:prop="i":label="i"border></el-table-column></template></el-table-column></el-table></template>
exportdefault{props:['device_id'],name:'charts',data(){return{chart:null,tableData:[],tableColumns:[]}},beforeMount(){this.getConnectionCharts()},methods:{//获取信息getConnectionCharts(){getConnectionCharts({device_id:422,// 查询全部数据type:5}).then(res=>{
console.log(res,'res')const[list, columns]=this.formatTableData(res.data.chart)this.tableData = list
this.tableColumns = columns
}).catch(err=>{this.tableData =[]})},formatTableData(data){const keys ={temp_face:'表皮温度',temp_battery:'电池温度',temp_line:'线芯温度',temp_a:'a相温度',temp_b:'b相温度',temp_c:'c相温度',temp_envir:'环境温度'}const result = Object.keys(keys).map(i=>({title: keys[i],key: i }))
console.log(keys,'keys')
result.forEach(item=>{
data.forEach(i=>{const k = i.temp_stamp.split(' ')[1].substring(0,5)
item[k]= i[item.key]})})const tableColumns = data.map(i=> i.temp_stamp.split(' ')[1].substring(0,5))return[result, tableColumns]}}}</script>