From 7a5993c584b42ebca679109ed705386e04ee1020 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 6 May 2023 22:54:41 +0800 Subject: [PATCH] =?UTF-8?q?code=20review=20=E5=95=86=E5=93=81=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit e92361ed401771998c6abd6d9ba53801a6e0cfa6) --- src/api/mall/product/management/spu.ts | 16 +++++-- src/router/modules/remaining.ts | 4 +- src/utils/constants.ts | 1 + src/utils/object.ts | 1 + .../product/{management => spu}/addForm.vue | 8 +++- .../components/BasicInfoForm.vue | 33 +++++++------- .../components/DescriptionForm.vue | 13 +++--- .../components/OtherSettingsForm.vue | 18 ++++---- .../components/ProductAttributes.vue | 3 ++ .../components/ProductAttributesAddForm.vue | 0 .../components/SkuList.vue | 16 +++++-- .../{management => spu}/components/index.ts | 0 .../product/{management => spu}/index.vue | 43 +++++++++++++++---- 13 files changed, 108 insertions(+), 48 deletions(-) rename src/views/mall/product/{management => spu}/addForm.vue (94%) rename src/views/mall/product/{management => spu}/components/BasicInfoForm.vue (90%) rename src/views/mall/product/{management => spu}/components/DescriptionForm.vue (99%) rename src/views/mall/product/{management => spu}/components/OtherSettingsForm.vue (93%) rename src/views/mall/product/{management => spu}/components/ProductAttributes.vue (99%) rename src/views/mall/product/{management => spu}/components/ProductAttributesAddForm.vue (100%) rename src/views/mall/product/{management => spu}/components/SkuList.vue (95%) rename src/views/mall/product/{management => spu}/components/index.ts (100%) rename src/views/mall/product/{management => spu}/index.vue (89%) diff --git a/src/api/mall/product/management/spu.ts b/src/api/mall/product/management/spu.ts index 2aa83e7a..07d7103e 100644 --- a/src/api/mall/product/management/spu.ts +++ b/src/api/mall/product/management/spu.ts @@ -1,30 +1,38 @@ import request from '@/config/axios' -import type { SpuType } from './type/spuType' +import type { SpuType } from './type/spuType' // TODO @puhui999: type 和 api 一起放,简单一点哈~ -// 获得spu列表 -export const getSpuList = (params: any) => { +// TODO @puhui999:中英文之间有空格 + +// 获得spu列表 TODO @puhui999:这个是 getSpuPage 哈 +export const getSpuList = (params: PageParam) => { return request.get({ url: '/product/spu/page', params }) } + // 获得spu列表tabsCount export const getTabsCount = () => { return request.get({ url: '/product/spu/tabsCount' }) } + // 创建商品spu export const createSpu = (data: SpuType) => { return request.post({ url: '/product/spu/create', data }) } + // 更新商品spu export const updateSpu = (data: SpuType) => { return request.put({ url: '/product/spu/update', data }) } + // 更新商品spu status export const updateStatus = (data: { id: number; status: number }) => { return request.put({ url: '/product/spu/updateStatus', data }) } -// 获得商品spu + +// 获得商品 spu export const getSpu = (id: number) => { return request.get({ url: `/product/spu/get-detail?id=${id}` }) } + // 删除商品Spu export const deleteSpu = (id: number) => { return request.delete({ url: `/product/spu/delete?id=${id}` }) diff --git a/src/router/modules/remaining.ts b/src/router/modules/remaining.ts index 02222d35..68e8ef8f 100644 --- a/src/router/modules/remaining.ts +++ b/src/router/modules/remaining.ts @@ -367,8 +367,8 @@ const remainingRouter: AppRouteRecordRaw[] = [ }, children: [ { - path: 'productManagementAdd', - component: () => import('@/views/mall/product/management/addForm.vue'), + path: 'productManagementAdd', // TODO @puhui999:最好拆成 add 和 edit 两个路由;添加商品;修改商品 + component: () => import('@/views/mall/product/spu/addForm.vue'), name: 'ProductManagementAdd', meta: { noCache: true, diff --git a/src/utils/constants.ts b/src/utils/constants.ts index fceee907..801e85a1 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -216,6 +216,7 @@ export const PayRefundStatusEnum = { name: '退款关闭' } } + /** * 商品SPU枚举类 */ diff --git a/src/utils/object.ts b/src/utils/object.ts index 8edd1888..6612da74 100644 --- a/src/utils/object.ts +++ b/src/utils/object.ts @@ -1,3 +1,4 @@ +// TODO @puhui999:这个方法,可以考虑放到 index.js /** * 将值复制到目标对象,且以目标对象属性为准,例:target: {a:1} source:{a:2,b:3} 结果为:{a:2} * @param target 目标对象 diff --git a/src/views/mall/product/management/addForm.vue b/src/views/mall/product/spu/addForm.vue similarity index 94% rename from src/views/mall/product/management/addForm.vue rename to src/views/mall/product/spu/addForm.vue index 7f31871f..28fc414d 100644 --- a/src/views/mall/product/management/addForm.vue +++ b/src/views/mall/product/spu/addForm.vue @@ -37,7 +37,6 @@ import { BasicInfoForm, DescriptionForm, OtherSettingsForm } from './components' import type { SpuType } from '@/api/mall/product/management/type/spuType' // 业务api import * as managementApi from '@/api/mall/product/management/spu' import * as PropertyApi from '@/api/mall/product/property' - const { t } = useI18n() // 国际化 const message = useMessage() // 消息弹窗 const { push, currentRoute } = useRouter() // 路由 @@ -69,7 +68,7 @@ const formData = ref({ skus: [ { /** - * 商品价格,单位:分 + * 商品价格,单位:分 TODO @puhui999:注释放在尾巴哈,简洁一点~ */ price: 0, /** @@ -120,6 +119,7 @@ const formData = ref({ recommendNew: false, // 是否新品 recommendGood: false // 是否优品 }) + /** 获得详情 */ const getDetail = async () => { const id = query.id as unknown as number @@ -129,6 +129,7 @@ const getDetail = async () => { const res = (await managementApi.getSpu(id)) as SpuType formData.value = res // 直接取第一个值就能得到所有属性的id + // TODO @puhui999:可以直接拿 propertyName 拼接处规格 id + 属性,可以看下商品 uniapp 详情的做法 const propertyIds = res.skus[0]?.properties.map((item) => item.propertyId) const PropertyS = await PropertyApi.getPropertyListAndValue({ propertyIds }) await nextTick() @@ -151,6 +152,7 @@ const submitForm = async () => { await unref(BasicInfoRef)?.validate() await unref(DescriptionRef)?.validate() await unref(OtherSettingsRef)?.validate() + // TODO @puhui:直接做深拷贝?这样最终 server 端不满足,不需要恢复 // 处理掉一些无关数据 formData.value.skus.forEach((item) => { // 给sku name赋值 @@ -166,6 +168,7 @@ const submitForm = async () => { const newSliderPicUrls = [] formData.value.sliderPicUrls.forEach((item) => { // 如果是前端选的图 + // TODO @puhui999:疑问哈,为啥会是 object 呀? if (typeof item === 'object') { newSliderPicUrls.push(item.url) } else { @@ -224,6 +227,7 @@ const resetForm = async () => { } /** 关闭按钮 */ const close = () => { + // TODO @puhui999:是不是不用 reset 呀?close 默认销毁 resetForm() delView(unref(currentRoute)) push('/product/product-management') diff --git a/src/views/mall/product/management/components/BasicInfoForm.vue b/src/views/mall/product/spu/components/BasicInfoForm.vue similarity index 90% rename from src/views/mall/product/management/components/BasicInfoForm.vue rename to src/views/mall/product/spu/components/BasicInfoForm.vue index 1b60c17e..249a3830 100644 --- a/src/views/mall/product/management/components/BasicInfoForm.vue +++ b/src/views/mall/product/spu/components/BasicInfoForm.vue @@ -7,6 +7,7 @@ + @@ -25,7 +27,7 @@ - + - + @@ -84,9 +86,8 @@ - 添加规格 - + + 添加规格 + + -