简单支持一下日志查看,后期再美化

This commit is contained in:
ngfchl
2022-12-05 11:59:34 +08:00
parent 6d0a926f9a
commit 4c46d0d075
7 changed files with 208 additions and 4 deletions

View File

@@ -27,6 +27,9 @@ urlpatterns = [
path(r'sign_in_api', views.sign_in_api, name='sign_in_api'),
path(r'update_site_api', views.update_site_api, name='update_site_api'),
path(r'edit_site_api', views.edit_site_api, name='edit_site_api'),
path(r'get_log_list', views.get_log_list, name='get_log_list'),
path(r'show_log_list', views.show_log_list, name='show_log_list'),
path(r'get_log_content', views.get_log_content, name='get_log_content'),
path(r'downloading_status', views.downloading_status, name='downloading_status'),
path(r'do_sql', views.do_sql, name='do_sql'),
]

View File

@@ -18,6 +18,7 @@ from pt_site.UtilityTool import MessageTemplate, FileSizeConvert
from pt_site.models import SiteStatus, MySite, Site, Downloader, TorrentInfo
from pt_site.views import scheduler, pt_spider
from ptools.base import CommonResponse, StatusCodeEnum, DownloaderCategory
from ptools.settings import BASE_DIR
logger = logging.getLogger('ptools')
@@ -778,3 +779,37 @@ def edit_site_api(request):
return JsonResponse(data=CommonResponse.success(
msg='ok'
).to_dict(), safe=False)
def get_log_list(request):
path = os.path.join(BASE_DIR, 'db')
print(path)
print(os.listdir(path))
names = [name for name in os.listdir(path)
if os.path.isfile(os.path.join(path, name)) and name.startswith('logs')]
print(names)
return JsonResponse(data=CommonResponse.success(
data={
'path': path,
'names': names
}
).to_dict(), safe=False)
def get_log_content(request):
name = request.GET.get('name')
path = os.path.join(BASE_DIR, 'db/' + name)
with open(path, 'r') as f:
logs = f.readlines()
print(logs)
return JsonResponse(data=CommonResponse.success(
data={
'path': path,
'logs': logs,
}
).to_dict(), safe=False)
def show_log_list(request):
return render(request, 'auto_pt/showlog.html')

View File

@@ -275,6 +275,10 @@ SIMPLEUI_CONFIG = {
'name': '站点导入',
'icon': 'el-icon-s-open',
'url': '/tasks/import_from_ptpp'
}, {
'name': '日志查看',
'icon': 'el-icon-s-open',
'url': '/tasks/show_log_list'
}, ]
}]
}

View File

@@ -0,0 +1,149 @@
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
{% include 'admin/includes/css-part.html' %}
<style>
.el-aside {
background-color: #D3DCE6;
color: #333;
text-align: center;
line-height: 200px;
}
.logs {
color: #F2F6FC;
background-color: #1f2c39;
margin-left: 25px;
font-size: 14px;
font-family: 'Heiti SC';
line-height: 18px;
}
</style>
</head>
<body>
<div id="logs">
<el-container style="height: 820px; border: 1px solid #eee">
<el-aside width="200px" style="background-color: rgb(138, 141, 146)">
<el-menu :default-openeds="['1']">
{# <el-submenu index="1">#}
{# <template slot="title"><i class="el-icon-message"></i>导航一</template>#}
<el-menu-item-group>
<template slot="title">日志列表</template>
<el-menu-item v-for="(name,index) in names" :index="index" v-text="name" @click="showLog(name)">
</el-menu-item>
</el-menu-item-group>
{# </el-submenu>#}
</el-menu>
</el-aside>
<el-container>
{# <el-header style="text-align: right; font-size: 12px">#}
{# <el-dropdown>#}
{# <i class="el-icon-setting" style="margin-right: 15px"></i>#}
{# <el-dropdown-menu slot="dropdown">#}
{# <el-dropdown-item>查看</el-dropdown-item>#}
{# <el-dropdown-item>新增</el-dropdown-item>#}
{# <el-dropdown-item>删除</el-dropdown-item>#}
{# </el-dropdown-menu>#}
{# </el-dropdown>#}
{# <span>王小虎</span>#}
{# </el-header>#}
<el-main class="logs">
<div v-for="log in logs">
<code v-text="log"></code>
</div>
</el-main>
</el-container>
</el-container>
</div>
{% include 'admin/includes/js-part.html' %}
<script src="{% static 'admin/simpleui-x/js/axios.min.js' %}"></script>
<script>
const vm = new Vue({
el: '#logs',
data() {
return {
names: [],
logs: []
}
},
beforeMount() {
},
mounted() {
{#this.chart = this.$refs.charts.chart#}
this.getLogs()
},
methods: {
getLogs() {
axios.get(
"{% url 'get_log_list' %}"
).then(res => {
console.log('获取数据列表成功', res.data)
{#let data = res.data#}
{#console.log(typeof res.data.data)#}
if (res.data.code === 0) {
this.names = res.data.data.names
console.log(this.logs)
//this.$message({
// type: 'success',
// message: res.data.msg
//});
} else {
this.loading = false
this.$message({
type: 'warning',
message: '获取数据列表失败!'
});
}
}).catch(res => {
console.log('获取数据列表失败', res)
this.$message({
type: 'warning',
message: '获取数据列表失败!' + res
});
})
},
showLog(name) {
console.log(name)
axios.get(
"{% url 'get_log_content' %}" + '?name=' + name
).then(res => {
console.log('获取数据列表成功', res.data)
{#let data = res.data#}
{#console.log(typeof res.data.data)#}
if (res.data.code === 0) {
this.logs = res.data.data.logs
console.log(this.logs)
//this.$message({
// type: 'success',
// message: res.data.msg
//});
} else {
this.loading = false
this.$message({
type: 'warning',
message: '获取数据列表失败!'
});
}
}).catch(res => {
console.log('获取数据列表失败', res)
this.$message({
type: 'warning',
message: '获取数据列表失败!' + res
});
})
},
}
})
</script>
</body>
</html>

View File

@@ -353,7 +353,6 @@
showLogo: true,
showLegend: true,
shuffle: false,
}
},
beforeMount() {

View File

@@ -1,10 +1,17 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
{% include 'admin/includes/css-part.html' %}
</head>
<body>
{% include 'admin/includes/js-part.html' %}
<script src="{% static 'admin/simpleui-x/js/axios.min.js' %}"></script>
</body>
</html>

View File

@@ -1,10 +1,17 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8">
<title>用户数据</title>
<title>Title</title>
{% include 'admin/includes/css-part.html' %}
</head>
<body>
{% include 'admin/includes/js-part.html' %}
<script src="{% static 'admin/simpleui-x/js/axios.min.js' %}"></script>
</body>
</html>