From 2ba73e57ca1f5094cda73e9627ac33d70e7cac41 Mon Sep 17 00:00:00 2001
From: liukangdong <898885815@qq.com>
Date: 星期四, 25 七月 2024 11:54:42 +0800
Subject: [PATCH] Merge branch 'master' of http://139.186.142.91:10010/r/productDev/zbomyoujia

---
 wechat_staff/utils/downloadSaveFile.js |  141 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 141 insertions(+), 0 deletions(-)

diff --git a/wechat_staff/utils/downloadSaveFile.js b/wechat_staff/utils/downloadSaveFile.js
new file mode 100644
index 0000000..6c11afe
--- /dev/null
+++ b/wechat_staff/utils/downloadSaveFile.js
@@ -0,0 +1,141 @@
+// 灏佽涓�涓柟娉� 鍦╱tils涓� 鍚嶄负 downloadSaveFile.js
+// 浣跨敤鏃� 寮曞叆锛堟寜鐓ц嚜宸辩殑璺姴鍐欙級  import { downloadFiles} from '../../utils/downloadSaveFile'
+
+
+function downloadFiles(type, urls) {
+  checkAuth(() => {
+    wx.showLoading({
+      title: '姝e湪涓嬭浇',
+      mask: true
+    })
+    for (let i = 0; i < urls.length; i++) {
+      downloadSaveFile(
+        urls[i],
+      );
+    }
+  })
+}
+
+//涓嬭浇鏂囦欢
+function downloadSaveFile(url, successc) {
+  let isimg = 'bmp,jpg,png,tif,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw,wmf, jpeg'.includes(url.split('.').slice(-1))
+  if (isimg) {
+  // 濡傛灉鏄浘鐗囩被鍨�
+    wx.downloadFile({
+      url: url,
+      success: res => {
+        if (res.statusCode === 200) {
+          wx.saveImageToPhotosAlbum({
+            filePath: res.tempFilePath,
+            success: res => {
+              wx.showToast({
+                title: '淇濆瓨鎴愬姛',
+                icon: "none"
+              })
+            },
+            fail: res => {
+              wx.showToast({
+                title: '淇濆瓨澶辫触',
+                icon: "none"
+              })
+            }
+          })
+
+        }
+      }
+    })
+
+  } else {
+  // 濡傛灉鏄棰戠被鍨�
+    wx.downloadFile({
+      url: url,
+      success: res => {
+        if (res.statusCode === 200) {
+          wx.saveVideoToPhotosAlbum({
+            filePath: res.tempFilePath,
+            success: res => {
+              // successc && successc();
+              wx.showToast({
+                title: '淇濆瓨鎴愬姛',
+                icon: "none"
+              })
+            },
+            fail: res => {
+                wx.showToast({
+                title: '淇濆瓨澶辫触',
+                icon: "none"
+              })
+            }
+          })
+        }
+      }
+    })
+  }
+}
+
+//妫�鏌ユ潈闄�
+function checkAuth(gotc) {
+  //鏌ヨ鏉冮檺
+  wx.showLoading({
+    title: '妫�鏌ユ巿鏉冩儏鍐�',
+    mask: true
+  })
+  wx.getSetting({
+    success(res) {
+      wx.hideLoading();
+      if (!res.authSetting['scope.writePhotosAlbum']) {
+        //璇锋眰鎺堟潈
+        wx.authorize({
+          scope: 'scope.writePhotosAlbum',
+          success() {
+            //鑾峰緱鎺堟潈锛屽紑濮嬩笅杞�
+            gotc && gotc();
+          },
+          fail() {
+            wx.showModal({
+              title: '',
+              content: '淇濆瓨鍒扮郴缁熺浉鍐岄渶瑕佹巿鏉�',
+              confirmText: '鎺堟潈',
+              success(res) {
+                if (res.confirm) {
+                  wx.openSetting({
+                    success(res) {
+                      if (res.authSetting['scope.writePhotosAlbum'] === true) {
+                        gotc && gotc();
+                      }
+                    }
+                  })
+                }
+              },
+              fail() {
+                wx.showToast({
+                  title: '鎵撳紑璁剧疆椤靛け璐�',
+                  icon: 'none',
+                })
+              }
+            })
+          }
+        })
+      } else {
+        //宸叉湁鎺堟潈
+        gotc && gotc();
+      }
+    },
+    fail() {
+      wx.hideLoading();
+      wx.showToast({
+        title: '鑾峰彇鎺堟潈澶辫触',
+        icon: 'none',
+      })
+    }
+  })
+}
+
+module.exports = {
+  downloadFiles,
+  checkAuth,
+  downloadSaveFile
+};
+
+
+

--
Gitblit v1.9.3