Browse Source

baocuntupian

邹能昇 3 months ago
parent
commit
d6717ea63f
1 changed files with 57 additions and 8 deletions
  1. 57 8
      nova-werun/pages/home/share/index.js

+ 57 - 8
nova-werun/pages/home/share/index.js

@@ -19,11 +19,10 @@ Page({
         sharList: [],
 
         images: [
-            'https://tse2-mm.cn.bing.net/th/id/OIP-C.kACuwmhGcHKV4G4Og9AFqgHaLG?rs=1&pid=ImgDetMain',
-            'https://tse1-mm.cn.bing.net/th/id/OIP-C.LYrbU3wnasLo4nvoAqs_HQHaLH?rs=1&pid=ImgDetMain',
-            'https://tse3-mm.cn.bing.net/th/id/OIP-C.KKzj-pCKvzmWJ9MU5pE5KwHaKq?rs=1&pid=ImgDetMain',
-            'https://ts1.cn.mm.bing.net/th/id/R-C.d8333a26a5494dfe1dc88e9fdd04fb31?rik=08fpnYZSbboHfQ&riu=http%3a%2f%2fpic.ibaotu.com%2fspiders%2f33817-59a6262d3ff70.jpg&ehk=fKs2FTTgk2k0kqet%2fVO%2bAS3D0Q6zlNyUPmT8UE%2bvpdY%3d&risl=&pid=ImgRaw&r=0',
-            'https://pic.nximg.cn/file/20230420/12106414_122949747127_2.jpg'
+            'https://file-cloud.fmode.cn/qpFbRRSZrO/20250102/gtontq125800552.jpg?imageView2/1/w/200/h/200',
+            'https://file-cloud.fmode.cn/qpFbRRSZrO/20250102/8e1ps0125800358.jpg?imageView2/1/w/200/h/200',
+            'https://file-cloud.fmode.cn/qpFbRRSZrO/20250102/l5321n125800284.jpg?imageView2/1/w/200/h/200',
+            'https://file-cloud.fmode.cn/qpFbRRSZrO/20250102/j1p6l7125757884.jpg?imageView2/1/w/200/h/200'
         ],
         randomImage: '',
         saveimage: ''
@@ -280,8 +279,8 @@ Page({
                             });
                         });
                     },
-                    fail: () => {
-                        console.error('用户头像加载失败');
+                    fail: (err) => {
+                        console.error('用户头像加载失败', this.data.sharList[0].user.avatar, err);
                     }
                 });
             },
@@ -447,5 +446,55 @@ Page({
                 icon: 'none'
             });
         }
-    }
+    },
+    savepic2() {
+        const that = this
+        let fileName = new Date().valueOf();
+        let filePath = wx.env.USER_DATA_PATH + '/' + fileName + '.jpg' //这边就是为了安卓做的兼容,因为安卓机有可能会将图片地址的后缀名读取为:unknow
+        wx.downloadFile({
+            url: that.data.saveimage, //需要保存的图片地址
+            filePath: filePath,
+            success: function (res) {
+                // 保存图片到系统相册
+                wx.saveImageToPhotosAlbum({
+                    filePath: filePath,
+                    success(data) {
+                        let fileMgr = wx.getFileSystemManager()
+                        fileMgr.unlink({
+                            filePath: filePath,
+                            success() {
+                                wx.showToast({
+                                    title: '已保存至您的相册',
+                                    icon: 'none',
+                                    duration: 1500
+                                });
+                            }
+                        })
+                    },
+                    fail(err) {
+                        if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
+                            wx.showModal({
+                                title: '提示',
+                                content: '需要您授权保存相册',
+                                showCancel: false,
+                                success: modalSuccess => {
+                                    wx.openSetting({
+                                        success(settingdata) {
+                                            if (settingdata.authSetting['scope.writePhotosAlbum']) {
+                                                console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
+                                            } else {
+                                                console.log('获取权限失败,给出不给权限就无法正常使用的提示')
+                                            }
+                                        }
+                                    })
+                                }
+                            })
+                        }
+                    }
+                })
+            },
+            fail: function (res) {}
+        })
+    },
+
 })