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 @@ + +