litian
2024-09-06 8dc4e50769a7ebc5f0a3d766f61aa08b8f23b772
packageDomain/pages/resourceDetails/document/index.js
@@ -1,4 +1,5 @@
// pages/resourceDetails/document/index.js
import Toast from 'tdesign-miniprogram/toast/index';
const app = getApp()
Page({
@@ -6,10 +7,16 @@
   * 页面的初始数据
   */
  data: {
    visible: false,
    showIndex: false,
    closeBtn: false,
    deleteBtn: false,
    images: [],
    webpageSrc: '',
    navBarHeight: '',
    barHeight: '',
    activeId: '',
    storeInfo: '',
    bookId: '',
    bookName: '',
    cmsId: '',
@@ -23,27 +30,46 @@
    naturalResources: [],
    titleName: '',
    pdfDatA: [],
    startTime: "", //进入页面当前时间
    pauseTime: 0, //暂停时间
    applyState: '',
    deadline: '',
    lzoomFlag: false, //定义 缩放事件 节流阀,防止一次缩放触发两次缩放事件
    distance: 0, //记录手指移动距离
    scale: 1, //定义初始化的页面缩放大小
    newScale: 1, //记录新的页面缩放大小
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({
      title: '资源详情'
    });
    console.log(options);
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    this.setData({
      navBarHeight: navBarHeight,
      barHeight: systInfo.statusBarHeight,
      activeId: options.activeId,
      bookId: options.bookId,
      bookName: options.bookName,
      storeInfo: options.storeInfo,
      cmsId: options.cmsId,
      parentName: options.parentName,
      parentProductLinkPath: options.parentProductLinkPath,
      productLinkPath: options.productLinkPath
      productLinkPath: options.productLinkPath,
      applyState: options.applyState,
      deadline: options.deadline
    })
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {} else {}
      })
    }
    this.resourceDetailsData()
  },
