LiteyukiBot-TriM/liteyuki/resources/templates/stats.html

364 lines
12 KiB
HTML
Raw Normal View History

2024-03-30 06:04:17 +08:00
<!DOCTYPE html>
2024-04-05 07:02:18 +08:00
<html lang="zh-CN">
2024-03-30 06:04:17 +08:00
<head>
<meta charset="UTF-8">
2024-04-05 07:02:18 +08:00
<meta name="viewport" content="width=1080, initial-scale=1.0">
<title>Liteyuki Stats</title>
2024-03-31 06:22:53 +08:00
<link rel="stylesheet" href="css/fonts.css">
<style>
2024-04-05 07:02:18 +08:00
@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;
}
2024-03-31 06:22:53 +08:00
body {
font-family: 'MiSans', serif;
background-repeat: repeat-y;
background-size: cover;
background-position: center;
background-image: url('img/bg1.jpg');
color: white;
// 上10px左右10px下0px
2024-04-05 07:02:18 +08:00
//margin: 24px;
margin: 20px;
2024-03-31 06:22:53 +08:00
}
.info-box {
2024-04-03 01:03:25 +08:00
border-radius: 30px;
padding: 30px;
2024-03-31 06:22:53 +08:00
backdrop-filter: blur(30px);
background-color: rgba(0, 0, 0, 0.3);
2024-04-05 07:02:18 +08:00
margin-bottom: 20px;
2024-03-31 06:22:53 +08:00
}
2024-04-05 07:02:18 +08:00
.pie-chart {
2024-04-03 01:03:25 +08:00
height: 240px;
width: 240px;
margin-bottom: 20px;
}
2024-04-05 07:02:18 +08:00
.pie-info {
2024-04-03 01:03:25 +08:00
margin: 0 40px;
align-items: center;
2024-03-31 06:22:53 +08:00
}
2024-04-05 07:02:18 +08:00
.bot-info {
2024-03-31 06:22:53 +08:00
align-items: center;
2024-04-05 07:02:18 +08:00
display: flex;
2024-03-31 06:22:53 +08:00
}
#hardware-info {
justify-content: center;
text-align: center;
2024-04-05 07:02:18 +08:00
display: flex;
2024-03-31 06:22:53 +08:00
}
2024-04-05 07:02:18 +08:00
#disks-info {
flex-wrap: wrap;
justify-content: center;
margin-bottom: 0;
}
.bot-icon {
2024-03-31 06:22:53 +08:00
border-radius: 50%;
2024-04-03 01:03:25 +08:00
height: 200px;
2024-04-05 07:02:18 +08:00
background-color: white;
2024-03-31 06:22:53 +08:00
}
2024-04-05 07:02:18 +08:00
.bot-name, .bot-tag {
2024-03-31 06:22:53 +08:00
margin-left: 20px;
}
2024-04-05 07:02:18 +08:00
.bot-name {
2024-04-03 01:03:25 +08:00
font-size: 42px;
2024-03-31 06:22:53 +08:00
font-weight: bold;
}
2024-04-05 07:02:18 +08:00
.bot-tag {
2024-03-31 06:22:53 +08:00
margin-top: 10px;
}
.chart-label {
2024-04-03 01:03:25 +08:00
font-size: 30px;
max-width: 240px;
2024-03-31 06:22:53 +08:00
}
.tag {
2024-04-05 07:02:18 +08:00
font-size: 32px;
font-weight: bold;
2024-03-31 06:22:53 +08:00
}
2024-04-05 07:02:18 +08:00
.tag[suffix="1"]::after {
content: " | ";
2024-03-31 06:22:53 +08:00
display: inline-block;
margin: 0 5px;
2024-04-02 08:51:34 +08:00
height: 50%;
line-height: 50%;
2024-04-05 07:02:18 +08:00
color: #ccc;
2024-03-31 06:22:53 +08:00
}
</style>
2024-03-31 07:25:29 +08:00
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@4.3.0/dist/echarts.min.js"></script>
2024-03-30 06:04:17 +08:00
</head>
<body>
2024-03-31 06:22:53 +08:00
<div class="info-box" id="hardware-info">
2024-04-05 07:02:18 +08:00
<div class="pie-info" id="cpu-info">
<div class="pie-chart" id="cpu-chart"></div>
2024-03-31 06:22:53 +08:00
</div>
2024-04-05 07:02:18 +08:00
<div class="pie-info" id="mem-info">
<div class="pie-chart" id="mem-chart"></div>
2024-03-31 06:22:53 +08:00
</div>
2024-04-05 07:02:18 +08:00
<div class="pie-info" id="swap-info">
<div class="pie-chart" id="swap-chart"></div>
2024-03-31 06:22:53 +08:00
</div>
2024-03-30 06:04:17 +08:00
</div>
2024-03-31 06:22:53 +08:00
2024-04-05 07:02:18 +08:00
<div class="info-box" id="disks-info">
</div>
2024-03-31 06:22:53 +08:00
2024-04-05 07:02:18 +08:00
<!--储存数据div不显示-->
<div id="data" style="display: none">{{ data | tojson }}</div>
2024-03-31 06:22:53 +08:00
<script>
{
2024-04-05 07:02:18 +08:00
// 环形图
let bgs = ["bg1.jpg", "bg2.jpg", "bg3.jpg", "bg4.jpg"]
2024-03-31 06:22:53 +08:00
// 随机选择背景图片
document.body.style.backgroundImage = `url(./img/${bgs[Math.floor(Math.random() * bgs.length)]})`;
2024-04-05 07:02:18 +08:00
2024-03-31 06:22:53 +08:00
let cpuInfo = echarts.init(document.getElementById('cpu-chart'));
let memInfo = echarts.init(document.getElementById('mem-chart'));
let swapInfo = echarts.init(document.getElementById('swap-chart'));
2024-04-05 07:02:18 +08:00
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
2024-03-31 06:22:53 +08:00
}
for (let key in sub_tag_data) {
2024-04-05 07:02:18 +08:00
console.log(key, sub_tag_data[key])
2024-03-31 06:22:53 +08:00
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);
});
}
2024-04-05 07:02:18 +08:00
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) {
2024-03-31 06:22:53 +08:00
return {
animation: false,
title: {
text: title,
left: 'center',
top: 'center',
textStyle: {
//文字颜色
color: '#fff',
2024-04-03 01:03:25 +08:00
fontSize: 30
2024-03-31 06:22:53 +08:00
}
},
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: {
2024-04-03 01:03:25 +08:00
fontSize: '50',
2024-03-31 06:22:53 +08:00
fontWeight: 'bold'
}
}
}
},
data: data
}
]
};
}
2024-04-05 07:02:18 +08:00
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]
}
},
}
]
};
}
2024-03-31 06:22:53 +08:00
}
</script>
</body>
</html>