From 28c725308aaf418e9032964ffcf5ca3b0d8a1208 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期四, 25 七月 2024 17:13:56 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 wechat_staff/pages/download/index.js |  166 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 145 insertions(+), 21 deletions(-)

diff --git a/wechat_staff/pages/download/index.js b/wechat_staff/pages/download/index.js
index e1c090c..a18659c 100644
--- a/wechat_staff/pages/download/index.js
+++ b/wechat_staff/pages/download/index.js
@@ -1,13 +1,22 @@
-// 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({
 
   /**
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
-    bottomLift: ''
+    bottomLift: '',
+    downloadList: [],
+    downloadConfig: {},
+    checkedAll: false,
+    showParam: false,
+    takeQrcode: true
   },
 
   /**
@@ -19,25 +28,140 @@
       bottomLift: app.bottomLift
     })
   },
-
-  /**
-   * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
-   */
-  onReady() {
-  },
-
-  /**
-   * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず
-   */
-  onShow() {
-    eventBus.on('batchDown', val => {
-      console.log('val', val);
+  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) {
+          getContentShareImg({
+            articleId: `${downloadConfig.id}_${downloadConfig.path}`,
+            type: this.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"
+                      })
+                    }
+                  })
+        
+                }
+              }
+            })
+          })
+        }
+      })
+    })
+    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 {
+        url: i,
+        paddingStatus: 0,
+        checked: false
+      }
+    })
+    this.setData({
+      downloadList: temp,
+      downloadConfig
+    })
+    setTimeout(() => {
+      wx.setStorageSync('downloadList', [])
+      wx.setStorageSync('downloadConfig', {})
+    }, 500)
+  },
+  openParam() {
+    const downloadList = this.data.downloadList.filter(i => i.checked)
+    if (downloadList.length === 0) return wx.showToast({
+      title: '璇峰厛閫夋嫨瑕佷笅杞界殑娴锋姤',
+      icon: 'none'
+    })
+    this.setData({
+      showParam: true
+    })
+  },
+  onClose() {
+    this.setData({
+      showParam: false
+    })
+  },
+  downCheck(e) {
+    const takeQrcode = e.currentTarget.dataset.flag
+    console.log('takeQrcode', takeQrcode);
+    this.setData({
+      takeQrcode
+    })
+  },
+  itemCheck(e) {
+    const i = e.currentTarget.dataset.i
+    const {
+      downloadList,
+      checkedAll
+    } = this.data
+    let count = 0
+    downloadList.forEach((item, index) => {
+      if (index === i) {
+        item.checked = !item.checked
+      }
+      if (item.checked) {
+        count++
+      }
+    })
+    this.setData({
+      checkedAll: count == downloadList.length,
+      downloadList
+    })
+  },
+  allCheck() {
+    const {
+      downloadList,
+      checkedAll
+    } = this.data
+    downloadList.forEach(item => {
+      item.checked = !checkedAll
+    })
+    this.setData({
+      checkedAll: !checkedAll,
+      downloadList
+    })
+  },
   onHide() {
 
   },

--
Gitblit v1.9.3