소스 검색

调整文件下载

yin_yu820 2 일 전
부모
커밋
b4d5444186
1개의 변경된 파일51개의 추가작업 그리고 43개의 파일을 삭제
  1. 51 43
      jp-mobile/pages/question/questionInfo.vue

+ 51 - 43
jp-mobile/pages/question/questionInfo.vue

@@ -758,49 +758,57 @@
 		
 
 			downloadFile(url) {
-				uni.downloadFile({
-					url: url,
-					success: (res) => {
-						if (res.statusCode === 200) {
-							const filePath = res.tempFilePath;
-							uni.saveFile({
-								tempFilePath: filePath,
-								success: (res) => {
-									uni.showToast({
-										title: '文件已保存:' + res.savedFilePath,
-										icon: 'none'
-									});
-									// 打开文档查看(仅支持Android)
-									if (plus.os.name === 'Android') {
-										uni.openDocument({
-											filePath: res.savedFilePath,
-											success: () => {
-												console.log('打开文档成功');
-											}
-										});
-									} else {
-										uni.showToast({
-											title: 'iOS系统请自行选择查看方式',
-											icon: 'none'
-										});
-									}
-								},
-								fail: () => {
-									uni.showToast({
-										title: '保存文件失败',
-										icon: 'none'
-									});
-								}
-							});
-						}
-					},
-					fail: () => {
-						uni.showToast({
-							title: '下载文件失败',
-							icon: 'none'
-						});
-					}
-				});
+				
+				const a = document.createElement('a');
+				a.href = url; //filePath 这里的地址是 uni.downloadFile 中的返回值里的地址
+				let aa=url.split("&name=")
+				a.download = aa[1]; // 可以设置下载文件名,如果是空字符串,则使用服务器端设置的文件名
+				a.click();
+				
+				
+				// uni.downloadFile({
+				// 	url: url,
+				// 	success: (res) => {
+				// 		if (res.statusCode === 200) {
+				// 			const filePath = res.tempFilePath;
+				// 			uni.saveFile({
+				// 				tempFilePath: filePath,
+				// 				success: (res) => {
+				// 					uni.showToast({
+				// 						title: '文件已保存:' + res.savedFilePath,
+				// 						icon: 'none'
+				// 					});
+				// 					// 打开文档查看(仅支持Android)
+				// 					if (plus.os.name === 'Android') {
+				// 						uni.openDocument({
+				// 							filePath: res.savedFilePath,
+				// 							success: () => {
+				// 								console.log('打开文档成功');
+				// 							}
+				// 						});
+				// 					} else {
+				// 						uni.showToast({
+				// 							title: 'iOS系统请自行选择查看方式',
+				// 							icon: 'none'
+				// 						});
+				// 					}
+				// 				},
+				// 				fail: () => {
+				// 					uni.showToast({
+				// 						title: '保存文件失败',
+				// 						icon: 'none'
+				// 					});
+				// 				}
+				// 			});
+				// 		}
+				// 	},
+				// 	fail: () => {
+				// 		uni.showToast({
+				// 			title: '下载文件失败',
+				// 			icon: 'none'
+				// 		});
+				// 	}
+				// });
 			},
 			
 			// 获取上传进度