Browse Source

feat: 文章详情阅读时长每次进入从0开始计时,10秒上报一次

- onShow 改为 startNewReadingSession:重置 readingSeconds/lastReportedSeconds,时长不再延续上一次会话
- 上报间隔 30000→10000,每10秒自动记录该用户已读时长
- 退出文章时 pauseReadingTimer 记录当时时长(保留原逻辑)
Xiaogang Liao 1 tháng trước cách đây
mục cha
commit
99d2bbfafe
1 tập tin đã thay đổi với 9 bổ sung2 xóa
  1. 9 2
      cfc-frontend/pages/article-center/article-detail.vue

+ 9 - 2
cfc-frontend/pages/article-center/article-detail.vue

@@ -106,7 +106,7 @@ export default {
     if (options && options.id) { this.articleId = options.id; this.loadDetail(options.id) }
     else { this.error = true; this.errorMsg = '参数错误'; this.loading = false }
   },
-  onShow() { if (this.article && !this.error) this.startReadingTimer() },
+  onShow() { if (this.article && !this.error) this.startNewReadingSession() },
   onHide() { this.pauseReadingTimer() },
   onUnload() { this.pauseReadingTimer() },
   methods: {
@@ -144,12 +144,19 @@ export default {
       return best ? best.code : ''
     },
     onScrollToBottom() {},
+    startNewReadingSession: function() {
+      // 每次进入文章详情页都从 0 开始新会话,时长不延续上一次
+      this.readingSeconds = 0
+      this.lastReportedSeconds = 0
+      this.startReadingTimer()
+    },
     startReadingTimer: function() {
       if (this.isTimerRunning || this.readingCompleted) return
       this.isTimerRunning = true
       var self = this
       this.timerHandle = setInterval(function() { self.readingSeconds++ }, 1000)
-      this.syncHandle = setInterval(function() { self.reportReadingTime() }, 30000)
+      // 每 10 秒自动记录一次该用户已读时长
+      this.syncHandle = setInterval(function() { self.reportReadingTime() }, 10000)
     },
     pauseReadingTimer: function() {
       if (!this.isTimerRunning) return