From 4fafb39efc206ced09d4728d47769f093adc5102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=83=E8=B4=A7?= <252048765@qq.com> Date: Mon, 7 Jul 2025 07:25:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E7=AE=A1=E7=90=86=E7=BB=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E5=8C=85=E5=90=AB=E5=B1=9E=E6=80=A7=E5=88=97=E8=A1=A8=E5=92=8C?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=80=BC=E7=9A=84=E5=A2=9E=E5=88=A0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/mall/product/spu/components/data.ts | 42 ++++++ .../mall/product/spu/components/model.d.ts | 37 ----- ...-fttributes.vue => product-attributes.vue} | 129 +++++++++--------- .../mall/product/spu/components/sku-form.vue | 63 ++++++++- 4 files changed, 164 insertions(+), 107 deletions(-) create mode 100644 apps/web-ele/src/views/mall/product/spu/components/data.ts rename apps/web-ele/src/views/mall/product/spu/components/{product-fttributes.vue => product-attributes.vue} (64%) diff --git a/apps/web-ele/src/views/mall/product/spu/components/data.ts b/apps/web-ele/src/views/mall/product/spu/components/data.ts new file mode 100644 index 000000000..50463a42d --- /dev/null +++ b/apps/web-ele/src/views/mall/product/spu/components/data.ts @@ -0,0 +1,42 @@ +import type { MallSpuApi } from '#/api/mall/product/spu'; +import type { PropertyAndValues } from './model'; + +/** + * 获得商品的规格列表 - 商品相关的公共函数 + * + * @param spu + * @return PropertyAndValues 规格列表 + */ +const getPropertyList = (spu: MallSpuApi.Spu): PropertyAndValues[] => { + // 直接拿返回的 skus 属性逆向生成出 propertyList + const properties: PropertyAndValues[] = []; + // 只有是多规格才处理 + if (spu.specType) { + spu.skus?.forEach((sku) => { + sku.properties?.forEach( + ({ propertyId, propertyName, valueId, valueName }) => { + // 添加属性 + if (!properties?.some((item) => item.id === propertyId)) { + properties.push({ + id: propertyId!, + name: propertyName!, + values: [], + }); + } + // 添加属性值 + const index = properties?.findIndex((item) => item.id === propertyId); + if ( + index !== undefined && + index >= 0 && + !properties[index]!.values?.some((value) => value.id === valueId) + ) { + properties[index]!.values?.push({ id: valueId!, name: valueName! }); + } + }, + ); + }); + } + return properties; +}; + +export { getPropertyList }; diff --git a/apps/web-ele/src/views/mall/product/spu/components/model.d.ts b/apps/web-ele/src/views/mall/product/spu/components/model.d.ts index 01e5ef181..ad01b21fa 100644 --- a/apps/web-ele/src/views/mall/product/spu/components/model.d.ts +++ b/apps/web-ele/src/views/mall/product/spu/components/model.d.ts @@ -1,5 +1,4 @@ import SkuList from './SkuList.vue'; -import { Spu } from '@/api/mall/product/spu'; interface PropertyAndValues { id: number; @@ -23,40 +22,4 @@ interface RuleConfig { message: string; } -/** - * 获得商品的规格列表 - 商品相关的公共函数 - * - * @param spu - * @return PropertyAndValues 规格列表 - */ -const getPropertyList = (spu: Spu): PropertyAndValues[] => { - // 直接拿返回的 skus 属性逆向生成出 propertyList - const properties: PropertyAndValues[] = []; - // 只有是多规格才处理 - if (spu.specType) { - spu.skus?.forEach((sku) => { - sku.properties?.forEach( - ({ propertyId, propertyName, valueId, valueName }) => { - // 添加属性 - if (!properties?.some((item) => item.id === propertyId)) { - properties.push({ - id: propertyId!, - name: propertyName!, - values: [], - }); - } - // 添加属性值 - const index = properties?.findIndex((item) => item.id === propertyId); - if ( - !properties[index].values?.some((value) => value.id === valueId) - ) { - properties[index].values?.push({ id: valueId!, name: valueName! }); - } - }, - ); - }); - } - return properties; -}; - export { SkuList, PropertyAndValues, RuleConfig, getPropertyList }; diff --git a/apps/web-ele/src/views/mall/product/spu/components/product-fttributes.vue b/apps/web-ele/src/views/mall/product/spu/components/product-attributes.vue similarity index 64% rename from apps/web-ele/src/views/mall/product/spu/components/product-fttributes.vue rename to apps/web-ele/src/views/mall/product/spu/components/product-attributes.vue index 5a488b584..f1c61d3e4 100644 --- a/apps/web-ele/src/views/mall/product/spu/components/product-fttributes.vue +++ b/apps/web-ele/src/views/mall/product/spu/components/product-attributes.vue @@ -1,55 +1,57 @@ - + - 属性名: - + 属性名: + {{ item.name }} - + - 属性值: - - {{ value.name }} - - - - - - + 添加 - + + 属性值: + + {{ value.name }} + + + + + + + 添加 + + - - + + @@ -178,12 +213,28 @@ const generateSkus = (propertyList: any[]) => { /> - 添加属性 - + 添加属性 + + + + + + + +