| | |
| | | // 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: '', |
| | | downloadList: [], |
| | | downloadConfig: {}, |
| | | checkedAll: false, |
| | | showParam: false, |
| | | takeQrcode: true |
| | |
| | | bottomLift: app.bottomLift |
| | | }) |
| | | }, |
| | | subDownload() { |
| | | let that = this |
| | | const downloadList = this.data.downloadList |
| | | const downloadConfig = this.data.downloadConfig |
| | | checkAuth(() => { |
| | | wx.showLoading({ |
| | | title: '正在下载', |
| | | 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正在下载2等待下载3下载完成 |
| | | return { |
| | |
| | | checked: false |
| | | } |
| | | }) |
| | | this.setData({ downloadList: temp }) |
| | | this.setData({ |
| | | downloadList: temp, |
| | | downloadConfig |
| | | }) |
| | | setTimeout(() => { |
| | | wx.setStorageSync('downloadList', []) |
| | | },500) |
| | | 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 }) |
| | | 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, |
| | | checkedAll |
| | | } = this.data |
| | | let count = 0 |
| | | downloadList.forEach((item, index) => { |
| | | if(index === i){ |
| | | if (index === i) { |
| | | 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() { |
| | | |