LiteyukiBot-TriM/liteyuki/resources/templates/stats.html
2024-04-05 07:02:18 +08:00

364 lines
12 KiB
HTML
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.

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=1080, initial-scale=1.0">
<title>Liteyuki Stats</title>
<link rel="stylesheet" href="css/fonts.css">
<style>
@font-face {
font-family: 'MiSans';
src: url('fonts/normal.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'MiSans';
src: url('fonts/bold.ttf') format('truetype');
font-weight: bold;
font-style: normal;
}
body {
font-family: 'MiSans', serif;
background-repeat: repeat-y;
background-size: cover;
background-position: center;
background-image: url('img/bg1.jpg');
color: white;
// 10px10px0px
//margin: 24px;
margin: 20px;
}
.info-box {
border-radius: 30px;
padding: 30px;
backdrop-filter: blur(30px);
background-color: rgba(0, 0, 0, 0.3);
margin-bottom: 20px;
}
.pie-chart {
height: 240px;
width: 240px;
margin-bottom: 20px;
}
.pie-info {
margin: 0 40px;
align-items: center;
}
.bot-info {
align-items: center;
display: flex;
}
#hardware-info {
justify-content: center;
text-align: center;
display: flex;
}
#disks-info {
flex-wrap: wrap;
justify-content: center;
margin-bottom: 0;
}
.bot-icon {
border-radius: 50%;
height: 200px;
background-color: white;
}
.bot-name, .bot-tag {
margin-left: 20px;
}
.bot-name {
font-size: 42px;
font-weight: bold;
}
.bot-tag {
margin-top: 10px;
}
.chart-label {
font-size: 30px;
max-width: 240px;
}
.tag {
font-size: 32px;
font-weight: bold;
}
.tag[suffix="1"]::after {
content: " | ";
display: inline-block;
margin: 0 5px;
height: 50%;
line-height: 50%;
color: #ccc;
}
</style>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@4.3.0/dist/echarts.min.js"></script>
</head>
<body>
<div class="info-box" id="hardware-info">
<div class="pie-info" id="cpu-info">
<div class="pie-chart" id="cpu-chart"></div>
</div>
<div class="pie-info" id="mem-info">
<div class="pie-chart" id="mem-chart"></div>
</div>
<div class="pie-info" id="swap-info">
<div class="pie-chart" id="swap-chart"></div>
</div>
</div>
<div class="info-box" id="disks-info">
</div>
<!--储存数据div不显示-->
<div id="data" style="display: none">{{ data | tojson }}</div>
<script>
{
// 环形图
let bgs = ["bg1.jpg", "bg2.jpg", "bg3.jpg", "bg4.jpg"]
// 随机选择背景图片
document.body.style.backgroundImage = `url(./img/${bgs[Math.floor(Math.random() * bgs.length)]})`;
let cpuInfo = echarts.init(document.getElementById('cpu-chart'));
let memInfo = echarts.init(document.getElementById('mem-chart'));
let swapInfo = echarts.init(document.getElementById('swap-chart'));
let data = JSON.parse(document.getElementById('data').innerText);
let cpuData = data.cpu;
let memData = data.mem;
let swapData = data.swap;
let diskData = data.disk;
let sub_tag_data = {
cpu: data.cpuTags,
mem: data.memTags,
swap: data.swapTags
}
for (let key in sub_tag_data) {
console.log(key, sub_tag_data[key])
let infoDiv = document.getElementById(key + '-info');
sub_tag_data[key].forEach(tag => {
let tagSpan = document.createElement('div');
tagSpan.innerText = tag;
tagSpan.className = 'chart-label';
infoDiv.appendChild(tagSpan);
});
}
cpuInfo.setOption(getPieOption(data.cpu_trans, cpuData));
memInfo.setOption(getPieOption(data.mem_trans, memData));
swapInfo.setOption(getPieOption(data.swap_trans, swapData));
// 在disks-info中插入每个disk的div用横向柱状图表示用量每一行div显示一个disk不加info-box
diskData.forEach(disk => {
let diskDiv = document.createElement('div');
document.getElementById('disks-info').appendChild(diskDiv);
let diskChart = document.createElement('div');
diskChart.style.width = '100%';
diskChart.style.height = '100px';
diskDiv.appendChild(diskChart);
let diskInfo = echarts.init(diskChart);
// let diskTitle = disk.name + ' {{ FREE }} ' + disk.free + ' {{ TOTAL }} ' + disk.total;
let diskTitle = `${disk.name} ${data.free_trans} ${disk.free} ${data.total_trans} ${disk.total}`;
diskInfo.setOption(getBarOption(diskTitle, disk.percent));
});
let botData = data.bot;
// 清空bot-info
let botInfos = document.getElementsByClassName('bot-info');
while (botInfos.length > 0) {
botInfos[0].remove();
}
botData.forEach(bot => {
// 在hardware-info前面插入一个div
let botDiv = document.createElement('div');
botDiv.className = 'info-box bot-info';
// 在body内的hardware-info前面插入botDiv
document.body.insertBefore(botDiv, document.getElementById('hardware-info'));
let botIconBlock = document.createElement('div');
let botIcon = document.createElement('img');
botIcon.src = bot.icon;
botIcon.className = 'bot-icon';
botIconBlock.appendChild(botIcon);
botDiv.appendChild(botIconBlock);
let botDetail = document.createElement('div');
let botName = document.createElement('div');
botName.className = 'bot-name';
botName.innerText = bot.name;
if (bot.self) {
// 添加颜色
botName.style.color = '#d0e9ff';
}
botDetail.appendChild(botName);
let botTags = document.createElement('div');
botTags.className = 'bot-tag';
botDetail.appendChild(botTags)
bot.tags.forEach((tag, index) => {
if (!tag) {
return;
}
let tagSpan = document.createElement('span');
tagSpan.innerText = tag;
tagSpan.className = 'tag';
if (bot.self) {
// 添加颜色
tagSpan.style.color = '#a2d8f4';
}
botTags.appendChild(tagSpan);
if (index === bot.tags.length - 1) {
tagSpan.setAttribute("suffix", "0")
} else {
tagSpan.setAttribute("suffix", "1")
}
});
botDiv.appendChild(botDetail);
}
)
function getPieOption(title, data) {
return {
animation: false,
title: {
text: title,
left: 'center',
top: 'center',
textStyle: {
//文字颜色
color: '#fff',
fontSize: 30
}
},
tooltip: {
show: true,
trigger: "item",
backgroundColor: "#ffffff00",
// {a}(系列名称),{b}(数据项名称),{c}(数值), {d}(百分比)
},
color: ['#a2d8f4', "#ffffff44", '#00a6ff'],
series: [
{
name: 'info',
type: 'pie',
radius: ['80%', '100%'],
center: ['50%', '50%'],
itemStyle: {
normal: {
label: {
show: false
},
labelLine: {
show: false
}
},
emphasis: {
label: {
show: true,
textStyle: {
fontSize: '50',
fontWeight: 'bold'
}
}
}
},
data: data
}
]
};
}
function getBarOption(title, percent) {
// data为百分比最大值为100
return {
background: '#d0e9ff',
title: {
text: title,
left: '5%',
top: 'center',
textStyle: {
color: '#fff',
fontSize: 30
}
},
tooltip: {
show: true,
trigger: "item",
backgroundColor: "#ffffff",
},
grid: {
left: '0',
right: '0',
top: '10%',
bottom: '10%'
},
xAxis: {
type: 'value',
show: false
},
yAxis: {
type: 'category',
data: [''],
show: false
},
series: [
{
name: 'Used',
type: 'bar',
stack: 'total',
data: [percent],
itemStyle: {
normal: {
color: '#a2d8f4',
barBorderRadius: [50, 0, 0, 50]
}
},
},
{
name: 'Free',
type: 'bar',
stack: 'total',
data: [100 - percent],
itemStyle: {
normal: {
color: '#d0e9ff',
barBorderRadius: [0, 50, 50, 0]
}
},
}
]
};
}
}
</script>
</body>
</html>