Skip to content

Commit 8d026f0

Browse files
committed
重构:商品详情界面的路由、文件路径
1 parent 9507e2b commit 8d026f0

File tree

9 files changed

+46
-77
lines changed

9 files changed

+46
-77
lines changed

src/router/modules/remaining.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,6 @@ const remainingRouter: AppRouteRecordRaw[] = [
195195
noTagsView: true
196196
}
197197
},
198-
{
199-
path: '/trade/order',
200-
component: Layout,
201-
name: 'order',
202-
meta: {
203-
hidden: true
204-
},
205-
children: [
206-
{
207-
path: 'detail',
208-
name: 'TradeOrderDetail',
209-
component: () => import('@/views/mall/trade/order/tradeOrderDetail.vue'),
210-
meta: { title: '订单详情', hidden: true }
211-
}
212-
]
213-
},
214198
{
215199
path: '/403',
216200
component: () => import('@/views/Error/403.vue'),
@@ -356,7 +340,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
356340
children: [
357341
{
358342
path: 'spu/add',
359-
component: () => import('@/views/mall/product/spu/addForm.vue'),
343+
component: () => import('@/views/mall/product/spu/form/index.vue'),
360344
name: 'ProductSpuAdd',
361345
meta: {
362346
noCache: true,
@@ -369,7 +353,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
369353
},
370354
{
371355
path: 'spu/edit/:spuId(\\d+)',
372-
component: () => import('@/views/mall/product/spu/addForm.vue'),
356+
component: () => import('@/views/mall/product/spu/form/index.vue'),
373357
name: 'ProductSpuEdit',
374358
meta: {
375359
noCache: true,
@@ -382,7 +366,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
382366
},
383367
{
384368
path: 'spu/detail/:spuId(\\d+)',
385-
component: () => import('@/views/mall/product/spu/addForm.vue'),
369+
component: () => import('@/views/mall/product/spu/form/index.vue'),
386370
name: 'ProductSpuDetail',
387371
meta: {
388372
noCache: true,
Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
import BasicInfoForm from './BasicInfoForm.vue'
2-
import DescriptionForm from './DescriptionForm.vue'
3-
import OtherSettingsForm from './OtherSettingsForm.vue'
4-
import ProductAttributes from './ProductAttributes.vue'
5-
import ProductPropertyAddForm from './ProductPropertyAddForm.vue'
61
import SkuList from './SkuList.vue'
72

8-
import { Spu } from '@/api/mall/product/spu'
9-
103
interface PropertyAndValues {
114
id: number
125
name: string
@@ -29,42 +22,4 @@ interface RuleConfig {
2922
message: string
3023
}
3124

32-
/**
33-
* 获得商品的规格列表
34-
*
35-
* @param spu
36-
* @return PropertyAndValues 规格列表
37-
*/
38-
const getPropertyList = (spu: Spu): PropertyAndValues[] => {
39-
// 直接拿返回的 skus 属性逆向生成出 propertyList
40-
const properties: PropertyAndValues[] = []
41-
// 只有是多规格才处理
42-
if (spu.specType) {
43-
spu.skus?.forEach((sku) => {
44-
sku.properties?.forEach(({ propertyId, propertyName, valueId, valueName }) => {
45-
// 添加属性
46-
if (!properties?.some((item) => item.id === propertyId)) {
47-
properties.push({ id: propertyId!, name: propertyName!, values: [] })
48-
}
49-
// 添加属性值
50-
const index = properties?.findIndex((item) => item.id === propertyId)
51-
if (!properties[index].values?.some((value) => value.id === valueId)) {
52-
properties[index].values?.push({ id: valueId!, name: valueName! })
53-
}
54-
})
55-
})
56-
}
57-
return properties
58-
}
59-
60-
export {
61-
BasicInfoForm,
62-
DescriptionForm,
63-
OtherSettingsForm,
64-
ProductAttributes,
65-
ProductPropertyAddForm,
66-
SkuList,
67-
getPropertyList,
68-
PropertyAndValues,
69-
RuleConfig
70-
}
25+
export { SkuList, PropertyAndValues, RuleConfig }

src/views/mall/product/spu/components/BasicInfoForm.vue renamed to src/views/mall/product/spu/form/BasicInfoForm.vue

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,17 @@ import { propTypes } from '@/utils/propTypes'
175175
import { checkSelectedNode, defaultProps, handleTree, treeToString } from '@/utils/tree'
176176
import { createImageViewer } from '@/components/ImageViewer'
177177
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
178-
import { UploadImg, UploadImgs } from '@/components/UploadFile'
179-
import { getPropertyList, ProductAttributes, ProductPropertyAddForm, SkuList } from './index'
178+
import { PropertyAndValues, SkuList } from '@/views/mall/product/spu/components/index.ts'
179+
import ProductAttributes from './ProductAttributes.vue'
180+
import ProductPropertyAddForm from './ProductPropertyAddForm.vue'
180181
import { basicInfoSchema } from './spu.data'
181182
import type { Spu } from '@/api/mall/product/spu'
182183
import * as ProductCategoryApi from '@/api/mall/product/category'
183-
import { getSimpleBrandList } from '@/api/mall/product/brand'
184-
import { getSimpleTemplateList } from '@/api/mall/trade/delivery/expressTemplate/index'
184+
import * as ProductBrandApi from '@/api/mall/product/brand'
185+
import * as ExpressTemplateApi from '@/api/mall/trade/delivery/expressTemplate'
186+
187+
defineOptions({ name: 'ProductSpuBasicInfoForm' })
188+
185189
// ====== 商品详情相关操作 ======
186190
const { allSchemas } = useCrudSchemas(basicInfoSchema)
187191
/** 商品图预览 */
@@ -198,9 +202,36 @@ const imagePreview = (args) => {
198202
urlList
199203
})
200204
}
201-
// ====== end ======
202205
203-
defineOptions({ name: 'ProductSpuBasicInfoForm' })
206+
/**
207+
* 获得商品的规格列表
208+
*
209+
* @param spu
210+
* @return PropertyAndValues 规格列表
211+
*/
212+
const getPropertyList = (spu: Spu): PropertyAndValues[] => {
213+
// 直接拿返回的 skus 属性逆向生成出 propertyList
214+
const properties: PropertyAndValues[] = []
215+
// 只有是多规格才处理
216+
if (spu.specType) {
217+
spu.skus?.forEach((sku) => {
218+
sku.properties?.forEach(({ propertyId, propertyName, valueId, valueName }) => {
219+
// 添加属性
220+
if (!properties?.some((item) => item.id === propertyId)) {
221+
properties.push({ id: propertyId!, name: propertyName!, values: [] })
222+
}
223+
// 添加属性值
224+
const index = properties?.findIndex((item) => item.id === propertyId)
225+
if (!properties[index].values?.some((value) => value.id === valueId)) {
226+
properties[index].values?.push({ id: valueId!, name: valueName! })
227+
}
228+
})
229+
})
230+
}
231+
return properties
232+
}
233+
234+
// ====== end ======
204235
205236
const message = useMessage() // 消息弹窗
206237
@@ -346,8 +377,8 @@ onMounted(async () => {
346377
const data = await ProductCategoryApi.getCategoryList({})
347378
categoryList.value = handleTree(data, 'id', 'parentId')
348379
// 获取商品品牌列表
349-
brandList.value = await getSimpleBrandList()
380+
brandList.value = await ProductBrandApi.getSimpleBrandList()
350381
// 获取运费模版
351-
deliveryTemplateList.value = await getSimpleTemplateList()
382+
deliveryTemplateList.value = await ExpressTemplateApi.getSimpleTemplateList()
352383
})
353384
</script>

src/views/mall/product/spu/addForm.vue renamed to src/views/mall/product/spu/form/index.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@
3939
<script lang="ts" setup>
4040
import { cloneDeep } from 'lodash-es'
4141
import { useTagsViewStore } from '@/store/modules/tagsView'
42-
import { BasicInfoForm, DescriptionForm, OtherSettingsForm } from './components'
43-
// 业务api
4442
import * as ProductSpuApi from '@/api/mall/product/spu'
43+
import BasicInfoForm from './BasicInfoForm.vue'
44+
import DescriptionForm from './DescriptionForm.vue'
45+
import OtherSettingsForm from './OtherSettingsForm.vue'
4546
import { convertToInteger, floatToFixed2, formatToFraction } from '@/utils'
4647
47-
// TODO @芋艿:后续稍微调整下;
48-
4948
defineOptions({ name: 'ProductSpuForm' })
5049
5150
const { t } = useI18n() // 国际化

0 commit comments

Comments
 (0)