import type { NdmSwitchPortInfo } from '@/apis'; export const getPortStatusVal = (portInfo: NdmSwitchPortInfo): string => { const { upDown } = portInfo; return upDown === 1 ? '启用' : upDown === 2 ? '禁用' : '未知'; }; export const transformPortSpeed = (portInfo: NdmSwitchPortInfo, type: 'in' | 'out' | 'total'): string => { const units = ['b/s', 'Kb/s', 'Mb/s', 'Gb/s', 'Tb/s']; const { inFlow, outFlow, flow } = portInfo; let result: number = 0; if (type === 'in') { result = inFlow; } else if (type === 'out') { result = outFlow; } else if (type === 'total') { result = flow; } let index = 0; while (result >= 1024 && index < units.length - 1) { result /= 1024; index++; } result *= 8; return `${result.toFixed(3)} ${units[index]}`; };