Files
autoAiWorkSys/app/mixins/taskMixin.js
张成 e17d5610f5 1
2025-12-22 16:26:59 +08:00

62 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 设备工作状态管理 Mixin
*/
export default {
computed: {
displayText() {
return this.$store ? this.$store.state.task.displayText : null;
},
nextExecuteTimeText() {
return this.$store ? this.$store.state.task.nextExecuteTimeText : null;
},
currentActivity() {
return this.$store ? this.$store.state.task.currentActivity : null;
},
pendingQueue() {
return this.$store ? this.$store.state.task.pendingQueue : null;
},
deviceStatus() {
return this.$store ? this.$store.state.task.deviceStatus : null;
}
},
methods: {
startTaskStatusUpdate() {
// 设备工作状态已通过 MQTT 实时推送,不再使用接口轮询
// 设备工作状态通过 device_work_status_${snCode} 主题推送,由 mqttService 处理并发送到渲染进程
// 通过 onDeviceWorkStatus 方法接收并更新状态
console.log('[TaskMixin] 设备工作状态更新已启动,使用 MQTT 实时推送');
},
stopTaskStatusUpdate() {
if (this.$store) {
this.$store.dispatch('task/clearDeviceWorkStatus');
}
},
/**
* 处理设备工作状态通知
* 服务端已格式化好显示文本,客户端直接使用,不做复杂处理
*/
onDeviceWorkStatus(workStatus) {
if (!workStatus || !this.$store) {
console.warn('[Renderer] 收到设备工作状态但数据无效:', workStatus);
return;
}
// 直接更新设备工作状态到 store服务端已处理好所有显示逻辑
try {
this.$store.dispatch('task/updateDeviceWorkStatus', workStatus);
// 验证更新是否成功
this.$nextTick(() => {
const state = this.$store.state.task;
});
} catch (error) {
console.error('[Renderer] 更新设备工作状态失败:', error);
}
}
}
};