【代码优化】代码格式化

pull/537/head
卢越 2024-09-05 12:46:58 +08:00
parent 40fe63a3fb
commit 4870231b61
7 changed files with 376 additions and 345 deletions

View File

@ -3,7 +3,7 @@ import {ComponentStyle, DiyComponent} from '@/components/DiyEditor/util'
/** 拼团属性 */
export interface PromotionCombinationProperty {
// 布局类型:单列 | 三列
layoutType: 'oneColBigImg' | 'oneColSmallImg' | 'twoCol';
layoutType: 'oneColBigImg' | 'oneColSmallImg' | 'twoCol'
// 商品字段
fields: {
// 商品名称

View File

@ -118,64 +118,67 @@
import { PromotionCombinationProperty } from './config'
import * as ProductSpuApi from '@/api/mall/product/spu'
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
import {fenToYuan} from "@/utils";
import { fenToYuan } from '@/utils'
/** 拼团卡片 */
defineOptions({ name: 'PromotionCombination' })
//
const props = defineProps<{ property: PromotionCombinationProperty }>();
const props = defineProps<{ property: PromotionCombinationProperty }>()
//
const spuList = ref<ProductSpuApi.Spu[]>([]);
const spuIdList = ref<number[]>([]);
const combinationActivityList = ref<CombinationActivityApi.CombinationActivityVO[]>([]);
const spuList = ref<ProductSpuApi.Spu[]>([])
const spuIdList = ref<number[]>([])
const combinationActivityList = ref<CombinationActivityApi.CombinationActivityVO[]>([])
watch(
() => props.property.activityIds,
async () => {
try {
// ID
const activityIds = props.property.activityIds;
const activityIds = props.property.activityIds
// ID
if (Array.isArray(activityIds) && activityIds.length > 0 && activityIds.every(item => item != null)) {
if (
Array.isArray(activityIds) &&
activityIds.length > 0 &&
activityIds.every((item) => item != null)
) {
//
combinationActivityList.value = await CombinationActivityApi.getCombinationActivityDetailList(activityIds);
combinationActivityList.value =
await CombinationActivityApi.getCombinationActivityDetailList(activityIds)
//
spuIdList.value = [];
spuList.value = [];
spuIdList.value = []
spuList.value = []
// spuId
spuIdList.value = combinationActivityList.value
.map(activity => activity.spuId)
.filter((spuId): spuId is number => typeof spuId === 'number');
.map((activity) => activity.spuId)
.filter((spuId): spuId is number => typeof spuId === 'number')
// spuId API
if (spuIdList.value.length > 0) {
spuList.value = await ProductSpuApi.getSpuDetailList(spuIdList.value);
spuList.value = await ProductSpuApi.getSpuDetailList(spuIdList.value)
} else {
console.warn('没有用于获取详细信息的有效 spuId。');
console.warn('没有用于获取详细信息的有效 spuId。')
}
// SPU
combinationActivityList.value.forEach(activity => {
activity.products.forEach(product => {
const spu = spuList.value.find(spu => spu.id === product.spuId);
combinationActivityList.value.forEach((activity) => {
activity.products.forEach((product) => {
const spu = spuList.value.find((spu) => spu.id === product.spuId)
if (spu) {
spu.price = Math.min(product.combinationPrice || Infinity, spu.price || Infinity);
spu.price = Math.min(product.combinationPrice || Infinity, spu.price || Infinity)
}
});
});
})
})
}
} catch (error) {
console.error('获取拼团活动细节或 SPU 细节时出错:', error);
console.error('获取拼团活动细节或 SPU 细节时出错:', error)
}
},
{
immediate: true,
deep: true
}
);
)
/**
* 计算商品的间距

View File

@ -143,7 +143,7 @@ import {PromotionCombinationProperty} from './config'
import { usePropertyForm } from '@/components/DiyEditor/util'
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
import { CommonStatusEnum } from '@/utils/constants'
import CombinationShowcase from "@/views/mall/promotion/combination/components/CombinationShowcase.vue";
import CombinationShowcase from '@/views/mall/promotion/combination/components/CombinationShowcase.vue'
//
defineOptions({ name: 'PromotionCombinationProperty' })
@ -158,7 +158,7 @@ onMounted(async () => {
status: CommonStatusEnum.ENABLE
})
activityList.value = list
console.log("formDa", props);
console.log('formDa', props)
})
</script>

View File

@ -153,7 +153,11 @@
>
<!--这里的 key 使用时间戳是为了保证每次点击组件都进行刷新-->
<component
:key="selectedComponent?.uid || selectedComponent?.id + new Date().getTime() || new Date().getTime().toString()"
:key="
selectedComponent?.uid ||
selectedComponent?.id + new Date().getTime() ||
new Date().getTime().toString()
"
:is="selectedComponent?.id + 'Property'"
v-model="selectedComponent.property"
/>

View File

@ -3,7 +3,8 @@
<div
v-for="(combinationActivity, index) in Activitys"
:key="combinationActivity.id"
class="select-box spu-pic">
class="select-box spu-pic"
>
<el-tooltip :content="combinationActivity.name">
<div class="relative h-full w-full">
<el-image :src="combinationActivity.picUrl" class="h-full w-full" />
@ -23,15 +24,18 @@
</el-tooltip>
</div>
<!-- 拼团活动选择对话框表格形式 -->
<CombinationTableSelect ref="combinationActivityTableSelectRef" :multiple="limit != 1"
@change="handleActivitySelected"/>
<CombinationTableSelect
ref="combinationActivityTableSelectRef"
:multiple="limit != 1"
@change="handleActivitySelected"
/>
</template>
<script lang="ts" setup>
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
import { propTypes } from '@/utils/propTypes'
import { oneOfType } from 'vue-types'
import { isArray } from '@/utils/is'
import CombinationTableSelect from "@/views/mall/promotion/combination/components/CombinationTableSelect.vue";
import CombinationTableSelect from '@/views/mall/promotion/combination/components/CombinationTableSelect.vue'
// 使
//
@ -73,7 +77,10 @@ watch(
return
}
//
if (Activitys.value.length === 0 || Activitys.value.some((combinationActivity) => !ids.includes(combinationActivity.id!))) {
if (
Activitys.value.length === 0 ||
Activitys.value.some((combinationActivity) => !ids.includes(combinationActivity.id!))
) {
Activitys.value = await CombinationActivityApi.getCombinationActivityDetailList(ids)
}
},
@ -91,7 +98,11 @@ const openCombinationActivityTableSelect = () => {
* 选择活动后触发
* @param activityVOs 选中的活动列表
*/
const handleActivitySelected = (activityVOs: CombinationActivityApi.CombinationActivityVO | CombinationActivityApi.CombinationActivityVO[]) => {
const handleActivitySelected = (
activityVOs:
| CombinationActivityApi.CombinationActivityVO
| CombinationActivityApi.CombinationActivityVO[]
) => {
Activitys.value = isArray(activityVOs) ? activityVOs : [activityVOs]
emitActivityChange()
}

View File

@ -64,7 +64,11 @@
<!-- 2. 单选模式 -->
<el-table-column label="#" width="55" v-else>
<template #default="{ row }">
<el-radio :value="row.id" v-model="selectedActivityId" @change="handleSingleSelected(row)">
<el-radio
:value="row.id"
v-model="selectedActivityId"
@change="handleSingleSelected(row)"
>
<!-- 空格不能省略是为了让单选框不显示label如果不指定label不会有选中的效果 -->
&nbsp;
</el-radio>
@ -137,11 +141,11 @@ import {handleTree} from '@/utils/tree'
import * as ProductCategoryApi from '@/api/mall/product/category'
import { propTypes } from '@/utils/propTypes'
import { CHANGE_EVENT } from 'element-plus'
import * as CombinationActivityApi from "@/api/mall/promotion/combination/combinationActivity";
import {fenToYuanFormat} from "@/utils/formatter";
import {DICT_TYPE, getIntDictOptions} from "@/utils/dict";
import {dateFormatter, formatDate} from "@/utils/formatTime";
import {fenToYuan} from "@/utils";
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
import { fenToYuanFormat } from '@/utils/formatter'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter, formatDate } from '@/utils/formatTime'
import { fenToYuan } from '@/utils'
type CombinationActivityVO = Required<CombinationActivityApi.CombinationActivityVO>
@ -190,7 +194,9 @@ const open = (CombinationList?: CombinationActivityVO[]) => {
//
if (CombinationList && CombinationList.length > 0) {
checkedActivitys.value = [...CombinationList]
checkedStatus.value = Object.fromEntries(CombinationList.map((activityVO) => [activityVO.id, true]))
checkedStatus.value = Object.fromEntries(
CombinationList.map((activityVO) => [activityVO.id, true])
)
}
dialogVisible.value = true
@ -208,7 +214,8 @@ const getList = async () => {
total.value = data.total
// checkboxundefinedbool
list.value.forEach(
(activityVO) => (checkedStatus.value[activityVO.id] = checkedStatus.value[activityVO.id] || false)
(activityVO) =>
(checkedStatus.value[activityVO.id] = checkedStatus.value[activityVO.id] || false)
)
//
calculateIsCheckAll()
@ -289,7 +296,11 @@ const handleCheckAll = (checked: boolean) => {
* @param combinationActivity 活动
* @param isCalcCheckAll 是否计算全选
*/
const handleCheckOne = (checked: boolean, combinationActivity: CombinationActivityVO, isCalcCheckAll: boolean) => {
const handleCheckOne = (
checked: boolean,
combinationActivity: CombinationActivityVO,
isCalcCheckAll: boolean
) => {
if (checked) {
checkedActivitys.value.push(combinationActivity)
checkedStatus.value[combinationActivity.id] = true
@ -309,13 +320,15 @@ const handleCheckOne = (checked: boolean, combinationActivity: CombinationActivi
}
//
const findCheckedIndex = (activityVO: CombinationActivityVO) => checkedActivitys.value.findIndex((item) => item.id === activityVO.id)
const findCheckedIndex = (activityVO: CombinationActivityVO) =>
checkedActivitys.value.findIndex((item) => item.id === activityVO.id)
//
const calculateIsCheckAll = () => {
isCheckAll.value = list.value.every((activityVO) => checkedStatus.value[activityVO.id])
// &&
isIndeterminate.value = !isCheckAll.value && list.value.some((activityVO) => checkedStatus.value[activityVO.id])
isIndeterminate.value =
!isCheckAll.value && list.value.some((activityVO) => checkedStatus.value[activityVO.id])
}
//