From d580040c5527cde8e96feed5eac1b820ad8e2c8c Mon Sep 17 00:00:00 2001 From: lvmeng <848755140@qq.com> Date: Wed, 20 May 2026 18:17:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(fragment):=20=E4=B8=8A=E4=BC=A0=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E6=97=B6=E9=80=8F=E4=BC=A0=E6=8E=A5=E5=8F=A3=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=8E=9F=E5=9B=A0=E8=87=B3=20toast=20=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- .../dish/match/ui/fragment/VectorCollectionFragment.kt | 7 ++++--- .../java/com/shuwei/dish/match/utils/ImageUploader.kt | 9 ++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/shuwei/dish/match/ui/fragment/VectorCollectionFragment.kt b/app/src/main/java/com/shuwei/dish/match/ui/fragment/VectorCollectionFragment.kt index e3d5607..390ac18 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/fragment/VectorCollectionFragment.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/fragment/VectorCollectionFragment.kt @@ -366,7 +366,8 @@ class VectorCollectionFragment : BaseFragment() // 直接 await 单批上传结果,成功返回 id 列表,失败返回 null 触发 onError val result = currentActivity.netViewModel.uploadFoodVectorDataBatch(files, params) log("uploadImage返回:result=${result.toJsonString()}") - if (result is UiState.Success) result.data else null + if (result is UiState.Success) result.data to null + else null to (result as? UiState.Error)?.msg }, onProgress = { count, batch, idList -> showWaitingDialog("图片上传中$count/$totalFileCount", timeoutMs = 60_000L) val foodList = batch.mapIndexed { index, it -> @@ -379,10 +380,10 @@ class VectorCollectionFragment : BaseFragment() ObjectBox.putAll(foodList) batch.forEach { it.isFinish = true } vectorAdapter.notifyDataSetChanged() - }, onError = { + }, onError = { _, errorMsg -> binding.root.postDelayed({ hideWaitingDialog() - toast("上传失败,请稍后重试") + toast("上传失败:${(errorMsg ?: "").ifBlank { "请稍后重试" }}") }, 1000) }, onComplete = { binding.root.postDelayed({ diff --git a/app/src/main/java/com/shuwei/dish/match/utils/ImageUploader.kt b/app/src/main/java/com/shuwei/dish/match/utils/ImageUploader.kt index 40a9b1a..a370cef 100644 --- a/app/src/main/java/com/shuwei/dish/match/utils/ImageUploader.kt +++ b/app/src/main/java/com/shuwei/dish/match/utils/ImageUploader.kt @@ -5,9 +5,9 @@ import java.util.concurrent.atomic.AtomicInteger class ImageUploader( private val totalList: List, - private val uploadImage: suspend (List) -> List?, + private val uploadImage: suspend (List) -> Pair?, String?>, private val onProgress: suspend (Int, List, List) -> Unit, - private val onError: (List) -> Unit, + private val onError: (List, String?) -> Unit, private val onComplete: () -> Unit ) { companion object { @@ -19,10 +19,9 @@ class ImageUploader( val batches = totalList.filter { it.imageVector!=null }.chunked(BATCH_SIZE) for (batch in batches) { - val idList = uploadImage(batch) + val (idList, errorMsg) = uploadImage(batch) if (idList.isNullOrEmpty()) { - //println("上传失败,终止流程") - onError(batch) + onError(batch, errorMsg) return } val fileCount = batch.count { it.imageFile!=null }