@@ -58,23 +84,55 @@
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      startTime: Date.now()
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    this.setData({
      pauseTime: Date.now()
    })
    if (wx.getStorageSync(app.config.tokenKey) && epubObj && 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 && 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 (this.data.bookId) {
      data.productId = this.data.bookId
    }
    //阅读资源的id
    if (this.data.cmsId) {
      data.cmsItemId = this.data.cmsId
    }
    app.MG.job.newJobWithApiNewEvent(data).then((res) => {})
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
@@ -124,14 +182,12 @@
        size: 999
      }
    }
    if (this.data.storeInfo) {
      query.storeInfo = this.data.storeInfo
    }
    app.MG.store.getProductDetail(query).then((res) => {
      console.log(res);
      res.datas.cmsDatas[0].datas.forEach((item) => {
        //刚刚进来的时候
        if (this.data.productLinkPath == item.productLinkPath) {
          this.handleTeachData(item)
          this.setData({
@@ -139,14 +195,21 @@
            selectType: item.selectType
          })
        }
      })
    })
  },
  //zpi文件下载
  onDownloadButton() {
    const item = this.data.zipData;
    if (this.data.applyState !== 'Normal') {
      if (!this.data.deadline == '永久') {
        const flag = new Date(this.data.deadline) > new Date()
        return wx.showToast({
          icon: 'none',
          title: '请先申请下载',
        })
      }
    }
    if (!item || !item.file) {
      wx.showToast({
        title: '文件信息缺失',
@@ -154,12 +217,10 @@
      });
      return;
    }
    const downloadUrl = app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file;
    wx.showLoading({
      title: '正在下载...',
    });
    wx.downloadFile({
      url: downloadUrl,
      success(res) {
@@ -214,11 +275,12 @@
  //刚进来的时候调用
  handleTeachData(item) {
    //图片
    console.log(item, 'item11111');
    if (item.selectType == 'picture') {
      this.setData({
        showData: app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file,
        showData: item.file ? app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file : app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.freeFile,
      })
      console.log(this.data.showData, 'showData');
    }
    // 下载文件zip
    if (item.selectType == 'zip') {
@@ -232,10 +294,11 @@
        webpageSrc: item.jsek_link
      })
    }
    //文档等
    if (item.selectType == 'pdf' || item.selectType == 'document') {
      app.MG.file.getPdfInfo({ md5: item.file }).then((res) => {
      app.MG.file.getPdfInfo({
        md5: item.file
      }).then((res) => {
        if (res && res.totalPages) {
          for (let i = 0; i < res.totalPages; i++) {
            const src = app.config.requestCtx + '/file/GetPdfPageImage?md5=' + item.file + '&index=' + (i + 1) + '&dpi=300'
@@ -244,24 +307,111 @@
          }
        }
      })
    }
  },
  handleTap: function () {
    const naturalResources = this.data.naturalResources;
    naturalResources.forEach(function (item) {
      // console.log(item);
    });
  }
  },
  onClick() {
    this.setData({
      images: [
        this.data.showData,
        // 'https://tdesign.gtimg.com/mobile/demos/swiper2.png',
      ],
      showIndex: true,
      visible: true,
    });
  },
  onChange(e) {
    const {
      index
    } = e.detail;
    console.log('change', index);
  },
  onDelete(e) {
    const {
      index
    } = e.detail;
    Toast({
      context: this,
      selector: '#t-toast',
      message: `删除第${index + 1}个`,
    });
  },
  onClose(e) {
    const {
      trigger
    } = e.detail;
    console.log(trigger);
    this.setData({
      visible: false,
    });
  },
  //预览图片,放大预览
  preview(event) {
    let urls = [event.currentTarget.dataset.src]
    wx.previewImage({
      urls: urls // 需要预览的图片http链接列表
    })
  },
  // myTouchStart(e) {
  //   //---------------------记录缩放事件信息---------------------
  //   // 当两根手指放上去的时候,将距离(distance)初始化。
  //   let xMove = e.touches[1].clientX - e.touches[0].clientX;
  //   let yMove = e.touches[1].clientY - e.touches[0].clientY;
  //   //计算开始触发两个手指坐标的距离
  //   const distance = Math.sqrt(xMove * xMove + yMove * yMove);
  //   this.setData({
  //     distance: distance
  //   })
  //   //---------------------记录缩放事件信息end---------------------
  // },
  // myTouchMove(e) {
  //   // ----------------监听手势缩小放大事件----------------
  //   // 单手指缩放不做任何操作
  //   if (e.touches.length != 1) {
  //     //双手指运动 x移动后的坐标和y移动后的坐标
  //     let xMove = e.touches[1].clientX - e.touches[0].clientX;
  //     let yMove = e.touches[1].clientY - e.touches[0].clientY;
  //     //双手指运动新的 ditance
  //     let newDistance = Math.sqrt(xMove * xMove + yMove * yMove);
  //     //计算移动的过程中实际移动了多少的距离
  //     let distanceDiff = newDistance - this.data.distance;
  //     // newScale = scale + 0.005 * distanceDiff
  //     console.log('移动距离', distanceDiff);
  //     this.setData({
  //       newScale: this.data.newScale + 0.005 * distanceDiff
  //     })
  //     // 打开缩放监听
  //     // zoomFlag = true
  //     this.setData({
  //       lzoomFlag: true
  //     })
  //     return
  //   }
  //   // ----------------监听手势缩小放大事件end----------------
  // },
  // myTouchEnd() {
  //   if (this.data.lzoomFlag) {
  //     if (this.data.newScale > 1.3) {
  //       console.log("放大了", this.data.newScale);
  //     } else if (this.data.newScale < 0.7, this.data.newScale) {
  //       console.log("缩小了");
  //     }
  //     // 关闭缩放监听
  //     // zoomFlag = false
  //     this.setData({
  //       lzoomFlag: false
  //     })
  //   }
  // },
})