This commit is contained in:
杜恒 2021-05-20 09:27:35 +08:00
parent 30d997bcca
commit 088c1b5400
16 changed files with 361 additions and 24 deletions

View File

@ -1 +1 @@
.joe_census__basic{display:grid;grid-template-columns:repeat(4, 1fr);gap:15px}.joe_census__basic-item{display:flex;align-items:center;justify-content:space-between;background:var(--background);box-shadow:var(--box-shadow);border-radius:var(--radius-inner) var(--radius-wrap) var(--radius-wrap) var(--radius-inner);padding:12px 15px}.joe_census__basic-item .count h6{font-size:12px;margin-bottom:10px;color:var(--seat)}.joe_census__basic-item .count p{font-size:22px;font-weight:700}.joe_census__basic-item .icon{fill:var(--classA)}.joe_census__basic-item:nth-child(1){border-left:5px solid #1cc88a;color:#1cc88a}.joe_census__basic-item:nth-child(2){border-left:5px solid #36b9cc;color:#36b9cc}.joe_census__basic-item:nth-child(3){border-left:5px solid #2196f3;color:#2196f3}.joe_census__basic-item:nth-child(4){border-left:5px solid #9c27b0;color:#9c27b0}
.joe_census__basic{display:grid;grid-template-columns:repeat(4, 1fr);gap:15px;margin-bottom:15px}.joe_census__basic-item{display:flex;align-items:center;justify-content:space-between;background:var(--background);box-shadow:var(--box-shadow);border-radius:var(--radius-inner) var(--radius-wrap) var(--radius-wrap) var(--radius-inner);padding:12px 15px}.joe_census__basic-item .count h6{font-size:12px;margin-bottom:10px;color:var(--seat)}.joe_census__basic-item .count p{font-size:22px;font-weight:700}.joe_census__basic-item .icon{fill:var(--classA)}.joe_census__basic-item:nth-child(1){border-left:5px solid #1cc88a;color:#1cc88a}.joe_census__basic-item:nth-child(2){border-left:5px solid #36b9cc;color:#36b9cc}.joe_census__basic-item:nth-child(3){border-left:5px solid #2196f3;color:#2196f3}.joe_census__basic-item:nth-child(4){border-left:5px solid #9c27b0;color:#9c27b0}.joe_census__server{display:grid;grid-template-columns:repeat(2, 1fr);gap:15px}.joe_census__server-item{background:var(--background);box-shadow:var(--box-shadow);border-radius:var(--radius-wrap)}.joe_census__server-item .title{display:flex;align-items:center;height:45px;padding:0 12px;border-bottom:1px solid var(--classD);color:var(--main);justify-content:space-between;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.joe_census__server-item .title .count{color:var(--minor);font-size:12px}.joe_census__server-item .title .count .split{margin:0 5px}.joe_census__server-item .content{padding:15px}.joe_census__server-item .content #work,.joe_census__server-item .content #flow{height:348px}

View File

@ -3,6 +3,7 @@
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 15px;
margin-bottom: 15px;
&-item {
display: flex;
align-items: center;
@ -43,4 +44,38 @@
}
}
}
&__server {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
&-item {
background: var(--background);
box-shadow: var(--box-shadow);
border-radius: var(--radius-wrap);
.title {
display: flex;
align-items: center;
height: 45px;
padding: 0 12px;
border-bottom: 1px solid var(--classD);
color: var(--main);
justify-content: space-between;
user-select: none;
.count {
color: var(--minor);
font-size: 12px;
.split {
margin: 0 5px;
}
}
}
.content {
padding: 15px;
#work,
#flow {
height: 348px;
}
}
}
}
}

View File

