main
陈博文 4 days ago
parent fff3aa5e19
commit a5a26bd315

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

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

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

@ -613,3 +613,12 @@ export function formatSmartPercentage(value) {
return parseFloat(rounded).toString(); // 去除多余的 0 和小数点 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