this.uploadTask = wx.downloadFile({
url: this.fileUrl.split('?')[0],
success: async downLoadFileRes => {
try {
const isSuccessGetFileInfo = await getFileInfo(downLoadFileRes)
this.tempFilePath = downLoadFileRes.tempFilePath || downLoadFileRes.filePath;
if (isSuccessGetFileInfo) {
const fileName = this.file.name || '默认文件'
const saveFileRes = await saveFile(downLoadFileRes, fileName)
if (saveFileRes) {
this.isLoading = false;
this.savedFilePath = saveFileRes.savedFilePath;
this.openDownloadedFile();
}
}
} catch (error) {
removeSaveFileList();
}
},
fail: error => {
removeSaveFileList();
uni.showToast({
title: '文件打开失败,请稍后重试',
duration: DURATION_LENGTH,
icon: 'none'
})
},
complete: e => {
removeSaveFileList();
}
})
this.uploadTask?.onProgressUpdate(({ progress }) => {
const FINISH_PROGRESS = 100
if (progress === FINISH_PROGRESS) {
this.progressText = '加载完成 请稍候'
} else {
this.progressText = `文件加载中... ${progress}%`
}
this.progress = progress
})