refactor: 重构helpers目录导出入口,整合原有分散的模块导出
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export * from './util';
|
||||
@@ -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]}`;
|
||||
};
|
||||
Reference in New Issue
Block a user