Compare commits
6 Commits
4117cbb489
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 623ebc22f7 | |||
| 1157a0c4ed | |||
| 6ad7f0d3d4 | |||
| 9d7453d3ee | |||
| 60478327e2 | |||
| 1d2b11bfd2 |
23
CLAUDE.md
23
CLAUDE.md
@@ -1013,21 +1013,21 @@ companion object {
|
|||||||
|
|
||||||
上传图片后提交表单时,**必须同时传 `pic`、`originalPic`、`picNumber` 三个字段**,缺一不可。
|
上传图片后提交表单时,**必须同时传 `pic`、`originalPic`、`picNumber` 三个字段**,缺一不可。
|
||||||
|
|
||||||
**`UploadUtil.upload()` 返回值**:
|
**`UploadUtil.upload()` 返回值**(注意:**与字面意思相反**):
|
||||||
- `data?.newName` — 缩略图/压缩图文件名
|
- `data?.newName` — **原图**文件名(较大)
|
||||||
- `data?.zipFileName` — 原图文件名
|
- `data?.zipFileName` — **缩略图/压缩图**文件名(较小)
|
||||||
|
|
||||||
**提交时字段映射**(参考事故签证 `AccidentVisaDetailsViewModel`):
|
**提交时字段映射**(参考事故签证 `AccidentVisaDetailsViewModel`、`IntImpAccidentVisaEditViewModel`):
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
// FileBean 字段含义:
|
// FileBean 字段含义(约定用途,与 UploadBean 字段名不一致):
|
||||||
// - FileBean.url = newName(缩略图文件名)
|
// - FileBean.url 作缩略图标识(提交到 bean.pic)
|
||||||
// - FileBean.originalPic = zipFileName(原图文件名)
|
// - FileBean.originalPic 作原图标识(提交到 bean.originalPic)
|
||||||
|
|
||||||
// 上传新图片
|
// 上传新图片(注意 UploadBean 字段名的误导性,按实际含义赋值)
|
||||||
val data = UploadUtil.upload(fileBean.path).data
|
val data = UploadUtil.upload(fileBean.path).data
|
||||||
fileBean.url = data?.newName ?: ""
|
fileBean.url = data?.zipFileName ?: "" // 缩略图
|
||||||
fileBean.originalPic = data?.zipFileName ?: ""
|
fileBean.originalPic = data?.newName ?: "" // 原图
|
||||||
|
|
||||||
// 提交时设置三个字段
|
// 提交时设置三个字段
|
||||||
bean.picNumber = list.size.toString()
|
bean.picNumber = list.size.toString()
|
||||||
@@ -1037,7 +1037,8 @@ bean.originalPic = list.joinToString(",") { MediaUtil.removeUrl(it.originalPic)
|
|||||||
|
|
||||||
**常见错误**:
|
**常见错误**:
|
||||||
- ❌ 只传 `images` 或 `originalPic` 单个字段 — 接口不认或数据不完整
|
- ❌ 只传 `images` 或 `originalPic` 单个字段 — 接口不认或数据不完整
|
||||||
- ❌ 只取 `newName` 不取 `zipFileName` — 丢失原图路径
|
- ❌ 只取 `newName` 不取 `zipFileName` — 丢失缩略图/原图之一
|
||||||
|
- ❌ 按 `UploadBean` 字段字面含义赋值(`url = newName`)— 会导致 pic/originalPic 内容和字段语义颠倒(缩略图字段装原图、原图字段装缩略图)
|
||||||
- ❌ 用 `fileBean.path.startsWith("http")` 判断已上传 — 应该用 `fileBean.url.isNotEmpty()`
|
- ❌ 用 `fileBean.path.startsWith("http")` 判断已上传 — 应该用 `fileBean.url.isNotEmpty()`
|
||||||
|
|
||||||
### 编辑页加载已有图片
|
### 编辑页加载已有图片
|
||||||
|
|||||||
@@ -75,23 +75,18 @@ class AccidentVisaDetailsViewModel : BaseViewModel(), IOnItemClickListener {
|
|||||||
onSuccess = {
|
onSuccess = {
|
||||||
dataBean.value = it.data ?: AccidentVisaBean()
|
dataBean.value = it.data ?: AccidentVisaBean()
|
||||||
|
|
||||||
// 渲染图片
|
// 渲染图片:pic 存缩略图文件名,originalPic 存原图文件名
|
||||||
val list = dataBean.value!!.pic.split(",")
|
val picList = dataBean.value!!.pic.split(",").filter { it.isNotEmpty() }
|
||||||
.filter { url -> url.isNotEmpty() }
|
val originalPicList = dataBean.value!!.originalPic.split(",").filter { it.isNotEmpty() }
|
||||||
.map { url ->
|
val list = picList.mapIndexed { index, picFilename ->
|
||||||
FileBean(MediaUtil.fillUrl(url), url)
|
val originalFilename = originalPicList.getOrElse(index) { picFilename }
|
||||||
|
FileBean(
|
||||||
|
path = MediaUtil.fillUrl(picFilename),
|
||||||
|
url = picFilename,
|
||||||
|
originalPic = MediaUtil.fillUrl(originalFilename)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
val zipList = dataBean.value!!.originalPic.split(",")
|
rv?.commonAdapter()?.loadMore(list)
|
||||||
.filter { url -> url.isNotEmpty() }
|
|
||||||
.map { url ->
|
|
||||||
FileBean(MediaUtil.fillUrl(url))
|
|
||||||
}
|
|
||||||
for ((index, fileBean) in list.withIndex()) {
|
|
||||||
val originalPic = zipList.get(index).path
|
|
||||||
list.get(index).originalPic = originalPic
|
|
||||||
}
|
|
||||||
rv?.commonAdapter()
|
|
||||||
?.loadMore(list)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,8 +105,10 @@ class AccidentVisaDetailsViewModel : BaseViewModel(), IOnItemClickListener {
|
|||||||
.filter { it.path.isNotEmpty() && it.url.isEmpty() }
|
.filter { it.path.isNotEmpty() && it.url.isEmpty() }
|
||||||
.onEach {
|
.onEach {
|
||||||
val data = UploadUtil.upload(it.path).data
|
val data = UploadUtil.upload(it.path).data
|
||||||
it.url = data?.newName ?: ""
|
// UploadUtil 返回:newName=原图(较大),zipFileName=缩略图(较小)
|
||||||
it.originalPic = data?.zipFileName ?: ""
|
// FileBean.url 用作缩略图标识,FileBean.originalPic 用作原图标识
|
||||||
|
it.url = data?.zipFileName ?: ""
|
||||||
|
it.originalPic = data?.newName ?: ""
|
||||||
}
|
}
|
||||||
.flowOn(Dispatchers.IO)
|
.flowOn(Dispatchers.IO)
|
||||||
.onStart { showLoading() }
|
.onStart { showLoading() }
|
||||||
@@ -124,8 +121,8 @@ class AccidentVisaDetailsViewModel : BaseViewModel(), IOnItemClickListener {
|
|||||||
val list =
|
val list =
|
||||||
(rv?.commonAdapter()?.items as List<FileBean>).filter { it.path.isNotEmpty() }
|
(rv?.commonAdapter()?.items as List<FileBean>).filter { it.path.isNotEmpty() }
|
||||||
bean.picnumber = list.size.toString()
|
bean.picnumber = list.size.toString()
|
||||||
bean.originalPic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.url) }
|
bean.pic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.url) }
|
||||||
bean.pic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.originalPic) }
|
bean.originalPic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.originalPic) }
|
||||||
|
|
||||||
NetApply.api.anyPost(
|
NetApply.api.anyPost(
|
||||||
url = if (pageType.value == DetailsPageType.Add) "GnAccidentVisa/saveVisa" else "GnAccidentVisa/updateVisa",
|
url = if (pageType.value == DetailsPageType.Add) "GnAccidentVisa/saveVisa" else "GnAccidentVisa/updateVisa",
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import com.lukouguoji.gnc.page.deposit.list.GncDepositListActivity
|
|||||||
import com.lukouguoji.gnc.page.distribution.home.GncDistributionHomeActivity
|
import com.lukouguoji.gnc.page.distribution.home.GncDistributionHomeActivity
|
||||||
import com.lukouguoji.gnc.page.fubang.list.GncFuBangListActivity
|
import com.lukouguoji.gnc.page.fubang.list.GncFuBangListActivity
|
||||||
import com.lukouguoji.gnc.page.shouyun.unlist.GncShouYunUnListActivity
|
import com.lukouguoji.gnc.page.shouyun.unlist.GncShouYunUnListActivity
|
||||||
|
import com.lukouguoji.gnj.activity.GnjChuKuListActivity
|
||||||
import com.lukouguoji.module_base.MyApplication
|
import com.lukouguoji.module_base.MyApplication
|
||||||
import com.lukouguoji.module_base.common.Constant
|
import com.lukouguoji.module_base.common.Constant
|
||||||
import com.lukouguoji.module_base.db.perference.SharedPreferenceUtil
|
import com.lukouguoji.module_base.db.perference.SharedPreferenceUtil
|
||||||
@@ -314,7 +315,8 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
//出库
|
//出库
|
||||||
Constant.AuthName.GnjChuKuList -> {
|
Constant.AuthName.GnjChuKuList -> {
|
||||||
GnjMoveStashListActivity.start(requireContext())
|
ARouter.getInstance().build(ARouterConstants.ACTIVITY_URL_GNJ_CHU_KU_LIST)
|
||||||
|
.navigation()
|
||||||
}
|
}
|
||||||
//仓库管理
|
//仓库管理
|
||||||
Constant.AuthName.GnjWareHouse -> {
|
Constant.AuthName.GnjWareHouse -> {
|
||||||
|
|||||||
@@ -12,12 +12,16 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
|
import com.bumptech.glide.load.model.GlideUrl
|
||||||
|
import com.bumptech.glide.load.model.LazyHeaders
|
||||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop
|
import com.bumptech.glide.load.resource.bitmap.CenterCrop
|
||||||
import com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners
|
import com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners
|
||||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||||
import com.lukouguoji.module_base.base.CommonAdapter
|
import com.lukouguoji.module_base.base.CommonAdapter
|
||||||
|
import com.lukouguoji.module_base.common.Constant
|
||||||
|
import com.lukouguoji.module_base.db.perference.SharedPreferenceUtil
|
||||||
import com.lukouguoji.module_base.ktx.loge
|
import com.lukouguoji.module_base.ktx.loge
|
||||||
import com.lukouguoji.module_base.util.SizeUtils
|
import com.lukouguoji.module_base.util.SizeUtils
|
||||||
|
|
||||||
@@ -111,10 +115,22 @@ fun loadImage(
|
|||||||
com.bumptech.glide.request.target.Target.SIZE_ORIGINAL
|
com.bumptech.glide.request.target.Target.SIZE_ORIGINAL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 对 http(s) 字符串 URL,自动包装为带 Authorization header 的 GlideUrl,避免 /file/getImg/ 接口 403
|
||||||
|
val actualSource: Any? = if (source is String && (source.startsWith("http://") || source.startsWith("https://"))) {
|
||||||
|
GlideUrl(
|
||||||
|
source,
|
||||||
|
LazyHeaders.Builder()
|
||||||
|
.addHeader("Authorization", SharedPreferenceUtil.getString(Constant.Share.token))
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
source
|
||||||
|
}
|
||||||
|
|
||||||
// 设置图片加载
|
// 设置图片加载
|
||||||
val load = Glide.with(imageView)
|
val load = Glide.with(imageView)
|
||||||
.setDefaultRequestOptions(requestOptions)
|
.setDefaultRequestOptions(requestOptions)
|
||||||
.load(source)
|
.load(actualSource)
|
||||||
.diskCacheStrategy(diskCacheStrategy)
|
.diskCacheStrategy(diskCacheStrategy)
|
||||||
.encodeFormat(encodeFormat)
|
.encodeFormat(encodeFormat)
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
package com.lukouguoji.module_base.impl
|
package com.lukouguoji.module_base.impl
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.luck.picture.lib.adapter.holder.PreviewImageHolder
|
import com.bumptech.glide.Glide
|
||||||
import com.luck.picture.lib.basic.PictureSelector
|
import com.bumptech.glide.load.model.GlideUrl
|
||||||
import com.lukouguoji.module_base.adapter.loadImage
|
import com.bumptech.glide.load.model.LazyHeaders
|
||||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||||
import com.lukouguoji.module_base.bean.FileBean
|
import com.lukouguoji.module_base.bean.FileBean
|
||||||
|
import com.lukouguoji.module_base.common.Constant
|
||||||
import com.lukouguoji.module_base.databinding.ItemImageSelectBinding
|
import com.lukouguoji.module_base.databinding.ItemImageSelectBinding
|
||||||
|
import com.lukouguoji.module_base.db.perference.SharedPreferenceUtil
|
||||||
import com.lukouguoji.module_base.ktx.commonAdapter
|
import com.lukouguoji.module_base.ktx.commonAdapter
|
||||||
import com.lukouguoji.module_base.ktx.logd
|
import com.lukouguoji.module_base.ktx.logd
|
||||||
import com.lukouguoji.module_base.ktx.loge
|
|
||||||
import com.lukouguoji.module_base.ui.page.preview.PreviewActivity
|
import com.lukouguoji.module_base.ui.page.preview.PreviewActivity
|
||||||
import com.lukouguoji.module_base.util.MediaUtil
|
import com.lukouguoji.module_base.util.MediaUtil
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class ImageSelectViewHolder(view: View) : BaseViewHolder<FileBean, ItemImageSelectBinding>(view) {
|
class ImageSelectViewHolder(view: View) : BaseViewHolder<FileBean, ItemImageSelectBinding>(view) {
|
||||||
|
|
||||||
@@ -19,6 +21,21 @@ class ImageSelectViewHolder(view: View) : BaseViewHolder<FileBean, ItemImageSele
|
|||||||
val bean = getItemBean(item)!!
|
val bean = getItemBean(item)!!
|
||||||
binding.bean = bean
|
binding.bean = bean
|
||||||
|
|
||||||
|
// 加载缩略图
|
||||||
|
if (bean.path.isNotEmpty()) {
|
||||||
|
if (bean.isOnlineResource()) {
|
||||||
|
val glideUrl = GlideUrl(
|
||||||
|
bean.path,
|
||||||
|
LazyHeaders.Builder()
|
||||||
|
.addHeader("Authorization", SharedPreferenceUtil.getString(Constant.Share.token))
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
Glide.with(itemView.context).load(glideUrl).into(binding.iv)
|
||||||
|
} else {
|
||||||
|
Glide.with(itemView.context).load(File(bean.path)).into(binding.iv)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
binding.rl.setOnClickListener {
|
binding.rl.setOnClickListener {
|
||||||
if (bean.path.isEmpty()) {
|
if (bean.path.isEmpty()) {
|
||||||
MediaUtil.pickImage(itemView.context, maxNum = 10) {
|
MediaUtil.pickImage(itemView.context, maxNum = 10) {
|
||||||
@@ -28,7 +45,15 @@ class ImageSelectViewHolder(view: View) : BaseViewHolder<FileBean, ItemImageSele
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PreviewActivity.start(itemView.context, listOf(bean))
|
val items = getRecyclerView()?.commonAdapter()?.items
|
||||||
|
?.filterIsInstance<FileBean>()
|
||||||
|
?.filter { it.path.isNotEmpty() }
|
||||||
|
?: listOf(bean)
|
||||||
|
val previewList = items.map { fb ->
|
||||||
|
FileBean(path = if (fb.originalPic.isNotEmpty()) fb.originalPic else fb.path)
|
||||||
|
}
|
||||||
|
val previewPosition = items.indexOfFirst { it === bean }.coerceAtLeast(0)
|
||||||
|
PreviewActivity.start(itemView.context, previewList, previewPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,13 +64,6 @@ class ImageSelectViewHolder(view: View) : BaseViewHolder<FileBean, ItemImageSele
|
|||||||
}
|
}
|
||||||
|
|
||||||
notifyItemClick(position, binding.ivDelete)
|
notifyItemClick(position, binding.ivDelete)
|
||||||
|
|
||||||
if (bean.isOnlineResource()) {
|
|
||||||
loge("开始下载 : ${bean.path}")
|
|
||||||
bean.download {
|
|
||||||
loadImage(binding.iv, it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/iv"
|
android:id="@+id/iv"
|
||||||
loadImage="@{bean.path}"
|
|
||||||
visible="@{bean.path}"
|
visible="@{bean.path}"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ class GjjManifestAddViewModel : BaseViewModel() {
|
|||||||
prefix = manifest.prefix
|
prefix = manifest.prefix
|
||||||
|
|
||||||
// 填充表单字段
|
// 填充表单字段
|
||||||
waybillNo.value = manifest.wbNo
|
waybillNo.value = manifest.getWaybillNo()
|
||||||
waybillNum.value = manifest.totalPc.toString()
|
waybillNum.value = manifest.totalPc.toString()
|
||||||
actualNum.value = manifest.pc.toString()
|
actualNum.value = manifest.pc.toString()
|
||||||
actualWeight.value = manifest.weight.toString()
|
actualWeight.value = manifest.weight.toString()
|
||||||
@@ -309,7 +309,7 @@ class GjjManifestAddViewModel : BaseViewModel() {
|
|||||||
prefix = manifest.prefix
|
prefix = manifest.prefix
|
||||||
|
|
||||||
// 填充表单字段
|
// 填充表单字段
|
||||||
waybillNo.value = manifest.wbNo
|
waybillNo.value = "${manifest.prefix}${manifest.no}"
|
||||||
waybillNum.value = manifest.totalPc.toString()
|
waybillNum.value = manifest.totalPc.toString()
|
||||||
actualNum.value = manifest.pc.toString()
|
actualNum.value = manifest.pc.toString()
|
||||||
actualWeight.value = manifest.weight.toString()
|
actualWeight.value = manifest.weight.toString()
|
||||||
@@ -373,11 +373,10 @@ class GjjManifestAddViewModel : BaseViewModel() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val params = mapOf(
|
val isModify = pageType.value == DetailsPageType.Modify
|
||||||
"mfId" to if (pageType.value == DetailsPageType.Modify) mfId else null,
|
|
||||||
|
val paramsMap = mutableMapOf<String, Any?>(
|
||||||
"fid" to fid,
|
"fid" to fid,
|
||||||
"no" to if (pageType.value == DetailsPageType.Modify) no else null,
|
|
||||||
"prefix" to if (pageType.value == DetailsPageType.Modify) prefix else null,
|
|
||||||
"wbNo" to waybillNo.value,
|
"wbNo" to waybillNo.value,
|
||||||
"agentCode" to agent.value,
|
"agentCode" to agent.value,
|
||||||
"spCode" to specialCode.value.let { if (it.isNullOrEmpty()) "NOR" else it },
|
"spCode" to specialCode.value.let { if (it.isNullOrEmpty()) "NOR" else it },
|
||||||
@@ -386,19 +385,30 @@ class GjjManifestAddViewModel : BaseViewModel() {
|
|||||||
"pc" to actualNum.value,
|
"pc" to actualNum.value,
|
||||||
"weight" to actualWeight.value,
|
"weight" to actualWeight.value,
|
||||||
"cashWeight" to billingWeight.value,
|
"cashWeight" to billingWeight.value,
|
||||||
"packageType" to packageType.value,
|
|
||||||
"origin" to departure.value,
|
"origin" to departure.value,
|
||||||
"dest" to destination.value,
|
"dest" to destination.value,
|
||||||
"goods" to goodsNameEn.value,
|
"goods" to goodsNameEn.value,
|
||||||
"goodsCn" to goodsNameCn.value,
|
"goodsCn" to goodsNameCn.value,
|
||||||
"awbType" to waybillType.value,
|
"awbType" to waybillType.value,
|
||||||
"cargoType" to goodsType.value,
|
)
|
||||||
"unNumber" to unNumber.value,
|
|
||||||
"remark" to remark.value,
|
// 可选字段:非空时才传
|
||||||
).toRequestBody(removeEmptyOrNull = true)
|
if (!packageType.value.isNullOrEmpty()) paramsMap["packageType"] = packageType.value
|
||||||
|
if (!goodsType.value.isNullOrEmpty()) paramsMap["cargoType"] = goodsType.value
|
||||||
|
if (!unNumber.value.isNullOrEmpty()) paramsMap["unNumber"] = unNumber.value
|
||||||
|
if (!remark.value.isNullOrEmpty()) paramsMap["remark"] = remark.value
|
||||||
|
|
||||||
|
// 编辑模式:必须传 mfId、no、prefix(不受空字符串过滤影响)
|
||||||
|
if (isModify) {
|
||||||
|
paramsMap["mfId"] = mfId
|
||||||
|
paramsMap["no"] = no
|
||||||
|
paramsMap["prefix"] = prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
val params = paramsMap.toRequestBody()
|
||||||
|
|
||||||
launchLoadingCollect({
|
launchLoadingCollect({
|
||||||
if (pageType.value == DetailsPageType.Modify) {
|
if (isModify) {
|
||||||
NetApply.api.gjjManifestUpdate(params)
|
NetApply.api.gjjManifestUpdate(params)
|
||||||
} else {
|
} else {
|
||||||
NetApply.api.gjjManifestInsert(params)
|
NetApply.api.gjjManifestInsert(params)
|
||||||
@@ -406,7 +416,7 @@ class GjjManifestAddViewModel : BaseViewModel() {
|
|||||||
}) {
|
}) {
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
if (it.verifySuccess()) {
|
if (it.verifySuccess()) {
|
||||||
val successMsg = if (pageType.value == DetailsPageType.Modify) "修改成功" else "保存成功"
|
val successMsg = if (isModify) "修改成功" else "保存成功"
|
||||||
showToast(successMsg)
|
showToast(successMsg)
|
||||||
|
|
||||||
// 发送刷新事件
|
// 发送刷新事件
|
||||||
|
|||||||
@@ -144,20 +144,19 @@ class IntImpAccidentVisaEditViewModel : BaseViewModel(), IOnItemClickListener {
|
|||||||
onSuccess = {
|
onSuccess = {
|
||||||
dataBean.value = it.data ?: GjAccidentVisaEditBean()
|
dataBean.value = it.data ?: GjAccidentVisaEditBean()
|
||||||
|
|
||||||
// 渲染图片
|
// 渲染图片:path 取原图 URL 确保预览清晰,url 取缩略图用于提交
|
||||||
val bean = dataBean.value!!
|
val bean = dataBean.value!!
|
||||||
val picList = bean.pic.split(",")
|
val picList = bean.pic.split(",").filter { it.isNotEmpty() }
|
||||||
.filter { url -> url.isNotEmpty() }
|
val originalList = bean.originalPic.split(",").filter { it.isNotEmpty() }
|
||||||
.map { url -> FileBean(MediaUtil.fillUrl(url), url) }
|
val images = picList.mapIndexed { index, picUrl ->
|
||||||
val originalList = bean.originalPic.split(",")
|
val originalUrl = originalList.getOrElse(index) { picUrl }
|
||||||
.filter { url -> url.isNotEmpty() }
|
FileBean(
|
||||||
.map { url -> FileBean(MediaUtil.fillUrl(url)) }
|
path = MediaUtil.fillUrl(originalUrl),
|
||||||
for ((index, fileBean) in picList.withIndex()) {
|
url = picUrl,
|
||||||
if (index < originalList.size) {
|
originalPic = originalUrl
|
||||||
picList[index].originalPic = originalList[index].path
|
)
|
||||||
}
|
}
|
||||||
}
|
rv?.commonAdapter()?.loadMore(images)
|
||||||
rv?.commonAdapter()?.loadMore(picList)
|
|
||||||
|
|
||||||
// 详情模式下无图片时显示占位提示
|
// 详情模式下无图片时显示占位提示
|
||||||
if (isDetailMode.value == true && picList.isEmpty()) {
|
if (isDetailMode.value == true && picList.isEmpty()) {
|
||||||
@@ -278,8 +277,10 @@ class IntImpAccidentVisaEditViewModel : BaseViewModel(), IOnItemClickListener {
|
|||||||
.filter { it.path.isNotEmpty() && it.url.isEmpty() }
|
.filter { it.path.isNotEmpty() && it.url.isEmpty() }
|
||||||
.onEach {
|
.onEach {
|
||||||
val data = UploadUtil.upload(it.path).data
|
val data = UploadUtil.upload(it.path).data
|
||||||
it.url = data?.newName ?: ""
|
// UploadUtil 返回:newName=原图(较大),zipFileName=缩略图(较小)
|
||||||
it.originalPic = data?.zipFileName ?: ""
|
// FileBean.url 用作缩略图标识,FileBean.originalPic 用作原图标识
|
||||||
|
it.url = data?.zipFileName ?: ""
|
||||||
|
it.originalPic = data?.newName ?: ""
|
||||||
}
|
}
|
||||||
.flowOn(Dispatchers.IO)
|
.flowOn(Dispatchers.IO)
|
||||||
.onStart { showLoading() }
|
.onStart { showLoading() }
|
||||||
@@ -292,8 +293,8 @@ class IntImpAccidentVisaEditViewModel : BaseViewModel(), IOnItemClickListener {
|
|||||||
val list = (rv?.commonAdapter()?.items as List<FileBean>)
|
val list = (rv?.commonAdapter()?.items as List<FileBean>)
|
||||||
.filter { it.path.isNotEmpty() }
|
.filter { it.path.isNotEmpty() }
|
||||||
bean.picNumber = list.size.toString()
|
bean.picNumber = list.size.toString()
|
||||||
bean.originalPic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.url) }
|
bean.pic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.url) }
|
||||||
bean.pic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.originalPic) }
|
bean.originalPic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.originalPic) }
|
||||||
bean.idFlag = "1"
|
bean.idFlag = "1"
|
||||||
|
|
||||||
if (pageType.value == DetailsPageType.Add) {
|
if (pageType.value == DetailsPageType.Add) {
|
||||||
|
|||||||
@@ -148,20 +148,10 @@
|
|||||||
title='@{"品名(中)"}'
|
title='@{"品名(中)"}'
|
||||||
titleLength="@{5}"
|
titleLength="@{5}"
|
||||||
type="@{DataLayoutType.INPUT}"
|
type="@{DataLayoutType.INPUT}"
|
||||||
value='@{viewModel.dataBean.goodsCn}'
|
value='@{viewModel.dataBean.goods}'
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="2" />
|
||||||
|
|
||||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
|
||||||
enable="@{false}"
|
|
||||||
title='@{"品名(英)"}'
|
|
||||||
titleLength="@{5}"
|
|
||||||
type="@{DataLayoutType.INPUT}"
|
|
||||||
value='@{viewModel.dataBean.goodsEn}'
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class GnjYiKuEditViewModel : BaseViewModel(), IOnItemClickListener {
|
|||||||
val bean = it.data ?: GnjYiKuBean()
|
val bean = it.data ?: GnjYiKuBean()
|
||||||
dataBean.value = bean
|
dataBean.value = bean
|
||||||
|
|
||||||
// 处理图片列表:pic=缩略图(newName),originalPic=原图(zipFileName)
|
// 处理图片列表:pic 字段存缩略图文件名,originalPic 字段存原图文件名
|
||||||
val picList = bean.pic.split(",").filter { it.isNotEmpty() }
|
val picList = bean.pic.split(",").filter { it.isNotEmpty() }
|
||||||
val originalPicList = bean.originalPic.split(",").filter { it.isNotEmpty() }
|
val originalPicList = bean.originalPic.split(",").filter { it.isNotEmpty() }
|
||||||
val images = picList.mapIndexed { index, picUrl ->
|
val images = picList.mapIndexed { index, picUrl ->
|
||||||
@@ -123,9 +123,11 @@ class GnjYiKuEditViewModel : BaseViewModel(), IOnItemClickListener {
|
|||||||
// 已上传的图片,保持原有的 url 和 originalPic
|
// 已上传的图片,保持原有的 url 和 originalPic
|
||||||
} else {
|
} else {
|
||||||
// 本地新图片需要上传
|
// 本地新图片需要上传
|
||||||
|
// UploadUtil 返回:newName=原图(较大),zipFileName=缩略图(较小)
|
||||||
|
// FileBean.url 用作缩略图标识,FileBean.originalPic 用作原图标识
|
||||||
val data = UploadUtil.upload(fileBean.path).data
|
val data = UploadUtil.upload(fileBean.path).data
|
||||||
fileBean.url = data?.newName ?: ""
|
fileBean.url = data?.zipFileName ?: ""
|
||||||
fileBean.originalPic = data?.zipFileName ?: ""
|
fileBean.originalPic = data?.newName ?: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,10 +62,23 @@ class GnjYiKuHandoverViewModel : BaseViewModel(), IOnItemClickListener {
|
|||||||
val bean = it.data ?: GnjYiKuBean()
|
val bean = it.data ?: GnjYiKuBean()
|
||||||
dataBean.value = bean
|
dataBean.value = bean
|
||||||
|
|
||||||
// 处理图片列表(拼接完整 URL)
|
// 处理图片列表(同时保留缩略图和原图信息,确保二次编辑时不丢失)
|
||||||
val images = bean.getImageList().map { url ->
|
val picList = bean.pic.split(",").filter { it.isNotEmpty() }
|
||||||
FileBean(path = MediaUtil.fillUrl(url), url = url)
|
val originalPicList = bean.originalPic.split(",").filter { it.isNotEmpty() }
|
||||||
|
val images = if (picList.isNotEmpty()) {
|
||||||
|
picList.mapIndexed { index, picUrl ->
|
||||||
|
val originalUrl = originalPicList.getOrElse(index) { picUrl }
|
||||||
|
FileBean(
|
||||||
|
path = MediaUtil.fillUrl(originalUrl),
|
||||||
|
url = picUrl,
|
||||||
|
originalPic = originalUrl
|
||||||
|
)
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
|
} else {
|
||||||
|
originalPicList.map { url ->
|
||||||
|
FileBean(path = MediaUtil.fillUrl(url), url = url, originalPic = url)
|
||||||
|
}.toMutableList()
|
||||||
|
}
|
||||||
|
|
||||||
// 编辑模式添加空 FileBean 用于显示"添加照片"按钮
|
// 编辑模式添加空 FileBean 用于显示"添加照片"按钮
|
||||||
if (pageType.value == DetailsPageType.Modify) {
|
if (pageType.value == DetailsPageType.Modify) {
|
||||||
@@ -75,7 +88,7 @@ class GnjYiKuHandoverViewModel : BaseViewModel(), IOnItemClickListener {
|
|||||||
imageList.value = images
|
imageList.value = images
|
||||||
|
|
||||||
// 详情模式下无图片时显示占位提示
|
// 详情模式下无图片时显示占位提示
|
||||||
if (pageType.value == DetailsPageType.Details && bean.getImageList().isEmpty()) {
|
if (pageType.value == DetailsPageType.Details && images.isEmpty()) {
|
||||||
showNoImage.value = true
|
showNoImage.value = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,9 +118,11 @@ class GnjYiKuHandoverViewModel : BaseViewModel(), IOnItemClickListener {
|
|||||||
// 已上传的图片,保持原有的 url 和 originalPic
|
// 已上传的图片,保持原有的 url 和 originalPic
|
||||||
} else {
|
} else {
|
||||||
// 本地新图片需要上传
|
// 本地新图片需要上传
|
||||||
|
// UploadUtil 返回:newName=原图(较大),zipFileName=缩略图(较小)
|
||||||
|
// FileBean.url 用作缩略图标识,FileBean.originalPic 用作原图标识
|
||||||
val data = UploadUtil.upload(fileBean.path).data
|
val data = UploadUtil.upload(fileBean.path).data
|
||||||
fileBean.url = data?.newName ?: ""
|
fileBean.url = data?.zipFileName ?: ""
|
||||||
fileBean.originalPic = data?.zipFileName ?: ""
|
fileBean.originalPic = data?.newName ?: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user