feat: 国际出港 附件查看

This commit is contained in:
2026-01-21 10:49:03 +08:00
parent b0b109de9a
commit a3fda12fd8

View File

@@ -144,22 +144,24 @@ class GjcInspectionDetailsViewModel : BaseViewModel() {
* @param attach 附件对象 * @param attach 附件对象
*/ */
fun onAttachClick(attach: ComAttach) { fun onAttachClick(attach: ComAttach) {
// 处理URL先处理转义字符再判断是否需要组装完整URL
val url = processAttachUrl(attach.path)
when { when {
// 图片格式使用PreviewActivity预览 // 图片格式使用PreviewActivity预览
attach.name.endsWith(".jpg", true) || attach.name.endsWith(".jpg", true) ||
attach.name.endsWith(".png", true) || attach.name.endsWith(".png", true) ||
attach.name.endsWith(".jpeg", true) -> { attach.name.endsWith(".jpeg", true) -> {
val fileBean = FileBean( val fileBean = FileBean(
// url = MediaUtil.fillUrl(attach.path), url = url,
// 服务器返回全url无需本地组装 path = url,
url = attach.path, originalPic = url
originalPic = attach.path
) )
PreviewActivity.start(getTopActivity(), listOf(fileBean)) PreviewActivity.start(getTopActivity(), listOf(fileBean))
} }
// PDF格式使用PdfPreviewActivity预览 // PDF格式使用PdfPreviewActivity预览
attach.name.endsWith(".pdf", true) -> { attach.name.endsWith(".pdf", true) -> {
PdfPreviewActivity.start(getTopActivity(), attach.path) PdfPreviewActivity.start(getTopActivity(), url)
} }
// 其他格式 // 其他格式
else -> { 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)
}
}
} }