fix: 修复主机延迟timeout显示NaN

This commit is contained in:
chaos-zhu
2026-04-26 20:20:18 +08:00
parent d90d1412c9
commit e9fb5ecf6c
2 changed files with 12 additions and 7 deletions

View File

@@ -14,11 +14,9 @@
</div>
</template>
<span class="host-info-ip" :title="host">{{ host }}</span>
<template v-if="pingMs">
<el-tooltip effect="dark" content="该值为EasyNode服务端主机到目标主机的ping值" placement="bottom">
<span class="host-ping" :style="{backgroundColor: handlePingColor(pingMs)}">{{ pingMs }}ms</span>
</el-tooltip>
</template>
<el-tooltip effect="dark" content="该值为EasyNode服务端主机到目标主机的ping值" placement="bottom">
<span class="host-ping" :style="{backgroundColor: handlePingColor(pingValue)}">{{ pingText }}</span>
</el-tooltip>
<el-tag size="small" style="cursor: pointer;margin-left: 10px;" @click="handleCopy">复制</el-tag>
</el-descriptions-item>
@@ -239,6 +237,12 @@ const props = defineProps({
}
})
const pingValue = computed(() => {
const value = Number(props.pingMs)
return Number.isFinite(value) && value > 0 ? value : null
})
const pingText = computed(() => pingValue.value ? `${ pingValue.value }ms` : 'TO')
// 状态数据
const serverData = ref({
connect: false,
@@ -616,6 +620,7 @@ const handleUsedColor = (num) => {
}
const handlePingColor = (num) => {
if (!num) return 'rgba(255, 73, 73, 0.5)' // #ff4949
if (num < 100) return 'rgba(19, 206, 102, 0.5)' // #13ce66
if (num < 250) return 'rgba(230, 162, 60, 0.5)' // #e6a23c
return 'rgba(255, 73, 73, 0.5)' // #ff4949

View File

@@ -322,8 +322,8 @@ const connectIO = () => {
}, 3000)
socket.value.emit('get_ping', host.value) // 获取服务端到客户端的ping值
socket.value.on('ping_data', (pingMs) => {
const time = Number(pingMs?.time)?.toFixed(0) || 0
emit('ping-data', { host: host.value, time: Number.isNaN(time) ? '--' : time })
const time = Number(pingMs?.time)
emit('ping-data', { host: host.value, time: Number.isFinite(time) ? time.toFixed(0) : 0 })
})
socket.value.on('terminal_print_info', (msg) => {