Skip to content

Commit 7d60b5a

Browse files
committed
【代码优化】商城:拼团装修重构
1 parent a2091df commit 7d60b5a

File tree

6 files changed

+11
-28
lines changed

6 files changed

+11
-28
lines changed

src/api/mall/promotion/combination/combinationActivity.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ export interface CombinationActivityVO {
1717
status?: number
1818
limitDuration?: number
1919
products: CombinationProductVO[]
20-
spuName?: string
21-
picUrl?: string
22-
marketPrice?: number
2320
}
2421

2522
// 拼团活动所需属性
@@ -39,7 +36,7 @@ export interface SpuExtension extends Spu {
3936
}
4037

4138
// 查询拼团活动列表
42-
export const getCombinationActivityPage = async (params) => {
39+
export const getCombinationActivityPage = async (params: any) => {
4340
return await request.get({ url: '/promotion/combination-activity/page', params })
4441
}
4542

@@ -48,8 +45,8 @@ export const getCombinationActivity = async (id: number) => {
4845
return await request.get({ url: '/promotion/combination-activity/get?id=' + id })
4946
}
5047

51-
// 查询拼团活动详情列表
52-
export const getCombinationActivityDetailList = (ids: number[]) => {
48+
// 获得拼团活动列表,基于活动编号数组
49+
export const getCombinationActivityListByIds = (ids: number[]) => {
5350
return request.get({ url: `/promotion/combination-activity/list-by-ids?ids=${ids}` })
5451
}
5552

src/components/DiyEditor/components/mobile/PromotionCombination/index.vue

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,30 +136,20 @@ watch(
136136
// 新添加的拼团组件,是没有活动ID的
137137
const activityIds = props.property.activityIds
138138
// 检查活动ID的有效性
139-
if (
140-
Array.isArray(activityIds) &&
141-
activityIds.length > 0 &&
142-
activityIds.every((item) => item != null)
143-
) {
139+
if (Array.isArray(activityIds) && activityIds.length > 0) {
144140
// 获取拼团活动详情列表
145141
combinationActivityList.value =
146-
await CombinationActivityApi.getCombinationActivityDetailList(activityIds)
142+
await CombinationActivityApi.getCombinationActivityListByIds(activityIds)
147143
148-
// 清空之前的数据,防止有重复
149-
spuIdList.value = []
144+
// 获取拼团活动的 SPU 详情列表
150145
spuList.value = []
151-
152-
// 生成有效的 spuId 列表
153146
spuIdList.value = combinationActivityList.value
154147
.map((activity) => activity.spuId)
155148
.filter((spuId): spuId is number => typeof spuId === 'number')
156-
157-
// 如果存在有效的 spuId,调用 API 获取详细信息
158149
if (spuIdList.value.length > 0) {
159150
spuList.value = await ProductSpuApi.getSpuDetailList(spuIdList.value)
160-
} else {
161-
console.warn('没有用于获取详细信息的有效 spuId。')
162151
}
152+
163153
// 更新 SPU 的最低价格
164154
combinationActivityList.value.forEach((activity) => {
165155
activity.products.forEach((product) => {

src/components/DiyEditor/components/mobile/PromotionCombination/property.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ onMounted(async () => {
158158
status: CommonStatusEnum.ENABLE
159159
})
160160
activityList.value = list
161-
console.log('formDa', props)
162161
})
163162
</script>
164163

src/components/DiyEditor/index.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,8 @@
151151
class="m-[calc(0px-var(--el-card-padding))]"
152152
view-class="p-[var(--el-card-padding)] p-b-[calc(var(--el-card-padding)+var(--el-card-padding))] property"
153153
>
154-
<!--这里的 key 使用时间戳是为了保证每次点击组件都进行刷新-->
155154
<component
156-
:key="
157-
selectedComponent?.uid ||
158-
selectedComponent?.id + new Date().getTime() ||
159-
new Date().getTime().toString()
160-
"
155+
:key="selectedComponent?.uid || selectedComponent?.id"
161156
:is="selectedComponent?.id + 'Property'"
162157
v-model="selectedComponent.property"
163158
/>

src/views/mall/product/spu/components/SpuShowcase.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const openSpuTableSelect = () => {
8585
8686
/**
8787
* 选择商品后触发
88+
*
8889
* @param spus 选中的商品列表
8990
*/
9091
const handleSpuSelected = (spus: ProductSpuApi.Spu | ProductSpuApi.Spu[]) => {
@@ -94,6 +95,7 @@ const handleSpuSelected = (spus: ProductSpuApi.Spu | ProductSpuApi.Spu[]) => {
9495
9596
/**
9697
* 删除商品
98+
*
9799
* @param index 商品索引
98100
*/
99101
const handleRemoveSpu = (index: number) => {

src/views/mall/promotion/combination/components/CombinationShowcase.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ watch(
8181
Activitys.value.length === 0 ||
8282
Activitys.value.some((combinationActivity) => !ids.includes(combinationActivity.id!))
8383
) {
84-
Activitys.value = await CombinationActivityApi.getCombinationActivityDetailList(ids)
84+
Activitys.value = await CombinationActivityApi.getCombinationActivityListByIds(ids)
8585
}
8686
},
8787
{ immediate: true }

0 commit comments

Comments
 (0)