@ -1,3 +1,209 @@
document.addEventListener('DOMContentLoaded', () => {
console.log(1);
})
/* 转换字节 */
const bytesToSize = bytes => {
const k = 1024,
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
};
const categories = [];
const upSeries = [];
const downSeries = [];
const flowDom = document.querySelector('#flow');
const workDom = document.querySelector('#work');
const flowChart = flowDom && echarts.init(flowDom);
const workChart = workDom && echarts.init(workDom);
if (flowDom && workDom) initChart();
function initChart() {
$.ajax({
url: Joe.BASE_API,
type: 'POST',
dataType: 'json',
data: {
routeType: 'server_status'
},
success(res) {
{
$('.joe_census__server-item .count .up').html(`总发送:${bytesToSize(res.upTotal)}`);
$('.joe_census__server-item .count .down').html(`总接收:${bytesToSize(res.downTotal)}`);
const stamp = new Date();
const hours = String(stamp.getHours()).padStart(2, 0);
const minutes = String(stamp.getMinutes()).padStart(2, 0);
const seconds = String(stamp.getSeconds()).padStart(2, 0);
const time = `${hours}:${minutes}:${seconds}`;
categories.push(time);
upSeries.push(res.up);
downSeries.push(res.down);
if (categories.length > 5) categories.shift();
if (upSeries.length > 5) upSeries.shift();
if (downSeries.length > 5) downSeries.shift();
flowChart.setOption({
title: {
subtext: '单位 KB/s'
},
grid: {
left: '3%',
right: '4%',
bottom: '0',
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985'
}
}
},
xAxis: {
axisTick: {
show: false
},
type: 'category',
boundaryGap: false,
data: categories
},
yAxis: {
type: 'value'
},
series: [
{
type: 'line',
name: '上行',
smooth: true,
showSymbol: false,
itemStyle: {
normal: {
color: '#f39494',
areaStyle: {
color: '#f39494'
},
lineStyle: {
width: 2,
color: '#f39494'
}
}
},
stack: '总量',
data: upSeries
},
{
type: 'line',
name: '下行',
smooth: true,
showSymbol: false,
itemStyle: {
normal: {
color: '#9dd3e8',
areaStyle: {
color: '#9dd3e8'
},
lineStyle: {
width: 2,
color: '#9dd3e8'
}
}
},
stack: '总量',
data: downSeries
}
]
});
}
{
/* CPU占用 */
const cpuUse = res.cpu[0];
/* 内存占用 */
const memoryRealUse = Math.round((res.memory.memRealUsed / res.memory.memTotal) * 1000) / 10;
/* 内存缓冲 */
const memoryCacheUse = Math.round((res.memory.memCached / res.memory.memTotal) * 1000) / 10;
/* 系统缓冲 */
const memoryBufferUse = Math.round((res.memory.memBuffers / res.memory.memTotal) * 1000) / 10;
/* 系统负载 */
const systemLoad = Math.round((res.load.one / res.load.max) * 100) > 100 ? 100 : Math.round((res.load.one / res.load.max) * 100);
workChart.setOption({
title: {
subtext: '单位 百分比'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
left: '3%',
right: '3%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
axisTick: {
show: false
},
data: ['CPU占用', '内存占用', '系统缓冲', '内存缓冲', '系统负载']
},
yAxis: {
type: 'value'
},
series: {
data: [
{
name: 'CPU占用',
value: cpuUse,
itemStyle: {
color: '#b3c25a'
}
},
{
name: '内存占用',
value: memoryRealUse,
itemStyle: {
color: '#67b580'
}
},
{
name: '系统缓冲',
value: memoryBufferUse,
itemStyle: {
color: '#86ba71'
}
},
{
name: '内存缓冲',
value: memoryCacheUse,
itemStyle: {
color: '#feb041'
}
},
{
name: '系统负载',
value: systemLoad,
itemStyle: {
color: '#fd7e55'
}
}
],
type: 'bar',
showBackground: true,
label: {
show: true,
color: '#ffffff',
formatter: params => `${params.data.value} %`
},
backgroundStyle: {
color: 'rgba(180, 180, 180, 0.2)'
}
}
});
}
setTimeout(initChart, 2000);
}
});
}
});

View File

