From a3fda12fd881a2e7913e5672bca87d395c2b4955 Mon Sep 17 00:00:00 2001 From: YANGJIANKUAN Date: Wed, 21 Jan 2026 10:49:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=BD=E9=99=85=E5=87=BA=E6=B8=AF=20?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E6=9F=A5=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GjcInspectionDetailsViewModel.kt | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcInspectionDetailsViewModel.kt b/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcInspectionDetailsViewModel.kt index 9254728..ad62732 100644 --- a/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcInspectionDetailsViewModel.kt +++ b/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcInspectionDetailsViewModel.kt @@ -144,22 +144,24 @@ class GjcInspectionDetailsViewModel : BaseViewModel() { * @param attach 附件对象 */ fun onAttachClick(attach: ComAttach) { + // 处理URL:先处理转义字符,再判断是否需要组装完整URL + val url = processAttachUrl(attach.path) + when { // 图片格式:使用PreviewActivity预览 attach.name.endsWith(".jpg", true) || attach.name.endsWith(".png", true) || attach.name.endsWith(".jpeg", true) -> { val fileBean = FileBean( -// url = MediaUtil.fillUrl(attach.path), - // 服务器返回全url,无需本地组装 - url = attach.path, - originalPic = attach.path + url = url, + path = url, + originalPic = url ) PreviewActivity.start(getTopActivity(), listOf(fileBean)) } // PDF格式:使用PdfPreviewActivity预览 attach.name.endsWith(".pdf", true) -> { - PdfPreviewActivity.start(getTopActivity(), attach.path) + PdfPreviewActivity.start(getTopActivity(), url) } // 其他格式 else -> { @@ -167,4 +169,21 @@ class GjcInspectionDetailsViewModel : BaseViewModel() { } } } + + /** + * 处理附件URL + * 1. 处理转义字符(如 \/ 替换为 /) + * 2. 如果不是以http开头,则使用MediaUtil.fillUrl组装完整URL + */ + private fun processAttachUrl(path: String): String { + // 先处理转义字符:\/ -> / + val cleanPath = path.replace("\\/", "/") + + // 判断是否已是完整URL + return if (cleanPath.startsWith("http://", true) || cleanPath.startsWith("https://", true)) { + cleanPath + } else { + MediaUtil.fillUrl(cleanPath) + } + } }