Jony/assets/js/joe.census.min.js
2021-05-25 10:37:56 +08:00

1 line
5.2 KiB
JavaScript

document.addEventListener("DOMContentLoaded",()=>{{const e=t=>{if(!t)return"0 B";const e=1e3,o=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],a=Math.floor(Math.log(t)/Math.log(e));return(t/Math.pow(e,a)).toPrecision(3)+" "+o[a]},o=t=>t<1024?parseInt(t)+" MB":parseInt(t/1024)+" GB",a=[],n=[],i=[],l=document.querySelector("#flow"),s=document.querySelector("#work"),r=l&&echarts.init(l),c=s&&echarts.init(s);function t(){$.ajax({url:Joe.BASE_API,type:"POST",dataType:"json",data:{routeType:"server_status"},success(l){l.status||Qmsg.warning("服务器接口异常!");{$(".joe_census__server-item .count .core").html(`${l.cpu[1]}`),$(".joe_census__server-item .count .ram").html(`${o(l.memory.memTotal)}`),$(".joe_census__server-item .count .up").html(`总发送:${e(l.upTotal)}`),$(".joe_census__server-item .count .down").html(`总接收:${e(l.downTotal)}`);const t=new Date,s=String(t.getHours()).padStart(2,0),c=String(t.getMinutes()).padStart(2,0),m=String(t.getSeconds()).padStart(2,0),d=`${s}:${c}:${m}`;a.push(d),n.push(l.up),i.push(l.down),a.length>5&&a.shift(),n.length>5&&n.shift(),i.length>5&&i.shift(),r.setOption({title:{subtext:"单位 KB/s"},grid:{left:"3%",right:"4%",bottom:"3%",containLabel:!0},tooltip:{trigger:"axis",axisPointer:{type:"cross",label:{backgroundColor:"#6a7985"}}},xAxis:{axisTick:{show:!1},type:"category",boundaryGap:!1,data:a},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:n},{type:"line",name:"下行",smooth:!0,showSymbol:!1,itemStyle:{normal:{color:"#9dd3e8",areaStyle:{color:"#9dd3e8"},lineStyle:{width:2,color:"#9dd3e8"}}},stack:"总量",data:i}]})}{const t=l.cpu[0],e=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,n=Math.round(l.load.one/l.load.max*100)>100?100:Math.round(l.load.one/l.load.max*100);c.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",max:100},series:{data:[{name:"CPU占用",value:t,itemStyle:{color:"#b3c25a"}},{name:"内存占用",value:e,itemStyle:{color:"#67b580"}},{name:"系统缓冲",value:a,itemStyle:{color:"#86ba71"}},{name:"内存缓冲",value:o,itemStyle:{color:"#feb041"}},{name:"系统负载",value:n,itemStyle:{color:"#fd7e55"}}],type:"bar",showBackground:!0,label:{show:!0,color:"#ffffff",formatter:t=>`${t.data.value}%`},backgroundStyle:{color:"rgba(180, 180, 180, 0.2)"}}})}setTimeout(t,2e3)}})}l&&s&&t()}{const t=document.querySelector("#category"),e=echarts.init(t),o=[];$(".joe_census__basic-item.category ul li").each((t,e)=>{o.push({name:e.getAttribute("data-name"),value:e.getAttribute("data-value")})}),e.setOption({tooltip:{trigger:"item"},series:[{type:"pie",roseType:"area",itemStyle:{borderRadius:8},data:o}]})}{const t=document.querySelector("#lately"),e=echarts.init(t);$.ajax({url:Joe.BASE_API,type:"POST",dataType:"json",data:{routeType:"comment_lately"},success(t){e.setOption({title:{subtext:"单位 数量"},tooltip:{trigger:"axis",axisPointer:{type:"cross",label:{backgroundColor:"#6a7985"}}},grid:{left:"3%",right:"3%",bottom:"3%",containLabel:!0},xAxis:{type:"category",axisTick:{show:!1},data:t.categories},yAxis:{type:"value"},series:{name:"数量",itemStyle:{normal:{color:"#91cc75",lineStyle:{width:2,color:"#91cc75"}}},data:t.series,type:"line",smooth:!0}})}})}{let t=0;function e(){"loading..."!==$(".joe_census__filing .button").html()&&$.ajax({url:Joe.BASE_API,type:"POST",dataType:"json",data:{routeType:"article_filing",page:++t},success(t){if(!t.length)return $(".joe_census__filing .item.load").remove(),Qmsg.warning("没有更多内容了");let e="";t.forEach(t=>{e+=`\n\t\t\t\t\t\t\t<div class="item">\n\t\t\t\t\t\t\t\t<div class="tail"></div>\n\t\t\t\t\t\t\t\t<div class="head"></div>\n\t\t\t\t\t\t\t\t<div class="wrapper">\n\t\t\t\t\t\t\t\t\t<div class="panel">${t.date}<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg"><path d="M21.6 772.8c28.8 28.8 74.4 28.8 103.2 0L512 385.6l387.2 387.2c28.8 28.8 74.4 28.8 103.2 0 28.8-28.8 28.8-74.4 0-103.2L615.2 282.4l-77.6-77.6c-14.4-14.4-37.6-14.4-51.2 0l-77.6 77.6L21.6 669.6c-28.8 28.8-28.8 75.2 0 103.2z" /></svg></div>\n\t\t\t\t\t\t\t\t\t<ol class="panel-body">\n\t\t\t\t\t\t\t\t\t\t${t.list.map(t=>`<li><a rel="noopener noreferrer" target="_blank" href="${t.permalink}">${t.title}</a></li>`).join("")}\n\t\t\t\t\t\t\t\t\t</ol>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t`}),$("#filing").append(e),$(".joe_census__filing .button").html("加载更多")}})}e(),$(".joe_census__filing .content").on("click",".panel",function(){const t=$(this).parents(".content");t.find(".panel").not($(this)).removeClass("in"),t.find(".panel-body").not($(this).siblings(".panel-body")).stop().hide("fast"),$(this).toggleClass("in").siblings(".panel-body").stop().toggle("fast")}),$(".joe_census__filing .button").on("click",function(){e(),$(this).html("loading...")})}});