/*
APP自定义保存
*/
plusSaveFile({url,customName='',opt}) {
return new Promise((resolve,reject)=>{
// 可自行修改参数
// 参数api: http://www.html5plus.org/doc/zh_cn/downloader.html#plus.downloader.DownloadOptions
let downloadOptions = {
method: "GET",
timeout: 120,
retryInterval: 10
};
customName&&(downloadOptions['filename']=`_downloads/files/${customName}`);
downloadOptions = {...downloadOptions,...opt};
this.downloadTask = plus.downloader.createDownload(url, downloadOptions,(d, status)=>{
// 下载完成
if(status == 200){
let tempFilePath = d.filename;
this.value = 100;
uni.showToast({
title: `文件保存位置:_downloads/files/${customName}`,
icon: "none",
duration: 3000
})
this.onCommit(resolve(tempFilePath))
} else {
this.errorHandler('下载失败',reject)
}
this.downloadTask = null;
});
this.downloadTask.addEventListener('statechanged',({downloadedSize=0,state=0,totalSize=0}={})=>{
if (state===3) {
let total = totalSize>0?totalSize:fileSize;
let progressVal = Math.ceil(downloadedSize / total* 100);
this.value = progressVal>100?100:progressVal;
this.$forceUpdate()
}
},false);
this.downloadTask.start();
});
},
uniaoo自定义保存
最新推荐文章于 2024-07-08 19:01:49 发布