From 89e7ed902461f28d6a7dd3e6c927eaf40b154f5e Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期四, 15 八月 2024 10:12:07 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 wechat_staff/pages/download/index.js |  179 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 152 insertions(+), 27 deletions(-)

diff --git a/wechat_staff/pages/download/index.js b/wechat_staff/pages/download/index.js
index c6066ce..2c3d458 100644
--- a/wechat_staff/pages/download/index.js
+++ b/wechat_staff/pages/download/index.js
@@ -1,6 +1,10 @@
-// pages/download/index.js
-const { HYEventBus } = require('hy-event-store')
-const eventBus = new HYEventBus()
+import {
+  getContentShareImg
+} from '../../api/index'
+import {
+  checkAuth,
+  downloadSaveFile
+} from '../../utils/downloadSaveFile'
 Page({
 
   /**
@@ -9,6 +13,7 @@
   data: {
     bottomLift: '',
     downloadList: [],
+    downloadConfig: {},
     checkedAll: false,
     showParam: false,
     takeQrcode: true
@@ -23,8 +28,115 @@
       bottomLift: app.bottomLift
     })
   },
+  subDownload() {
+    let that = this
+    const downloadList = this.data.downloadList
+    const downloadConfig = this.data.downloadConfig
+    checkAuth(() => {
+      wx.showLoading({
+        title: '姝e湪涓嬭浇',
+        mask: true
+      })
+      downloadList.forEach(item => {
+        if (item.checked) {
+          item.paddingStatus = 2
+        }
+      })
+      this.setData({
+        downloadList
+      })
+      downloadList.forEach(item => {
+        if (item.checked) {
+          if (that.data.takeQrcode == 1) {
+            getContentShareImg({
+              articleId: `${downloadConfig.id}_${downloadConfig.path}`,
+              type: that.data.takeQrcode ? 1 : 0,
+              imgurl: item.url
+            }).then(res => {
+              wx.downloadFile({
+                url: res.data,
+                success: res => {
+                  if (res.statusCode === 200) {
+                    wx.saveImageToPhotosAlbum({
+                      filePath: res.tempFilePath,
+                      success: res => {
+                        item.paddingStatus = 3
+                        item.checked = false
+                        that.setData({
+                          downloadList
+                        })
+                        wx.showToast({
+                          title: '淇濆瓨鎴愬姛',
+                          icon: "none"
+                        })
+                      },
+                      fail: res => {
+                        item.paddingStatus = 4
+                        item.checked = false
+                        that.setData({
+                          downloadList
+                        })
+                        wx.showToast({
+                          title: '淇濆瓨澶辫触',
+                          icon: "none"
+                        })
+                      }
+                    })
+
+                  }
+                }
+              })
+            })
+          }else{
+            wx.downloadFile({
+              url: item.url,
+              success: res => {
+                if (res.statusCode === 200) {
+                  wx.saveImageToPhotosAlbum({
+                    filePath: res.tempFilePath,
+                    success: res => {
+                      item.paddingStatus = 3
+                      item.checked = false
+                      that.setData({
+                        downloadList
+                      })
+                      wx.showToast({
+                        title: '淇濆瓨鎴愬姛',
+                        icon: "none"
+                      })
+                    },
+                    fail: res => {
+                      item.paddingStatus = 4
+                      item.checked = false
+                      that.setData({
+                        downloadList
+                      })
+                      wx.showToast({
+                        title: '淇濆瓨澶辫触',
+                        icon: "none"
+                      })
+                    }
+                  })
+
+                }
+              },
+              fail(err) { 
+                wx.showToast({
+                  title: '鍥剧墖涓嬭浇澶辫触',icon: 'none'
+                })
+              }
+            })
+          }
+        }
+      })
+    })
+    this.setData({
+      showParam: false
+    })
+  },
   onShow() {
     const downloadList = wx.getStorageSync('downloadList') || []
+    const downloadConfig = wx.getStorageSync('downloadConfig') || {}
     let temp = downloadList.map(i => {
       // paddingStatus锛� 0鏈笅杞�1姝e湪涓嬭浇2绛夊緟涓嬭浇3涓嬭浇瀹屾垚
       return {
@@ -33,54 +145,67 @@
         checked: false
       }
     })
-    this.setData({ downloadList: temp })
-    setTimeout(() => {
-      wx.setStorageSync('downloadList', [])
-    },500)
+    this.setData({
+      downloadList: temp,
+      downloadConfig
+    })
   },
   openParam() {
     const downloadList = this.data.downloadList.filter(i => i.checked)
-    if(downloadList.length === 0) return wx.showToast({title: '璇峰厛閫夋嫨瑕佷笅杞界殑娴锋姤', icon: 'none'})
-    this.setData({ showParam: true })
+    if (downloadList.length === 0) return wx.showToast({
+      title: '璇峰厛閫夋嫨瑕佷笅杞界殑娴锋姤',
+      icon: 'none'
+    })
+    this.setData({
+      showParam: true
+    })
   },
   onClose() {
-    this.setData({ showParam: false })
+    this.setData({
+      showParam: false
+    })
   },
   downCheck(e) {
     const takeQrcode = e.currentTarget.dataset.flag
     console.log('takeQrcode', takeQrcode);
-    this.setData({ takeQrcode })
-  },
-  subDownload() {
-    const downloadList = this.data.downloadList
-    downloadList.forEach(item => {
-      if(item.checked){
-        
-      }
+    this.setData({
+      takeQrcode
     })
-
-    this.setData({ showParam: false })
   },
   itemCheck(e) {
     const i = e.currentTarget.dataset.i
-    const { downloadList, checkedAll } = this.data
+    const {
+      downloadList
+    } = this.data
     let count = 0
     downloadList.forEach((item, index) => {
-      if(index === i){
+      if (index === i) {
+        if (item.paddingStatus == 3) {
+          item.paddingStatus = 0
+        }
         item.checked = !item.checked
       }
-      if(item.checked) {
-        count ++
+      if (item.checked) {
+        count++
       }
     })
-    this.setData({ checkedAll: count == downloadList.length,  downloadList})
+    this.setData({
+      checkedAll: count == downloadList.length,
+      downloadList
+    })
   },
   allCheck() {
-    const { downloadList, checkedAll } = this.data
+    const {
+      downloadList,
+      checkedAll
+    } = this.data
     downloadList.forEach(item => {
       item.checked = !checkedAll
     })
-    this.setData({ checkedAll: !checkedAll, downloadList })
+    this.setData({
+      checkedAll: !checkedAll,
+      downloadList
+    })
   },
   onHide() {
 

--
Gitblit v1.9.3