perf(ecom-dmb): 商品卡片保存改为就地更新,无需重新加载全量列表

后端:
- UpdateProductResultDTO 新增 product 字段,返回更新后的完整商品信息

前端:
- ProductVO.UpdateProductResult 新增 product 字段
- ProductCard 保存成功后 emit('updated', product) 携带商品数据
- ProductGridView.refreshTable(product) 收到数据后原地替换 productList 中对应商品,无需重新请求列表
This commit is contained in:
小蟑螂
2026-04-26 21:33:43 +08:00
parent a90446dff6
commit 6ec45a7e0d
5 changed files with 26 additions and 5 deletions
@@ -2,6 +2,7 @@ package top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
import java.util.List; import java.util.List;
@@ -17,4 +18,10 @@ public class UpdateProductResultDTO {
*/ */
@Schema(description = "成本发生变更的规格ID列表") @Schema(description = "成本发生变更的规格ID列表")
private List<Long> costChangedSpecIds; private List<Long> costChangedSpecIds;
/**
* 更新后的商品完整信息
*/
@Schema(description = "更新后的商品完整信息")
private ProductVO product;
} }
@@ -316,6 +316,14 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
// 返回结果 // 返回结果
UpdateProductResultDTO result = new UpdateProductResultDTO(); UpdateProductResultDTO result = new UpdateProductResultDTO();
result.setCostChangedSpecIds(costChangedSpecIds); result.setCostChangedSpecIds(costChangedSpecIds);
// 重新查询更新后的商品完整信息
ProductPO updatedProduct = this.getById(id);
if (updatedProduct != null) {
ProductVO productVO = convertToVO(updatedProduct);
result.setProduct(productVO);
}
return result; return result;
} }
@@ -37,6 +37,8 @@ export namespace ProductVO {
export interface UpdateProductResult { export interface UpdateProductResult {
/** 本次更新中成本发生变更的规格ID列表 */ /** 本次更新中成本发生变更的规格ID列表 */
costChangedSpecIds: number[]; costChangedSpecIds: number[];
/** 更新后的商品完整信息 */
product: ProductVO.Info;
} }
/** 商品规格信息 */ /** 商品规格信息 */
@@ -99,7 +99,7 @@ interface Props {
interface Emits { interface Emits {
(e: 'delete', product: ProductVO.Info): void; (e: 'delete', product: ProductVO.Info): void;
(e: 'updated'): void; (e: 'updated', product: ProductVO.Info): void;
(e: 'editing-change', editing: boolean): void; (e: 'editing-change', editing: boolean): void;
} }
@@ -344,7 +344,7 @@ const saveEdit = async () => {
const result = await updateProductApi(props.product.id, payload); const result = await updateProductApi(props.product.id, payload);
message.success('商品保存成功'); message.success('商品保存成功');
isEditing.value = false; isEditing.value = false;
emit('updated'); emit('updated', result.product);
emit('editing-change', false); emit('editing-change', false);
// 如果有规格成本变更,弹出同步确认框 // 如果有规格成本变更,弹出同步确认框
if (result.costChangedSpecIds?.length > 0) { if (result.costChangedSpecIds?.length > 0) {
@@ -184,8 +184,12 @@ const handleEditingChange = async () => {
}; };
// 刷新列表 // 刷新列表
function refreshTable() { function refreshTable(updatedProduct: ProductVO.Info) {
handleSearch(); // 就地更新商品数据,不重新请求列表
const index = productList.value.findIndex((p) => p.id === updatedProduct.id);
if (index !== -1) {
productList.value[index] = updatedProduct;
}
} }
// 暴露方法 // 暴露方法
@@ -306,7 +310,7 @@ onUnmounted(() => {
<div class="w-full"> <div class="w-full">
<ProductCard <ProductCard
:product="item" :product="item"
@updated="refreshTable" @updated="(product) => refreshTable(product)"
@delete="handleDelete" @delete="handleDelete"
@editing-change="handleEditingChange" @editing-change="handleEditingChange"
/> />