调整
This commit is contained in:
parent
f094ac4d39
commit
60b0b5938c
1
app/wails/frontend/components.d.ts
vendored
1
app/wails/frontend/components.d.ts
vendored
@ -20,6 +20,7 @@ declare module 'vue' {
|
||||
ElTabs: typeof import('element-plus/es')['ElTabs']
|
||||
ElTooltip: typeof import('element-plus/es')['ElTooltip']
|
||||
MemoryUsage: typeof import('./src/components/system/memory/MemoryUsage.vue')['default']
|
||||
MemoryUsageChart: typeof import('./src/components/system/memory/MemoryUsageChart.vue')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
TabScaffold: typeof import('./src/components/scaffold/TabScaffold.vue')['default']
|
||||
|
@ -97,7 +97,8 @@ const chart = reactive({
|
||||
name: 'CPU使用率',
|
||||
type: 'line',
|
||||
showSymbol: false,
|
||||
data: []
|
||||
data: [],
|
||||
areaStyle: {}
|
||||
}
|
||||
]
|
||||
})
|
||||
@ -109,7 +110,6 @@ onMounted(()=>{
|
||||
|
||||
watch(singleUsage,(v)=>{
|
||||
let data = chart.series[0].data
|
||||
console.log("data", data)
|
||||
data.push({
|
||||
name: moment().format("HH:mm:ss"),
|
||||
value: [moment().format("HH:mm:ss"), v]
|
||||
|
@ -0,0 +1,170 @@
|
||||
<script setup>
|
||||
import {
|
||||
useCpuUsage,
|
||||
useMemoryTotalSize, useMemoryTotalSizeWithByte,
|
||||
useMemoryUsage,
|
||||
useMemoryUsageSize,
|
||||
useMemoryUsageSizeWithByte
|
||||
} from "src/utils/system";
|
||||
import {computed, onMounted, reactive, ref, watch} from "vue";
|
||||
import * as echarts from "echarts";
|
||||
import moment from "moment";
|
||||
import {bytesToSizeWithUnit} from "src/utils/file/file";
|
||||
const props = defineProps({
|
||||
showLabel: {
|
||||
type:Boolean,
|
||||
default: true,
|
||||
},
|
||||
label: {
|
||||
type: String,
|
||||
default: "内存使用情况",
|
||||
},
|
||||
labelPosition :{
|
||||
type: String,
|
||||
default: "center",
|
||||
},
|
||||
labelStyle: {
|
||||
type: Object,
|
||||
default: {
|
||||
fontSize: 14
|
||||
}
|
||||
},
|
||||
maxStep:{
|
||||
type: Number,
|
||||
default: 600
|
||||
},
|
||||
showMax: {
|
||||
type:Boolean,
|
||||
default: false
|
||||
}
|
||||
})
|
||||
const memoryTotal = useMemoryTotalSizeWithByte()
|
||||
const memoryUsage = useMemoryUsageSizeWithByte()
|
||||
const singleUsage = computed(()=>{
|
||||
return memoryUsage.value || 0
|
||||
})
|
||||
const colors = [
|
||||
{ color: '#f56c6c', percentage: 100 },
|
||||
{ color: '#e6a23c', percentage: 80 },
|
||||
{ color: '#5cb87a', percentage: 30 },
|
||||
]
|
||||
|
||||
const chartRef = ref()
|
||||
const chart = reactive({
|
||||
title: {
|
||||
left: props.labelPosition,
|
||||
text: props.label,
|
||||
textStyle: props.labelStyle
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
formatter: (params)=> {
|
||||
params = params[0];
|
||||
return `
|
||||
<div>${params.value[0]}</div>
|
||||
<div class="text-center">${bytesToSizeWithUnit(params.value[1])}</div>
|
||||
`;
|
||||
},
|
||||
axisPointer: {
|
||||
animation: false
|
||||
}
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
splitLine: {
|
||||
show: false
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
boundaryGap: [0, '100%'],
|
||||
splitLine: {
|
||||
show: false
|
||||
},
|
||||
axisLabel: {
|
||||
align: 'right',
|
||||
overflow: 'truncate',
|
||||
ellipsis: '...',
|
||||
width: 75,
|
||||
formatter(value,index){
|
||||
return bytesToSizeWithUnit(value)
|
||||
}
|
||||
},
|
||||
min: 0,
|
||||
max: props.showMax?memoryTotal:undefined,
|
||||
},
|
||||
grid:{
|
||||
left: 75,
|
||||
containLabel: false
|
||||
},
|
||||
visualMap: getVisualMap(),
|
||||
series: [
|
||||
{
|
||||
name: '内存使用情况',
|
||||
type: 'line',
|
||||
showSymbol: false,
|
||||
data: [],
|
||||
areaStyle: {}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
function getVisualMap(){
|
||||
return {
|
||||
show: false,
|
||||
pieces: [
|
||||
{
|
||||
gte: 0,
|
||||
lte: memoryTotal.value * 0.3,
|
||||
color: '#5cb87a'
|
||||
},
|
||||
{
|
||||
gt: memoryTotal.value * 0.3,
|
||||
lte: memoryTotal.value * 0.8,
|
||||
color: '#e6a23c'
|
||||
},
|
||||
{
|
||||
gt: memoryTotal.value * 0.8,
|
||||
lte: memoryTotal.value,
|
||||
color: '#f56c6c'
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(()=>{
|
||||
const chartInst = echarts.init(chartRef.value)
|
||||
chartInst.setOption(chart)
|
||||
chartInst.resize()
|
||||
|
||||
watch(singleUsage,(v)=>{
|
||||
chart.visualMap = getVisualMap()
|
||||
let data = chart.series[0].data
|
||||
data.push({
|
||||
name: moment().format("HH:mm:ss"),
|
||||
value: [moment().format("HH:mm:ss"), v]
|
||||
})
|
||||
if(data.length > props.maxStep){
|
||||
data.splice(0,1)
|
||||
}
|
||||
chartInst.setOption(chart)
|
||||
})
|
||||
window.addEventListener("resize",()=>{
|
||||
chartInst.resize()
|
||||
})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="chartRef" class="w-full h-full"></div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.percentage-value {
|
||||
font-size: 18px;
|
||||
}
|
||||
.percentage-text {
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
@ -56,6 +56,15 @@ export function useMemoryUsage(){
|
||||
return computed(()=> Number((stat.memory.usage.data || 0).toFixed(2)))
|
||||
}
|
||||
|
||||
|
||||
export function useMemoryUsageSizeWithByte(){
|
||||
if(stat.memory.usage.interval == null){
|
||||
loopMemory()
|
||||
}
|
||||
|
||||
return computed(()=> stat.memory.data.used || 0)
|
||||
}
|
||||
|
||||
export function useMemoryUsageSize(){
|
||||
if(stat.memory.usage.interval == null){
|
||||
loopMemory()
|
||||
@ -72,4 +81,10 @@ export function useMemoryTotalSize(){
|
||||
return computed(()=> bytesToSizeWithUnit(stat.memory.data.total || 0))
|
||||
}
|
||||
|
||||
export function useMemoryTotalSizeWithByte(){
|
||||
if(stat.memory.usage.interval == null){
|
||||
loopMemory()
|
||||
}
|
||||
|
||||
return computed(()=> stat.memory.data.total || 0)
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ import {useRouter} from "vue-router";
|
||||
import CPUUsage from "src/components/system/cpu/CPUUsage.vue";
|
||||
import MemoryUsage from "src/components/system/memory/MemoryUsage.vue";
|
||||
import CPUUsageChart from "src/components/system/cpu/CPUUsageChart.vue";
|
||||
import MemoryUsageChart from "src/components/system/memory/MemoryUsageChart.vue";
|
||||
function switchLocale(){
|
||||
console.log(globalConfigState.ui.value.locale)
|
||||
if(globalConfigState.ui.value.locale.name === 'zh-cn'){
|
||||
@ -113,6 +114,9 @@ const generateData = (
|
||||
<el-col :span="12">
|
||||
<CPUUsageChart style="height: 300px"/>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<MemoryUsageChart style="height: 300px"/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user