优化项目

This commit is contained in:
guanj
2026-06-04 19:06:36 +08:00
parent 4f32f84132
commit 4f907a80c4
53 changed files with 987 additions and 3499 deletions

View File

@@ -484,7 +484,7 @@
<div style="height: calc(100vh - 340px)" v-if="dataSet.indexOf('_trenddata') != -1">
<Trend ref="trendRef" :TrendList="TrendList"></Trend>
</div>
<!-- 电数据 -->
<!-- 电数据 -->
<div style="height: calc(100vh - 340px)" v-if="dataSet.indexOf('_kilowattHour') != -1">
<electroplating ref="electroplatingRef" :TrendList="TrendList"></electroplating>
</div>
@@ -585,7 +585,7 @@ import { ElMessage } from 'element-plus'
import DatePicker from '@/components/form/datePicker/index.vue'
import Trend from './tabs/trend.vue' //趋势数据
import realTime from './tabs/realtime.vue' //实时数据-主界面
import electroplating from './tabs/electroplating.vue' //电数据-主界面
import electroplating from './tabs/electroplating.vue' //电数据-主界面
import realTrend from './tabs/components/realtrend.vue' //实时数据-实时趋势
import operatingTrend from './tabs/operatingTrend.vue' //运行趋势
import harmonicSpectrum from './tabs/components/harmonicSpectrum.vue' //实时数据-谐波频谱子页面
@@ -705,6 +705,25 @@ const activeTrendName: any = ref(0)
const trendTimer: any = ref()
const trendDataTime: any = ref()
const showButton = ref(false)
const decodeMqttPayload = (message: any) => {
try {
return JSON.parse(JSON.stringify(JSON.parse(new TextDecoder().decode(message))))
} catch {
return {}
}
}
/** 谐波频谱 MQTT 消息(命名函数,便于 off 避免重复注册) */
const onMqttTrendMessage = (topic: any, message: any) => {
const obj = decodeMqttPayload(message) || {}
if ((obj.hasOwnProperty('data1') || obj.hasOwnProperty('data2')) && obj.dataTime) {
trendDataTime.value = obj.dataTime
realTrendRef.value?.setRealTrendData(obj)
tableLoading.value = false
}
}
//谐波频谱方法
const handleTrend = async () => {
realTimeFlag.value = false
@@ -728,21 +747,7 @@ const handleTrend = async () => {
// console.log(res, '获取谐波频谱数据')
})
}, 30000)
mqttRef.value.on('message', (topic: any, message: any) => {
let obj = JSON.parse(JSON.stringify(JSON.parse(new TextDecoder().decode(message)))) || {}
if ((obj.hasOwnProperty('data1') || obj.hasOwnProperty('data2')) && obj.dataTime) {
trendDataTime.value = obj.dataTime
realTrendRef.value && realTrendRef.value.setRealTrendData(obj)
tableLoading.value = false
// console.log(
// '谐波频谱---mqtt接收到消息',
// JSON.parse(JSON.stringify(JSON.parse(new TextDecoder().decode(message))))
// )
}
// else {
// trendDataTime.value = obj.dataTime
// }
})
bindMqttMessage(onMqttTrendMessage)
} else {
ElMessage.warning('设备应答失败')
}
@@ -885,8 +890,8 @@ const lineId: any = ref('')
const dataLevel: any = ref('')
const dataSource = ref([])
const engineeringName = ref('')
const nodeClick = async (e: anyObj, node: any) => {
if (e == undefined || e.level == 2) {
const nodeClick = async (e: anyObj, node?: any) => {
if (e == undefined) {
return (loading.value = false)
}
searchValue.value = ''
@@ -900,7 +905,7 @@ const nodeClick = async (e: anyObj, node: any) => {
}
//选中设备名称后,点击标签页也能查询数据,要求点击设备名称后,点击标签页默认查询第一个监测点数据
if (e.level == 3 || e.level == 2) {
if (e.level == 3 ) {
engineeringName.value = node?.parent.parent.data.name
await queryDictType({
@@ -940,7 +945,7 @@ const nodeClick = async (e: anyObj, node: any) => {
if (item.type === 'trenddata') {
item.id = item.id + '_trenddata'
}
//电数据
//电数据
if (item.type === 'kilowattHour') {
item.id = item.id + '_kilowattHour'
}
@@ -995,6 +1000,14 @@ const trendRef: any = ref()
const eventRef: any = ref()
const mqttRef = ref()
const url: any = window.localStorage.getItem('MQTTURL')
/** 同一 handler 先 off 再 on避免重复 message 监听 */
const bindMqttMessage = (handler: (topic: any, message: any) => void) => {
if (!mqttRef.value) return
mqttRef.value.off('message', handler)
mqttRef.value.on('message', handler)
}
const connectMqtt = () => {
if (mqttRef.value) {
if (mqttRef.value.connected) {
@@ -1035,16 +1048,44 @@ const getRealDataMqttMsg = async () => {
// console.log(res, '获取基础实时数据')
})
}, 30000)
mqttRef.value.on('message', (topic: any, message: any) => {
// console.log(
// '实时数据&实时趋势---mqtt接收到消息',
// JSON.parse(JSON.stringify(JSON.parse(new TextDecoder().decode(message))))
// )
let obj = JSON.parse(JSON.stringify(JSON.parse(new TextDecoder().decode(message))))
bindMqttMessage(onMqttRealDataMessage)
//2.建立mqtt通讯
//每隔30s调用一下接口通知后台推送mqtt消息
if (lineId.value != obj.lineId || adminInfo.userIndex != obj.userId) return
mqttRef.value.on('error', (error: any) => {
console.log('mqtt连接失败...', error)
mqttRef.value.end()
})
//处理mqtt数据 1转2除 2转1乘
mqttRef.value.on('close', function () {
console.log('mqtt客户端已断开连接.....')
})
setTimeout(() => {
tableLoading.value = false
}, 6000)
} else {
ElMessage.success('设备应答失败')
tableLoading.value = false
}
})
.catch(e => {
setTimeout(() => {
tableLoading.value = false
}, 0)
})
}
//tab点击事件
const realDataTimer: any = ref()
const mqttMessage = ref<any>({})
/** 实时数据 / 实时趋势 MQTT 消息(命名函数,便于 off 避免重复注册) */
const onMqttRealDataMessage = (topic: any, message: any) => {
let obj = decodeMqttPayload(message)
if (lineId.value != obj.lineId || adminInfo.userIndex != obj.userId) return
//处理mqtt数据 1转2除 2转1乘
//如果消息返回值是二次值,下拉框是二次值只需要单位换算 除以1000
//如果消息返回值是一次值,下拉框是一次值只需要单位换算 除以1000
if (obj.dataLevel == formInline.dataLevel) {
@@ -1178,36 +1219,8 @@ const getRealDataMqttMsg = async () => {
// sonTab.value == 1 &&
// realTrendRef.value &&
// realTrendRef.value.setRealTrendData(obj)
})
//2.建立mqtt通讯
//每隔30s调用一下接口通知后台推送mqtt消息
mqttRef.value.on('error', (error: any) => {
console.log('mqtt连接失败...', error)
mqttRef.value.end()
})
mqttRef.value.on('close', function () {
console.log('mqtt客户端已断开连接.....')
})
setTimeout(() => {
tableLoading.value = false
}, 6000)
} else {
ElMessage.success('设备应答失败')
tableLoading.value = false
}
})
.catch(e => {
setTimeout(() => {
tableLoading.value = false
}, 0)
})
}
//tab点击事件
const realDataTimer: any = ref()
const mqttMessage = ref<any>({})
const handleClick = async (tab?: any) => {
tableLoading.value = true
showButton.value = false
@@ -1272,7 +1285,7 @@ const handleClick = async (tab?: any) => {
tableLoading.value = false
}, 0)
}
//电数据
//电数据
if (dataSet.value.includes('_kilowattHour')) {
let obj = {
devId: deviceId.value, //e.id
@@ -1475,6 +1488,8 @@ const handleClick = async (tab?: any) => {
window.clearInterval(trendTimer.value)
}
if (mqttRef.value) {
mqttRef.value.off('message', onMqttTrendMessage)
mqttRef.value.off('message', onMqttRealDataMessage)
mqttRef.value.end()
}
}
@@ -1557,6 +1572,8 @@ onBeforeUnmount(() => {
realDataTimer.value = 0
trendTimer.value = 0
if (mqttRef.value) {
mqttRef.value.off('message', onMqttTrendMessage)
mqttRef.value.off('message', onMqttRealDataMessage)
mqttRef.value.end()
}
})