Sfoglia il codice sorgente

修改报告odf打开方式(解决安卓机型一直打不开的情况)

htc 1 giorno fa
parent
commit
e9f2fe704b

+ 37 - 3
pagesHome/components/report/generateList.vue

@@ -188,14 +188,48 @@
 			},
 			},
 			reviewReport(item){
 			reviewReport(item){
 				const { isPC, isMobile, platform } = getPlatformInfo();
 				const { isPC, isMobile, platform } = getPlatformInfo();
+				console.log(platform,'platform');//android
 				if (isPC) {
 				if (isPC) {
 					this.$showModal('请在手机端该微信小程序中查看报告')
 					this.$showModal('请在手机端该微信小程序中查看报告')
 				} else if (isMobile||platform==='devtools') {
 				} else if (isMobile||platform==='devtools') {
 					if(!item.fileUrl) return this.$showToast('报告pdf为空,请稍后再试。')
 					if(!item.fileUrl) return this.$showToast('报告pdf为空,请稍后再试。')
-					uni.navigateTo({
-						url:'/pages/webView?src='+item.fileUrl
-					})
+					this.openPdf(item.fileUrl)
+					// uni.navigateTo({
+					// 	url:'/pages/webView?src='+item.fileUrl
+					// })
+				}
+			},
+			async openPdf(pdfUrl) {
+			  try {
+				// 1. 显示加载提示
+				uni.showLoading({ title: '加载中...' });
+				// 2. 先下载PDF文件到本地(解决安卓直接预览网络文件慢的问题)
+				const downloadRes = await uni.downloadFile({
+				  url: pdfUrl,
+				  // 可选:设置超时时间,避免长时间等待
+				  timeout: 30000
+				});
+				
+				const dres = downloadRes[1]||null;
+				
+				if (dres.statusCode !== 200) {
+				  uni.hideLoading();
+				  uni.showToast({ title: '文件下载失败', icon: 'none' });
+				  return;
 				}
 				}
+		
+				// 3. 用微信原生API打开本地PDF
+				const openRes = await uni.openDocument({
+				  filePath: dres.tempFilePath,
+				  fileType: 'pdf',
+				  showMenu: true // 允许用户转发/保存等
+				});
+		
+				uni.hideLoading();
+			  } catch (error) {
+				uni.hideLoading();
+				uni.showToast({ title: '加载失败,请重试', icon: 'none' });
+			  }
 			},
 			},
 			askReport(item){
 			askReport(item){
 				uni.navigateTo({
 				uni.navigateTo({

+ 36 - 3
pagesHome/components/report/receiveList.vue

@@ -71,11 +71,44 @@
 					this.$showModal('请在手机端该微信小程序中查看报告')
 					this.$showModal('请在手机端该微信小程序中查看报告')
 				} else if (isMobile||platform==='devtools') {
 				} else if (isMobile||platform==='devtools') {
 					if(!item.fileUrl) return this.$showToast('报告pdf为空,请稍后再试。')
 					if(!item.fileUrl) return this.$showToast('报告pdf为空,请稍后再试。')
-					uni.navigateTo({
-						url:'/pages/webView?src='+item.fileUrl
-					})
+					this.openPdf(item.fileUrl)
+					// uni.navigateTo({
+					// 	url:'/pages/webView?src='+item.fileUrl
+					// })
 				}
 				}
 			},
 			},
+			async openPdf(pdfUrl) {
+			  try {
+				// 1. 显示加载提示
+				uni.showLoading({ title: '加载中...' });
+				// 2. 先下载PDF文件到本地(解决安卓直接预览网络文件慢的问题)
+				const downloadRes = await uni.downloadFile({
+				  url: pdfUrl,
+				  // 可选:设置超时时间,避免长时间等待
+				  timeout: 30000
+				});
+				
+				const dres = downloadRes[1]||null;
+				
+				if (dres.statusCode !== 200) {
+				  uni.hideLoading();
+				  uni.showToast({ title: '文件下载失败', icon: 'none' });
+				  return;
+				}
+		
+				// 3. 用微信原生API打开本地PDF
+				const openRes = await uni.openDocument({
+				  filePath: dres.tempFilePath,
+				  fileType: 'pdf',
+				  showMenu: true // 允许用户转发/保存等
+				});
+		
+				uni.hideLoading();
+			  } catch (error) {
+				uni.hideLoading();
+				uni.showToast({ title: '加载失败,请重试', icon: 'none' });
+			  }
+			},
 			askReport(item){
 			askReport(item){
 				uni.navigateTo({
 				uni.navigateTo({
 					url:`/pages/reportAsk?pdfUrl=${item.fileUrl}&fileName=${this.typeCfg[item.type]||'个人版'}-${item.reportName}`
 					url:`/pages/reportAsk?pdfUrl=${item.fileUrl}&fileName=${this.typeCfg[item.type]||'个人版'}-${item.reportName}`