From 50ca1ad0d141d7dc0ddf29b2d3051b85ceff8f56 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期二, 05 十一月 2024 10:21:05 +0800
Subject: [PATCH] pdf阅读优化

---
 packageDomain/pages/resourceDetails/document/index.js |  125 +++++++++++++++++++++++++++++++++++------
 1 files changed, 107 insertions(+), 18 deletions(-)

diff --git a/packageDomain/pages/resourceDetails/document/index.js b/packageDomain/pages/resourceDetails/document/index.js
index 2276497..0f5bb65 100644
--- a/packageDomain/pages/resourceDetails/document/index.js
+++ b/packageDomain/pages/resourceDetails/document/index.js
@@ -1,6 +1,9 @@
 // pages/resourceDetails/document/index.js
 import Toast from 'tdesign-miniprogram/toast/index';
 const app = getApp()
+import {
+  loginInfo
+} from '../../../../assets/js/login';
 Page({
 
   /**
@@ -16,6 +19,7 @@
     navBarHeight: '',
     barHeight: '',
     activeId: '',
+    storeInfo: '',
     bookId: '',
     bookName: '',
     cmsId: '',
@@ -33,6 +37,11 @@
     pauseTime: 0, //鏆傚仠鏃堕棿
     applyState: '',
     deadline: '',
+    lzoomFlag: false, //瀹氫箟 缂╂斁浜嬩欢 鑺傛祦闃�,闃叉涓�娆$缉鏀捐Е鍙戜袱娆$缉鏀句簨浠�
+    distance: 0, //璁板綍鎵嬫寚绉诲姩璺濈
+    scale: 1, //瀹氫箟鍒濆鍖栫殑椤甸潰缂╂斁澶у皬
+    newScale: 1, //璁板綍鏂扮殑椤甸潰缂╂斁澶у皬
+    pdfSrc: ''
   },
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
@@ -51,6 +60,7 @@
       activeId: options.activeId,
       bookId: options.bookId,
       bookName: options.bookName,
+      storeInfo: options.storeInfo,
       cmsId: options.cmsId,
       parentName: options.parentName,
       parentProductLinkPath: options.parentProductLinkPath,
@@ -58,7 +68,18 @@
       applyState: options.applyState,
       deadline: options.deadline
     })
-    this.resourceDetailsData()
+    const token = wx.getStorageSync(app.config.tokenKey)
+    if (!token) {
+      loginInfo(app, (data) => {
+        if (data) {
+          this.resourceDetailsData()
+        } else {
+          this.resourceDetailsData()
+        }
+      })
+    } else {
+      this.resourceDetailsData()
+    }
   },
 
   /**
@@ -131,21 +152,21 @@
   /**
    * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁�
    */
-  onReachBottom() {
-
-  },
+  onReachBottom() {},
 
   /**
    * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�
    */
-  onShareAppMessage() {
-
-  },
+  onShareAppMessage() {},
+  onShareTimeline() {},
   goBack() {
     wx.navigateBack()
   },
 
   resourceDetailsData() {
+    wx.showLoading({
+      title: '姝e湪鍔犺浇...',
+    });
     let query = {
       path: '*',
       queryType: '*',
@@ -169,6 +190,9 @@
         start: 0,
         size: 999
       }
+    }
+    if (this.data.storeInfo) {
+      query.storeInfo = this.data.storeInfo
     }
     app.MG.store.getProductDetail(query).then((res) => {
       console.log(res);
@@ -260,39 +284,55 @@
   //鍒氳繘鏉ョ殑鏃跺�欒皟鐢�
   handleTeachData(item) {
     //鍥剧墖
-    console.log(item, 'item11111');
     if (item.selectType == 'picture') {
       this.setData({
         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');
+      wx.hideLoading();
     }
     // 涓嬭浇鏂囦欢zip
     if (item.selectType == 'zip') {
       this.setData({
         zipData: item
       })
+      wx.hideLoading();
     }
     //缃戦〉
     if (item.selectType == 'webpage') {
       this.setData({
         webpageSrc: item.jsek_link
       })
+      wx.hideLoading();
     }
+    // if (item.selectType == 'pdf') {
+    //   console.log('pdf', item);
+    //   wx.hideLoading()
+    //   let md5 = item.file ? item.file : item.freeFile
+    //   let pdfSrc = app.config.pdfUrl + "?MD5=" + md5 + "&url=" + app.config.requestCtx + '&currentPage=' + "1" + "&isPreview=" + false + "&warterMark=" + "鍖椾含甯堣寖澶у鍑虹増绀�" + "&previewPages=" + 30 + "&token=" + wx.getStorageSync(app.config.tokenKey)
+    //   this.setData({
+    //     pdfSrc: pdfSrc
+    //   })
+    // }
     //鏂囨。绛�
-    if (item.selectType == 'pdf' || item.selectType == 'document') {
+    if (item.selectType == 'document' || item.selectType == 'pdf') {
+      let md5 = item.file ? item.file : item.freeFile
       app.MG.file.getPdfInfo({
-        md5: item.file
+        md5: md5
       }).then((res) => {
+        let naturalResources = []
         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'
-            this.data.naturalResources.push(src)
-            // console.log(this.data.naturalResources, ' this.data.naturalResources');
+            const src = app.config.requestCtx + '/file/GetPdfPageImage?md5=' + md5 + '&index=' + (i + 1) + '&dpi=300'
+            naturalResources.push(src)
           }
         }
+        this.setData({
+          naturalResources
+        })
+        wx.hideLoading();
       })
     }
+
   },
 
   handleTap: function () {
@@ -342,12 +382,61 @@
   },
   //棰勮鍥剧墖锛屾斁澶ч瑙�
   preview(event) {
-    console.log(event.currentTarget.dataset.src)
-    let currentUrl = event.currentTarget.dataset.src
+    let urls = [event.currentTarget.dataset.src]
     wx.previewImage({
-      current: currentUrl, // 褰撳墠鏄剧ず鍥剧墖鐨刪ttp閾炬帴
-      // urls: this.data.showData // 闇�瑕侀瑙堢殑鍥剧墖http閾炬帴鍒楄〃
+      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绉诲姩鍚庣殑鍧愭爣鍜寉绉诲姩鍚庣殑鍧愭爣
+  //     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
+  //     })
+  //   }
+  // },
 })
\ No newline at end of file

--
Gitblit v1.9.1