Przeglądaj źródła

fix(report): open received deerflow documents

Developer 4 dni temu
rodzic
commit
4c65dec4f0
1 zmienionych plików z 11 dodań i 7 usunięć
  1. 11 7
      pagesHome/components/report/receiveList.vue

+ 11 - 7
pagesHome/components/report/receiveList.vue

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