Browse Source

优化阅读页

bayi 2 years ago
parent
commit
28452160f7
2 changed files with 8 additions and 4 deletions
  1. 7 3
      pages/reading/index.js
  2. 1 1
      pages/reading/index.wxml

+ 7 - 3
pages/reading/index.js

@@ -3,6 +3,8 @@ import {
 } from '~/api/video'
 let rowHeight = 0
 let videoContext = null
+let stl = null
+let setTimeoutObj = null
 Page({
     data: {
         videoInfo: {},
@@ -103,7 +105,7 @@ Page({
         this.setData({
             'countDown.state': true
         })
-        setInterval(() => {
+        this.stl = setInterval(() => {
             if (this.data.countDown.num == 0) {
                 clearInterval(this.stl)
                 this.setData({
@@ -123,6 +125,7 @@ Page({
         }, 1000)
     },
     startRecording() {
+        console.log('递归');
         if (this.data.currentRow == null) {
             this.setData({
                 currentRow: 0
@@ -132,7 +135,7 @@ Page({
         if (!row.readTime) {
             return
         }
-        let setTimeoutObj = setTimeout(() => {
+        this.setTimeoutObj = setTimeout(() => {
                 this.setData({
                     currentRow: ++this.data.currentRow
                 })
@@ -155,7 +158,8 @@ Page({
      * 生命周期函数--监听页面卸载
      */
     onUnload() {
-
+        clearTimeout(this.setTimeoutObj)
+        clearInterval(this.stl)
     },
     onShareAppMessage() {
 

+ 1 - 1
pages/reading/index.wxml

@@ -1,5 +1,5 @@
 <view class="readingBox">
-    <video id="myVideo" src="{{videoInfo.userRead.videoPath}}" bindended='videoEnd' controls="{{false}}"
+    <video id="myVideo" src="{{videoInfo.userRead.videoPath}}" bindended='videoEnd' controls="{{false}}" 
         show-center-play-btn="{{false}}"></video>
     <view class="contentBox">
         <view class="articleMask"></view>