@ -1 +1 @@
document.addEventListener("DOMContentLoaded",()=>{console.log(1)});
document.addEventListener("DOMContentLoaded",()=>{function e(){$.ajax({url:Joe.BASE_API,type:"POST",dataType:"json",data:{routeType:"server_status"},success(l){{$(".joe_census__server-item .count .up").html(`总发送:${t(l.upTotal)}`),$(".joe_census__server-item .count .down").html(`总接收:${t(l.downTotal)}`);const e=new Date,n=String(e.getHours()).padStart(2,0),i=String(e.getMinutes()).padStart(2,0),m=String(e.getSeconds()).padStart(2,0),d=`${n}:${i}:${m}`;o.push(d),a.push(l.up),r.push(l.down),o.length>5&&o.shift(),a.length>5&&a.shift(),r.length>5&&r.shift(),s.setOption({title:{subtext:"单位 KB/s"},grid:{left:"3%",right:"4%",bottom:"0",containLabel:!0},tooltip:{trigger:"axis",axisPointer:{type:"cross",label:{backgroundColor:"#6a7985"}}},xAxis:{axisTick:{show:!1},type:"category",boundaryGap:!1,data:o},yAxis:{type:"value"},series:[{type:"line",name:"上行",smooth:!0,showSymbol:!1,itemStyle:{normal:{color:"#f39494",areaStyle:{color:"#f39494"},lineStyle:{width:2,color:"#f39494"}}},stack:"总量",data:a},{type:"line",name:"下行",smooth:!0,showSymbol:!1,itemStyle:{normal:{color:"#9dd3e8",areaStyle:{color:"#9dd3e8"},lineStyle:{width:2,color:"#9dd3e8"}}},stack:"总量",data:r}]})}{const e=l.cpu[0],t=Math.round(l.memory.memRealUsed/l.memory.memTotal*1e3)/10,o=Math.round(l.memory.memCached/l.memory.memTotal*1e3)/10,a=Math.round(l.memory.memBuffers/l.memory.memTotal*1e3)/10,r=Math.round(l.load.one/l.load.max*100)>100?100:Math.round(l.load.one/l.load.max*100);i.setOption({title:{subtext:"单位 百分比"},tooltip:{trigger:"axis",axisPointer:{type:"shadow"}},grid:{left:"3%",right:"3%",bottom:"3%",containLabel:!0},xAxis:{type:"category",axisTick:{show:!1},data:["CPU占用","内存占用","系统缓冲","内存缓冲","系统负载"]},yAxis:{type:"value"},series:{data:[{name:"CPU占用",value:e,itemStyle:{color:"#b3c25a"}},{name:"内存占用",value:t,itemStyle:{color:"#67b580"}},{name:"系统缓冲",value:a,itemStyle:{color:"#86ba71"}},{name:"内存缓冲",value:o,itemStyle:{color:"#feb041"}},{name:"系统负载",value:r,itemStyle:{color:"#fd7e55"}}],type:"bar",showBackground:!0,label:{show:!0,color:"#ffffff",formatter:e=>`${e.data.value} %`},backgroundStyle:{color:"rgba(180, 180, 180, 0.2)"}}})}setTimeout(e,2e3)}})}const t=e=>{const t=1024,o=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],a=Math.floor(Math.log(e)/Math.log(t));return(e/Math.pow(t,a)).toPrecision(3)+" "+o[a]},o=[],a=[],r=[],l=document.querySelector("#flow"),n=document.querySelector("#work"),s=l&&echarts.init(l),i=n&&echarts.init(n);l&&n&&e()});

View File

