From 12e72812d28c95394a17ec495985d44aff1c77f7 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期三, 06 十一月 2024 15:13:22 +0800
Subject: [PATCH] 文档资源查看优化

---
 packageDomain/pages/resourceDetails/document/index.js |   72 ++++++++++++++++++++++++++----------
 1 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/packageDomain/pages/resourceDetails/document/index.js b/packageDomain/pages/resourceDetails/document/index.js
index 0ca3e50..2001062 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: '',
@@ -37,6 +41,7 @@
     distance: 0, //璁板綍鎵嬫寚绉诲姩璺濈
     scale: 1, //瀹氫箟鍒濆鍖栫殑椤甸潰缂╂斁澶у皬
     newScale: 1, //璁板綍鏂扮殑椤甸潰缂╂斁澶у皬
+    pdfSrc: ''
   },
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
@@ -45,7 +50,6 @@
     wx.setNavigationBarTitle({
       title: '璧勬簮璇︽儏'
     });
-    console.log(options);
     const systInfo = wx.getSystemInfoSync();
     const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
     const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
@@ -55,6 +59,7 @@
       activeId: options.activeId,
       bookId: options.bookId,
       bookName: options.bookName,
+      storeInfo: options.storeInfo,
       cmsId: options.cmsId,
       parentName: options.parentName,
       parentProductLinkPath: options.parentProductLinkPath,
@@ -62,7 +67,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()
+    }
   },
 
   /**
@@ -88,7 +104,7 @@
     this.setData({
       pauseTime: Date.now()
     })
-    if (wx.getStorageSync(app.config.tokenKey) && epubObj && epubObj.bookBuy) {
+    if (wx.getStorageSync(app.config.tokenKey)) {
       let duration = this.data.pauseTime - this.data.startTime
       this.count(duration)
     }
@@ -101,7 +117,7 @@
     this.setData({
       pauseTime: Date.now()
     })
-    if (wx.getStorageSync(app.config.tokenKey) && epubObj && epubObj.bookBuy) {
+    if (wx.getStorageSync(app.config.tokenKey)) {
       let duration = this.data.pauseTime - this.data.startTime
       this.count(duration)
     }
@@ -135,21 +151,21 @@
   /**
    * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁�
    */
-  onReachBottom() {
-
-  },
+  onReachBottom() {},
 
   /**
    * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�
    */
-  onShareAppMessage() {
-
-  },
+  onShareAppMessage() {},
+  onShareTimeline() {},
   goBack() {
     wx.navigateBack()
   },
 
   resourceDetailsData() {
+    wx.showLoading({
+      title: '姝e湪鍔犺浇...',
+    });
     let query = {
       path: '*',
       queryType: '*',
@@ -174,8 +190,10 @@
         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)
@@ -264,45 +282,60 @@
   //鍒氳繘鏉ョ殑鏃跺�欒皟鐢�
   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 () {
     const naturalResources = this.data.naturalResources;
     naturalResources.forEach(function (item) {
-      // console.log(item);
     });
   },
 
@@ -339,7 +372,6 @@
     const {
       trigger
     } = e.detail;
-    console.log(trigger);
     this.setData({
       visible: false,
     });

--
Gitblit v1.9.1