Skip to content

Commit

Permalink
default和serverstatus主题温度展示相关 (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
nap0o authored Jun 22, 2024
1 parent ce66f72 commit 6e6ec32
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 43 deletions.
4 changes: 4 additions & 0 deletions resource/static/theme-default/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ td {
z-index: 9999;
}

.temp-detail {
cursor: pointer;
}

.ui.content {
margin:0 !important;
padding:1em !important;
Expand Down
4 changes: 4 additions & 0 deletions resource/static/theme-server-status/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ body {
max-width: 50px;
}

.temp-detail {
cursor: pointer;
}

/*正文结束*/

/* 服务页 正文*/
Expand Down
2 changes: 1 addition & 1 deletion resource/template/theme-default/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<link rel="stylesheet" href="https://unpkg.com/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="https://unpkg.com/flag-icons@7.2.3/css/flag-icons.min.css">
<link rel="stylesheet" type="text/css" href="/static/semantic-ui-alerts.min.css">
<link rel="stylesheet" type="text/css" href="/static/theme-default/css/main.css?v20240226">
<link rel="stylesheet" type="text/css" href="/static/theme-default/css/main.css?v20240616">
<script src="https://unpkg.com/jquery@3.7.1/dist/jquery.min.js"></script>
<script src="https://unpkg.com/semantic-ui@2.4.0/dist/semantic.min.js"></script>
<script src="https://unpkg.com/vue@2.6.14/dist/vue.min.js"></script>
Expand Down
91 changes: 56 additions & 35 deletions resource/template/theme-default/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,19 @@
<br />
{{tr "LastActive"}}: @#new Date(server.LastActive).toLocaleString()#@
<br />
<template>
<div>
<template v-if="server.State.Temperatures">
<a href="#" @click.prevent="toggleDetailedTemp">
{{tr "Temperature"}}: <span v-if="!showDetailedTemp">@#getTemperature(server.State.Temperatures, sensorList)#@°C</span>
<span v-else>
<span v-for="temp in server.State.Temperatures" :key="temp.Name">
@#temp.Name#@: @#temp.Temperature#@°C &nbsp;
</span>
</span>
</a>
<br />
</template>
</div>
</template>
<div v-if="server.State.Temperatures && getTemperature(server.State.Temperatures, sensorList) > 0" class="temp-detail" @click="toggleDetailedTemp(server.ID)" :id="`temp-${server.ID}`" temp-detail-show="0">
{{tr "Temperature"}}:
<span :id="`temp-main-${server.ID}`">
@#getTemperature(server.State.Temperatures, sensorList)#@°C
<i class="bi bi-chevron-double-down"></i>
</span>
<span :id="`temp-detail-${server.ID}`" style="display:none">
<span v-for="temp in server.State.Temperatures" :key="temp.Name" v-if="temp.Temperature !== 0">
[ @#temp.Name#@: @#temp.Temperature#@°C ]
</span>
<i class="bi bi-chevron-double-up"></i>
</span>
</div>
{{tr "Version"}}: @#server.Host.Version#@
<div class="chartbox" :key="server.ID" :ref="`chart${server.ID}`" style="width: 100%; height: auto; margin-bottom: 2px;"></div>
</div>
Expand Down Expand Up @@ -177,16 +175,18 @@
'TC0D', //CPU Die 温度,代表 CPU 内部的温度
'TC0H', //CPU Heatsink 温度,代表 CPU 散热器的温度
'TC0P', //CPU Proximity 温度,代表 CPU 附近的温度
'coretemp_package_id_0',
'soc_thermal',
'cpu_thermal_zone',
'ACPI\\ThermalZone\\TZ0__0',
'ACPI\\ThermalZone\\CPUZ_0',
'ACPI\\ThermalZone\\TZ00_0',
'ACPI\\ThermalZone\\TZ001_0',
'ACPI\\ThermalZone\\THM0_0'
],
showDetailedTemp: false
'k10temp', //AMD K10(Phenom、Athlon、Sempron 等)系列处理器的温度监测
'coretemp_package_id_0', //整个封装处理器温度
'cpu_thermal_zone', //全志
'cpu-thermal', //树莓派(博通)
'soc_thermal', //新瑞芯微
'cpu_thermal', //老瑞芯微
'ACPI\\ThermalZone\\TZ0__0', //Windows
'ACPI\\ThermalZone\\CPUZ_0', //Windows
'ACPI\\ThermalZone\\TZ00_0', //Windows
'ACPI\\ThermalZone\\TZ001_0', //Windows
'ACPI\\ThermalZone\\THM0_0' //Windows
]
},
mixins: [mixinsVue],
created() {
Expand Down Expand Up @@ -504,27 +504,48 @@
listTipsMouseleave(obj){
layer.close(this.layerIndex)
},
toggleDetailedTemp(){
this.showDetailedTemp = !this.showDetailedTemp;
toggleDetailedTemp(id){
const tempDom = document.getElementById(`temp-${id}`);
const tempDetailShow = tempDom.getAttribute('temp-detail-show');
const tempMain = document.getElementById(`temp-main-${id}`);
const tempDetail = document.getElementById(`temp-detail-${id}`);
if (tempDetailShow == 0){
tempMain.style.display = 'none';
tempDetail.style.display = 'inline';
tempDom.setAttribute('temp-detail-show', 1);
} else {
tempMain.style.display = 'inline';
tempDetail.style.display = 'none';
tempDom.setAttribute('temp-detail-show', 0);
}
},
getTemperature(arr, sensorList) {
getTemperature(temperatureList, sensorList) {
// 将 sensorList 中的所有项转换为小写
const lowerCaseSensorList = sensorList.map(sensor => sensor.toLowerCase());

// 过滤出 Name 在 sensorList 中的元素(忽略大小写)
const filtered = arr.filter(item => lowerCaseSensorList.includes(item.Name.toLowerCase()));

// 合并过滤逻辑:过滤出 Temperature 不为 0 且 Name 在 sensorList 中的元素(忽略大小写)
const filtered = temperatureList.filter(item => item.Temperature !== 0 && lowerCaseSensorList.includes(item.Name.toLowerCase()));
//console.log('filtered:',filtered);

// 如果有匹配的元素,则计算这些元素的 Temperature 的最大值
if (filtered.length > 0) {
return filtered.reduce((max, current) => {
return current.Temperature > max ? current.Temperature : max;
}, filtered[0].Temperature);
}

// 如果没有匹配的元素,则计算 arr 中所有元素的 Temperature 的最大值
return arr.reduce((max, current) => {
return current.Temperature > max ? current.Temperature : max;
}, arr[0].Temperature);
// 如果没有匹配的元素,则计算 temperatureList 中所有 Temperature 不为 0 的元素的最大值
const nonZeroTemps = temperatureList.filter(item => item.Temperature !== 0);
//console.log('nonZeroTemps:',nonZeroTemps);

if (nonZeroTemps.length > 0) {
return nonZeroTemps.reduce((max, current) => {
return current.Temperature > max ? current.Temperature : max;
}, nonZeroTemps[0].Temperature);
}

// 如果所有元素的 Temperature 都为 0,则返回一个默认值 0
return 0;
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion resource/template/theme-server-status/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="shortcut icon" type="image/png" href="/static/logo.svg" />
<link rel="stylesheet" href="https://unpkg.com/bootstrap@3.4.1/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://unpkg.com/bootstrap@3.4.1/dist/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="/static/theme-server-status/css/main.css?v20240407">
<link rel="stylesheet" href="/static/theme-server-status/css/main.css?v20240616">
<link rel="stylesheet" href="/static/theme-server-status/css/dark.css?v20240407">
<link rel="stylesheet" href="/static/theme-server-status/css/light.css?v20240407">
<link rel="stylesheet" href="https://unpkg.com/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
Expand Down
15 changes: 14 additions & 1 deletion resource/template/theme-server-status/home-group-false.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
</span>
<span class="node-cell-expand">
<span class="node-cell-expand-label">{{tr "MemUsed"}}:</span>
@#formatByteSize(node.state.MemUsed)#@ / @#formatByteSize(node.host.MemTotal)#@ (@#toFixed2(node.state.MemUsed / node.host.MemTotal * 100)#@%)
@#formatByteSize(node.state.MemUsed)#@ / @#formatByteSize(node.host.MemTotal)#@ (@#node.memory.percent#@%)
</span>
<span v-if="node.host.SwapTotal > 0" class="node-cell-expand">
<span class="node-cell-expand-label">{{tr "SwapUsed"}}:</span>
Expand Down Expand Up @@ -120,6 +120,19 @@
<span class="node-cell-expand-label">{{tr "Uptime"}}:</span>
@#node.uptime#@
</span>
<span v-if="node.state.Temperatures && getTemperature(node.state.Temperatures, sensorList) > 0" @click="toggleDetailedTemp(node.ID)" class="node-cell-expand temp-detail" :id="`temp-${node.ID}`" temp-detail-show="0">
<span class="node-cell-expand-label">{{tr "Temperature"}}:</span>
<span :id="`temp-main-${node.ID}`" class="node-cell-expand-label">
@#getTemperature(node.state.Temperatures, sensorList)#@°C
<i class="bi bi-chevron-double-down"></i>
</span>
<span :id="`temp-detail-${node.ID}`" class="node-cell-expand-label" style="display:none">
<span v-for="temp in node.state.Temperatures" :key="temp.Name" v-if="temp.Temperature !== 0">
[ @#temp.Name#@ : @#temp.Temperature#@°C ]
</span>
<i class="bi bi-chevron-double-up"></i>
</span>
</span>
<span class="node-cell-expand">
<span class="node-cell-expand-label">{{tr "Version"}}:</span>
@#node.host.Version#@
Expand Down
21 changes: 17 additions & 4 deletions resource/template/theme-server-status/home-group-true.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@
<span class="node-cell-expand-label">CPU:</span>
@#node.host.CPU.join(",")#@ (@#node.cpu.percent#@%)
</span>
<span class="node-cell-expand">
<span class="node-cell-expand-label">{{tr "MemUsed"}}:</span>
@#formatByteSize(node.state.MemUsed)#@ / @#formatByteSize(node.host.MemTotal)#@ (@#toFixed2(node.state.MemUsed / node.host.MemTotal * 100)#@%)
</span>
<span class="node-cell-expand">
<span class="node-cell-expand-label">{{tr "DiskUsed"}}:</span>
@#formatByteSize(node.state.DiskUsed)#@ / @#formatByteSize(node.host.DiskTotal)#@ (@#node.hdd.percent#@%)
</span>
<span class="node-cell-expand">
<span class="node-cell-expand-label">{{tr "MemUsed"}}:</span>
@#formatByteSize(node.state.MemUsed)#@ / @#formatByteSize(node.host.MemTotal)#@ (@#node.memory.percent#@%)
</span>
<span v-if="node.host.SwapTotal > 0" class="node-cell-expand">
<span class="node-cell-expand-label">{{tr "SwapUsed"}}:</span>
@#formatByteSize(node.state.SwapUsed)#@ / @#formatByteSize(node.host.SwapTotal)#@
Expand Down Expand Up @@ -123,6 +123,19 @@
<span class="node-cell-expand-label">{{tr "Uptime"}}:</span>
@#node.uptime#@
</span>
<span v-if="node.state.Temperatures && getTemperature(node.state.Temperatures, sensorList) > 0" @click="toggleDetailedTemp(node.ID)" class="node-cell-expand temp-detail" :id="`temp-${node.ID}`" temp-detail-show="0">
<span class="node-cell-expand-label">{{tr "Temperature"}}:</span>
<span :id="`temp-main-${node.ID}`" class="node-cell-expand-label">
@#getTemperature(node.state.Temperatures, sensorList)#@°C
<i class="bi bi-chevron-double-down"></i>
</span>
<span :id="`temp-detail-${node.ID}`" class="node-cell-expand-label" style="display:none">
<span v-for="temp in node.state.Temperatures" :key="temp.Name" v-if="temp.Temperature !== 0">
[ @#temp.Name#@ : @#temp.Temperature#@°C ]
</span>
<i class="bi bi-chevron-double-up"></i>
</span>
</span>
<span class="node-cell-expand">
<span class="node-cell-expand-label">{{tr "Version"}}:</span>
@#node.host.Version#@
Expand Down
Loading

0 comments on commit 6e6ec32

Please sign in to comment.