data(){
return {
isShowProgress: false,
progress: 0,
},
downloadFile(item) {
const downloadTask = uni.downloadFile({
url: item.fileDownloadPath, //这里写要下载的链接地址
success: res => {
if (res.statusCode === 200) {
this.isShowProgress = false;
console.log('下载成功');
}
let that = this;
uni.saveFile({
tempFilePath: res.tempFilePath,
success: function(red) {
that.isShowProgress = false;
uni.showModal({
title: '提示',
content: '文件已保存:' + red.savedFilePath,
cancelText: '我知道了',
confirmText: '打开文件',
success: function(res) {
if (res.confirm) {
uni.openDocument({
filePath: red.savedFilePath,
success: (sus) => {
console.log('成功打开');
}
})
}
}
});
}
});
}
})
downloadTask.onProgressUpdate((res) => {
if (res.progress > 0) {
this.isShowProgress = true;
}
this.progress = res.progress;
console.log('下载进度:' + res.progress);
console.log('已下载长度:' + res.totalBytesWritten);
console.log('文件总长度:' + res.totalBytesExpectedToWrite);
})
}
uniapp实现文件的保存
于 2023-12-17 13:51:24 首次发布