yjwang 3 дней назад
Родитель
Сommit
91319468e8
1 измененных файлов с 19 добавлено и 16 удалено
  1. 19 16
      src/views/course/userCoursePeriod/courseStatistics.vue

+ 19 - 16
src/views/course/userCoursePeriod/courseStatistics.vue

@@ -170,13 +170,13 @@
             <el-col :span="6">
               <div class="stat-item">
                 <div class="stat-label">人均看课时长</div>
-                <div class="stat-value">{{ (detailDialog.data.avgWatchDurationMinutes || 0) + '分' }}</div>
+                <div class="stat-value">{{ formatDuration(detailDialog.data.avgWatchDurationMinutes)}}</div>
               </div>
             </el-col>
             <el-col :span="6">
               <div class="stat-item">
                 <div class="stat-label">人均完课时长</div>
-                <div class="stat-value">{{ (detailDialog.data.avgCompletedDuration || 0) + '分' }}</div>
+                <div class="stat-value">{{ formatDuration(detailDialog.data.avgCompletedDuration)}}</div>
               </div>
             </el-col>
             <el-col :span="6">
@@ -571,20 +571,23 @@ export default {
         });
       }).catch(() => {});
     },
-    /** 格式化时长 */
-    formatDuration(seconds) {
-        if (seconds == null || isNaN(Number(seconds))) return '0分';
-        let totalSeconds = Math.abs(Number(seconds));
-        if (totalSeconds < 1) {
-            return `${(totalSeconds / 60).toFixed(2)}分`;
-        }
-        const hours = totalSeconds / 3600;
-        if (hours >= 1) {
-            return `${hours.toFixed(2)}小时`;
-        }
-        const minutes = totalSeconds / 60;
-        return `${minutes.toFixed(2)}分`;
-    }
+      /** 格式化时长 */
+      formatDuration(seconds) {
+          if (seconds == null || isNaN(seconds)) return '0秒';
+          let total = Math.abs(seconds);
+          const hours = Math.floor(total / 3600);
+          const minutes = Math.floor((total % 3600) / 60);
+          const secs = Math.floor(total % 60);
+
+          const parts = [];
+          if (hours > 0) parts.push(`${hours}小时`);
+          if (minutes > 0) parts.push(`${minutes}分`);
+          if (secs > 0 || parts.length === 0) {
+              parts.push(`${secs}秒`);
+          }
+
+          return parts.join('');
+      }
   }
 };
 </script>