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

49 lines
1.4 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: {
uptime() {
return this.$store ? this.$store.state.system.uptime : '0分钟';
},
cpuUsage() {
return this.$store ? this.$store.state.system.cpuUsage : '0%';
},
memUsage() {
return this.$store ? this.$store.state.system.memUsage : '0MB';
},
deviceId() {
return this.$store ? this.$store.state.system.deviceId : '-';
}
},
methods: {
// 更新运行时间(仅计算,不请求)
startSystemInfoUpdate() {
const updateUptime = () => {
if (this.$store && this.startTime) {
const elapsed = Math.floor((Date.now() - this.startTime) / 1000 / 60);
this.$store.dispatch('system/updateUptime', `${elapsed}分钟`);
}
};
updateUptime();
setInterval(updateUptime, 5000);
},
// 接收主进程推送的系统信息(不做处理,直接更新 store
updateSystemInfo(data) {
if (this.$store && data) {
if (data.cpu !== undefined) {
this.$store.dispatch('system/updateCpuUsage', data.cpu);
}
if (data.memory !== undefined) {
this.$store.dispatch('system/updateMemUsage', data.memory);
}
if (data.deviceId !== undefined) {
this.$store.dispatch('system/updateDeviceId', data.deviceId);
}
}
}
}
};