bugfix: 没有产品主图时自动选中问题

This commit is contained in:
2026-05-07 17:06:06 +08:00
parent b2c6c61515
commit e093cccb8d
2 changed files with 3 additions and 9 deletions

View File

@@ -50,6 +50,7 @@ When saving, preserve the backend's expected image categories. Confirm backend n
- The `main` badge represents the first selected product image, not the most recently selected one.
- `firstSelectedIndex` is stored on each `ListingItem` and passed to `ProductImageList.vue`.
- Hydrating detail data must only set `mainProductImage` from explicit `main_product` or `mainProductImage` rows. Never infer it from selected `product` rows.
- Selecting a product image should only set `mainProductImage` when no main image is currently tracked by that listing's `firstSelectedIndex`.
- Unselecting the current main product image clears `mainProductImage` and resets `firstSelectedIndex`.
- Videos can be selected and saved, but they cannot become `mainProductImage`, must not set `firstSelectedIndex`, and must not display the `main` badge.
@@ -57,6 +58,7 @@ When saving, preserve the backend's expected image categories. Confirm backend n
中文补充:
- `main` 标识只给图片,不给视频。
- 数据回显时,只有接口明确返回 `main_product` / `mainProductImage` 才能设置主图。不要因为某个 `product` 是已选中状态,就自动把它当成 `mainProductImage` 或显示 `main`
- 第一次选择视频时可以弹 warning但视频本身仍然要保持选中只是不要把它写入 `mainProductImage`,也不要更新 `firstSelectedIndex`
- 如果先选中视频,再选中图片,图片仍然可以成为第一个主图。
- 如果取消的是当前主图图片,需要清空 `mainProductImage``firstSelectedIndex`;取消普通图片或视频不应影响主图。

View File

@@ -313,10 +313,6 @@
if (videoItem) listing.prodImageList.push(videoItem)
})
if (!listing.mainProductImage) {
listing.mainProductImage =
listing.prodImageList.find((item) => item.selected && !item.isVideo)?.url || ""
}
if (coverFromImageUrl) {
listing.coverFrom = resolveCoverSourceFromImageUrl(coverFromImageUrl, listing)
}
@@ -324,11 +320,7 @@
const mainProductIndex = listing.prodImageList.findIndex(
(item) => !item.isVideo && item.url === listing.mainProductImage
)
const selectedIndex =
mainProductIndex === -1
? listing.prodImageList.findIndex((item) => item.selected && !item.isVideo)
: mainProductIndex
listing.firstSelectedIndex = selectedIndex === -1 ? null : selectedIndex
listing.firstSelectedIndex = mainProductIndex === -1 ? null : mainProductIndex
listing.productImage = listing.prodImageList.map((item) => item.url)
listing.apparelSketch = listing.sketchList