|
@@ -1459,31 +1459,48 @@
|
|
|
uni.showLoading({
|
|
|
title: '文件下载中'
|
|
|
});
|
|
|
- uni.downloadFile({
|
|
|
- url: file,
|
|
|
- success(val) {
|
|
|
- uni.saveFile({
|
|
|
- tempFilePath: val.tempFilePath, //临时路径
|
|
|
- success: function(res) {
|
|
|
- uni.hideLoading();
|
|
|
- uni.showToast({
|
|
|
- icon: 'none',
|
|
|
- mask: true,
|
|
|
- title: '文件已保存到:' + res.savedFilePath +
|
|
|
- ',正在打开文件', //保存路径
|
|
|
- duration: 3000,
|
|
|
- });
|
|
|
- setTimeout(() => {
|
|
|
- //打开文档查看
|
|
|
- uni.openDocument({
|
|
|
- filePath: res.savedFilePath,
|
|
|
- success: function(res) {}
|
|
|
- });
|
|
|
- }, 1500)
|
|
|
- }
|
|
|
- });
|
|
|
+ let index = file.lastIndexOf("\/")
|
|
|
+ let name = file.substring(index + 1, file.length)
|
|
|
+ let dtask = plus.downloader.createDownload(file, {
|
|
|
+ filename: "_downloads/" + name
|
|
|
+ }, function(d, status) {
|
|
|
+ if (status == 200) {
|
|
|
+ uni.hideLoading()
|
|
|
+ //下载成功,d.filename是文件在保存在本地的相对路径,使用下面的API可转为平台绝对路径
|
|
|
+ let fileSaveUrl = plus.io.convertLocalFileSystemURL(d.filename);
|
|
|
+ plus.runtime.openFile(d.filename); //选择软件打开文件
|
|
|
+ } else {
|
|
|
+ uni.hideLoading()
|
|
|
+ //下载失败
|
|
|
+ plus.downloader.clear(); //清除下载任务
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
+ dtask.start();
|
|
|
+ // uni.downloadFile({
|
|
|
+ // url: file,
|
|
|
+ // success(val) {
|
|
|
+ // uni.saveFile({
|
|
|
+ // tempFilePath: val.tempFilePath, //临时路径
|
|
|
+ // success: function(res) {
|
|
|
+ // uni.hideLoading();
|
|
|
+ // uni.showToast({
|
|
|
+ // icon: 'none',
|
|
|
+ // mask: true,
|
|
|
+ // title: '文件已保存到:' + res.savedFilePath +
|
|
|
+ // ',正在打开文件', //保存路径
|
|
|
+ // duration: 3000,
|
|
|
+ // });
|
|
|
+ // setTimeout(() => {
|
|
|
+ // //打开文档查看
|
|
|
+ // uni.openDocument({
|
|
|
+ // filePath: res.savedFilePath,
|
|
|
+ // success: function(res) {}
|
|
|
+ // });
|
|
|
+ // }, 1500)
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
//#endif
|
|
|
//#ifdef H5
|
|
|
var win = window.open();
|