From e199410bcbfce49aaa7009014735bbc0299e4860 Mon Sep 17 00:00:00 2001
From: HuoWenBo <1684240320@qq.com>
Date: Tue, 25 Jul 2023 11:49:59 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=86=85=E5=AD=98?=
=?UTF-8?q?=E5=8D=95=E4=BD=8D=E6=98=BE=E7=A4=BA=E4=B8=BA=E8=87=AA=E9=80=82?=
=?UTF-8?q?=E5=BA=94?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
applications/view/system/monitor.py | 50 +++++++++++++++--------------
templates/system/common/memory.html | 13 ++++++++
templates/system/monitor.html | 23 ++++++-------
3 files changed, 51 insertions(+), 35 deletions(-)
create mode 100644 templates/system/common/memory.html
diff --git a/applications/view/system/monitor.py b/applications/view/system/monitor.py
index c4c1264..972d49c 100644
--- a/applications/view/system/monitor.py
+++ b/applications/view/system/monitor.py
@@ -1,11 +1,13 @@
import os
+import platform
import re
import sys
import time
-import psutil
-import platform
from datetime import datetime
+
+import psutil
from flask import Blueprint, render_template, jsonify
+
from applications.common.utils.rights import authorize
bp = Blueprint('adminMonitor', __name__, url_prefix='/monitor')
@@ -29,9 +31,9 @@ def main():
memory_information = psutil.virtual_memory()
# 内存使用率
memory_usage = memory_information.percent
- memory_used = str(round(memory_information.used / 1024 / 1024))
- memory_total = str(round(memory_information.total / 1024 / 1024))
- memory_free = str(round(memory_information.free / 1024 / 1024))
+ memory_used: int = memory_information.used
+ memory_total: int = memory_information.total
+ memory_free: int = memory_information.free
# 磁盘信息
disk_partitions_list = []
@@ -43,9 +45,9 @@ def main():
disk_partitions_dict = {
'device': i.device,
'fstype': i.fstype,
- 'total': str(round(a.total / 1024 / 1024)),
- 'used': str(round(a.used / 1024 / 1024)),
- 'free': str(round(a.free / 1024 / 1024)),
+ 'total': a.total,
+ 'used': a.used,
+ 'free': a.free,
'percent': a.percent
}
disk_partitions_list.append(disk_partitions_dict)
@@ -58,22 +60,22 @@ def main():
# 当前时间
time_now = time.strftime('%H:%M:%S ', time.localtime(time.time()))
- return render_template('system/monitor.html',
- hostname=hostname,
- system_version=system_version,
- python_version=python_version,
- cpus_percent=cpus_percent,
- memory_usage=memory_usage,
- cpu_count=cpu_count,
- memory_used=memory_used,
- memory_total=memory_total,
- memory_free=memory_free,
- boot_time=boot_time,
- up_time_format=up_time_format,
- disk_partitions_list=disk_partitions_list,
- time_now=time_now
-
- )
+ return render_template(
+ 'system/monitor.html',
+ hostname=hostname,
+ system_version=system_version,
+ python_version=python_version,
+ cpus_percent=cpus_percent,
+ memory_usage=memory_usage,
+ cpu_count=cpu_count,
+ memory_used=memory_used,
+ memory_total=memory_total,
+ memory_free=memory_free,
+ boot_time=boot_time,
+ up_time_format=up_time_format,
+ disk_partitions_list=disk_partitions_list,
+ time_now=time_now
+ )
# 图表 api
diff --git a/templates/system/common/memory.html b/templates/system/common/memory.html
new file mode 100644
index 0000000..d7a0821
--- /dev/null
+++ b/templates/system/common/memory.html
@@ -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 %}
\ No newline at end of file
diff --git a/templates/system/monitor.html b/templates/system/monitor.html
index 6ea17e9..4643bd7 100644
--- a/templates/system/monitor.html
+++ b/templates/system/monitor.html
@@ -1,3 +1,4 @@
+{% from 'system/common/memory.html' import memory_format %}
@@ -54,19 +55,19 @@
空闲内存
-
{{ memory_free }}M
+
{{ memory_format(memory_free) }}
最大内存
-
{{ memory_total }}M
+
{{ memory_format(memory_total) }}
已用内存
-
{{ memory_used }}M
+
{{ memory_format(memory_used) }}
@@ -96,18 +97,18 @@
- {% for i in disk_partitions_list %}
+ {% for disk in disk_partitions_list %}
-
-
{{ i.device }}
- {{ i.fstype }}
- 磁盘大小 {{ i.total }}M
- 空闲大小 {{ i.free }}M
+ {{ disk.device }}
+ {{ disk.fstype }}
+ 磁盘大小: {{ memory_format(disk.total) }}
+ 空闲大小: {{ memory_format(disk.free) }}
- 已经使用 {{ i.used }}M
- 使用概率 {{ i.percent }}%
+ 已经使用: {{ memory_format(disk.used) }}
+ 使用率: {{ disk.percent }}%
- 详情
+ 详情
{% endfor %}
From 895377714c2f2db9fc2c5a7313d0bae530c78b36 Mon Sep 17 00:00:00 2001
From: HuoWenBo <1684240320@qq.com>
Date: Thu, 21 Sep 2023 14:26:16 +0800
Subject: [PATCH 2/4] =?UTF-8?q?=E9=87=8D=E6=96=B0=E7=94=9F=E6=88=90=20requ?=
=?UTF-8?q?irements.txt=20=E9=9C=80=E6=B1=82=E6=96=87=E4=BB=B6=20=E4=BF=AE?=
=?UTF-8?q?=E5=A4=8D=E4=BA=86=20from=20flask=5Fsqlalchemy=20import=20BaseQ?=
=?UTF-8?q?uery=20=E4=B8=8D=E8=83=BD=E5=AF=BC=E5=85=A5=E7=9A=84=E9=97=AE?=
=?UTF-8?q?=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
applications/extensions/init_sqlalchemy.py | 3 ++-
requirements.txt | Bin 181 -> 1548 bytes
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/applications/extensions/init_sqlalchemy.py b/applications/extensions/init_sqlalchemy.py
index c0aff14..d128c22 100644
--- a/applications/extensions/init_sqlalchemy.py
+++ b/applications/extensions/init_sqlalchemy.py
@@ -2,7 +2,8 @@ import datetime
import os
from flask import Flask, request
-from flask_sqlalchemy import SQLAlchemy, BaseQuery
+from flask_sqlalchemy import SQLAlchemy
+from flask_sqlalchemy.query import Query as BaseQuery
from flask_marshmallow import Marshmallow
from marshmallow import fields
from marshmallow.validate import (
diff --git a/requirements.txt b/requirements.txt
index 44355bb819fc2f97cce37cb5b4cb65a2b9c07ce2..9e385c2e8e4c67caf0aafee065191bcdd002f8a3 100644
GIT binary patch
literal 1548
zcmaJ>O>f#z5ZrU5{uD=GNIwoe
FBvKANR>pzgBp4T)H1Olw&g}U4nLs1UfV{K&
zW@g9y{gc_VEo^ObD=fFKxQ2F#Tc027!me#{Z_e)eUB5V469Cr;c$4#Mbs!Sp(FA<0|mo
zJ96w=h!=}{u*=(N#EYqzP&rS$!Fie0Et?d*)T;hiOWyHD{;_lXW@2LBoF$#2Rx*no
z^`}q3p#YPB`U0f*EjxaRJF*4WmH&Enr+#-mL!+|635N+L%c%x_@C3RkSC1V?>^l%U
zxXT@6$N+P|4r-(?r_*P42bI_8P;S=kE|i#{g6A)AmB1~qJIsVn@`@_HiaYgVwlBR<@|o
zl^K37aY|q>SLh+LdVVuX6Lo5z=aC6G|AKD5qsKnVA?87fD`5EUWY9}R4=o$%A(tth
z_p>o{mpLa)sG+8D6qPVFoPXuXsj$BsTBRqv-Si`E6-O;7
From a476856ce1718b2f77746a2f493d2def41b1b5ef Mon Sep 17 00:00:00 2001
From: HuoWenBo <1684240320@qq.com>
Date: Sat, 18 Nov 2023 12:49:26 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=94=A7=E4=BF=AE=E5=A4=8D=E9=AA=8C?=
=?UTF-8?q?=E8=AF=81=E7=A0=81=E5=88=B7=E6=96=B0BUG?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
templates/system/login.html | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/templates/system/login.html b/templates/system/login.html
index bef6b6d..70b88b6 100644
--- a/templates/system/login.html
+++ b/templates/system/login.html
@@ -43,6 +43,29 @@
let popup = layui.popup;
let captchaPath = "{{ url_for('system.passport.get_captcha') }}";
+ /**
+ * 刷新验证码函数
+ */
+ const refreshCaptchaImage = (function () {
+ let captchaImage = document.getElementById("captchaImage")
+ return function () {
+ captchaImage.src = captchaPath + "?" + Math.random()
+ }
+ })()
+
+ /**
+ * 立即刷新验证码并且每隔 30秒 刷新
+ */
+ const initCaptchaImageTimer = (function () {
+ let captchaImageTimer = null
+ return function () {
+ captchaImageTimer = setInterval(function () {
+ refreshCaptchaImage()
+ }, 30 * 1000);
+ refreshCaptchaImage()
+ }
+ })()
+
form.on('submit(login)', function (data) {
let loader = layer.load();
let btn = button.load({elem: '.login'});
@@ -59,7 +82,7 @@
})
} else {
popup.failure(result.msg, function () {
- document.getElementById("captchaImage").src = captchaPath + "?" + Math.random();
+ initCaptchaImageTimer()
});
}
})
@@ -67,13 +90,9 @@
});
return false;
});
-
$("#captchaImage").click(function () {
- document.getElementById("captchaImage").src = captchaPath + "?" + Math.random();
+ initCaptchaImageTimer()
});
- setInterval(function () {
- document.getElementById("captchaImage").src = captchaPath + "?" + Math.random();
- }, 30 * 1000);
})