节点列表带宽保存两位小数数字

This commit is contained in:
刘祥超
2023-03-17 15:20:53 +08:00
parent 7e9224680e
commit c25bd71592
3 changed files with 24 additions and 9 deletions

View File

@@ -140,27 +140,42 @@ window.teaweb = {
} }
return (Math.round(bytes * 100 / Math.pow(1024, 6)) / 100) + "EB"; return (Math.round(bytes * 100 / Math.pow(1024, 6)) / 100) + "EB";
}, },
formatBits: function (bits) { formatBits: function (bits, decimal) {
bits = Math.ceil(bits); bits = Math.ceil(bits);
let div = 10000
switch (decimal) {
case 1:
div = 10
break
case 2:
div = 100
break
case 3:
div = 1000
break
case 4:
div = 10000
break
}
if (bits < Math.pow(1024, 1)) { if (bits < Math.pow(1024, 1)) {
return bits + "bps"; return bits + "bps";
} }
if (bits < Math.pow(1024, 2)) { if (bits < Math.pow(1024, 2)) {
return (Math.round(bits * 10000 / Math.pow(1024, 1)) / 10000) + "Kbps"; return (Math.round(bits * div / Math.pow(1024, 1)) / div) + "Kbps";
} }
if (bits < Math.pow(1024, 3)) { if (bits < Math.pow(1024, 3)) {
return (Math.round(bits * 10000 / Math.pow(1024, 2)) / 10000) + "Mbps"; return (Math.round(bits * div / Math.pow(1024, 2)) / div) + "Mbps";
} }
if (bits < Math.pow(1024, 4)) { if (bits < Math.pow(1024, 4)) {
return (Math.round(bits * 10000 / Math.pow(1024, 3)) / 10000) + "Gbps"; return (Math.round(bits * div / Math.pow(1024, 3)) / div) + "Gbps";
} }
if (bits < Math.pow(1024, 5)) { if (bits < Math.pow(1024, 5)) {
return (Math.round(bits * 10000 / Math.pow(1024, 4)) / 10000) + "Tbps"; return (Math.round(bits * div / Math.pow(1024, 4)) / div) + "Tbps";
} }
if (bits < Math.pow(1024, 6)) { if (bits < Math.pow(1024, 6)) {
return (Math.round(bits * 10000 / Math.pow(1024, 5)) / 10000) + "Pbps"; return (Math.round(bits * div / Math.pow(1024, 5)) / div) + "Pbps";
} }
return (Math.round(bits * 10000 / Math.pow(1024, 6)) / 10000) + "Ebps"; return (Math.round(bits * div / Math.pow(1024, 6)) / div) + "Ebps";
}, },
formatNumber: function (x) { formatNumber: function (x) {
if (x == null) { if (x == null) {

View File

@@ -127,7 +127,7 @@
<span v-else class="disabled">-</span> <span v-else class="disabled">-</span>
</td> </td>
<td class="center" v-if="windowWidth < miniWidth || windowWidth > columnWidth3"> <td class="center" v-if="windowWidth < miniWidth || windowWidth > columnWidth3">
<span v-if="node.status.isActive && node.status.trafficOutBytes > 0">{{teaweb.formatBits(node.status.trafficOutBytes * 8/60)}}</span> <span v-if="node.status.isActive && node.status.trafficOutBytes > 0">{{teaweb.formatBits(node.status.trafficOutBytes * 8/60, 2)}}</span>
<span v-else class="disabled">-</span> <span v-else class="disabled">-</span>
</td> </td>
<td class="center" v-if="windowWidth < miniWidth || windowWidth > columnWidth4"> <td class="center" v-if="windowWidth < miniWidth || windowWidth > columnWidth4">

View File

@@ -121,7 +121,7 @@
<span v-else class="disabled">-</span> <span v-else class="disabled">-</span>
</td> </td>
<td class="center" v-if="windowWidth < miniWidth || windowWidth > columnWidth3"> <td class="center" v-if="windowWidth < miniWidth || windowWidth > columnWidth3">
<span v-if="node.status.isActive && node.status.trafficOutBytes > 0">{{teaweb.formatBits(node.status.trafficOutBytes * 8/60)}}</span> <span v-if="node.status.isActive && node.status.trafficOutBytes > 0">{{teaweb.formatBits(node.status.trafficOutBytes * 8/60, 2)}}</span>
<span v-else class="disabled">-</span> <span v-else class="disabled">-</span>
</td> </td>
<td class="center" v-if="windowWidth < miniWidth || windowWidth > columnWidth4"> <td class="center" v-if="windowWidth < miniWidth || windowWidth > columnWidth4">