Browse Source

feat: 新增流量数 注册数

xdd 3 days ago
parent
commit
12e6ee0238
1 changed files with 22 additions and 1 deletions
  1. 22 1
      src/views/statistics/section/inline.vue

+ 22 - 1
src/views/statistics/section/inline.vue

@@ -121,7 +121,11 @@
         </template>
       </el-table-column>
 
-      <el-table-column prop="trafficSum" label="流量数" align="center"/>
+      <el-table-column prop="trafficSum" label="流量数" align="center">
+        <template #default="scope">
+          {{ formatTraffic(scope.row.trafficSum) }}
+        </template>
+      </el-table-column>
       <el-table-column prop="regNum" label="注册数" align="center"/>
 
     </el-table>
@@ -218,6 +222,23 @@ export default {
     })
   },
   methods: {
+    formatTraffic(bytes) {
+      if (!bytes || bytes === 0) return '0 B';
+
+      const units = ['B', 'KB', 'MB', 'GB', 'TB'];
+      const k = 1024;
+
+      // 计算单位级别
+      const i = Math.floor(Math.log(bytes) / Math.log(k));
+
+      // 确保不超出单位数组范围
+      const unitIndex = Math.min(i, units.length - 1);
+
+      // 计算值并保留2位小数
+      const value = bytes / Math.pow(k, unitIndex);
+
+      return `${value.toFixed(2)} ${units[unitIndex]}`;
+    },
     getSummaries(param) {
       const { columns, data } = param;
       const sums = [];