优化后台首页显示

This commit is contained in:
hdm 2021-10-29 08:59:52 +08:00
parent 89fb136559
commit de7816122f
3 changed files with 488 additions and 404 deletions

View File

@ -223,6 +223,21 @@ function hour_document($arrData)
return $documents;
}
//访问按日期归档统计
function date_document($arrData)
{
$documents = array();
foreach ($arrData as $index => $value) {
$archivesTime = date("Y-m-d", $value['create_time']);
if (empty($documents[$archivesTime])) {
$documents[$archivesTime] = 1;
} else {
$documents[$archivesTime] += 1;
}
}
return $documents;
}
/**
* 管理员操作日志
* @param string $type 操作类型 login add edit view delete

View File

@ -304,14 +304,19 @@ class Api extends BaseController
{
$param = get_params();
$first_time = time();
$second_time = time() - 86400;
$second_time = $first_time - 86400;
$three_time = $first_time - 86400*365;
$begin_first = strtotime(date('Y-m-d', $first_time) . " 00:00:00");
$end_first = strtotime(date('Y-m-d', $first_time) . " 23:59:59");
$begin_second = strtotime(date('Y-m-d', $second_time) . " 00:00:00");
$end_second = strtotime(date('Y-m-d', $second_time) . " 23:59:59");
$begin_three = strtotime(date('Y-m-d', $three_time) . " 00:00:00");
$data_first = Db::name('UserLog')->field('create_time')->whereBetween('create_time', "$begin_first,$end_first")->select();
$data_second = Db::name('UserLog')->field('create_time')->whereBetween('create_time', "$begin_second,$end_second")->select();
return to_assign(0, '', ['data_first' => hour_document($data_first), 'data_second' => hour_document($data_second)]);
$data_three = Db::name('UserLog')->field('create_time')->whereBetween('create_time', "$begin_three,$end_first")->select();
return to_assign(0, '', ['data_first' => hour_document($data_first), 'data_second' => hour_document($data_second), 'data_three'=>date_document($data_three)]);
}
}

View File

@ -2,35 +2,18 @@
{block name="style"}
<style type="text/css">
.clearfix {
display: block;
.table-title {
font-size: 18px;
font-weight: 800;
padding: 15px 0 5px 15px;
}
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
* html .clearfix {
height: 0.1%;
}
.panel-right {
border-bottom: 1px solid #e8e8e8;
padding: 0 20px 20px;
}
.panel-num table {
width: 100%;
}
.panel-num td {
text-align: center;
padding: 20px 0;
width: 16.6%;
width: 20%;
border-bottom: 1px solid #eee;
border-left: 1px solid #eee
}
@ -46,24 +29,20 @@
color: #009688;
}
.latest-news {
padding-top: 12px;
padding-bottom: 30px;
position: relative;
}
.latest-news .layui-timeline-title {
.layui-timeline-title {
padding-bottom: 0;
}
.latest-news .layui-timeline-item {
.layui-timeline-item {
padding-bottom: 1px;
}
.layui-timeline-title span {
color: #999
}
.layui-timeline{
padding-bottom: 30px;
}
.panel-more {
width: 100%;
height: 48px;
@ -72,103 +51,22 @@
position: absolute;
bottom: 0;
left: 0;
background: linear-gradient(rgba(225, 225, 225, 0), rgba(225, 225, 225, .8));
background: linear-gradient(rgba(225, 225, 225, 0), rgba(225, 225, 225, .9));
}
.panel-more a {
color: #0088FF
}
.index-row {
margin-right: 351px;
}
.panel {
padding: 0 20px;
background-color: #fff;
}
.panel-title {
font-size: 18px;
font-weight: 800;
padding: 20px 0 15px;
}
.table-title {
font-size: 18px;
font-weight: 800;
padding: 20px 0 5px;
}
.row-right {
width: 350px;
float: right;
border-left: 1px solid #e8e8e8;
background-color: #f7f7f7;
}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<div style="background-color: #fff;">
<div class="row-right">
<div class="panel-right">
<div class="table-title">最新动态</div>
<div class="latest-news">
<ul class="layui-timeline" id="logs">
</ul>
<div class="panel-more"><a href="/admin/api/log_list/">查看更多动态</a></div>
</div>
</div>
<div class="panel-right">
<div class="table-title">系统信息</div>
<table class="layui-table" lay-skin="" lay-size="sm">
{if condition="($install == true)"}
<tr>
<td colspan="2" style="color: #E94335;">提醒发现app目录下的install文件夹没删除为了系统的安全,请手动去删除。</td>
</tr>
{/if}
<tr>
<td><b>服务器系统</b></td>
<td>{:get_system_info('os')}</td>
</tr>
<tr>
<td><b>PHP版本</b></td>
<td>{:get_system_info('php')}</td>
</tr>
<tr>
<td><b>系统版本</b></td>
<td>{:CMS_VERSION}</td>
</tr>
<tr>
<td><b>ThinkPHP版本</b></td>
<td>{:TP_VERSION}<a class="layui-badge layui-bg-blue" style="margin-left:20px"
href="https://www.kancloud.cn/manual/thinkphp6_0" target="_blank">TP6文档</a></td>
</tr>
<tr>
<td><b>Layui版本</b></td>
<td>{:LAYUI_VERSION}<a class="layui-badge layui-bg-blue" style="margin-left:20px" href="https://www.layui.com/doc/"
target="_blank">Layui文档</a></td>
</tr>
<tr>
<td><b>上传附件限制</b></td>
<td>{:get_system_info('upload_max_filesize')}</td>
</tr>
<tr>
<td><b>执行时间限制</b></td>
<td>{:get_system_info('max_execution_time')}</td>
</tr>
<tr>
<td><b>BUG反馈</b></td>
<td><a href="mailto:hdm58@qq.com" target="_blank">hdm58@qq.com</a></td>
</tr>
</table>
</div>
</div>
<div class="index-row">
<div class="panel-num">
<div class="layui-row layui-col-space10">
<div class="layui-col-md8">
<div class="layui-row layui-col-space10">
<div class="layui-col-md12">
<div class="layui-card panel-num">
<table>
<tr>
<td>
@ -194,39 +92,83 @@
</tr>
</table>
</div>
<div class="panel">
<div class="layui-card">
<div class="table-title">注册用户</div>
<table id="UserList" class="layui-table layui-table-view">
<thead>
<tr>
<th>用户名</th>
<th>头像</th>
<th>登录次数</th>
<th>最后登录时间</th>
</tr>
</thead>
</table>
<div style="clear: left;"></div>
<div style="padding: 0 15px 5px;">
<table id="UserList" lay-filter="UserList" class="layui-hide"></table>
</div>
<div class="panel">
</div>
<div class="layui-card">
<div class="table-title">文章列表</div>
<table id="Article" class="layui-table layui-table-view">
<thead>
<div style="padding: 0 15px 5px;">
<table id="Article" lay-filter="Article" class="layui-hide" style="margin-top:0"></table>
</div>
</div>
<div class="layui-card">
<div id="chartView" style="width: 100%;height:300px;"></div>
</div>
<div class="layui-card">
<div id="chartYear" style="width: 100%;height:240px;"></div>
</div>
</div>
</div>
</div>
<div class="layui-col-md4">
<div class="layui-card">
<div class="table-title">系统信息</div>
<div class="layui-card-body">
<table class="layui-table" lay-skin="" lay-size="sm">
{if condition="($install == true)"}
<tr>
<th>文章标题</th>
<th>文章分类</th>
<th>发布时间</th>
<td colspan="2" style="color: #E94335;">提醒发现app目录下的install文件夹没删除为了系统的安全,请手动去删除。</td>
</tr>
{/if}
<tr>
<td><b>服务器系统</b></td>
<td>{:get_system_info('os')}</td>
</tr>
<tr>
<td><b>PHP版本</b></td>
<td>{:get_system_info('php')}</td>
</tr>
<tr>
<td><b>勾股博客版本</b></td>
<td>{:CMS_VERSION}<a class="layui-badge layui-bg-blue" style="margin-left:20px"
href="https://www.gougucms.com/" target="_blank">勾股CMS</a></td>
</tr>
<tr>
<td><b>ThinkPHP版本</b></td>
<td>{:TP_VERSION}<a class="layui-badge layui-bg-blue" style="margin-left:20px"
href="https://www.kancloud.cn/manual/thinkphp6_0" target="_blank">TP6文档</a></td>
</tr>
<tr>
<td><b>Layui版本</b></td>
<td>{:LAYUI_VERSION}<a class="layui-badge layui-bg-blue" style="margin-left:20px"
href="https://www.layui.site/doc/" target="_blank">Layui文档</a></td>
</tr>
<tr>
<td><b>上传附件限制</b></td>
<td>{:get_system_info('upload_max_filesize')}</td>
</tr>
<tr>
<td><b>执行时间限制</b></td>
<td>{:get_system_info('max_execution_time')}</td>
</tr>
<tr>
<td><b>BUG反馈</b></td>
<td><a href="mailto:hdm58@qq.com" target="_blank">hdm58@qq.com</a></td>
</tr>
</thead>
</table>
<div style="clear: left;"></div>
</div>
<div class="panel">
<div class="table-title">访问统计</div>
<div id="chartView" style="width: 100%;height:396px;"></div>
</div>
</div>
<div style="clear: right;"></div>
<div class="layui-card">
<div class="table-title">操作日志</div>
<div class="layui-card-body">
<ul class="layui-timeline" id="logs"></ul>
<div class="panel-more"><a href="/admin/api/log_list/">查看更多日志</a></div>
</div>
</div>
</div>
</div>
{/block}
<!-- /主体 -->
@ -241,7 +183,7 @@
type: 'post',
data: {
page: 1,
limit: 10
limit: 20
},
success: function (e) {
if (e.code == 0) {
@ -250,7 +192,7 @@
html += '<li class="layui-timeline-item">\
<i class="layui-icon layui-timeline-axis"></i>\
<div class="layui-timeline-content layui-text">\
<div class="layui-timeline-title"><span title="'+value.id+'">'+ value.times + '</span>' + value.content + '</div>\
<div class="layui-timeline-title"><span title="'+ value.id + '">' + value.times + '</span>' + value.content + '</div>\
</div>\
</li>';
});
@ -260,74 +202,63 @@
})
}
function getUsers() {
$.ajax({
url: "/admin/api/get_user_list",
type: 'post',
success: function (e) {
if (e.code == 0) {
var html = '';
if(e.data.length==0){
html +='<tr>\
<td colspan="4" style="padding:10px 0; color:#999; text-align:center;">暂无用户</td>\
</tr>';
function init(layui) {
var layer = layui.layer, table = layui.table;
getLogs();
//注册用户
table.render({
elem: '#UserList'
, url: '/admin/api/get_user_list' //数据接口
, page: false //开启分页
, cols: [[ //表头
{ field: 'username', title: '用户名'}
,{ field: 'username', title: '昵称', align: 'center', 'width': 120}
,{ field: 'sex', title: '性别','width': 60, align: 'center', templet: function (d) {
let str='-';
if(d.sex==1){
str='男';
}
else{
$.each(e.data, function (key, value) {
html += '<tr>\
<td>'+value.username+'</td>\
<td>\
<img src="' + value.headimgurl + '" width="20" height="20" />\
</td>\
<td>'+value.login_num+'</td>\
<td>'+value.last_login_time+'</td>\
</tr>';
});
}
$('#UserList').append(html);
}
}
})
}
function getArticles() {
$.ajax({
url: "/admin/api/get_article_list",
type: 'post',
success: function (e) {
if (e.code == 0) {
var html = '';
if(e.data.length==0){
html +='<tr>\
<td colspan="3" style="padding:10px 0; color:#999; text-align:center;">暂无文章</td>\
</tr>';
}
else{
$.each(e.data, function (key, value) {
html += '<tr>\
<td>'+value.title+'</td>\
<td>' + value.cate_title + '</td>\
<td>'+value.create_time+'</td>\
</tr>';
});
}
$('#Article').append(html);
}
}
})
}
var echartsTheme={color:["#1AAD19","#1890FF","#5FB878","#FFB980","#D87A80","#8d98b3","#e5cf0d","#97b552","#95706d","#dc69aa","#07a2a4","#9a7fd1","#588dd5","#f5994e","#c05050","#59678c","#c9ab00","#7eb00a","#6f5553","#c14089"],title:{textStyle:{fontWeight:"normal",color:"#666"}},dataRange:{itemWidth:15,color:["#009688","#e0ffff"]},toolbox:{color:["#1e90ff","#1e90ff","#1e90ff","#1e90ff"],effectiveColor:"#ff4500"},tooltip:{axisPointer:{type:"line",lineStyle:{color:"#999"},crossStyle:{color:"#008acd"},shadowStyle:{color:"rgba(200,200,200,0.2)"}}},dataZoom:{dataBackgroundColor:"#efefff",fillerColor:"rgba(182,162,222,0.2)",handleColor:"#008acd"},grid:{borderColor:"#eee"},categoryAxis:{axisLine:{lineStyle:{color:"#555555"}},axisTick:{show:!1},splitLine:{lineStyle:{color:["#eee"]}}},valueAxis:{axisLine:{lineStyle:{color:"#555555"}},splitArea:{show:!0,areaStyle:{color:["rgba(250,250,250,0.1)","rgba(200,200,200,0.1)"]}},splitLine:{lineStyle:{color:["#eee"]}}},polar:{axisLine:{lineStyle:{color:"#ddd"}},splitArea:{show:!0,areaStyle:{color:["rgba(250,250,250,0.2)","rgba(200,200,200,0.2)"]}},splitLine:{lineStyle:{color:"#ddd"}}},timeline:{lineStyle:{color:"#009688"},controlStyle:{normal:{color:"#009688"},emphasis:{color:"#009688"}},symbol:"emptyCircle",symbolSize:3},bar:{itemStyle:{normal:{barBorderRadius:2},emphasis:{barBorderRadius:2}}},line:{smooth:!0,symbol:"emptyCircle",symbolSize:8},k:{itemStyle:{normal:{color:"#d87a80",color0:"#2ec7c9",lineStyle:{color:"#d87a80",color0:"#2ec7c9"}}}},scatter:{symbol:"circle",symbolSize:4},radar:{symbol:"emptyCircle",symbolSize:3},map:{itemStyle:{normal:{areaStyle:{color:"#ddd"},label:{textStyle:{color:"#d87a80"}}},emphasis:{areaStyle:{color:"#fe994e"}}}},force:{itemStyle:{normal:{linkStyle:{color:"#1e90ff"}}}},chord:{itemStyle:{normal:{borderWidth:1,borderColor:"rgba(128, 128, 128, 0.5)",chordStyle:{lineStyle:{color:"rgba(128, 128, 128, 0.5)"}}},emphasis:{borderWidth:1,borderColor:"rgba(128, 128, 128, 0.5)",chordStyle:{lineStyle:{color:"rgba(128, 128, 128, 0.5)"}}}}},gauge:{axisLine:{lineStyle:{color:[[.2,"#2ec7c9"],[.8,"#5ab1ef"],[1,"#d87a80"]],width:10}},axisTick:{splitNumber:10,length:15,lineStyle:{color:"auto"}},splitLine:{length:22,lineStyle:{color:"auto"}},pointer:{width:5}},textStyle:{fontFamily:"微软雅黑, Arial, Verdana, sans-serif"}};
function setHour(num){
var str= num+':00';
if(num<10){
str='0'+num+':00';
else if(d.sex==2){
str='女';
}
return str;
}
var chartView = echarts.init(document.getElementById('chartView'),echartsTheme);
function get_view_data() {
$.ajax({
}}
, {
field: 'headimgurl', title: '头像', align: 'center','width': 60, templet: function (d) {
return '<img src="' + d.headimgurl + '" width="20" height="20" />';
}
}
, { field: 'login_num', title: '登录次数', align: 'center','width': 100}
, { field: 'last_login_time', title: '最后登录时间', align: 'center','width': 168}
]]
});
//文章
table.render({
elem: '#Article'
, url: '/admin/api/get_article_list' //数据接口
, page: false //开启分页
, cols: [[ //表头
{ field: 'title', title: '文章标题'}
, { field: 'cate_title', title: '文章分类', align: 'center','width': 150 }
, { field: 'read', title: '访问量', align: 'center','width': 100 }
, { field: 'create_time', title: '发布时间', align: 'center','width': 168}
]]
});
get_view_data();
}
function setHour(num) {
var str = num + ':00';
if (num < 10) {
str = '0' + num + ':00';
}
return str;
}
var chartView = echarts.init(document.getElementById('chartView'));
function get_view_data() {
$.ajax({
url: "/admin/api/get_view_data",
type: 'post',
data: {},
@ -335,13 +266,14 @@ $.ajax({
if (e.code == 0) {
var data_first = e.data.data_first;
var data_second = e.data.data_second;
archiveCalendar = e.data.data_three;
var myDate = new Date();
var nowHour = myDate.getHours(); //获取当前小时数(0-23)
var xData=[];
var yData1=[];
var yData2=[];
var xData = [];
var yData1 = [];
var yData2 = [];
$.each(data_first, function (key, value) {
if(key<=nowHour){
if (key <= nowHour) {
yData1.push(value);
}
});
@ -349,12 +281,21 @@ $.ajax({
xData.push(setHour(key));
yData2.push(value);
});
var ops= {
color:["#1AAD19","#1890FF"],
var ops = {
title: {
top: '15px',
text: '今日与昨日访问统计',
left: '12px',
textStyle: {
fontSize: '18',
color: '#333',
}
},
color: ["#1AAD19", "#1890FF"],
grid: {
left: '10px',
right: '20px',
bottom: '20px',
left: '20px',
right: '30px',
bottom: '15px',
top: '60px',
containLabel: true
},
@ -371,15 +312,29 @@ $.ajax({
show: true,
},
legend: {
data: ["今日", "昨日"]
data: ["今日", "昨日"],
top: '18px',
},
xAxis: [{
type: "category",
boundaryGap: !1,
data: xData
data: xData,
axisLine: {
lineStyle: {
color: '#999999',
width: 1,
}
},
}],
yAxis: [{
type: "value"
type: "value",
axisLine: {
show: true,
lineStyle: {
color: '#999999',
width: 1,
}
},
}],
series: [{
name: "今日",
@ -389,7 +344,7 @@ $.ajax({
normal: {
areaStyle: {
type: "default",
opacity:0.2
opacity: 0.2
}
}
},
@ -402,7 +357,7 @@ $.ajax({
normal: {
areaStyle: {
type: "default",
opacity:0.2
opacity: 0.2
}
}
},
@ -410,26 +365,135 @@ $.ajax({
}]
}
chartView.setOption(ops);
setTimeout(function() {
window.onresize = function() {
let myChart = echarts.init(document.getElementById('chartYear'));
let option = {
title: {
top: '15px',
text: '近一年访问统计',
left: '12px',
textStyle: {
fontSize: '18',
color: '#333',
}
},
tooltip: {
padding: 6,
formatter: function (obj) {
var value = obj.value;
return '<div style="font-size: 12px;">' + value[0] + '' + value[1] + ' 个访客</div>';
}
},
visualMap: {
min: 0,
max: 300,
show: false,
inRange: {
color: ['#fafafa', '#1AAD19']
}
},
calendar: {
top: 75,
left: 52,
right: 20,
range: getRange(),
cellSize: ['auto', 21],
splitLine: {
lineStyle: {
color: '#aaa',
type: 'dashed'
}
},
itemStyle: {
borderWidth: 0.5
},
yearLabel: { show: false },
monthLabel: {
nameMap: 'cn',
fontSize: 12
},
dayLabel: {
show: true,
formatter: '{start} 1st',
fontWeight: 'lighter',
nameMap: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
fontSize: 12
}
},
series: [{
type: 'heatmap',
coordinateSystem: 'calendar',
calendarIndex: 0,
data: getDay()
}]
};
myChart.setOption(option);
setTimeout(function () {
window.onresize = function () {
chartView.resize();
myChart.resize();
}
})
console.log(e.data);
}
}
})
}
})
function init(layui) {
var layer = layui.layer, table = layui.table;
getLogs();
getUsers();
getArticles();
get_view_data();
var archiveCalendar = {};
function getRange() {
let today = new Date();
let tYear = today.getFullYear();
let tMonth = today.getMonth() + 1;
let tDate = today.getDate();
let dateFirst = tYear + "-" + tMonth + "-" + tDate;
let datelast = (tYear - 1) + "-" + tMonth + "-" + tDate;
let dataRange = [];
dataRange.push(dateFirst);
dataRange.push(datelast);
return dataRange;
}
function getDay() {
var today = new Date();
var dayArray = [];
for (var i = 0; i < 366; i++) {
var targetday_milliseconds = today.getTime() - 1000 * 60 * 60 * 24 * i;
var date = new Date(targetday_milliseconds);
dayArray.push(retunDay(date));
}
return dayArray;
}
function retunDay(day) {
var tYear = day.getFullYear();
var tMonth = day.getMonth();
var tDate = day.getDate();
tMonth = tMonth + 1;
if (tMonth.toString().length == 1) {
tMonth = "0" + tMonth;
}
if (tDate.toString().length == 1) {
tDate = "0" + tDate;
}
var dateStr = tYear + "-" + tMonth + "-" + tDate;
var dateArray = [];
dateArray.push(dateStr);
if (archiveCalendar[dateStr]) {
dateArray.push(archiveCalendar[dateStr]);
}
else {
dateArray.push(0);
}
return dateArray;
}
}
</script>
{include file="common/layui" base="base" extend="[]" callback="init" /}
{include file="common/layui" base='base' extend="[]" callback="init" /}
{/block}
<!-- /脚本 -->