@ -327,6 +327,7 @@ document.addEventListener('DOMContentLoaded', () => {
const type = $('.joe_comment__respond-form').attr('data-type');
const parent = $('.joe_comment__respond-form').attr('data-coid');
const author = $(".joe_comment__respond-form .head input[name='author']").val();
const _ = $(".joe_comment__respond-form input[name='_']").val();
const mail = $(".joe_comment__respond-form .head input[name='mail']").val();
let text = $(".joe_comment__respond-form .body textarea[name='text']").val();
if (author.trim() === '') return Qmsg.info('请输入昵称!');
@ -346,7 +347,7 @@ document.addEventListener('DOMContentLoaded', () => {
$.ajax({
url,
type: 'POST',
data: { author, mail, text, parent, captcha },
data: { author, mail, text, parent, captcha, _ },
dataType: 'text',
success(res) {
let arr = [],
@ -364,9 +365,9 @@ document.addEventListener('DOMContentLoaded', () => {
}
},
error() {
isSubmit = false
isSubmit = false;
$('.joe_comment__respond-form .foot .submit button').html('发表评论');
Qmsg.warning('发送失败!请刷新重试!')
Qmsg.warning('发送失败!请刷新重试!');
}
});
});

File diff suppressed because one or more lines are too long

View File

@ -25,6 +25,7 @@
<div class="joe_container">
<div class="joe_main">
<?php Typecho_Widget::widget('Widget_Stat')->to($item); ?>
<!-- 基础统计 -->
<div class="joe_census__basic">
<div class="joe_census__basic-item">
<div class="count">
@ -65,6 +66,29 @@
</svg>
</div>
</div>
<?php if ($this->options->JBTPanel && $this->options->JBTKey) : ?>
<div class="joe_census__server">
<div class="joe_census__server-item">
<div class="title">实时负载</div>
<div class="content">
<div id="work"></div>
</div>
</div>
<div class="joe_census__server-item">
<div class="title">
<span>实时流量</span>
<div class="count">
<span class="up">总发送0 B</span>
<span class="split">/</span>
<span class="down">总接收0 B</span>
</div>
</div>
<div class="content">
<div id="flow"></div>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php $this->need('public/footer.php'); ?>

View File

@ -21,8 +21,6 @@ _startCountTime();
/* 主题初始化 */
function themeInit($self)
{
/* 强制用户关闭反垃圾保护 */
Helper::options()->commentsAntiSpam = false;
/* 强制用户要求填写邮箱 */
Helper::options()->commentsRequireMail = true;
/* 强制用户要求无需填写url */
@ -63,6 +61,9 @@ function themeInit($self)
case 'huya_list':
_getHuyaList($self);
break;
case 'server_status':
_getServerStatus($self);
break;
};
}

View File

@ -2,7 +2,7 @@
/* 获取主题当前版本号 */
function _getVersion()
{
return "6.9.8";
return "6.9.9";
};
/* 判断是否是手机 */
@ -157,7 +157,7 @@ function _endCountTime($precision = 3)
/* 通过邮箱生成头像地址 */
function _getAvatarByMail($mail)
{
$gravatarsUrl = Helper::options()->JCustomAvatarSource ? Helper::options()->JCustomAvatarSource : 'https://gravatar.helingqi.com/wavatar/';
$gravatarsUrl = Helper::options()->JCustomAvatarSource ? Helper::options()->JCustomAvatarSource : 'https://gravatar.ihuan.me/avatar/';
$mailLower = strtolower($mail);
$md5MailLower = md5($mailLower);
$qqMail = str_replace('@qq.com', '', $mailLower);

View File

@ -293,3 +293,49 @@ function _getHuyaList($self)
]);
}
}
function _getServerStatus($self)
{
header("HTTP/1.1 200 OK");
header('Access-Control-Allow-Origin:*');
header("Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept");
$api_panel = Helper::options()->JBTPanel;
$api_sk = Helper::options()->JBTKey;
if (!$api_panel) return $self->response->throwJson([
"code" => 0,
"data" => "宝塔面板地址未填写!"
]);
if (!$api_sk) return $self->response->throwJson([
"code" => 0,
"data" => "宝塔接口密钥未填写!"
]);
$request_time = time();
$request_token = md5($request_time . '' . md5($api_sk));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_panel . '/system?action=GetNetWork');
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("request_time" => $request_time, "request_token" => $request_token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
$self->response->throwJson(array(
/* 上行流量KB */
"up" => $response["up"],
/* 下行流量KB */
"down" => $response["down"],
/* 总发送(字节数) */
"upTotal" => $response["upTotal"],
/* 总接收(字节数) */
"downTotal" => $response["downTotal"],
/* 内存占用 */
"memory" => $response["mem"],
/* CPU */
"cpu" => $response["cpu"],
/* 系统负载 */
"load" => $response["load"],
));
}

