补充组件
This commit is contained in:
@@ -1,242 +1,295 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, onMounted, ref, onBeforeUnmount } from 'vue';
|
||||
<!-- <script setup lang="ts">
|
||||
import { reactive, onMounted } from 'vue';
|
||||
import { PageContainer } from 'antdv-pro-layout';
|
||||
import ChartLine from '@/components/ChartLine/index.vue';
|
||||
import { getLoad } from '@/api/monitor/monitor';
|
||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import { listNe, stateNe } from '@/api/ne/ne';
|
||||
import { message } from 'ant-design-vue/lib';
|
||||
import { getGraphData } from '@/api/monitor/topology';
|
||||
import { parseDateToStr } from '@/utils/date-utils';
|
||||
import { Graph, GraphData, Menu, Tooltip } from '@antv/g6';
|
||||
import {
|
||||
edgeCubicAnimateCircleMove,
|
||||
edgeCubicAnimateLineDash,
|
||||
edgeLineAnimateState,
|
||||
} from '@/views/monitor/topologyBuild/hooks/registerEdge';
|
||||
import {
|
||||
nodeCircleAnimateShapeR,
|
||||
nodeCircleAnimateShapeStroke,
|
||||
nodeImageAnimateState,
|
||||
nodeRectAnimateState,
|
||||
} from '@/views/monitor/topologyBuild/hooks/registerNode';
|
||||
import * as echarts from 'echarts/core';
|
||||
import { TooltipComponent } from 'echarts/components';
|
||||
import { GaugeChart } from 'echarts/charts';
|
||||
import { CanvasRenderer } from 'echarts/renderers';
|
||||
|
||||
import useI18n from '@/hooks/useI18n';
|
||||
import {
|
||||
YYYY_MM_DD_HH_MM_SS,
|
||||
parseDateToStr,
|
||||
parseDateWithoutYear,
|
||||
parseStrToDate,
|
||||
} from '@/utils/date-utils';
|
||||
import { parseSizeFromKBs } from '@/utils/parse-utils';
|
||||
import dayjs, { Dayjs } from 'dayjs';
|
||||
const { t } = useI18n();
|
||||
|
||||
echarts.use([TooltipComponent, GaugeChart, CanvasRenderer]);
|
||||
|
||||
type EChartsOption = echarts.ComposeOption<GaugeSeriesOption>;
|
||||
|
||||
/**图DOM节点实例对象 */
|
||||
const neResourcesDom = ref<HTMLElement | undefined>(undefined);
|
||||
|
||||
/**图实例对象 */
|
||||
const neResourcesChart = ref<any>(null);
|
||||
|
||||
const optionData: EChartsOption = {
|
||||
tooltip: {
|
||||
formatter: '{a} <br> {b} : {c}%',
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '系统内存',
|
||||
type: 'gauge',
|
||||
center: ['30%', '25%'],
|
||||
radius: '40%',
|
||||
startAngle: 90,
|
||||
endAngle: -270,
|
||||
min: 1,
|
||||
max: 100,
|
||||
itemStyle: {
|
||||
color: '#1890ff',
|
||||
},
|
||||
progress: {
|
||||
show: true,
|
||||
width: 10,
|
||||
overlap: true,
|
||||
roundCap: true,
|
||||
clip: false,
|
||||
},
|
||||
pointer: {
|
||||
show: false,
|
||||
},
|
||||
axisLine: {
|
||||
lineStyle: {
|
||||
width: 10,
|
||||
},
|
||||
},
|
||||
axisTick: {
|
||||
show: false,
|
||||
},
|
||||
splitLine: {
|
||||
show: false,
|
||||
},
|
||||
axisLabel: {
|
||||
show: false,
|
||||
},
|
||||
anchor: {
|
||||
show: false,
|
||||
},
|
||||
title: {
|
||||
show: true,
|
||||
offsetCenter: [0, -5],
|
||||
fontSize: 10,
|
||||
color: '#fafafa',
|
||||
},
|
||||
detail: {
|
||||
valueAnimation: true,
|
||||
width: '60%',
|
||||
lineHeight: 40,
|
||||
borderRadius: 8,
|
||||
offsetCenter: [0, 10],
|
||||
fontSize: 10,
|
||||
fontWeight: 'bolder',
|
||||
formatter: '{value}%',
|
||||
color: 'inherit',
|
||||
},
|
||||
data: [
|
||||
{
|
||||
name: '系统内存',
|
||||
value: 20,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: '系统CPU',
|
||||
type: 'gauge',
|
||||
center: ['70%', '25%'],
|
||||
radius: '40%',
|
||||
startAngle: 90,
|
||||
endAngle: -270,
|
||||
min: 1,
|
||||
max: 100,
|
||||
itemStyle: {
|
||||
color: '#1890ff',
|
||||
},
|
||||
progress: {
|
||||
show: true,
|
||||
width: 10,
|
||||
overlap: true,
|
||||
roundCap: true,
|
||||
clip: false,
|
||||
},
|
||||
pointer: {
|
||||
show: false,
|
||||
},
|
||||
axisLine: {
|
||||
lineStyle: {
|
||||
width: 10,
|
||||
},
|
||||
},
|
||||
axisTick: {
|
||||
show: false,
|
||||
},
|
||||
splitLine: {
|
||||
show: false,
|
||||
},
|
||||
axisLabel: {
|
||||
show: false,
|
||||
},
|
||||
anchor: {
|
||||
show: false,
|
||||
},
|
||||
title: {
|
||||
show: true,
|
||||
offsetCenter: [0, -5],
|
||||
fontSize: 10,
|
||||
color: '#fafafa',
|
||||
},
|
||||
detail: {
|
||||
valueAnimation: true,
|
||||
width: '60%',
|
||||
lineHeight: 40,
|
||||
borderRadius: 8,
|
||||
offsetCenter: [0, 10],
|
||||
fontSize: 10,
|
||||
fontWeight: 'bolder',
|
||||
formatter: '{value}%',
|
||||
color: 'inherit',
|
||||
},
|
||||
data: [
|
||||
{
|
||||
name: '系统内存',
|
||||
value: 20,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
/**开始结束时间类型 */
|
||||
type RangePickerType = {
|
||||
placeholder: [string, string];
|
||||
ranges: Record<string, [Dayjs, Dayjs]>;
|
||||
/**全局时间 */
|
||||
all: [string, string];
|
||||
/**网络 */
|
||||
network: [string, string];
|
||||
};
|
||||
|
||||
/**图数据渲染 */
|
||||
function handleRanderChart(
|
||||
container: HTMLElement | undefined,
|
||||
option: EChartsOption
|
||||
) {
|
||||
if (!container) return;
|
||||
const { clientHeight, clientWidth } = container;
|
||||
/**开始结束时间 */
|
||||
let rangePicker = reactive<RangePickerType>({
|
||||
placeholder: [
|
||||
t('views.monitor.monitor.startTime'),
|
||||
t('views.monitor.monitor.endTime'),
|
||||
],
|
||||
ranges: {
|
||||
[t('views.monitor.monitor.today')]: [
|
||||
dayjs().subtract(1, 'day').startOf('day'),
|
||||
dayjs().subtract(1, 'day').endOf('day'),
|
||||
],
|
||||
[t('views.monitor.monitor.yesterday')]: [dayjs().startOf('day'), dayjs()],
|
||||
[t('views.monitor.monitor.week')]: [
|
||||
dayjs().startOf('week'),
|
||||
dayjs().endOf('week'),
|
||||
],
|
||||
[t('views.monitor.monitor.month')]: [
|
||||
dayjs().startOf('month'),
|
||||
dayjs().endOf('month'),
|
||||
],
|
||||
},
|
||||
all: ['', ''],
|
||||
network: ['', ''],
|
||||
});
|
||||
|
||||
neResourcesChart.value = echarts.init(container, 'light', {
|
||||
width: clientWidth,
|
||||
height: clientHeight - 36,
|
||||
/**查询全部资源数据列表 */
|
||||
function fnGetList() {
|
||||
let startTime = null;
|
||||
let endTime = null;
|
||||
const dateString = rangePicker.all;
|
||||
if (dateString[0]) {
|
||||
startTime = parseStrToDate(dateString[0], YYYY_MM_DD_HH_MM_SS);
|
||||
endTime = parseStrToDate(dateString[1], YYYY_MM_DD_HH_MM_SS);
|
||||
} else {
|
||||
const now = new Date();
|
||||
now.setHours(0, 0, 0, 0);
|
||||
startTime = now;
|
||||
endTime = new Date();
|
||||
}
|
||||
|
||||
getLoad({
|
||||
type: 'network',
|
||||
startTime: startTime.getTime(),
|
||||
endTime: endTime.getTime(),
|
||||
neType: '#',
|
||||
neId: '#',
|
||||
}).then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
||||
fnNetworkChart(res.data.network);
|
||||
}
|
||||
});
|
||||
option && neResourcesChart.value.setOption(option);
|
||||
|
||||
// 设置初始时间段
|
||||
const initRangePicker: [string, string] = [
|
||||
parseDateToStr(startTime, YYYY_MM_DD_HH_MM_SS),
|
||||
parseDateToStr(endTime, YYYY_MM_DD_HH_MM_SS),
|
||||
];
|
||||
rangePicker.all = initRangePicker;
|
||||
rangePicker.network = initRangePicker;
|
||||
}
|
||||
|
||||
/**图表显示数据 */
|
||||
const chartsOption = reactive({
|
||||
/**网络 */
|
||||
networkChart: {},
|
||||
});
|
||||
|
||||
/**初始图表数据-Network */
|
||||
function fnNetworkChart(data: Record<string, any>[]) {
|
||||
let networkDate: string[] = [];
|
||||
let networkUp: string[] = [];
|
||||
let networkDown: string[] = [];
|
||||
|
||||
for (const item of data) {
|
||||
networkDate.push(parseDateWithoutYear(item.createTime));
|
||||
networkUp.push(Number(item.up).toFixed(2));
|
||||
networkDown.push(Number(item.down).toFixed(2));
|
||||
}
|
||||
|
||||
// 图标参数
|
||||
const option = {
|
||||
xDatas: networkDate,
|
||||
yDatas: [
|
||||
{
|
||||
name: t('views.monitor.monitor.up'),
|
||||
data: networkUp,
|
||||
},
|
||||
{
|
||||
name: t('views.monitor.monitor.down'),
|
||||
data: networkDown,
|
||||
},
|
||||
],
|
||||
grid: {
|
||||
left: '5%',
|
||||
right: '5%',
|
||||
bottom: '20%',
|
||||
},
|
||||
formatStr: 'KB/s',
|
||||
};
|
||||
chartsOption.networkChart = option;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
setInterval(function () {
|
||||
const random = +(Math.random() * 90).toFixed(2);
|
||||
const random2 = +(Math.random() * 90).toFixed(2);
|
||||
const random3 = +(Math.random() * 90).toFixed(2);
|
||||
const random4 = +(Math.random() * 90).toFixed(2);
|
||||
let color = '#1890ff';
|
||||
if (random < 30) {
|
||||
color = '#73d13d';
|
||||
}
|
||||
if (random > 60) {
|
||||
color = '#ff4d4f';
|
||||
}
|
||||
neResourcesChart.value.setOption({
|
||||
series: [
|
||||
{
|
||||
data: [
|
||||
{
|
||||
name: '系统内存',
|
||||
value: random,
|
||||
itemStyle: {
|
||||
color: color,
|
||||
shadowColor: color,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
data: [
|
||||
{
|
||||
name: '系统CPU',
|
||||
value: random2,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
}, 2000);
|
||||
|
||||
handleRanderChart(neResourcesDom.value, optionData);
|
||||
fnGetList();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="neResourcesDom" class="chart"></div>
|
||||
<div class="chart">
|
||||
<ChartLine
|
||||
:option="chartsOption.networkChart"
|
||||
></ChartLine>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.chart {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
height: 400px;
|
||||
}
|
||||
</style> -->
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, onMounted } from 'vue';
|
||||
import { PageContainer } from 'antdv-pro-layout';
|
||||
import ChartLine from '@/components/ChartLine/index.vue';
|
||||
import { getLoad } from '@/api/monitor/monitor';
|
||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import useI18n from '@/hooks/useI18n';
|
||||
import {
|
||||
YYYY_MM_DD_HH_MM_SS,
|
||||
parseDateToStr,
|
||||
parseDateWithoutYear,
|
||||
parseStrToDate,
|
||||
} from '@/utils/date-utils';
|
||||
import { parseSizeFromKBs } from '@/utils/parse-utils';
|
||||
import dayjs, { Dayjs } from 'dayjs';
|
||||
const { t } = useI18n();
|
||||
|
||||
/**开始结束时间类型 */
|
||||
type RangePickerType = {
|
||||
placeholder: [string, string];
|
||||
ranges: Record<string, [Dayjs, Dayjs]>;
|
||||
/**全局时间 */
|
||||
all: [string, string];
|
||||
/**网络 */
|
||||
network: [string, string];
|
||||
};
|
||||
|
||||
/**开始结束时间 */
|
||||
let rangePicker = reactive<RangePickerType>({
|
||||
placeholder: [
|
||||
t('views.monitor.monitor.startTime'),
|
||||
t('views.monitor.monitor.endTime'),
|
||||
],
|
||||
ranges: {
|
||||
[t('views.monitor.monitor.today')]: [
|
||||
dayjs().subtract(1, 'day').startOf('day'),
|
||||
dayjs().subtract(1, 'day').endOf('day'),
|
||||
],
|
||||
[t('views.monitor.monitor.yesterday')]: [dayjs().startOf('day'), dayjs()],
|
||||
[t('views.monitor.monitor.week')]: [
|
||||
dayjs().startOf('week'),
|
||||
dayjs().endOf('week'),
|
||||
],
|
||||
[t('views.monitor.monitor.month')]: [
|
||||
dayjs().startOf('month'),
|
||||
dayjs().endOf('month'),
|
||||
],
|
||||
},
|
||||
all: ['', ''],
|
||||
network: ['', ''],
|
||||
});
|
||||
|
||||
/**查询全部资源数据列表 */
|
||||
function fnGetList() {
|
||||
let startTime = null;
|
||||
let endTime = null;
|
||||
const dateString = rangePicker.all;
|
||||
if (dateString[0]) {
|
||||
startTime = parseStrToDate(dateString[0], YYYY_MM_DD_HH_MM_SS);
|
||||
endTime = parseStrToDate(dateString[1], YYYY_MM_DD_HH_MM_SS);
|
||||
} else {
|
||||
const now = new Date();
|
||||
now.setHours(0, 0, 0, 0);
|
||||
startTime = now;
|
||||
endTime = new Date();
|
||||
}
|
||||
|
||||
getLoad({
|
||||
type: 'network',
|
||||
startTime: startTime.getTime(),
|
||||
endTime: endTime.getTime(),
|
||||
neType: '#',
|
||||
neId: '#',
|
||||
}).then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
||||
fnNetworkChart(res.data.network);
|
||||
}
|
||||
});
|
||||
|
||||
// 设置初始时间段
|
||||
const initRangePicker: [string, string] = [
|
||||
parseDateToStr(startTime, YYYY_MM_DD_HH_MM_SS),
|
||||
parseDateToStr(endTime, YYYY_MM_DD_HH_MM_SS),
|
||||
];
|
||||
rangePicker.all = initRangePicker;
|
||||
rangePicker.network = initRangePicker;
|
||||
}
|
||||
|
||||
/**图表显示数据 */
|
||||
const chartsOption = reactive({
|
||||
/**网络 */
|
||||
networkChart: {},
|
||||
});
|
||||
|
||||
/**初始图表数据-Network */
|
||||
function fnNetworkChart(data: Record<string, any>[]) {
|
||||
let networkDate: string[] = [];
|
||||
let networkUp: string[] = [];
|
||||
let networkDown: string[] = [];
|
||||
|
||||
for (const item of data) {
|
||||
networkDate.push(parseDateWithoutYear(item.createTime));
|
||||
networkUp.push(Number(item.up).toFixed(2));
|
||||
networkDown.push(Number(item.down).toFixed(2));
|
||||
}
|
||||
|
||||
// 图标参数
|
||||
const option = {
|
||||
xDatas: networkDate,
|
||||
yDatas: [
|
||||
{
|
||||
name: t('views.monitor.monitor.up'),
|
||||
data: networkUp,
|
||||
},
|
||||
{
|
||||
name: t('views.monitor.monitor.down'),
|
||||
data: networkDown,
|
||||
},
|
||||
],
|
||||
grid: {
|
||||
left: '5%',
|
||||
right: '5%',
|
||||
bottom: '20%',
|
||||
},
|
||||
formatStr: 'KB/s',
|
||||
};
|
||||
chartsOption.networkChart = option;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fnGetList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="chart">
|
||||
<ChartLine :option="chartsOption.networkChart"></ChartLine>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.chart {
|
||||
width: 100%;
|
||||
height: 400px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user