feat: 国际出港 附件查看
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user