bugfixed
This commit is contained in:
parent
ce845b7f58
commit
bb99330cbf
@ -609,12 +609,18 @@ const handleRes = (res: any, selectAllDevices: any) => {
|
||||
attIndex = highSpeedExoprtHeader.value.indexOf(attName)
|
||||
}
|
||||
xData.forEach((time: any, index: number) => {
|
||||
const dataItem = [
|
||||
escapeCsvValue(deviceName + '\t'), // 风机名称
|
||||
escapeCsvValue(timestampToTime(time) + '\t'), // 时间
|
||||
]
|
||||
dataItem[attIndex] = escapeCsvValue(yData[index] + '\t')
|
||||
highSpeedExoprtData.value.push(dataItem.join(','))
|
||||
const tableDataIndex = highSpeedExoprtData.value.findIndex(
|
||||
(data: any) => data.name == deviceName && data.time == timestampToTime(time)
|
||||
)
|
||||
if (tableDataIndex > -1) {
|
||||
highSpeedExoprtData.value[tableDataIndex][attName] = yData[index]
|
||||
} else {
|
||||
highSpeedExoprtData.value.push({
|
||||
name: deviceName,
|
||||
time: timestampToTime(time),
|
||||
[attName]: yData[index],
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
let attIndex = lowSpeedExoprtHeader.value.indexOf(attName)
|
||||
@ -623,26 +629,20 @@ const handleRes = (res: any, selectAllDevices: any) => {
|
||||
attIndex = lowSpeedExoprtHeader.value.indexOf(attName)
|
||||
}
|
||||
xData.forEach((time: any, index: number) => {
|
||||
const dataItem = [
|
||||
escapeCsvValue(deviceName) + '\t', // 风机名称
|
||||
escapeCsvValue(timestampToTime(time)) + '\t' + '\t', // 时间
|
||||
]
|
||||
dataItem[attIndex] = escapeCsvValue(yData[index] + '\t')
|
||||
lowSpeedExoprtData.value.push(dataItem.join(','))
|
||||
const tableDataIndex = lowSpeedExoprtData.value.findIndex(
|
||||
(data: any) => data.name == deviceName && data.time == timestampToTime(time)
|
||||
)
|
||||
if (tableDataIndex > -1) {
|
||||
lowSpeedExoprtData.value[tableDataIndex][attName] = yData[index]
|
||||
} else {
|
||||
lowSpeedExoprtData.value.push({
|
||||
name: deviceName,
|
||||
time: timestampToTime(time),
|
||||
[attName]: yData[index],
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
highcsvContent.value = highSpeedExoprtData.value.length
|
||||
? highSpeedExoprtHeader.value + '\n' + highSpeedExoprtData.value.join('\n')
|
||||
: []
|
||||
lowcsvContent.value = lowSpeedExoprtData.value.length
|
||||
? lowSpeedExoprtHeader.value + '\n' + lowSpeedExoprtData.value.join('\n')
|
||||
: []
|
||||
if (!yData.length) {
|
||||
ElMessage.info(`${deviceName + attName}数据为空`)
|
||||
return
|
||||
}
|
||||
console.log(selectAllDevicesIndex)
|
||||
console.log(irnIndex)
|
||||
const seriesData = {
|
||||
name: deviceName + attName,
|
||||
type: 'line',
|
||||
@ -681,37 +681,41 @@ const handleRes = (res: any, selectAllDevices: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
const escapeCsvValue = (value: any) => {
|
||||
if (value === undefined || value === null) {
|
||||
return ' '
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
if (value.includes(',') || value.includes('"') || value.includes('\n')) {
|
||||
return `"${value.replace(/"/g, '""')}"`
|
||||
}
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
const statAnalysisExport = () => {
|
||||
const tables = [
|
||||
{ data: highcsvContent.value, filename: '多机对比_高频' + new Date().getTime() + '.csv' },
|
||||
{ data: lowcsvContent.value, filename: '多机对比_低频' + new Date().getTime() + '.csv' },
|
||||
{ header: highSpeedExoprtHeader.value, data: highSpeedExoprtData.value, filename: '多机对比_高频' + new Date().getTime() + '.csv' },
|
||||
{ header: lowSpeedExoprtHeader.value, data: lowSpeedExoprtData.value, filename: '多机对比_低频' + new Date().getTime() + '.csv' },
|
||||
]
|
||||
|
||||
tables.forEach((table) => {
|
||||
const csvContent = table.data
|
||||
if (csvContent.length) {
|
||||
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' })
|
||||
const link = document.createElement('a')
|
||||
if (link.download !== undefined) {
|
||||
const url = URL.createObjectURL(blob)
|
||||
link.setAttribute('href', url)
|
||||
link.setAttribute('download', table.filename)
|
||||
link.style.visibility = 'hidden'
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
if (table.data.length) {
|
||||
let str = ''
|
||||
table.data.forEach((item: any) => {
|
||||
table.header.forEach((prop: any, index: number) => {
|
||||
let val = ''
|
||||
if (index == 0) {
|
||||
val = item.name
|
||||
} else if (index == 1) {
|
||||
val = item.time
|
||||
} else {
|
||||
val = typeof item[prop] === 'number' ? String(item[prop]) : item[prop] ? item[prop] : ''
|
||||
}
|
||||
str += val + '\t' + ','
|
||||
})
|
||||
str += '\n'
|
||||
})
|
||||
str = table.header + '\n' + str
|
||||
if (str.length) {
|
||||
const blob = new Blob([str], { type: 'text/csv;charset=utf-8;' })
|
||||
const link = document.createElement('a')
|
||||
if (link.download !== undefined) {
|
||||
const url = URL.createObjectURL(blob)
|
||||
link.setAttribute('href', url)
|
||||
link.setAttribute('download', table.filename)
|
||||
link.style.visibility = 'hidden'
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user