litian
2024-04-02 6a734d758720185f538e672c879121adb6732274
packageBookService/pages/components/webView/index.js
@@ -12,6 +12,8 @@
    currentPage: '',
    pdfList: [],
    skeletonLoding: true,
    startTime: "", //进入页面当前时间
    pauseTime: 0 //暂停时间
  },
  /**
@@ -86,7 +88,6 @@
        md5: data.md5
      }).then((res) => {
        let pageCount = data.bookBuy ? res.totalPages : Number(data.freePage)
        if (pageCount) {
          let list = [];
@@ -179,21 +180,54 @@
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      startTime: Date.now()
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    this.setData({
      pauseTime: Date.now()
    })
    if (wx.getStorageSync(app.config.tokenKey) && epubObj.bookBuy) {
      let duration = this.data.pauseTime - this.data.startTime
      this.count(duration)
    }
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    this.setData({
      pauseTime: Date.now()
    })
    if (wx.getStorageSync(app.config.tokenKey) && epubObj.bookBuy) {
      let duration = this.data.pauseTime - this.data.startTime
      this.count(duration)
    }
  },
  count(timeStr) {
    const data = {
      appRefCode: app.config.appRefCode,
      type: 'LearningTime', //统计类型--阅读时长
      data: timeStr + '', //统计内容--时长毫秒
      event: 'LearningTime',
      sysType: 'App'
    }
    //阅读商品的id
    if (epubObj.bookId) {
      data.productId = epubObj.bookId
    }
    //阅读资源的id
    // if (product.cmsItemId) {
    //   data.cmsItemId = product.cmsItemId
    // }
    app.MG.job.newJobWithApiNewEvent(data).then((res) => {})
  },
  /**