refactor: 重构helpers目录导出入口,整合原有分散的模块导出

This commit is contained in:
yangsy
2026-05-18 15:01:53 +08:00
parent 3fae0b841b
commit 18378b79a6
9 changed files with 8 additions and 3 deletions
+1
View File
@@ -0,0 +1 @@
export * from './util';
+26
View File
@@ -0,0 +1,26 @@
import type { NdmSwitchPortInfo } from '@/apis';
export const getPortStatusValue = (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 unit = 0;
result *= 8;
while (result >= 1024 && unit < units.length - 1) {
result /= 1024;
unit++;
}
return `${result.toFixed(3)} ${units[unit]}`;
};