Bläddra i källkod

保单下载功能重做

@dongkboy 1 år sedan
förälder
incheckning
a509e64867
2 ändrade filer med 43 tillägg och 26 borttagningar
  1. 2 2
      manifest.json
  2. 41 24
      pages/carInsure1/quoteDetail1.vue

+ 2 - 2
manifest.json

@@ -7,8 +7,8 @@
 		"sizes": "分辨率,192x192",
 		"src": "图片路径"
 	}],
-	"versionName": "1.0.179",
-	"versionCode": 179,
+	"versionName": "1.0.180",
+	"versionCode": 180,
 	"app-plus": {
 		"error": {
 			"url": "hybrid/html/error.html"

+ 41 - 24
pages/carInsure1/quoteDetail1.vue

@@ -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();