download: function(e) {
var that = this;
console.log(e)
var data = {
“fileName”: e.currentTarget.dataset.name,
“fileNo”: e.currentTarget.id
}
console.log(data)
wx.request({
url: getApp().globalData.url + ‘file/download’,
header: {
‘Content-Type’: getApp().globalData.contentType
},
method: “POST”,
data: data,
dataType: ‘json’,
success: function(data) {
console.log(data);
if (data.data.code == 200) {
if (e.currentTarget.dataset.name) {
var url = getApp().globalData.url + “resources/” + e.currentTarget.dataset.name;
url = encodeURI(url);
const downloadTask = wx.downloadFile({
url: url,
success: function(res) {
console.info(res)
if (res.statusCode == 200 && res.tempFilePath) {
if (check.check.isImage(res.tempFilePath)) {
console.log(“这是张图片”);
that.setData({
downimg: res.tempFilePath,
imgshow: true,
})
} else {
var filePath = res.tempFilePath;
wx.saveFile({
tempFilePath: filePath,
success: function(res1) {
console.info(res1)
var filep = res1.savedFilePath;
wx.openDocument({
filePath: filep,
success: function(res2) {
//console.info(res2)
//console.log(‘打开文档成功’)
},
fail: function(res) {
//console.log(res)
wx.showToast({
title: ‘该文件暂不提供下载!’,
icon: ‘none’
});
}
})
}
})
}
}
}
})
downloadTask.onProgressUpdate((res) => {
wx.showLoading({
title: '下载进度 ' + res.progress + “%”,
})
if (res.progress == 100){
wx.hideLoading();
}
})
} else {
wx.showToast({
title: ‘该文件暂不提供下载!’,
icon: ‘none’
});
}
} else {
wx.showToast({
title: ‘该文件暂不提供下载!’,
icon: ‘none’
});
}
}
})
这是我dwonload的整个代码