62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
/**
|
||
* 设备工作状态管理 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);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
|