// component/documentItem/documentItem.ts Component({ /** * 组件的属性列表 */ properties: { itemData: null, itemIndex: { type: String, value: '' }, }, /** * 组件的初始数据 */ data: { type: 1, hasDownLoad: false, downLoadProgress: '' }, lifetimes: { attached: function () { // 在组件实例被从页面节点树添加时执行 this.setData({ type: this.properties.itemData.type }) console.log("itemIndex:", this.properties.itemIndex) }, detached: function () { // 在组件实例被从页面节点树移除时执行 }, }, /** * 组件的方法列表 */ methods: { showActionWindow: function () { this.triggerEvent("showActionWindow", { item: this.properties.itemData, itemIndex: this.properties.itemIndex }) }, setDownLoadProgress: function (data: any) { console.log("设置下载百分比:", data.detail.progress) this.setData({ downLoadProgress: '下载:' + data.detail.progress + '%', hasDownLoad: true }) }, downLoadComplete: function (data: any) { // console.log("下载成功:", data) // console.log("data.detail.data.tempFilePath:", data.detail.data.tempFilePath) if (this.data.type == 0) { //0是图片,图片保存到相册 wx.saveImageToPhotosAlbum({ filePath: data.detail.data.tempFilePath, success(res) { wx.showModal({ content: '保存相册成功' }) } }) } else if (this.data.type == 1) { //1是视频,视频保存到相册 wx.saveVideoToPhotosAlbum({ filePath: data.detail.data.tempFilePath, success(res) { // console.log(res.errMsg) wx.showModal({ content: '保存相册成功' }) } }) } this.setData({ downLoadProgress: '下载完成' }) }, downLoadError: function (data: any) { console.log("下载失败:", data) this.setData({ downLoadProgress: '下载失败' }) } } })