View File

@ -351,8 +351,8 @@ function themeConfig($form)
NULL,
'自定义头像源(非必填)',
'介绍:用于修改全站头像源地址 <br>
例如https://gravatar.ihuan.me/avatar/ <br>
其他:非必填,默认头像源为禾令奇 <br>
例如https://gravatar.helingqi.com/wavatar/ <br>
其他:非必填,默认头像源为gravatar.ihuan.me <br>
注意:填写时,务必保证最后有一个/字符,否则不起作用!'
);
$JCustomAvatarSource->setAttribute('class', 'joe_content joe_global');
@ -836,6 +836,30 @@ function themeConfig($form)
$JSiteMap->setAttribute('class', 'joe_content joe_other');
$form->addInput($JSiteMap->multiMode());
$JBTPanel = new Typecho_Widget_Helper_Form_Element_Text(
'JBTPanel',
NULL,
NULL,
'宝塔面板地址',
'介绍:用于统计页面获取服务器状态使用 <br>
例如http://192.168.1.245:8888/ <br>
注意:结尾需要带有一个 / 字符!<br>
该功能需要去宝塔面板开启开放API并添加白名单才可使用'
);
$JBTPanel->setAttribute('class', 'joe_content joe_other');
$form->addInput($JBTPanel->multiMode());
$JBTKey = new Typecho_Widget_Helper_Form_Element_Text(
'JBTKey',
NULL,
NULL,
'宝塔开放接口密钥',
'介绍:用于统计页面获取服务器状态使用 <br>
例如thVLXFtUCCNzBShBweKTPBmw8296q8R8 <br>
该功能需要去宝塔面板开启开放API并添加白名单才可使用'
);
$JBTKey->setAttribute('class', 'joe_content joe_other');
$form->addInput($JBTKey->multiMode());
/* 评论发信 */
$JCommentMail = new Typecho_Widget_Helper_Form_Element_Select(

View File

@ -1,6 +1,6 @@
{
"name": "typecho-joe-next",
"version": "6.9.8",
"version": "6.9.9",
"description": "A Theme Of Typecho",
"main": "index.php",
"keywords": [

View File

@ -12,7 +12,7 @@
</div>
<?php else : ?>
<?php if ($this->allow('comment')) : ?>
<div class="joe_comment__respond">
<div id="<?php $this->respondId(); ?>" class="joe_comment__respond">
<div class="joe_comment__respond-type">
<button class="item" data-type="draw">画图模式</button>
<button class="item active" data-type="text">文本模式</button>

View File

@ -18,7 +18,7 @@
<?php endif; ?>
<link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/joe.mode.min.css'); ?>">
<link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/joe.normalize.min.css'); ?>">
<link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/joe.global.min.css?v=20210517'); ?>">
<link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/joe.global.min.css'); ?>">
<link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/joe.responsive.min.css'); ?>">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typecho-joe-next@6.0.0/plugin/qmsg/qmsg.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
@ -40,6 +40,6 @@
<?php if ($this->options->JCursorEffects && $this->options->JCursorEffects !== 'off') : ?>
<script src="<?php $this->options->themeUrl('assets/cursor/' . $this->options->JCursorEffects); ?>" async></script>
<?php endif; ?>
<script src="<?php $this->options->themeUrl('assets/js/joe.global.min.js?v=20210517'); ?>"></script>
<script src="<?php $this->options->themeUrl('assets/js/joe.global.min.js?v=20210520'); ?>"></script>
<script src="<?php $this->options->themeUrl('assets/js/joe.short.min.js'); ?>"></script>
<?php $this->options->JCustomHeadEnd() ?>

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
"dependencies": {
"@codemirror/closebrackets": "^0.18.0",
"@codemirror/commands": "^0.18.2",
"@codemirror/highlight": "^0.18.3",
"@codemirror/highlight": "^0.18.4",
"@codemirror/history": "^0.18.1",
"@codemirror/lang-markdown": "^0.18.2",
"@codemirror/matchbrackets": "^0.18.0",