scr-web/src/views/screen/RealTimeUsed.vue

342 lines
9.5 KiB
Vue
Raw Normal View History

2024-07-19 02:27:21 +00:00
<template>
2024-07-25 04:22:54 +00:00
<!-- 外面拉伸时圆环保持不变 -->
<div
id="RealTimeUsed"
:style="{
transform: `scale(${scale.hRatio},${scale.wRatio})`
}"
></div>
2024-07-19 02:27:21 +00:00
</template>
<script>
import * as echarts from 'echarts'
import { getRealTimeUtilization } from './api.js'
export default {
name: 'UsedTrend',
2024-07-25 04:22:54 +00:00
props: {
scale: {
type: Object,
default: () => ({ wRatio: 1, hRatio: 1 })
}
},
2024-07-19 02:27:21 +00:00
data() {
return {
myChart: null,
2024-07-25 04:22:54 +00:00
used: 0,
2024-07-19 02:27:21 +00:00
timer: null
}
},
mounted() {
const chartDom = document.getElementById('RealTimeUsed')
this.myChart = echarts.init(chartDom)
this.getRealTimeUesdView()
2024-07-24 10:05:24 +00:00
this.getRealTimeData()
2024-07-19 02:27:21 +00:00
this.timer = setInterval(() => {
this.getRealTimeData()
2024-07-19 04:08:15 +00:00
}, 10000)
2024-07-19 02:27:21 +00:00
},
unmounted() {
clearInterval(this.timer)
},
methods: {
// 平台实用利用率
async getRealTimeData() {
const res = await getRealTimeUtilization()
2024-07-24 10:05:24 +00:00
if (res?.status !== 'success') return
2024-07-25 04:24:57 +00:00
const value = res.data?.result?.[0]?.value[1] * 100 || 0
2024-07-24 10:05:24 +00:00
this.used = value.toFixed(2)
2024-07-19 02:27:21 +00:00
},
getRealTimeUesdView() {
let angle = 0
const value = this.used
const option = {
title: {
text: '{a|' + value + '}{c|%}',
x: 'center',
y: 'center',
textStyle: {
rich: {
a: {
fontSize: 20,
color: '#29EEF3'
},
c: {
fontSize: 18,
color: '#ffffff'
}
}
}
},
series: [
{
name: 'ring5',
type: 'custom',
coordinateSystem: 'none',
2024-07-24 10:05:24 +00:00
renderItem: function (params, api) {
2024-07-19 02:27:21 +00:00
return {
type: 'arc',
shape: {
cx: api.getWidth() / 2,
cy: api.getHeight() / 2,
r: (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.6,
startAngle: ((0 + angle) * Math.PI) / 180,
endAngle: ((90 + angle) * Math.PI) / 180
},
style: {
stroke: '#0CD3DB',
fill: 'transparent',
lineWidth: 1.5
},
silent: true
}
},
data: [0]
},
{
name: 'ring5',
type: 'custom',
coordinateSystem: 'none',
2024-07-24 10:05:24 +00:00
renderItem: function (params, api) {
2024-07-19 02:27:21 +00:00
return {
type: 'arc',
shape: {
cx: api.getWidth() / 2,
cy: api.getHeight() / 2,
r: (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.6,
startAngle: ((180 + angle) * Math.PI) / 180,
endAngle: ((270 + angle) * Math.PI) / 180
},
style: {
stroke: '#0CD3DB',
fill: 'transparent',
lineWidth: 1.5
},
silent: true
}
},
data: [0]
},
{
name: 'ring5',
type: 'custom',
coordinateSystem: 'none',
2024-07-24 10:05:24 +00:00
renderItem: function (params, api) {
2024-07-19 02:27:21 +00:00
return {
type: 'arc',
shape: {
cx: api.getWidth() / 2,
cy: api.getHeight() / 2,
r: (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.65,
startAngle: ((270 + -angle) * Math.PI) / 180,
endAngle: ((40 + -angle) * Math.PI) / 180
},
style: {
stroke: '#0CD3DB',
fill: 'transparent',
lineWidth: 1.5
},
silent: true
}
},
data: [0]
},
{
name: 'ring5',
type: 'custom',
coordinateSystem: 'none',
2024-07-24 10:05:24 +00:00
renderItem: function (params, api) {
2024-07-19 02:27:21 +00:00
return {
type: 'arc',
shape: {
cx: api.getWidth() / 2,
cy: api.getHeight() / 2,
r: (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.65,
startAngle: ((90 + -angle) * Math.PI) / 180,
endAngle: ((220 + -angle) * Math.PI) / 180
},
style: {
stroke: '#0CD3DB',
fill: 'transparent',
lineWidth: 1.5
},
silent: true
}
},
data: [0]
},
{
name: 'ring5',
type: 'custom',
coordinateSystem: 'none',
2024-07-24 10:05:24 +00:00
renderItem: function (params, api) {
2024-07-19 02:27:21 +00:00
const x0 = api.getWidth() / 2
const y0 = api.getHeight() / 2
const r = (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.65
const point = getCirlPoint(x0, y0, r, 90 + -angle)
return {
type: 'circle',
shape: {
cx: point.x,
cy: point.y,
r: 4
},
style: {
stroke: '#0CD3DB', // 粉
fill: '#0CD3DB'
},
silent: true
}
},
data: [0]
},
{
name: 'ring5', // 绿点
type: 'custom',
coordinateSystem: 'none',
2024-07-24 10:05:24 +00:00
renderItem: function (params, api) {
2024-07-19 02:27:21 +00:00
const x0 = api.getWidth() / 2
const y0 = api.getHeight() / 2
const r = (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.65
const point = getCirlPoint(x0, y0, r, 270 + -angle)
return {
type: 'circle',
shape: {
cx: point.x,
cy: point.y,
r: 4
},
style: {
stroke: '#0CD3DB', // 绿
fill: '#0CD3DB'
},
silent: true
}
},
data: [0]
},
{
type: 'pie',
radius: ['58%', '45%'],
silent: true,
clockwise: true,
startAngle: 90,
z: 0,
zlevel: 0,
label: {
normal: {
position: 'center'
}
},
data: [
{
value: value,
name: '',
itemStyle: {
normal: {
color: {
// 完成的圆环的颜色
colorStops: [
{
offset: 0,
color: '#4FADFD' // 0% 处的颜色
},
{
offset: 1,
color: '#28E8FA' // 100% 处的颜色
}
]
}
}
}
},
{
value: 100 - value,
name: '',
label: {
normal: {
show: false
}
},
itemStyle: {
normal: {
color: '#173164'
}
}
}
]
},
{
name: '',
type: 'gauge',
radius: '58%',
center: ['50%', '50%'],
startAngle: 0,
endAngle: 359.9,
splitNumber: 8,
hoverAnimation: true,
axisTick: {
show: false
},
splitLine: {
length: 12,
lineStyle: {
width: 5,
color: '#061740'
}
},
axisLabel: {
show: false
},
pointer: {
show: false
},
axisLine: {
lineStyle: {
opacity: 0
}
},
detail: {
show: false
},
data: [
{
value: 0,
name: ''
}
]
}
]
}
// 获取圆上面某点的坐标(x0,y0表示坐标r半径angle角度)
function getCirlPoint(x0, y0, r, angle) {
const x1 = x0 + r * Math.cos((angle * Math.PI) / 180)
const y1 = y0 + r * Math.sin((angle * Math.PI) / 180)
return {
x: x1,
y: y1
}
}
setInterval(() => {
angle = angle + 3
option.title.text = `{a|${this.used}}{c|%}`
option.series[6].data[0].value = this.used
option.series[6].data[1].value = 100 - parseFloat(this.used)
this.myChart.setOption(option, true)
}, 100)
window.addEventListener('resize', () => {
this.myChart.resize()
})
}
}
}
</script>
<style scoped>
#RealTimeUsed {
height: 100%;
}
</style>