main
陈博文 3 days ago
parent fff3aa5e19
commit a5a26bd315

@ -1,4 +1,8 @@
import { timeParse, formatSmartPercentage } from '@/utils';
import {
timeParse,
formatSmartPercentage,
getFirstNonEmptyArray,
} from '@/utils';
export const getRangeOptions = ({
core = [],
@ -6,6 +10,8 @@ export const getRangeOptions = ({
cpu = [],
internal = [],
}) => {
const xData = getFirstNonEmptyArray([core, memory, cpu, internal]);
return {
legend: {
// data: [],
@ -38,7 +44,7 @@ export const getRangeOptions = ({
},
xAxis: {
type: 'category',
data: core.map((item) => timeParse(+item.timestamp)),
data: xData.map((item) => timeParse(+item.timestamp)),
axisLabel: {
formatter: function (value) {
return timeParse(value, 'HH:mm');

@ -25,7 +25,7 @@
</div>
</template>
</div>
<template #footer>
<template v-if="nodeList && nodeList.length > 0" #footer>
<el-button @click="dialogVisible = false">取消</el-button>
<el-button :loading="btnLoading" type="primary" @click="handleOk"></el-button>
</template>

@ -1,4 +1,8 @@
import { timeParse, formatSmartPercentage } from '@/utils';
import {
timeParse,
formatSmartPercentage,
getFirstNonEmptyArray,
} from '@/utils';
export const getRangeOptions = ({
core = [],
@ -6,6 +10,8 @@ export const getRangeOptions = ({
cpu = [],
internal = [],
}) => {
const xData = getFirstNonEmptyArray([core, memory, cpu, internal]);
return {
legend: {
// data: [],
@ -38,7 +44,7 @@ export const getRangeOptions = ({
},
xAxis: {
type: 'category',
data: core.map((item) => timeParse(+item.timestamp)),
data: xData.map((item) => timeParse(+item.timestamp)),
axisLabel: {
formatter: function (value) {
return timeParse(value, 'HH:mm');

@ -613,3 +613,12 @@ export function formatSmartPercentage(value) {
return parseFloat(rounded).toString(); // 去除多余的 0 和小数点
}
export function getFirstNonEmptyArray(arrays, defaultValue = []) {
for (const arr of arrays) {
if (arr && arr.length > 0) {
return arr;
}
}
return defaultValue;
}

Loading…
Cancel
Save