修改b,c类设备的采集

This commit is contained in:
zhougf committed 2026-04-18 13:56:26 +08:00
1 parent b583feb2a4
commit bc93fb4d61
17 files changed
+1398 -135

No files matched your search

+29 -29
View File
@@ -6,7 +6,7 @@
<!-- ===== 左侧面板 ===== -->
<div class="left-panel panel-box">
<StatusSummary
:devices="devices"
:devices="mqtt.devices"
:weeklyLabels="weeklyLabels"
:weeklyProduce="weeklyProduceTotal"
:todayIdx="todayIdx"
@@ -61,14 +61,20 @@
<!-- 底部状态栏 -->
<div class="refresh-indicator">
<span class="refresh-dot" :class="{ pulse: refreshing }"></span>
数据刷新间隔:{{ REFRESH_SEC }}s &nbsp;|&nbsp; 上次刷新:{{ lastRefresh }}
<span class="refresh-dot" :class="{ pulse: mqtt.connected }"></span>
MQTT:{{ mqtt.connected ? '已连接' : '未连接' }}{{ mqtt.reconnecting ? '(重连中)' : '' }}
&nbsp;|&nbsp; 超时阈值:{{ mqtt.offlineThresholdMs / 1000 }}s
<template v-if="mqtt.lastMessageAt">
&nbsp;|&nbsp; 最近消息:{{ mqtt.lastMessageTopic }} @ {{ mqtt.lastMessageAt }}
</template>
<span v-if="mqtt.error" class="mqtt-err">&nbsp;|&nbsp; {{ mqtt.error }}</span>
</div>
<div v-if="mqtt.lastRouteHint" class="mqtt-hint">{{ mqtt.lastRouteHint }}</div>
</div>
</template>
<script setup>
import { ref, reactive, computed, onMounted, onUnmounted } from 'vue'
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import HeaderBar from '../components/HeaderBar.vue'
import LaserCard from '../components/LaserCard.vue'
@@ -76,28 +82,24 @@ import CncCard from '../components/CncCard.vue'
import PowerCard from '../components/PowerCard.vue'
import StatusSummary from '../components/StatusSummary.vue'
import AlarmPanel from '../components/AlarmPanel.vue'
import { baseDevices, applyMutations, getWeeklyInfo } from '../services/mockData.js'
import { mqttRuntime } from '../services/mqttDeviceStore.js'
import { getWeeklyInfo } from '../utils/weekLabels.js'
import { getDeviceStatus } from '../composables/useDeviceStatus.js'
const router = useRouter()
const REFRESH_SEC = 5
const refreshing = ref(false)
const lastRefresh = ref('--')
// 创建 reactive 设备数据(基于真实格式的深拷贝)
const devices = reactive(JSON.parse(JSON.stringify(baseDevices)))
const mqtt = mqttRuntime
// 按类型过滤
const laserDevices = computed(() => devices.filter(d => d.type === 'laser'))
const cncDevices = computed(() => devices.filter(d => d.type === 'cnc'))
const powerDevices = computed(() => devices.filter(d => d.type === 'power'))
const laserDevices = computed(() => mqttRuntime.devices.filter(d => d.type === 'laser'))
const cncDevices = computed(() => mqttRuntime.devices.filter(d => d.type === 'cnc'))
const powerDevices = computed(() => mqttRuntime.devices.filter(d => d.type === 'power'))
// 周报表
const { labels: weeklyLabels, todayIdx } = getWeeklyInfo()
const weeklyProduceTotal = computed(() => {
const totals = [0, 0, 0, 0, 0, 0, 0]
devices.forEach(d => {
mqttRuntime.devices.forEach(d => {
if (d.weeklyStats?.produce) {
d.weeklyStats.produce.forEach((v, i) => {
if (i <= todayIdx) totals[i] += v
@@ -111,7 +113,7 @@ const weeklyProduceTotal = computed(() => {
const alarms = computed(() => {
const arr = []
const now = new Date()
devices.forEach(d => {
mqttRuntime.devices.forEach(d => {
if (!d.online || !d.machineData) return
const status = getDeviceStatus(d)
if (status.key !== 'alarm') return
@@ -137,19 +139,6 @@ function goDetail(id) {
router.push({ name: 'DeviceDetail', params: { id } })
}
function refresh() {
refreshing.value = true
applyMutations(devices)
lastRefresh.value = new Date().toLocaleTimeString('zh-CN', { hour12: false })
setTimeout(() => { refreshing.value = false }, 400)
}
let timer = null
onMounted(() => {
refresh()
timer = setInterval(refresh, REFRESH_SEC * 1000)
})
onUnmounted(() => clearInterval(timer))
</script>
<style scoped>
@@ -258,4 +247,15 @@ onUnmounted(() => clearInterval(timer))
animation: pulse-dot 0.4s ease-in-out;
}
@keyframes pulse-dot { 0%{transform:scale(1)} 50%{transform:scale(1.6)} 100%{transform:scale(1)} }
.mqtt-err { color: #ff6b6b; }
.mqtt-hint {
flex-shrink: 0;
padding: 4px 16px 6px;
font-size: 10px;
line-height: 1.35;
color: #c9a227;
background: rgba(40, 30, 0, 0.35);
border-top: 1px solid rgba(201, 162, 39, 0.25);
word-break: break-all;
}
</style>