chengjunhui hace 1 mes
padre
commit
5c7f011e8b
Se han modificado 2 ficheros con 38 adiciones y 17 borrados
  1. 38 16
      pages/download/download.js
  2. 0 1
      pages/match/index.js

+ 38 - 16
pages/download/download.js

@@ -5,13 +5,13 @@ Page({
    * 页面的初始数据
    */
   data: {
-
+      pageNum: 0,
   },
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
-    console.log(options)
+    // console.log(options)
     const url = decodeURIComponent(options.url || '')
     if (url) {
       this.downloadFileH5(url)
@@ -24,24 +24,40 @@ Page({
       title: '文件下载中...',
       mask: true
     })
+    let type = url.split('.');
+    type = type[type.length - 1];
+    // return
     wx.downloadFile({
       url: url,
       success: (ret) => {
         console.log(ret)
         if (ret.statusCode == 200) {
-          //下载完文件
-          wx.getFileSystemManager().saveFile({
-            tempFilePath: ret.tempFilePath,
-            complete: (err) => {
-              wx.hideLoading();
-              wx.showToast({
-                title: err.errMsg == 'saveFile:ok' ? '下载成功' : '下载失败',
-              })
-              setTimeout(() => {
-                wx.navigateBack();
-              }, 500);
-            }
-          })
+          if ((["png", "jpeg", "jpg"].includes(type))) {
+            wx.saveImageToPhotosAlbum({
+              filePath: ret.tempFilePath,
+              complete: (err) => {
+                // console.log(err)
+                wx.hideLoading();
+                wx.showToast({
+                  title: err.errMsg == 'saveImageToPhotosAlbum:ok' ? '下载成功' : '下载失败',
+                })
+                setTimeout(() => {
+                  wx.navigateBack();
+                }, 500);
+              }
+            })
+          } else {
+            wx.openDocument({
+              filePath: ret.tempFilePath,
+              showMenu: true,
+              success: function (res) {
+                console.log('打开文档成功')
+              },
+              complete: (err)=>{
+                console.log(err)
+              }
+            })
+          }
         } else {
           wx.hideLoading();
           wx.showToast({
@@ -72,7 +88,13 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
-
+    if(this.data.pageNum){
+      wx.navigateBack();
+      return
+    }
+    this.setData({
+      pageNum: 1,
+    })
   },
 
   /**

+ 0 - 1
pages/match/index.js

@@ -42,7 +42,6 @@ Page({
         webViewUrl: `${app.webViewUrl}?token=${token || ''}`,
       });
     }
-
   },
 
   /**