优化添加组件及页面

This commit is contained in:
wangxiaowei
2025-09-01 17:28:32 +08:00
parent 6ac45bef6b
commit d05eeebdb1
18 changed files with 695 additions and 95 deletions

View File

@ -7,72 +7,77 @@
</template>
<script lang="ts" setup name="PriceFormat">
import { ref, onMounted, watch } from 'vue'
/**
* PriceFormat 金额格式化
* @description 列表或者详情页价格格式化展示
*/
const props = defineProps({
price: {
type: [String, Number],
default: '0.00'
},
firstSize: {
type: [String, Number],
default: 36
},
secondSize: {
type: [String, Number],
default: 24
},
subscriptSize: {
type: [String, Number],
default: 24
},
color: {
type: String,
default: '#E54444'
},
weight: {
type: String,
default: 'bold'
},
lineThrough: {
type: Boolean,
default: false
},
showSubscript: {
type: Boolean,
default: true
}
})
import { ref, onMounted, watch } from 'vue'
const priceSlice = ref<{ first: string | number; second?: string | number }>({ first: 0 })
const props = defineProps({
price: {
type: [String, Number],
default: '0.00'
},
firstSize: {
type: [String, Number],
default: 36
},
secondSize: {
type: [String, Number],
default: 24
},
subscriptSize: {
type: [String, Number],
default: 24
},
color: {
type: String,
default: '#E54444'
},
weight: {
type: String,
default: 'bold'
},
lineThrough: {
type: Boolean,
default: false
},
showSubscript: {
type: Boolean,
default: true
}
})
onMounted(() => {
priceFormat.format()
})
const priceSlice = ref<{ first: string | number; second?: string | number }>({ first: 0 })
const priceFormat = {
format: () => {
let price = props.price
let formattedPrice: { first: string | number; second?: string | number } = { first: 0 }
if(price !== null && price !== '' && price !== undefined) {
price = parseFloat(price);
// 保留两位小数
const priceStr = price.toFixed(2);
const priceArr = priceStr.split('.');
formattedPrice.first = priceArr[0];
formattedPrice.second = priceArr[1];
priceSlice.value = formattedPrice
}else {
priceSlice.value = {
first: 0
onMounted(() => {
priceFormat.format()
})
const priceFormat = {
format: () => {
let price = props.price
let formattedPrice: { first: string | number; second?: string | number } = { first: 0 }
if(price !== null && price !== '' && price !== undefined) {
price = parseFloat(price);
// 保留两位小数
const priceStr = price.toFixed(2);
const priceArr = priceStr.split('.');
formattedPrice.first = priceArr[0];
formattedPrice.second = priceArr[1];
priceSlice.value = formattedPrice
}else {
priceSlice.value = {
first: 0
}
}
}
}
}
watch(() => props.price, () => {
priceFormat.format()
})
watch(() => props.price, () => {
priceFormat.format()
})
</script>
<script lang="ts">