From 0fba3fd5033a451cfe2c33a1dc8a3d91c90ed9b3 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 24 May 2023 20:27:45 +0800 Subject: [PATCH] =?UTF-8?q?review=20+=20mall=EF=BC=9A=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/vite/optimize.ts | 3 +- src/api/mall/product/spu.ts | 2 + src/utils/index.ts | 1 + src/views/mall/product/spu/addForm.vue | 1 - .../product/spu/components/BasicInfoForm.vue | 17 +++---- .../spu/components/OtherSettingsForm.vue | 13 ++--- .../mall/product/spu/components/SkuList.vue | 50 ++++++++++++------- src/views/mall/product/spu/index.vue | 35 ++++++------- 8 files changed, 63 insertions(+), 59 deletions(-) diff --git a/build/vite/optimize.ts b/build/vite/optimize.ts index 9d576191..70fc3b8f 100644 --- a/build/vite/optimize.ts +++ b/build/vite/optimize.ts @@ -102,7 +102,8 @@ const include = [ 'element-plus/es/components/timeline-item/style/css', 'element-plus/es/components/collapse/style/css', 'element-plus/es/components/collapse-item/style/css', - 'element-plus/es/components/button-group/style/css' + 'element-plus/es/components/button-group/style/css', + 'element-plus/es/components/text/style/css' ] const exclude = ['@iconify/json'] diff --git a/src/api/mall/product/spu.ts b/src/api/mall/product/spu.ts index ace7e417..e58f2ec8 100644 --- a/src/api/mall/product/spu.ts +++ b/src/api/mall/product/spu.ts @@ -7,6 +7,7 @@ export interface Property { valueName?: string // 属性值名称 } +// TODO puhui999:是不是直接叫 Sku 更简洁一点哈。type 待后面,总感觉有个类型? export interface SkuType { id?: number // 商品 SKU 编号 spuId?: number // SPU 编号 @@ -24,6 +25,7 @@ export interface SkuType { salesCount?: number // 商品销量 } +// TODO puhui999:是不是直接叫 Spu 更简洁一点哈。type 待后面,总感觉有个类型? export interface SpuType { id?: number name?: string // 商品名称 diff --git a/src/utils/index.ts b/src/utils/index.ts index cf8ba38e..3d596a36 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -174,6 +174,7 @@ export const copyValueToTarget = (target, source) => { Object.assign(target, newObj) } +// TODO @puhui999:返回要带上 .00 哈.例如说 1.00 /** * 将一个整数转换为分数保留两位小数 * @param num diff --git a/src/views/mall/product/spu/addForm.vue b/src/views/mall/product/spu/addForm.vue index bc0941cd..18f9d0b6 100644 --- a/src/views/mall/product/spu/addForm.vue +++ b/src/views/mall/product/spu/addForm.vue @@ -146,7 +146,6 @@ const submitForm = async () => { const newSliderPicUrls = [] deepCopyFormData.sliderPicUrls.forEach((item) => { // 如果是前端选的图 - // TODO @puhui999:疑问哈,为啥会是 object 呀?fix typeof item === 'object' ? newSliderPicUrls.push(item.url) : newSliderPicUrls.push(item) }) deepCopyFormData.sliderPicUrls = newSliderPicUrls diff --git a/src/views/mall/product/spu/components/BasicInfoForm.vue b/src/views/mall/product/spu/components/BasicInfoForm.vue index eac3de9c..d800e332 100644 --- a/src/views/mall/product/spu/components/BasicInfoForm.vue +++ b/src/views/mall/product/spu/components/BasicInfoForm.vue @@ -96,7 +96,6 @@ - 添加规格 @@ -137,9 +136,8 @@ const props = defineProps({ }, activeName: propTypes.string.def('') }) -const attributesAddFormRef = ref() // 添加商品属性表单 TODO @puhui999:小写开头哈 fix -const productSpuBasicInfoRef = ref() // 表单Ref TODO @puhui999:小写开头哈 fix -// TODO @puhui999:attributeList 改成 propertyList,会更统一一点 fix +const attributesAddFormRef = ref() // 添加商品属性表单 +const productSpuBasicInfoRef = ref() // 表单 Ref const propertyList = ref([]) // 商品属性列表 const skuListRef = ref() // 商品属性列表Ref /** 调用 SkuList generateTableData 方法*/ @@ -180,17 +178,17 @@ const rules = reactive({ watch( () => props.propFormData, (data) => { - if (!data) return - // fix:三个表单组件监听赋值必须使用 copyValueToTarget 使用 formData.value = data 会监听非常多次 + if (!data) { + return + } copyValueToTarget(formData, data) - // fix: 多图上传组件需要一个包含url属性的对象才能正常回显 formData.sliderPicUrls = data['sliderPicUrls'].map((item) => ({ url: item })) + // TODO @puhui999:if return,减少嵌套层级 // 只有是多规格才处理 if (formData.specType) { - // TODO @puhui999:可以直接拿 propertyName 拼接处规格 id + 属性,可以看下商品 uniapp 详情的做法 - // fix: 直接拿返回的 skus 属性逆向生成出 propertyList + // 直接拿返回的 skus 属性逆向生成出 propertyList const properties = [] formData.skus.forEach((sku) => { sku.properties.forEach(({ propertyId, propertyName, valueId, valueName }) => { @@ -209,7 +207,6 @@ watch( } }, { - // fix: 去掉深度监听只有对象引用发生改变的时候才执行,解决改一动多的问题 immediate: true } ) diff --git a/src/views/mall/product/spu/components/OtherSettingsForm.vue b/src/views/mall/product/spu/components/OtherSettingsForm.vue index 8189f9c7..48608b7b 100644 --- a/src/views/mall/product/spu/components/OtherSettingsForm.vue +++ b/src/views/mall/product/spu/components/OtherSettingsForm.vue @@ -1,7 +1,6 @@ - -