Explorar el Código

fix(report): open deerflow docx preview

Developer hace 2 meses
padre
commit
5768c41642
Se han modificado 1 ficheros con 25 adiciones y 17 borrados
  1. 25 17
      pagesHome/components/report/generateList.vue

+ 25 - 17
pagesHome/components/report/generateList.vue

@@ -190,31 +190,35 @@
 				this.$refs.selectTeamUser.selectNums = 0;
 				this.$refs.selectTeamUser.selectAll = false;
 			},
-			reviewPdf(item){
-				let url = `/pagesHome/pdf?reportId=${item.reportId}`;
-				if(item.type==2) url = `/pagesHome/pdfZyb?reportId=${item.reportId}`
-				uni.navigateTo({ url })
-			},
-			reviewReport(item){
+			reviewPdf(item){
+				if(this.isDeerFlowReport(item)) return this.reviewReport(item)
+				let url = `/pagesHome/pdf?reportId=${item.reportId}`;
+				if(item.type==2) url = `/pagesHome/pdfZyb?reportId=${item.reportId}`
+				uni.navigateTo({ url })
+			},
+			isDeerFlowReport(item){
+				return !!(item.fileUrl && item.fileUrl.indexOf('/profile/deerflow/') !== -1)
+			},
+			reviewReport(item){
 				const { isPC, isMobile, platform } = getPlatformInfo();
 				console.log(platform,'platform');//android
 				if (isPC) {
 					this.$showModal('请在手机端该微信小程序中查看报告')
 				} else if (isMobile||platform==='devtools') {
 					if(!item.fileUrl) return this.$showToast('报告pdf为空,请稍后再试。')
-					this.openPdf(item.fileUrl)
+					this.openReportDocument(item.fileUrl)
 					// uni.navigateTo({
 					// 	url:'/pages/webView?src='+item.fileUrl
 					// })
 				}
 			},
-			async openPdf(pdfUrl) {
+			async openReportDocument(fileUrl) {
 			  try {
 				// 1. 显示加载提示
 				uni.showLoading({ title: '加载中...' });
 				// 2. 先下载PDF文件到本地(解决安卓直接预览网络文件慢的问题)
 				const downloadRes = await uni.downloadFile({
-				  url: pdfUrl,
+				  url: fileUrl,
 				  // 可选:设置超时时间,避免长时间等待
 				  timeout: 30000
 				});
@@ -227,19 +231,23 @@
 				  return;
 				}
 		
-				// 3. 用微信原生API打开本地PDF
-				const openRes = await uni.openDocument({
-				  filePath: dres.tempFilePath,
-				  fileType: 'pdf',
-				  showMenu: false
+				// 3. 按实际扩展名使用微信原生文档预览
+				const openRes = await uni.openDocument({
+				  filePath: dres.tempFilePath,
+				  fileType: this.documentType(fileUrl),
+				  showMenu: false
 				});
 		
 				uni.hideLoading();
 			  } 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}`
@@ -459,4 +467,4 @@
 			}
 		}
 	}
-</style>
+</style>