feat: 新增收集式校验错误弹窗及工位报警语音播报

新增 ErrorListDialog 组件用于统一展示结构化校验错误信息,实现报错一次收全;新增工位报警语音播报功能,通过浏览器 SpeechSynthesis 播放本工位相关报警;调整物料类别及序列号字段文案,移除「其他」类别;新增工单实际开始字段及采集方式配置;优化 AGV 及 PlcSend 页签刷新逻辑;新增看板物料追溯及工位报警接口;删除 PLC 强制写 M 位及相关测试代码;同步数据库字段注释及补丁。
This commit is contained in:
SunYF
2026-10-20 16:36:26 +08:00
parent f743cf21fb
commit b0c048d9aa
126 changed files with 4603 additions and 1639 deletions
@@ -22,6 +22,9 @@
待同步 {{ pendingTotal }}<template v-if="deadTotal"> · 待处理 {{ deadTotal }}</template>
</el-button>
<el-button size="large" @click="wlRef?.open()">我的工作量</el-button>
<el-button size="large" :title="speechMuted ? '语音播报已关闭,点击开启' : '语音播报中,点击静音'" @click="toggleSpeechMuted">
{{ speechMuted ? '🔇' : '🔊' }}
</el-button>
<span class="user-name">{{ user.name || user.username || '-' }}</span>
<span class="clock">{{ clock }}</span>
<el-button size="large" type="danger" plain @click="logout">退出</el-button>
@@ -71,7 +74,7 @@
<script setup>
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { ElMessage, ElNotification } from 'element-plus'
import WorkPanel from './panels/WorkPanel.vue'
import MaterialPanel from './panels/MaterialPanel.vue'
import PdfPanel from './panels/PdfPanel.vue'
@@ -89,7 +92,8 @@ import {
helpPdf,
helpWorkstation
} from '../help'
import { stationLogout } from '../api'
import { stationLogout, getStationAlerts } from '../api'
import { speak, setSpeechMuted } from '../utils/speech'
import { clearAuth } from '../utils/request'
import {
hasNg,
@@ -143,6 +147,94 @@ let timerTask = null
let timerTight = null
let timerStats = null
let timerClock = null
let alertES = null // 本机报警 SSE(EventSource,断线自动重连)
// ---------- 本工位报警语音播报(谁受影响谁播报,2026-10-20 事件驱动) ----------
// 平时走 EventSource /api/alerts/stream(后端长连 MES,按本机工位过滤后推送);
// 断线由 EventSource 自动重连,重连成功后一次性调 GET /api/alerts/station 补拉最近报警(非轮询)。
// 同一条报警只播一次(localStorage 记账,上限 500 条,刷新/重启不重播)。
const SPEAK_SEEN_KEY = 'ws_spoken_alert_ids'
const SPEAK_MUTE_KEY = 'ws_speech_muted'
const speechMuted = ref(localStorage.getItem(SPEAK_MUTE_KEY) === '1')
function toggleSpeechMuted() {
speechMuted.value = !speechMuted.value
localStorage.setItem(SPEAK_MUTE_KEY, speechMuted.value ? '1' : '0')
setSpeechMuted(speechMuted.value)
}
setSpeechMuted(speechMuted.value)
function loadSpokenIds() {
try {
return new Set(JSON.parse(localStorage.getItem(SPEAK_SEEN_KEY) || '[]'))
} catch {
return new Set()
}
}
function persistSpokenIds(set) {
// 只留最近 500 条,防 localStorage 无限膨胀
const arr = [...set].slice(-500)
localStorage.setItem(SPEAK_SEEN_KEY, JSON.stringify(arr))
}
// handleAlerts 处理一批报警(事件推送/补拉共用):去重 → 语音播报 + 通知条
function handleAlerts(list) {
if (!Array.isArray(list) || !list.length) return
const spoken = loadSpokenIds()
let changed = false
// 按时间正序播报(旧→新),符合事件发生顺序
const sorted = [...list].sort((a, b) => (a.id || 0) - (b.id || 0))
for (const a of sorted) {
const id = a.id
if (!id || spoken.has(id)) continue
spoken.add(id)
changed = true
speak(`工位报警:${a.title || a.content || ''}`)
ElNotification({
title: '本工位报警',
message: a.title || a.content || '',
type: 'warning',
duration: 10000
})
}
if (changed) persistSpokenIds(spoken)
}
function connectAlertStream() {
if (!stationNo.value || alertES) return
let everFailed = false // 断过线才在重连成功后补拉,平时事件即实时
try {
alertES = new EventSource('/api/alerts/stream')
alertES.addEventListener('station.alert', (e) => {
try {
handleAlerts([JSON.parse(e.data)])
} catch { /* 脏帧忽略 */ }
})
alertES.onopen = () => {
if (everFailed) {
everFailed = false
// 断线期间可能漏推:重连成功后一次性补拉最近 10 分钟报警(非轮询)
pollStationAlerts()
}
}
alertES.onerror = () => { everFailed = true }
} catch {
alertES = null // 浏览器不支持 SSE:静默降级,无播报
}
}
// pollStationAlerts 一次性补拉(仅断线重连后调用)
async function pollStationAlerts() {
if (!stationNo.value) return
let list = null
try {
list = await getStationAlerts(stationNo.value, 10)
} catch {
return // 静默:MES/终端后端不可达不提示不播报
}
handleAlerts(list)
}
function tickClock() {
const d = new Date()
@@ -186,6 +278,7 @@ onMounted(async () => {
timerTask = setInterval(loadTask, 5000) // 任务 5 秒
timerTight = setInterval(loadTight, 2000) // 拧紧结果 2 秒
timerStats = setInterval(loadStats, 10000) // 同步统计 10 秒
connectAlertStream() // 本机报警事件流(SSE,断线自动重连)
timerClock = setInterval(() => {
tickClock()
loadPoints() // 点位台账 10 秒
@@ -199,6 +292,7 @@ onBeforeUnmount(() => {
clearInterval(timerTight)
clearInterval(timerStats)
clearInterval(timerClock)
if (alertES) { alertES.close(); alertES = null }
})
</script>