Compare commits
4 Commits
60478327e2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 623ebc22f7 | |||
| 1157a0c4ed | |||
| 6ad7f0d3d4 | |||
| 9d7453d3ee |
23
CLAUDE.md
23
CLAUDE.md
@@ -1013,21 +1013,21 @@ companion object {
|
||||
|
||||
上传图片后提交表单时,**必须同时传 `pic`、`originalPic`、`picNumber` 三个字段**,缺一不可。
|
||||
|
||||
**`UploadUtil.upload()` 返回值**:
|
||||
- `data?.newName` — 缩略图/压缩图文件名
|
||||
- `data?.zipFileName` — 原图文件名
|
||||
**`UploadUtil.upload()` 返回值**(注意:**与字面意思相反**):
|
||||
- `data?.newName` — **原图**文件名(较大)
|
||||
- `data?.zipFileName` — **缩略图/压缩图**文件名(较小)
|
||||
|
||||
**提交时字段映射**(参考事故签证 `AccidentVisaDetailsViewModel`):
|
||||
**提交时字段映射**(参考事故签证 `AccidentVisaDetailsViewModel`、`IntImpAccidentVisaEditViewModel`):
|
||||
|
||||
```kotlin
|
||||
// FileBean 字段含义:
|
||||
// - FileBean.url = newName(缩略图文件名)
|
||||
// - FileBean.originalPic = zipFileName(原图文件名)
|
||||
// FileBean 字段含义(约定用途,与 UploadBean 字段名不一致):
|
||||
// - FileBean.url 作缩略图标识(提交到 bean.pic)
|
||||
// - FileBean.originalPic 作原图标识(提交到 bean.originalPic)
|
||||
|
||||
// 上传新图片
|
||||
// 上传新图片(注意 UploadBean 字段名的误导性,按实际含义赋值)
|
||||
val data = UploadUtil.upload(fileBean.path).data
|
||||
fileBean.url = data?.newName ?: ""
|
||||
fileBean.originalPic = data?.zipFileName ?: ""
|
||||
fileBean.url = data?.zipFileName ?: "" // 缩略图
|
||||
fileBean.originalPic = data?.newName ?: "" // 原图
|
||||
|
||||
// 提交时设置三个字段
|
||||
bean.picNumber = list.size.toString()
|
||||
@@ -1037,7 +1037,8 @@ bean.originalPic = list.joinToString(",") { MediaUtil.removeUrl(it.originalPic)
|
||||
|
||||
**常见错误**:
|
||||
- ❌ 只传 `images` 或 `originalPic` 单个字段 — 接口不认或数据不完整
|
||||
- ❌ 只取 `newName` 不取 `zipFileName` — 丢失原图路径
|
||||
- ❌ 只取 `newName` 不取 `zipFileName` — 丢失缩略图/原图之一
|
||||
- ❌ 按 `UploadBean` 字段字面含义赋值(`url = newName`)— 会导致 pic/originalPic 内容和字段语义颠倒(缩略图字段装原图、原图字段装缩略图)
|
||||
- ❌ 用 `fileBean.path.startsWith("http")` 判断已上传 — 应该用 `fileBean.url.isNotEmpty()`
|
||||
|
||||
### 编辑页加载已有图片
|
||||
|
||||
@@ -75,23 +75,18 @@ class AccidentVisaDetailsViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
onSuccess = {
|
||||
dataBean.value = it.data ?: AccidentVisaBean()
|
||||
|
||||
// 渲染图片
|
||||
val list = dataBean.value!!.pic.split(",")
|
||||
.filter { url -> url.isNotEmpty() }
|
||||
.map { url ->
|
||||
FileBean(MediaUtil.fillUrl(url), url)
|
||||
// 渲染图片:pic 存缩略图文件名,originalPic 存原图文件名
|
||||
val picList = dataBean.value!!.pic.split(",").filter { it.isNotEmpty() }
|
||||
val originalPicList = dataBean.value!!.originalPic.split(",").filter { it.isNotEmpty() }
|
||||
val list = picList.mapIndexed { index, picFilename ->
|
||||
val originalFilename = originalPicList.getOrElse(index) { picFilename }
|
||||
FileBean(
|
||||
path = MediaUtil.fillUrl(picFilename),
|
||||
url = picFilename,
|
||||
originalPic = MediaUtil.fillUrl(originalFilename)
|
||||
)
|
||||
}
|
||||
val zipList = dataBean.value!!.originalPic.split(",")
|
||||
.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)
|
||||
rv?.commonAdapter()?.loadMore(list)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,8 +105,10 @@ class AccidentVisaDetailsViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
.filter { it.path.isNotEmpty() && it.url.isEmpty() }
|
||||
.onEach {
|
||||
val data = UploadUtil.upload(it.path).data
|
||||
it.url = data?.newName ?: ""
|
||||
it.originalPic = data?.zipFileName ?: ""
|
||||
// UploadUtil 返回:newName=原图(较大),zipFileName=缩略图(较小)
|
||||
// FileBean.url 用作缩略图标识,FileBean.originalPic 用作原图标识
|
||||
it.url = data?.zipFileName ?: ""
|
||||
it.originalPic = data?.newName ?: ""
|
||||
}
|
||||
.flowOn(Dispatchers.IO)
|
||||
.onStart { showLoading() }
|
||||
@@ -124,8 +121,8 @@ class AccidentVisaDetailsViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
val list =
|
||||
(rv?.commonAdapter()?.items as List<FileBean>).filter { it.path.isNotEmpty() }
|
||||
bean.picnumber = list.size.toString()
|
||||
bean.originalPic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.url) }
|
||||
bean.pic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.originalPic) }
|
||||
bean.pic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.url) }
|
||||
bean.originalPic = list.joinToString(separator = ",") { MediaUtil.removeUrl(it.originalPic) }
|
||||
|
||||
NetApply.api.anyPost(
|
||||
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.fubang.list.GncFuBangListActivity
|
||||
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.common.Constant
|
||||
import com.lukouguoji.module_base.db.perference.SharedPreferenceUtil
|
||||
@@ -314,7 +315,8 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
//出库
|
||||
Constant.AuthName.GnjChuKuList -> {
|
||||
GnjMoveStashListActivity.start(requireContext())
|
||||
ARouter.getInstance().build(ARouterConstants.ACTIVITY_URL_GNJ_CHU_KU_LIST)
|
||||
.navigation()
|
||||
}
|
||||
//仓库管理
|
||||
Constant.AuthName.GnjWareHouse -> {
|
||||
|
||||
@@ -12,12 +12,16 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
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.GranularRoundedCorners
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
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.util.SizeUtils
|
||||
|
||||
@@ -111,10 +115,22 @@ fun loadImage(
|
||||
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)
|
||||
.setDefaultRequestOptions(requestOptions)
|
||||
.load(source)
|
||||
.load(actualSource)
|
||||
.diskCacheStrategy(diskCacheStrategy)
|
||||
.encodeFormat(encodeFormat)
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package com.lukouguoji.module_base.impl
|
||||
|
||||
import android.view.View
|
||||
import com.luck.picture.lib.adapter.holder.PreviewImageHolder
|
||||
import com.luck.picture.lib.basic.PictureSelector
|
||||
import com.lukouguoji.module_base.adapter.loadImage
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.model.GlideUrl
|
||||
import com.bumptech.glide.load.model.LazyHeaders
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
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.db.perference.SharedPreferenceUtil
|
||||
import com.lukouguoji.module_base.ktx.commonAdapter
|
||||
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.util.MediaUtil
|
||||
import java.io.File
|
||||
|
||||
class ImageSelectViewHolder(view: View) : BaseViewHolder<FileBean, ItemImageSelectBinding>(view) {
|
||||
|
||||
@@ -19,6 +21,21 @@ class ImageSelectViewHolder(view: View) : BaseViewHolder<FileBean, ItemImageSele
|
||||
val bean = getItemBean(item)!!
|
||||
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 {
|
||||
if (bean.path.isEmpty()) {
|
||||
MediaUtil.pickImage(itemView.context, maxNum = 10) {
|
||||
@@ -28,7 +45,15 @@ class ImageSelectViewHolder(view: View) : BaseViewHolder<FileBean, ItemImageSele
|
||||
}
|
||||
}
|
||||
} 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)
|
||||
|
||||
if (bean.isOnlineResource()) {
|
||||
loge("开始下载 : ${bean.path}")
|
||||
bean.download {
|
||||
loadImage(binding.iv, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv"
|
||||
loadImage="@{bean.path}"
|
||||
visible="@{bean.path}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
@@ -279,7 +279,7 @@ class GjjManifestAddViewModel : BaseViewModel() {
|
||||
prefix = manifest.prefix
|
||||
|
||||
// 填充表单字段
|
||||
waybillNo.value = manifest.wbNo
|
||||
waybillNo.value = manifest.getWaybillNo()
|
||||
waybillNum.value = manifest.totalPc.toString()
|
||||
actualNum.value = manifest.pc.toString()
|
||||
actualWeight.value = manifest.weight.toString()
|
||||
@@ -309,7 +309,7 @@ class GjjManifestAddViewModel : BaseViewModel() {
|
||||
prefix = manifest.prefix
|
||||
|
||||
// 填充表单字段
|
||||
waybillNo.value = manifest.wbNo
|
||||
waybillNo.value = "${manifest.prefix}${manifest.no}"
|
||||
waybillNum.value = manifest.totalPc.toString()
|
||||
actualNum.value = manifest.pc.toString()
|
||||
actualWeight.value = manifest.weight.toString()
|
||||
|
||||
@@ -277,8 +277,10 @@ class IntImpAccidentVisaEditViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
.filter { it.path.isNotEmpty() && it.url.isEmpty() }
|
||||
.onEach {
|
||||
val data = UploadUtil.upload(it.path).data
|
||||
it.url = data?.newName ?: ""
|
||||
it.originalPic = data?.zipFileName ?: ""
|
||||
// UploadUtil 返回:newName=原图(较大),zipFileName=缩略图(较小)
|
||||
// FileBean.url 用作缩略图标识,FileBean.originalPic 用作原图标识
|
||||
it.url = data?.zipFileName ?: ""
|
||||
it.originalPic = data?.newName ?: ""
|
||||
}
|
||||
.flowOn(Dispatchers.IO)
|
||||
.onStart { showLoading() }
|
||||
|
||||
@@ -148,20 +148,10 @@
|
||||
title='@{"品名(中)"}'
|
||||
titleLength="@{5}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.goodsCn}'
|
||||
value='@{viewModel.dataBean.goods}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<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" />
|
||||
android:layout_weight="2" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ class GnjYiKuEditViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
val bean = it.data ?: GnjYiKuBean()
|
||||
dataBean.value = bean
|
||||
|
||||
// 处理图片列表:pic=缩略图(newName),originalPic=原图(zipFileName)
|
||||
// 处理图片列表:pic 字段存缩略图文件名,originalPic 字段存原图文件名
|
||||
val picList = bean.pic.split(",").filter { it.isNotEmpty() }
|
||||
val originalPicList = bean.originalPic.split(",").filter { it.isNotEmpty() }
|
||||
val images = picList.mapIndexed { index, picUrl ->
|
||||
@@ -123,9 +123,11 @@ class GnjYiKuEditViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
// 已上传的图片,保持原有的 url 和 originalPic
|
||||
} else {
|
||||
// 本地新图片需要上传
|
||||
// UploadUtil 返回:newName=原图(较大),zipFileName=缩略图(较小)
|
||||
// FileBean.url 用作缩略图标识,FileBean.originalPic 用作原图标识
|
||||
val data = UploadUtil.upload(fileBean.path).data
|
||||
fileBean.url = data?.newName ?: ""
|
||||
fileBean.originalPic = data?.zipFileName ?: ""
|
||||
fileBean.url = data?.zipFileName ?: ""
|
||||
fileBean.originalPic = data?.newName ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,9 +118,11 @@ class GnjYiKuHandoverViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
// 已上传的图片,保持原有的 url 和 originalPic
|
||||
} else {
|
||||
// 本地新图片需要上传
|
||||
// UploadUtil 返回:newName=原图(较大),zipFileName=缩略图(较小)
|
||||
// FileBean.url 用作缩略图标识,FileBean.originalPic 用作原图标识
|
||||
val data = UploadUtil.upload(fileBean.path).data
|
||||
fileBean.url = data?.newName ?: ""
|
||||
fileBean.originalPic = data?.zipFileName ?: ""
|
||||
fileBean.url = data?.zipFileName ?: ""
|
||||
fileBean.originalPic = data?.newName ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user