Files
EdgeAdmin/web/views/@default/dashboard/index.js

152 lines
3.0 KiB
JavaScript
Raw Normal View History

2021-01-21 18:55:53 +08:00
Tea.context(function () {
2021-05-11 22:47:21 +08:00
this.trafficTab = "hourly"
2021-01-21 18:55:53 +08:00
2021-05-11 22:47:21 +08:00
this.$delay(function () {
this.reloadHourlyTrafficChart()
})
2021-01-21 18:55:53 +08:00
2021-05-11 22:47:21 +08:00
this.selectTrafficTab = function (tab) {
this.trafficTab = tab
if (tab == "hourly") {
this.$delay(function () {
this.reloadHourlyTrafficChart()
})
} else if (tab == "daily") {
this.$delay(function () {
this.reloadDailyTrafficChart()
})
}
}
2021-01-21 18:55:53 +08:00
2021-05-11 22:47:21 +08:00
this.reloadHourlyTrafficChart = function () {
2021-07-11 11:09:41 +08:00
let axis = teaweb.bytesAxis(this.hourlyTrafficStats, function (v) {
return v.bytes
})
2021-05-11 22:47:21 +08:00
let chartBox = document.getElementById("hourly-traffic-chart-box")
2021-07-21 08:07:46 +08:00
let chart = teaweb.initChart(chartBox)
2021-07-11 11:09:41 +08:00
let that = this
2021-05-11 22:47:21 +08:00
let option = {
xAxis: {
data: this.hourlyTrafficStats.map(function (v) {
return v.hour;
})
},
2021-07-11 11:09:41 +08:00
yAxis: {
axisLabel: {
formatter: function (v) {
return v + axis.unit
}
}
},
2021-05-11 22:47:21 +08:00
tooltip: {
show: true,
trigger: "item",
2021-07-11 11:09:41 +08:00
formatter: function (args) {
let index = args.dataIndex
return that.hourlyTrafficStats[index].hour + "时:" + teaweb.formatBytes(that.hourlyTrafficStats[index].bytes)
}
2021-05-11 22:47:21 +08:00
},
grid: {
left: 40,
top: 10,
right: 20
},
series: [
{
name: "流量",
type: "line",
data: this.hourlyTrafficStats.map(function (v) {
2021-07-11 11:09:41 +08:00
return v.bytes / axis.divider;
2021-05-11 22:47:21 +08:00
}),
itemStyle: {
color: "#9DD3E8"
},
lineStyle: {
color: "#9DD3E8"
},
areaStyle: {
color: "#9DD3E8"
2021-07-26 14:32:24 +08:00
},
smooth: true
2021-05-11 22:47:21 +08:00
}
],
animation: false
}
chart.setOption(option)
chart.resize()
}
2021-01-24 14:41:43 +08:00
2021-05-11 22:47:21 +08:00
this.reloadDailyTrafficChart = function () {
2021-07-11 11:09:41 +08:00
let axis = teaweb.bytesAxis(this.dailyTrafficStats, function (v) {
return v.bytes
})
2021-05-11 22:47:21 +08:00
let chartBox = document.getElementById("daily-traffic-chart-box")
2021-07-21 08:07:46 +08:00
let chart = teaweb.initChart(chartBox)
2021-07-11 11:09:41 +08:00
let that = this
2021-05-11 22:47:21 +08:00
let option = {
xAxis: {
data: this.dailyTrafficStats.map(function (v) {
return v.day;
})
},
2021-07-11 11:09:41 +08:00
yAxis: {
axisLabel: {
formatter: function (v) {
return v + axis.unit
}
}
},
2021-05-11 22:47:21 +08:00
tooltip: {
show: true,
trigger: "item",
2021-07-11 11:09:41 +08:00
formatter: function (args) {
let index = args.dataIndex
return that.dailyTrafficStats[index].day + "" + teaweb.formatBytes(that.dailyTrafficStats[index].bytes)
}
2021-05-11 22:47:21 +08:00
},
grid: {
left: 40,
top: 10,
right: 20
},
series: [
{
name: "流量",
type: "line",
data: this.dailyTrafficStats.map(function (v) {
2021-07-11 11:09:41 +08:00
return v.bytes / axis.divider;
2021-05-11 22:47:21 +08:00
}),
itemStyle: {
color: "#9DD3E8"
},
lineStyle: {
color: "#9DD3E8"
},
areaStyle: {
color: "#9DD3E8"
2021-07-26 14:32:24 +08:00
},
smooth: true
2021-05-11 22:47:21 +08:00
}
],
animation: false
}
chart.setOption(option)
chart.resize()
}
/**
* 升级提醒
*/
this.closeMessage = function (e) {
let target = e.target
while (true) {
target = target.parentNode
if (target.tagName.toUpperCase() == "DIV") {
target.style.cssText = "display: none"
break
}
}
}
2021-01-21 18:55:53 +08:00
})