mirror of
https://github.com/hi2shark/nazhua.git
synced 2026-01-12 07:10:43 +08:00
fix: 修复获取CPU信息时的可选链问题,确保在未提供CPU数据时不会抛出错误
This commit is contained in:
parent
f2fb191b52
commit
5b2bea95a0
@ -24,7 +24,7 @@
|
||||
* - {string} core CPU核心信息
|
||||
* - {string} cores CPU核心数
|
||||
*/
|
||||
export function getCPUInfo(text) {
|
||||
export function getCPUInfo(text = '') {
|
||||
const cpuInfo = {
|
||||
company: '',
|
||||
model: '',
|
||||
|
||||
@ -87,7 +87,7 @@ const { cpuAndMemAndDisk } = handleServerInfo({
|
||||
});
|
||||
|
||||
const slogan = computed(() => props.info?.PublicNote?.customData?.slogan);
|
||||
const cpuInfo = computed(() => hostUtils.getCPUInfo(props.info.Host.CPU[0]));
|
||||
const cpuInfo = computed(() => hostUtils.getCPUInfo(props.info?.Host?.CPU?.[0]));
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@ -13,7 +13,7 @@ export default (params) => {
|
||||
return {};
|
||||
}
|
||||
const cpuInfo = computed(() => {
|
||||
if (props.info?.Host?.CPU) {
|
||||
if (props.info?.Host?.CPU?.[0]) {
|
||||
return hostUtils.getCPUInfo(props.info.Host.CPU[0]);
|
||||
}
|
||||
return {};
|
||||
@ -61,6 +61,8 @@ export default (params) => {
|
||||
const serverStatusList = computed(() => statusListTpl.split(',').map((i) => {
|
||||
switch (i) {
|
||||
case 'cpu':
|
||||
{
|
||||
const CoresVal = cpuInfo.value?.cores ? `${cpuInfo.value?.cores}C` : '-';
|
||||
return {
|
||||
type: 'cpu',
|
||||
used: (props.info.State?.CPU || 0).toFixed(1) * 1,
|
||||
@ -71,10 +73,11 @@ export default (params) => {
|
||||
valText: `${(props.info.State?.CPU || 0).toFixed(1) * 1}%`,
|
||||
label: 'CPU',
|
||||
content: {
|
||||
default: cpuInfo.value?.core,
|
||||
mobile: `${cpuInfo.value?.cores}C`,
|
||||
default: cpuInfo.value?.core || CoresVal,
|
||||
mobile: CoresVal,
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'mem':
|
||||
{
|
||||
let usedVal;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user