262 lines
7.3 KiB
Vue
262 lines
7.3 KiB
Vue
<template>
|
||
<div class="dashboard">
|
||
<HeaderBar />
|
||
|
||
<div class="main-content">
|
||
<!-- ===== 左侧面板 ===== -->
|
||
<div class="left-panel panel-box">
|
||
<StatusSummary
|
||
:devices="mqtt.devices"
|
||
:weeklyLabels="weeklyLabels"
|
||
:weeklyProduce="weeklyProduceTotal"
|
||
:todayIdx="todayIdx"
|
||
/>
|
||
</div>
|
||
|
||
<!-- ===== 中央区域 ===== -->
|
||
<div class="center-panel">
|
||
|
||
<!-- A类 · 激光切割设备 -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<dv-decoration-6 class="section-deco" :color="['#ff4444','#ff8a80']" />
|
||
<span class="section-title">A类 · 激光切割设备</span>
|
||
<dv-decoration-6 class="section-deco flip" :color="['#ff4444','#ff8a80']" />
|
||
</div>
|
||
<div class="laser-grid">
|
||
<LaserCard v-for="d in laserDevices" :key="d.id" :device="d" @click="goDetail(d.id)" />
|
||
</div>
|
||
</div>
|
||
|
||
<!-- B类 · CNC加工中心 -->
|
||
<div class="section section-grow">
|
||
<div class="section-header">
|
||
<dv-decoration-6 class="section-deco" :color="['#04b9ff','#00e676']" />
|
||
<span class="section-title">B类 · CNC加工中心</span>
|
||
<dv-decoration-6 class="section-deco flip" :color="['#04b9ff','#00e676']" />
|
||
</div>
|
||
<div class="cnc-grid">
|
||
<CncCard v-for="d in cncDevices" :key="d.id" :device="d" @click="goDetail(d.id)" />
|
||
</div>
|
||
</div>
|
||
|
||
<!-- C类 · 电力监测设备 -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<dv-decoration-6 class="section-deco" :color="['#ffca28','#ff9800']" />
|
||
<span class="section-title">C类 · 电力监测设备</span>
|
||
<dv-decoration-6 class="section-deco flip" :color="['#ffca28','#ff9800']" />
|
||
</div>
|
||
<div class="power-grid">
|
||
<PowerCard v-for="d in powerDevices" :key="d.id" :device="d" @click="goDetail(d.id)" />
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ===== 右侧面板 ===== -->
|
||
<div class="right-panel panel-box">
|
||
<AlarmPanel :alarms="alarms" />
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 底部状态栏 -->
|
||
<div class="refresh-indicator">
|
||
<span class="refresh-dot" :class="{ pulse: mqtt.connected }"></span>
|
||
MQTT:{{ mqtt.connected ? '已连接' : '未连接' }}{{ mqtt.reconnecting ? '(重连中)' : '' }}
|
||
| 超时阈值:{{ mqtt.offlineThresholdMs / 1000 }}s
|
||
<template v-if="mqtt.lastMessageAt">
|
||
| 最近消息:{{ mqtt.lastMessageTopic }} @ {{ mqtt.lastMessageAt }}
|
||
</template>
|
||
<span v-if="mqtt.error" class="mqtt-err"> | {{ mqtt.error }}</span>
|
||
</div>
|
||
<div v-if="mqtt.lastRouteHint" class="mqtt-hint">{{ mqtt.lastRouteHint }}</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { computed } from 'vue'
|
||
import { useRouter } from 'vue-router'
|
||
import HeaderBar from '../components/HeaderBar.vue'
|
||
import LaserCard from '../components/LaserCard.vue'
|
||
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 { mqttRuntime } from '../services/mqttDeviceStore.js'
|
||
import { getWeeklyInfo } from '../utils/weekLabels.js'
|
||
import { getDeviceStatus } from '../composables/useDeviceStatus.js'
|
||
|
||
const router = useRouter()
|
||
const mqtt = mqttRuntime
|
||
|
||
// 按类型过滤
|
||
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]
|
||
mqttRuntime.devices.forEach(d => {
|
||
if (d.weeklyStats?.produce) {
|
||
d.weeklyStats.produce.forEach((v, i) => {
|
||
if (i <= todayIdx) totals[i] += v
|
||
})
|
||
}
|
||
})
|
||
return totals
|
||
})
|
||
|
||
// 报警汇总
|
||
const alarms = computed(() => {
|
||
const arr = []
|
||
const now = new Date()
|
||
mqttRuntime.devices.forEach(d => {
|
||
if (!d.online || !d.machineData) return
|
||
const status = getDeviceStatus(d)
|
||
if (status.key !== 'alarm') return
|
||
|
||
let msg = ''
|
||
if (d.type === 'cnc') {
|
||
const a = d.machineData.alarm
|
||
msg = a?.length ? a[0] : 'CNC系统报警'
|
||
} else if (d.type === 'laser') {
|
||
const nc = d.machineData.CutSystemState?.NcState
|
||
msg = nc?.AlarmMsg || `报警 ${nc?.AlarmCount || 0} 个`
|
||
}
|
||
arr.push({
|
||
time: now.toLocaleTimeString('zh-CN', { hour12: false }),
|
||
device: d.type === 'cnc' ? `CNC-${d.name}` : d.name,
|
||
message: msg
|
||
})
|
||
})
|
||
return arr
|
||
})
|
||
|
||
function goDetail(id) {
|
||
router.push({ name: 'DeviceDetail', params: { id } })
|
||
}
|
||
|
||
</script>
|
||
|
||
<style scoped>
|
||
.dashboard {
|
||
width: 1920px;
|
||
height: 1080px;
|
||
background: #020c20;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
font-family: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
|
||
}
|
||
|
||
.main-content {
|
||
flex: 1;
|
||
display: flex;
|
||
gap: 10px;
|
||
padding: 8px 12px;
|
||
min-height: 0;
|
||
}
|
||
|
||
/* 左右面板 */
|
||
.left-panel { flex: 0 0 258px; }
|
||
.right-panel { flex: 0 0 258px; }
|
||
.panel-box {
|
||
background: rgba(4, 20, 55, 0.55);
|
||
border: 1px solid rgba(4, 185, 255, 0.15);
|
||
border-radius: 8px;
|
||
padding: 10px;
|
||
backdrop-filter: blur(4px);
|
||
height: 100%;
|
||
}
|
||
|
||
/* 中央区域 */
|
||
.center-panel {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 6px;
|
||
min-height: 0;
|
||
}
|
||
|
||
.section { flex: 0 0 auto; }
|
||
.section-grow { flex: 1; display: flex; flex-direction: column; min-height: 0; }
|
||
|
||
.section-header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 8px;
|
||
margin-bottom: 6px;
|
||
}
|
||
.section-deco { width: 80px; height: 20px; }
|
||
.section-deco.flip { transform: scaleX(-1); }
|
||
.section-title {
|
||
font-size: 13px;
|
||
font-weight: 700;
|
||
color: #8eb8d8;
|
||
letter-spacing: 3px;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
/* A类 激光网格:2列 */
|
||
.laser-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(2, 1fr);
|
||
gap: 10px;
|
||
}
|
||
|
||
/* B类 CNC网格:4列,自适应行 */
|
||
.cnc-grid {
|
||
flex: 1;
|
||
display: grid;
|
||
grid-template-columns: repeat(4, 1fr);
|
||
grid-template-rows: repeat(3, 1fr);
|
||
gap: 8px;
|
||
min-height: 0;
|
||
}
|
||
|
||
/* C类 电力网格:2列 */
|
||
.power-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(2, 1fr);
|
||
gap: 10px;
|
||
}
|
||
|
||
/* 底部刷新指示 */
|
||
.refresh-indicator {
|
||
height: 22px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
padding-right: 16px;
|
||
font-size: 11px;
|
||
color: #304a6a;
|
||
letter-spacing: 0.5px;
|
||
border-top: 1px solid rgba(4,185,255,0.08);
|
||
gap: 6px;
|
||
}
|
||
.refresh-dot {
|
||
width: 6px; height: 6px; border-radius: 50%;
|
||
background: #304a6a; display: inline-block; transition: background 0.3s;
|
||
}
|
||
.refresh-dot.pulse {
|
||
background: #00e676; box-shadow: 0 0 6px #00e676;
|
||
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>
|