|
@@ -1,4 +1,5 @@
|
|
|
// component/documentItem/documentItem.ts
|
|
|
+import { httpUtil } from "../../utils/restful"
|
|
|
Component({
|
|
|
/**
|
|
|
* 组件的属性列表
|
|
@@ -17,7 +18,8 @@ Component({
|
|
|
data: {
|
|
|
type: 1,
|
|
|
hasDownLoad: false,
|
|
|
- downLoadProgress: ''
|
|
|
+ downLoadProgress: '',
|
|
|
+ progressType: 0,
|
|
|
},
|
|
|
lifetimes: {
|
|
|
attached: function () {
|
|
@@ -42,34 +44,80 @@ Component({
|
|
|
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
|
|
|
+
|
|
|
+ downLoadItem: function (progressType, fileType) {
|
|
|
+ console.log("fileType:", fileType)
|
|
|
+ let that = this;
|
|
|
+ that.setData({
|
|
|
+ progressType: progressType,
|
|
|
+ type: fileType
|
|
|
})
|
|
|
+ //文件下载
|
|
|
+ httpUtil.wxDownLoadFile(that.data.itemData.url, function (res: any) {
|
|
|
+ // console.log("下载没===", res)
|
|
|
+ that.setDownLoadProgress(res)
|
|
|
+ }).then((res) => {
|
|
|
+ // console.log("下载成功:", res)
|
|
|
+ that.downLoadComplete(res)
|
|
|
+
|
|
|
+
|
|
|
+ }).catch((res) => {
|
|
|
+ // console.log("下载失败")
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ setDownLoadProgress: function (data: any) {
|
|
|
+
|
|
|
+ if (this.data.progressType == 0) {
|
|
|
+ console.log("设置下载百分比:", data.detail.progress)
|
|
|
+ this.setData({
|
|
|
+ downLoadProgress: '下载:' + data.detail.progress + '%',
|
|
|
+ hasDownLoad: true
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.setData({
|
|
|
+ downLoadProgress: '下载:' + data.progress + '%',
|
|
|
+ hasDownLoad: true
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
downLoadComplete: function (data: any) {
|
|
|
- // console.log("下载成功:", data)
|
|
|
+ console.log("下载成功:", data)
|
|
|
// console.log("data.detail.data.tempFilePath:", data.detail.data.tempFilePath)
|
|
|
+ console.log("downLoadComplete:", this.data.type)
|
|
|
+ let path = ''
|
|
|
+ if (this.data.progressType == 0) {
|
|
|
+ path = data.detail.data.tempFilePath
|
|
|
+ } else if (this.data.progressType == 1) {
|
|
|
+ path = data.tempFilePath
|
|
|
+ }
|
|
|
+
|
|
|
if (this.data.type == 0) {
|
|
|
//0是图片,图片保存到相册
|
|
|
wx.saveImageToPhotosAlbum({
|
|
|
- filePath: data.detail.data.tempFilePath,
|
|
|
+ filePath: path,
|
|
|
success(res) {
|
|
|
- wx.showModal({
|
|
|
- content: '保存相册成功'
|
|
|
+ wx.showToast({
|
|
|
+ title: '保存相册成功',
|
|
|
+ icon: 'succes',
|
|
|
+ duration: 1000,
|
|
|
+ mask: true
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
} else if (this.data.type == 1) {
|
|
|
//1是视频,视频保存到相册
|
|
|
wx.saveVideoToPhotosAlbum({
|
|
|
- filePath: data.detail.data.tempFilePath,
|
|
|
+ filePath: path,
|
|
|
success(res) {
|
|
|
// console.log(res.errMsg)
|
|
|
- wx.showModal({
|
|
|
- content: '保存相册成功'
|
|
|
+ wx.showToast({
|
|
|
+ title: '保存相册成功',
|
|
|
+ icon: 'succes',
|
|
|
+ duration: 1000,
|
|
|
+ mask: true
|
|
|
})
|
|
|
}
|
|
|
})
|