49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
/**
|
||
* 系统信息管理 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);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
};
|
||
|