feat: 工厂设备智能监控平台初始版本 - 包含 A/B/C 三类设备看板、单设备明细页、mock 数据、Vue Router 路由

Made-with: Cursor
This commit is contained in:
zhougf committed 2026-04-11 19:39:59 +08:00
commit b583feb2a4
25 files changed
+7212

No files matched your search

+261
View File
@@ -0,0 +1,261 @@
<template>
<div class="dashboard">
<HeaderBar />
<div class="main-content">
<!-- ===== 左侧面板 ===== -->
<div class="left-panel panel-box">
<StatusSummary
:devices="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: refreshing }"></span>
数据刷新间隔:{{ REFRESH_SEC }}s &nbsp;|&nbsp; 上次刷新:{{ lastRefresh }}
</div>
</div>
</template>
<script setup>
import { ref, reactive, computed, onMounted, onUnmounted } 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 { baseDevices, applyMutations, getWeeklyInfo } from '../services/mockData.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 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 { labels: weeklyLabels, todayIdx } = getWeeklyInfo()
const weeklyProduceTotal = computed(() => {
const totals = [0, 0, 0, 0, 0, 0, 0]
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()
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 } })
}
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>
.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)} }
</style>