This commit is contained in:
lcw
2026-04-15 16:04:50 +08:00
parent 763057ed9f
commit fbf259663b
41 changed files with 3651 additions and 2148 deletions

View File

@ -29,23 +29,27 @@ const timekeeping = ref(null);
const countdown = ref(0); // 倒计时时间(秒)
// 音频播放器实例映射
const audioPlayers = ref({
"01": null, // 预警信息
"02": null, // 信息上报
"03": null, // 研判审批
"04": null, // 研判指令
"05": null, // 线索下发,
"06": null, // 警情监测
"07": null, // 线索处理
"08": null, // 线索下发
"09": null, // 线索处理
10: null, // 林安码
11: null, // 发布了新的线索
12: null, // 有新的研判指令
13: null, // 有新的研判约稿通知
14: null, // 有新的公文发布
15: null // 有新的待审核工作(补发音效)
});
const audioPlayers = new Map();
// 预加载音频播放器(仅加载 playAudioByType 中实际用到的类型)
const initAudioPlayers = async () => {
const usedTypes = ["03", "09", "10", "11", "12", "13", "16", "17", "18", "19"];
await Promise.all(
usedTypes.map(
(type) =>
new Promise((resolve) => {
const player = new AudioPlayerClass();
audioPlayers.set(type, player);
player.init(audioPaths[type], false).then(resolve).catch(resolve);
})
)
);
};
// 获取指定类型的音频播放器
const getAudioPlayer = (type) => {
return audioPlayers.get(type);
};
// 音频文件路径映射
const audioPaths = {
@ -67,19 +71,7 @@ const audioPaths = {
"16": require("@/assets/images/16.mp3"), //有新的一级临控预警,请及时签收处理!
"17": require("@/assets/images/17.mp3"), //有新的紧急预警信息,请及时签收处理!
"18": require("@/assets/images/18.mp3"), //滴滴滴~~~叮~~~~
"19": require("@/assets/images/19.mp3"), //有新的预警信息,请您注意查收
};
// 初始化音频播放器
const initAudioPlayers = () => {
Object.keys(audioPaths).forEach((type) => {
try {
audioPlayers.value[type] = new AudioPlayerClass();
audioPlayers.value[type].init(audioPaths[type], false);
} catch (error) {
console.error(`初始化类型${type}的音频播放器失败:`, error);
}
});
"19": require("@/assets/images/19.mp3") //有新的预警信息,请您注意查收
};
// 根据类型播放音频
@ -89,33 +81,12 @@ const playAudioByType = (val) => {
// 01 布控预警、02 七类重点人、03 政保
switch (val.yjlb) {
case "01":
switch (val.yjJb) {
case "01":
audioPlayers.value["18"].play();
audioPlayers.value["17"].play();
// audioPlayers.value["01"].play();
// audioPlayers.value["06"].play();
break;
default:
audioPlayers.value["19"].play();
// audioPlayers.value["02"].play();
// audioPlayers.value["07"].play();
break;
}
break;
case "02":
switch (val.yjJb) {
case "01":
audioPlayers.value["18"].play();
audioPlayers.value["17"].play();
// audioPlayers.value["01"].play();
// audioPlayers.value["04"].play();
break;
default:
audioPlayers.value["19"].play();
// audioPlayers.value["02"].play();
// audioPlayers.value["05"].play();
break;
if (val.yjJb == "01") {
getAudioPlayer("18")?.play();
getAudioPlayer("17")?.play();
} else {
getAudioPlayer("19")?.play();
}
break;
case "03":
@ -123,56 +94,40 @@ const playAudioByType = (val) => {
}
break;
case "02": //信息汇聚
audioPlayers.value["03"].play();
audioPlayers.value["09"].play();
getAudioPlayer("03")?.play();
getAudioPlayer("09")?.play();
break;
case "03": //约稿
audioPlayers.value["03"].play();
audioPlayers.value["13"].play();
getAudioPlayer("03")?.play();
getAudioPlayer("13")?.play();
break;
case "04": //指令
audioPlayers.value["03"].play();
audioPlayers.value["12"].play();
getAudioPlayer("03")?.play();
getAudioPlayer("12")?.play();
break;
case "05": //新线索
audioPlayers.value["03"].play();
audioPlayers.value["11"].play();
getAudioPlayer("03")?.play();
getAudioPlayer("11")?.play();
break;
case "06": //检测警情
switch (val.jqdjdm) {
case "01":
audioPlayers.value["18"].play();
audioPlayers.value["17"].play();
break;
default:
audioPlayers.value["19"].play();
break;
if (val.jqdjdm == "01") {
getAudioPlayer("18")?.play();
getAudioPlayer("17")?.play();
} else {
getAudioPlayer("19")?.play();
}
// audioPlayers.value["02"].play();
// audioPlayers.value["15"].play();
break;
// case '07':
// audioPlayers.value['07'].play()
// break
case "08": //林安码
audioPlayers.value["03"].play();
audioPlayers.value["10"].play();
getAudioPlayer("03")?.play();
getAudioPlayer("10")?.play();
break;
case "11":
audioPlayers.value["03"].play();
audioPlayers.value["16"].play();
getAudioPlayer("03")?.play();
getAudioPlayer("16")?.play();
break;
default:
break;
}
// if (audioPlayers.value[type]) {
// try {
// audioPlayers.value[type].play()
// } catch (error) {
// console.error(`播放类型${type}的音频失败:`, error)
// }
// }
};
// 手动关闭
const handleClose = () => {
@ -202,30 +157,31 @@ const resetCountdown = () => {
// 做一个定时器15s一次
const checkNews = ref(null);
const checkNewsInterval = 15000; // 15秒
checkNews.value = setInterval(() => {
dataModel();
}, checkNewsInterval);
onMounted(() => {
// 初始化音频播放器
initAudioPlayers();
emitter.on("webSocketMessage", (newsDate) => {
if (newsDate) {
dataList.value = newsDate;
// dataList.value.unshift({...newsDate.data,typeMasgeLx:newsDate.type})
// 根据消息类型播放音频
playAudioByType(newsDate[0]);
resetCountdown();
}
});
});
const idEntityCard = ref(getItem("idEntityCard"));
onMounted(async () => {
await initAudioPlayers();
// 音频预加载完成后再启动轮询,避免定时器先触发但播放器还未就绪
checkNews.value = setInterval(() => {
dataModel();
}, checkNewsInterval);
// 注册事件监听(需在 onUnmounted 中精确解绑)
emitter.on("webSocketMessage", handleWebSocketMessage);
});
// 处理 WebSocket 消息事件(需在 onUnmounted 中解绑,提取到模块作用域)
const handleWebSocketMessage = (newsDate) => {
if (newsDate) {
dataList.value = newsDate;
playAudioByType(newsDate[0]);
resetCountdown();
}
};
const dataModel = () => {
qcckGet({}, "/mosty-gsxt/dsjJbxx/message").then((res) => {
if (res) {
// const yjmasg = res.filter(item => item.type === '01')
// if (yjmasg.length > 0) {
// emitter.emit('openYp', yjmasg[0].obj); // 触发音频播放
// }
const data = res.filter((item) =>
item.sfzList.includes(idEntityCard.value)
);
@ -235,35 +191,26 @@ const dataModel = () => {
typeMasgeLx: item.type
};
});
console.log(infoMasge, "xxxxxxxxxxxx");
emitter.emit("webSocketMessage", infoMasge);
}
});
};
// if (newsDate.type === '01') {
// // 触发音频播放
// console.log('触发音频播放');
// emitter.emit('openYp', newsDate.data); // 传递消息数据
// } else {
onUnmounted(() => {
emitter.off("webSocketMessage");
emitter.off("webSocketMessage", handleWebSocketMessage);
if (timekeeping.value) {
clearInterval(timekeeping.value);
}
// 销毁所有音频播放器实例
Object.values(audioPlayers.value).forEach((player) => {
if (player) {
player.destroy();
}
audioPlayers.forEach((player) => {
player.destroy();
});
audioPlayers.clear();
// 清除定时器
if (checkNews.value) {
clearInterval(checkNews.value);
checkNews.value = null;
}
// 组件卸载时执行的操作
console.log("组件卸载时执行的操作");
});
</script>