From 6ec45a7e0df542bfe7df74162cb7c311a98aa4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Sun, 26 Apr 2026 21:33:43 +0800 Subject: [PATCH] =?UTF-8?q?perf(ecom-dmb):=20=E5=95=86=E5=93=81=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E4=BF=9D=E5=AD=98=E6=94=B9=E4=B8=BA=E5=B0=B1=E5=9C=B0?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=8C=E6=97=A0=E9=9C=80=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=85=A8=E9=87=8F=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端: - UpdateProductResultDTO 新增 product 字段,返回更新后的完整商品信息 前端: - ProductVO.UpdateProductResult 新增 product 字段 - ProductCard 保存成功后 emit('updated', product) 携带商品数据 - ProductGridView.refreshTable(product) 收到数据后原地替换 productList 中对应商品,无需重新请求列表 --- .../ecom/product/model/dto/UpdateProductResultDTO.java | 7 +++++++ .../ecom/product/service/impl/ProductServiceImpl.java | 8 ++++++++ .../src/api/ecommerce/product/types/types.vo.ts | 2 ++ .../views/ecommerce/product/components/ProductCard.vue | 4 ++-- .../ecommerce/product/views/ProductGridView/index.vue | 10 +++++++--- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/dto/UpdateProductResultDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/dto/UpdateProductResultDTO.java index 47e2f60e..e66c6d34 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/dto/UpdateProductResultDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/dto/UpdateProductResultDTO.java @@ -2,6 +2,7 @@ package top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO; import java.util.List; @@ -17,4 +18,10 @@ public class UpdateProductResultDTO { */ @Schema(description = "成本发生变更的规格ID列表") private List costChangedSpecIds; + + /** + * 更新后的商品完整信息 + */ + @Schema(description = "更新后的商品完整信息") + private ProductVO product; } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductServiceImpl.java index 6f0717ae..e3e1d90f 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductServiceImpl.java @@ -316,6 +316,14 @@ public class ProductServiceImpl extends ServiceImpl im // 返回结果 UpdateProductResultDTO result = new UpdateProductResultDTO(); result.setCostChangedSpecIds(costChangedSpecIds); + + // 重新查询更新后的商品完整信息 + ProductPO updatedProduct = this.getById(id); + if (updatedProduct != null) { + ProductVO productVO = convertToVO(updatedProduct); + result.setProduct(productVO); + } + return result; } diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/product/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/product/types/types.vo.ts index 20658e8b..fb02617e 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/product/types/types.vo.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/product/types/types.vo.ts @@ -37,6 +37,8 @@ export namespace ProductVO { export interface UpdateProductResult { /** 本次更新中成本发生变更的规格ID列表 */ costChangedSpecIds: number[]; + /** 更新后的商品完整信息 */ + product: ProductVO.Info; } /** 商品规格信息 */ diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/components/ProductCard.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/components/ProductCard.vue index a0a501ff..e45045c2 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/components/ProductCard.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/components/ProductCard.vue @@ -99,7 +99,7 @@ interface Props { interface Emits { (e: 'delete', product: ProductVO.Info): void; - (e: 'updated'): void; + (e: 'updated', product: ProductVO.Info): void; (e: 'editing-change', editing: boolean): void; } @@ -344,7 +344,7 @@ const saveEdit = async () => { const result = await updateProductApi(props.product.id, payload); message.success('商品保存成功'); isEditing.value = false; - emit('updated'); + emit('updated', result.product); emit('editing-change', false); // 如果有规格成本变更,弹出同步确认框 if (result.costChangedSpecIds?.length > 0) { diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/views/ProductGridView/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/views/ProductGridView/index.vue index 82d0d552..5b098fdf 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/views/ProductGridView/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/views/ProductGridView/index.vue @@ -184,8 +184,12 @@ const handleEditingChange = async () => { }; // 刷新列表 -function refreshTable() { - handleSearch(); +function refreshTable(updatedProduct: ProductVO.Info) { + // 就地更新商品数据,不重新请求列表 + const index = productList.value.findIndex((p) => p.id === updatedProduct.id); + if (index !== -1) { + productList.value[index] = updatedProduct; + } } // 暴露方法 @@ -306,7 +310,7 @@ onUnmounted(() => {