修改b,c类设备的采集
This commit is contained in:
1 parent
b583feb2a4
commit
bc93fb4d61
17 files changed
+1398
-135
No files matched your search
+158
-20
@@ -1,12 +1,19 @@
|
||||
<template>
|
||||
<div class="detail-page">
|
||||
<div class="offline-page" v-if="!allDevices.length">
|
||||
<div class="offline-box">
|
||||
<div class="offline-title">未配置设备</div>
|
||||
<div class="offline-reason">请配置 VITE_MQTT_TOPICS(逗号分隔);可选 VITE_MQTT_TOPIC_PREFIX 拼接路径,或直接写完整 topic(如 topic/xx/rbiot-c01-001)</div>
|
||||
</div>
|
||||
</div>
|
||||
<template v-else>
|
||||
<!-- 顶部导航 -->
|
||||
<div class="detail-header">
|
||||
<div class="header-left">
|
||||
<button class="back-btn" @click="goBack">← 返回全景看板</button>
|
||||
<select v-model="selectedId" @change="switchDevice" class="device-select">
|
||||
<option v-for="d in allDevices" :key="d.id" :value="d.id">
|
||||
{{ d.id }} · {{ d.name }} ({{ typeLabel(d.type) }})
|
||||
{{ d.mqttTopic }} · {{ d.name }} ({{ typeLabel(d.type) }})
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -16,7 +23,7 @@
|
||||
</div>
|
||||
|
||||
<!-- 离线设备 -->
|
||||
<div class="offline-page" v-if="!device?.online">
|
||||
<div class="offline-page" v-if="device && !device.online">
|
||||
<div class="offline-box">
|
||||
<div class="offline-icon">⚠</div>
|
||||
<div class="offline-title">设备离线</div>
|
||||
@@ -25,7 +32,7 @@
|
||||
</div>
|
||||
|
||||
<!-- ===== CNC 明细 ===== -->
|
||||
<div class="detail-content" v-else-if="device.type === 'cnc'">
|
||||
<div class="detail-content" v-else-if="device && device.type === 'cnc'">
|
||||
<div class="cards-row">
|
||||
<!-- 基本状态 -->
|
||||
<div class="detail-card">
|
||||
@@ -67,14 +74,14 @@
|
||||
<div class="param-item"><span class="p-label">实际转速</span><span class="p-val text-cyan">{{ md.spindleSpeedAndFeedRate?.speed || 0 }} RPM</span></div>
|
||||
<div class="param-item"><span class="p-label">实际进给</span><span class="p-val text-cyan">{{ md.spindleSpeedAndFeedRate?.feedRate || 0 }} mm/m</span></div>
|
||||
</div>
|
||||
<div class="load-bars">
|
||||
<div class="load-bars" v-if="md.axisNames?.length">
|
||||
<div class="axis-load" v-for="(name, idx) in md.axisNames" :key="name">
|
||||
<span class="ax-name">{{ name }}轴</span>
|
||||
<div class="load-bg"><div class="load-fill" :class="loadClass(md.axisLoad?.[idx])" :style="{ width: Math.min(Math.abs(md.axisLoad?.[idx] || 0), 100) + '%' }"></div></div>
|
||||
<span class="ax-val" :class="loadClass(md.axisLoad?.[idx])">{{ md.axisLoad?.[idx] }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="coords-box">
|
||||
<div class="coords-box" v-if="md.axisNames?.length">
|
||||
<div class="coords-title">绝对坐标</div>
|
||||
<div class="coords-vals">
|
||||
<span class="coord" v-for="(name, idx) in md.axisNames" :key="name">{{ name }}: <span class="mono text-cyan">{{ (md.allCoors?.absolute[idx] || 0).toFixed(3) }}</span></span>
|
||||
@@ -91,7 +98,7 @@
|
||||
</div>
|
||||
|
||||
<!-- ===== 激光明细 ===== -->
|
||||
<div class="detail-content" v-else-if="device.type === 'laser'">
|
||||
<div class="detail-content" v-else-if="device && device.type === 'laser'">
|
||||
<div class="cards-row">
|
||||
<div class="detail-card">
|
||||
<div class="card-title">系统状态与作业</div>
|
||||
@@ -160,10 +167,14 @@
|
||||
</div>
|
||||
|
||||
<!-- ===== 电力明细 ===== -->
|
||||
<div class="detail-content" v-else-if="device.type === 'power'">
|
||||
<div class="detail-content" v-else-if="device && device.type === 'power'">
|
||||
<div class="cards-row">
|
||||
<div class="detail-card" style="flex:0 0 50%;">
|
||||
<div class="card-title">实时三相电流</div>
|
||||
<div class="detail-card" style="flex:0 0 42%;">
|
||||
<div class="card-title">实时三相电流(线电压 380V)</div>
|
||||
<div class="power-kw-row">
|
||||
<span class="kw-label">估算视在功率</span>
|
||||
<span class="kw-val">{{ lastPowerKw }} <small>kVA</small></span>
|
||||
</div>
|
||||
<div class="power-display">
|
||||
<div class="phase-big" v-for="(item, idx) in powerPhases" :key="idx">
|
||||
<div class="phase-label">{{ item.label }}</div>
|
||||
@@ -171,8 +182,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="detail-card chart-card-power" v-if="device.online">
|
||||
<div class="card-title">实时功率曲线(√3×380V×Ī,仅供参考)</div>
|
||||
<div class="chart-container" ref="powerChartRef"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -180,15 +196,37 @@
|
||||
import { ref, computed, onMounted, onUnmounted, nextTick, watch } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import * as echarts from 'echarts'
|
||||
import { baseDevices } from '../services/mockData.js'
|
||||
import { mqttRuntime, findDeviceByRouteParam } from '../services/mqttDeviceStore.js'
|
||||
import { getCncWorkModeText, getLaserSysStateText } from '../composables/useDeviceStatus.js'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const allDevices = baseDevices
|
||||
const selectedId = ref(route.params.id || allDevices[0]?.id)
|
||||
const device = computed(() => allDevices.find(d => d.id === selectedId.value))
|
||||
const allDevices = computed(() => mqttRuntime.devices)
|
||||
const selectedId = ref(String(route.params.id || ''))
|
||||
const device = computed(() => findDeviceByRouteParam(selectedId.value) || findDeviceByRouteParam(route.params.id))
|
||||
|
||||
watch(
|
||||
() => route.params.id,
|
||||
(id) => {
|
||||
const sid = id ? String(id) : ''
|
||||
if (sid && findDeviceByRouteParam(sid)) selectedId.value = sid
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
watch(
|
||||
() => mqttRuntime.devices.map(d => d.id).join(','),
|
||||
() => {
|
||||
const list = mqttRuntime.devices
|
||||
if (!list.length) return
|
||||
if (!selectedId.value || !findDeviceByRouteParam(selectedId.value)) {
|
||||
const rid = route.params?.id ? String(route.params.id) : ''
|
||||
selectedId.value = (rid && findDeviceByRouteParam(rid)) ? rid : list[0].id
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
const md = computed(() => device.value?.machineData || {})
|
||||
const nc = computed(() => md.value?.CutSystemState?.NcState)
|
||||
const ds = computed(() => md.value?.CutSystemState?.DeviceState)
|
||||
@@ -197,13 +235,34 @@ const lmd = computed(() => md.value || {})
|
||||
const powerPhases = computed(() => {
|
||||
const s = md.value?.slave1
|
||||
if (!s) return []
|
||||
const n = (v) => {
|
||||
if (v === 'invalid') return NaN
|
||||
return parseFloat(String(v).replace(/A$/i, ''))
|
||||
}
|
||||
return [
|
||||
{ label: 'A相电流', value: s.current1, warn: parseFloat(s.current1) > 16 },
|
||||
{ label: 'B相电流', value: s.current2, warn: parseFloat(s.current2) > 16 },
|
||||
{ label: 'C相电流', value: s.current3, warn: parseFloat(s.current3) > 16 }
|
||||
{ label: 'A相电流', value: s.current1, warn: Number.isFinite(n(s.current1)) && n(s.current1) > 16 },
|
||||
{ label: 'B相电流', value: s.current2, warn: Number.isFinite(n(s.current2)) && n(s.current2) > 16 },
|
||||
{ label: 'C相电流', value: s.current3, warn: Number.isFinite(n(s.current3)) && n(s.current3) > 16 }
|
||||
]
|
||||
})
|
||||
|
||||
function parseAmpereVal(v) {
|
||||
if (v === undefined || v === null || v === 'invalid') return NaN
|
||||
return parseFloat(String(v).replace(/A$/i, '').trim())
|
||||
}
|
||||
|
||||
const lastPowerKw = computed(() => {
|
||||
const s = md.value?.slave1
|
||||
if (!s) return '0'
|
||||
const i1 = parseAmpereVal(s.current1)
|
||||
const i2 = parseAmpereVal(s.current2)
|
||||
const i3 = parseAmpereVal(s.current3)
|
||||
if (![i1, i2, i3].every(Number.isFinite)) return '--'
|
||||
const iAvg = (i1 + i2 + i3) / 3
|
||||
const kw = (Math.sqrt(3) * 380 * iAvg) / 1000
|
||||
return (Math.round(kw * 1000) / 1000).toLocaleString('zh-CN')
|
||||
})
|
||||
|
||||
function typeLabel(t) {
|
||||
return { laser: '激光', cnc: 'CNC', power: '电力' }[t] || t
|
||||
}
|
||||
@@ -225,15 +284,61 @@ function formatSec(sec) {
|
||||
return `${h}H ${m}M`
|
||||
}
|
||||
|
||||
// ====== ECharts ======
|
||||
// ====== ECharts(CNC / 激光周趋势)======
|
||||
const chartRef = ref(null)
|
||||
let chartInstance = null
|
||||
|
||||
// ====== 电力实时功率曲线 ======
|
||||
const powerChartRef = ref(null)
|
||||
let powerChartInstance = null
|
||||
|
||||
function initChart() {
|
||||
if (!chartRef.value || !device.value?.weeklyStats) return
|
||||
if (device.value.type === 'power') return
|
||||
if (chartInstance) {
|
||||
chartInstance.dispose()
|
||||
chartInstance = null
|
||||
}
|
||||
chartInstance = echarts.init(chartRef.value)
|
||||
updateChart()
|
||||
window.addEventListener('resize', () => chartInstance?.resize())
|
||||
}
|
||||
|
||||
function onChartResize() {
|
||||
chartInstance?.resize()
|
||||
powerChartInstance?.resize()
|
||||
}
|
||||
|
||||
function initPowerChart() {
|
||||
if (!powerChartRef.value || device.value?.type !== 'power') return
|
||||
if (powerChartInstance) {
|
||||
powerChartInstance.dispose()
|
||||
powerChartInstance = null
|
||||
}
|
||||
powerChartInstance = echarts.init(powerChartRef.value)
|
||||
updatePowerChart()
|
||||
}
|
||||
|
||||
function updatePowerChart() {
|
||||
if (!powerChartInstance || device.value?.type !== 'power') return
|
||||
const hist = device.value.powerHistory || []
|
||||
const times = hist.map(h => h.t)
|
||||
const kws = hist.map(h => h.kw)
|
||||
powerChartInstance.setOption({
|
||||
backgroundColor: 'transparent',
|
||||
tooltip: { trigger: 'axis' },
|
||||
grid: { left: '3%', right: '4%', bottom: '8%', top: '28px', containLabel: true },
|
||||
xAxis: { type: 'category', data: times, axisLabel: { color: '#6a8a9a', fontSize: 10 } },
|
||||
yAxis: {
|
||||
type: 'value', name: 'kVA', nameTextStyle: { color: '#6a8a9a' },
|
||||
axisLabel: { color: '#6a8a9a' }, splitLine: { lineStyle: { color: 'rgba(26,58,106,0.3)' } }
|
||||
},
|
||||
series: [{
|
||||
name: '估算视在功率', type: 'line', smooth: true, symbol: 'none',
|
||||
lineStyle: { width: 2, color: '#ff9800' },
|
||||
areaStyle: { color: 'rgba(255,152,0,0.15)' },
|
||||
data: kws
|
||||
}]
|
||||
}, true)
|
||||
}
|
||||
|
||||
function updateChart() {
|
||||
@@ -279,14 +384,36 @@ function updateChart() {
|
||||
watch(selectedId, () => {
|
||||
nextTick(() => {
|
||||
if (chartInstance) { chartInstance.dispose(); chartInstance = null }
|
||||
if (powerChartInstance) { powerChartInstance.dispose(); powerChartInstance = null }
|
||||
initChart()
|
||||
initPowerChart()
|
||||
})
|
||||
})
|
||||
|
||||
onMounted(() => { nextTick(initChart) })
|
||||
watch(
|
||||
() => [device.value?.type, device.value?.powerHistory?.length, device.value?.machineData?.timestamp],
|
||||
() => {
|
||||
if (device.value?.type === 'power' && device.value?.online) {
|
||||
nextTick(() => {
|
||||
if (!powerChartInstance && powerChartRef.value) initPowerChart()
|
||||
else updatePowerChart()
|
||||
})
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('resize', onChartResize)
|
||||
nextTick(() => {
|
||||
initChart()
|
||||
initPowerChart()
|
||||
})
|
||||
})
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', () => chartInstance?.resize())
|
||||
window.removeEventListener('resize', onChartResize)
|
||||
chartInstance?.dispose()
|
||||
powerChartInstance?.dispose()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -401,4 +528,15 @@ onUnmounted(() => {
|
||||
.phase-label { font-size: 14px; color: #5a7a9a; margin-bottom: 8px; }
|
||||
.phase-value { font-size: 42px; font-weight: 800; color: #00e5ff; font-family: 'Consolas',monospace; }
|
||||
.phase-value.warn { color: #ff4444; }
|
||||
|
||||
.power-kw-row {
|
||||
display: flex; justify-content: space-between; align-items: center;
|
||||
margin-bottom: 12px; padding: 8px 12px; background: #0d2654; border-radius: 6px;
|
||||
}
|
||||
.kw-label { font-size: 13px; color: #5a7a9a; }
|
||||
.kw-val { font-size: 22px; font-weight: 800; color: #ff9800; font-family: Consolas, monospace; }
|
||||
.kw-val small { font-size: 12px; color: #8a9aaa; font-weight: 600; }
|
||||
|
||||
.cards-row .chart-card-power { flex: 1; min-height: 280px; display: flex; flex-direction: column; }
|
||||
.chart-card-power .chart-container { flex: 1; min-height: 220px; }
|
||||
</style>
|
||||
Reference in new issue
Block a user