liyongli 1 vuosi sitten
vanhempi
commit
17b4eed0a7
3 muutettua tiedostoa jossa 47 lisäystä ja 61 poistoa
  1. 40 60
      pages/downZS/index.js
  2. 6 0
      pages/expert/index.js
  3. 1 1
      pages/expert/index.wxml

+ 40 - 60
pages/downZS/index.js

@@ -57,83 +57,63 @@ Page({
 
   download() {
     if (!this.data.ls_url) return
-    wx.downloadFile({
-      url: this.data.ls_url, // 这里替换为你的图片链接  
-      success: function (res) {
-        if (res.statusCode === 200) {
-          wx.saveImageToPhotosAlbum({
-            filePath: res.tempFilePath, // 使用下载得到的临时文件路径  
-            success: function (saveRes) {
-              wx.showToast({
-                title: '保存成功',
-                icon: 'success',
-                duration: 2000
-              });
-            },
-            fail: function (err) {
-              if (err.errMsg === 'saveImageToPhotosAlbum:fail:auth denied') {
-                wx.showModal({
-                  title: '保存失败',
-                  content: '请前往设置页面授权保存图片到相册',
-                  showCancel: false,
-                  success: function (modalRes) {
-                    wx.openSetting({
-                      withSubscriptions: true,
-                      success: function (res) {
-                        if (res.authSetting['scope.writePhotosAlbum']) {
-                          // 用户重新授权后,再次尝试保存图片  
-                          wx.saveImageToPhotosAlbum({
-                            filePath: res.tempFilePath,
-                            success: function (saveRes) {
-                              wx.showToast({
-                                title: '保存成功',
-                                icon: 'success',
-                                duration: 2000
-                              });
-                            },
-                            fail: function (err) {
-                              wx.showToast({
-                                title: '保存失败',
-                                icon: 'none',
-                                duration: 2000
-                              });
-                            }
-                          });
-                        }
+    wx.saveImageToPhotosAlbum({
+      filePath: this.data.ls_url, // 使用下载得到的临时文件路径  
+      success: function (saveRes) {
+        wx.showToast({
+          title: '已保存至相册',
+          icon: 'success',
+          duration: 2000
+        });
+      },
+      fail: function (err) {
+        if (err.errMsg === 'saveImageToPhotosAlbum:fail:auth denied') {
+          wx.showModal({
+            title: '保存失败',
+            content: '请前往设置页面授权保存图片到相册',
+            showCancel: false,
+            success: function (modalRes) {
+              wx.openSetting({
+                withSubscriptions: true,
+                success: function (res) {
+                  if (res.authSetting['scope.writePhotosAlbum']) {
+                    // 用户重新授权后,再次尝试保存图片  
+                    wx.saveImageToPhotosAlbum({
+                      filePath: res.tempFilePath,
+                      success: function (saveRes) {
+                        wx.showToast({
+                          title: '保存成功',
+                          icon: 'success',
+                          duration: 2000
+                        });
                       },
                       fail: function (err) {
                         wx.showToast({
-                          title: '打开设置页面失败',
+                          title: '保存失败',
                           icon: 'none',
                           duration: 2000
                         });
                       }
                     });
                   }
-                });
-              } else {
-                wx.showToast({
-                  title: '保存失败',
-                  icon: 'none',
-                  duration: 2000
-                });
-              }
+                },
+                fail: function (err) {
+                  wx.showToast({
+                    title: '打开设置页面失败',
+                    icon: 'none',
+                    duration: 2000
+                  });
+                }
+              });
             }
           });
         } else {
           wx.showToast({
-            title: '下载失败',
+            title: '保存失败',
             icon: 'none',
             duration: 2000
           });
         }
-      },
-      fail: function (err) {
-        wx.showToast({
-          title: '下载失败',
-          icon: 'none',
-          duration: 2000
-        });
       }
     });
   },

+ 6 - 0
pages/expert/index.js

@@ -29,6 +29,12 @@ Page({
     ]
   },
 
+  showimge(e){
+    wx.previewImage({
+      urls: [e.currentTarget.dataset.url],
+    })
+  },
+
   /**
    * 生命周期函数--监听页面加载
    */

+ 1 - 1
pages/expert/index.wxml

@@ -2,7 +2,7 @@
 <view class="list_item" wx:for="{{list}}" wx:key="index">
   <Container>
     <view class="row">
-      <image src="{{item.works}}" mode="aspectFit" class="col-d"></image>
+      <image bind:tap="showimge"src="{{item.works}}" data-url="{{item.works}}" mode="aspectFit" class="col-d"></image>
       <view class="col">
         <view>姓名:{{item.name}}</view>
         <view>指导老师:{{item.teacher}}</view>