更改内存硬盘单位自适应

This commit is contained in:
HuoWenBo
2023-07-25 11:40:54 +08:00
parent 10ae5f39f0
commit c058e03fbf
3 changed files with 51 additions and 35 deletions
+13
View File
@@ -0,0 +1,13 @@
{% macro memory_format(memory) %}
{%- if memory > 1024 ** 4 * 2 -%}
{{- (memory / 1024 ** 4) | round(2) -}}TB
{% elif memory > 1024 ** 3 * 2 %}
{{- (memory / 1024 ** 3) | round(2) -}}GB
{% elif memory > 1024 ** 2 * 2 %}
{{- (memory / 1024 ** 2) | round(2) -}}MB
{% elif memory > 1024 ** 1 * 2 %}
{{- (memory / 1024 ** 1) | round(2) -}}KB
{% else %}
{{- memory -}}B
{% endif %}
{% endmacro %}
+12 -11
View File
@@ -1,3 +1,4 @@
{% from 'system/common/memory.html' import memory_format %}
<!DOCTYPE html>
<html>
<head>
@@ -54,19 +55,19 @@
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
<div class="pear-card2">
<div class="title">空闲内存</div>
<div class="count pear-text">{{ memory_free }}M</div>
<div class="count pear-text">{{ memory_format(memory_free) }}</div>
</div>
</div>
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
<div class="pear-card2">
<div class="title">最大内存</div>
<div class="count pear-text">{{ memory_total }}M</div>
<div class="count pear-text">{{ memory_format(memory_total) }}</div>
</div>
</div>
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
<div class="pear-card2">
<div class="title">已用内存</div>
<div class="count pear-text">{{ memory_used }}M</div>
<div class="count pear-text">{{ memory_format(memory_used) }}</div>
</div>
</div>
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
@@ -96,18 +97,18 @@
<div class="layui-card-header">磁盘信息</div>
<div class="layui-card-body">
<ul class="pear-card-status">
{% for i in disk_partitions_list %}
{% for disk in disk_partitions_list %}
<li>
<p>{{ i.device }}</p>
<p>{{ i.fstype }}</p>
磁盘大小&nbsp;<span>{{ i.total }}M</span>&nbsp;&nbsp;
空闲大小&nbsp;<span>{{ i.free }}M</span>&nbsp;&nbsp;
<p>{{ disk.device }}</p>
<p>{{ disk.fstype }}</p>
磁盘大小: <span>{{ memory_format(disk.total) }}</span>&nbsp;&nbsp;
空闲大小: <span>{{ memory_format(disk.free) }}</span>&nbsp;&nbsp;
<br/>
<br/>
已经使用&nbsp;<span>{{ i.used }}M</span>&nbsp;&nbsp;
使用概率&nbsp;<span>{{ i.percent }}%</span>
已经使用: <span>{{ memory_format(disk.used) }}</span>&nbsp;&nbsp;
使用率: <span>{{ disk.percent }}%</span>
<br/>
<a href="javascript:;" data-id="1" class="pear-btn pear-btn-xs pear-btn-primary pear-reply">详情</a>
<a href="javascript:0" data-id="1" class="pear-btn pear-btn-xs pear-btn-primary pear-reply">详情</a>
</li>
{% endfor %}
</ul>