|
|
@@ -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
|