feat: 日历组件|复选框组件优化

This commit is contained in:
duanshuwen
2025-08-05 21:36:26 +08:00
parent 931511b0cf
commit c6271e9f4b
8 changed files with 65 additions and 21 deletions

View File

@@ -46,9 +46,9 @@
@tap="handleDateClick(dateInfo)"
>
<template v-if="dateInfo">
<text class="date-label" v-if="dateInfo.label">{{
dateInfo.label
}}</text>
<text class="date-label" v-if="dateInfo.label">
{{ dateInfo.label }}
</text>
<text class="date-number">{{ dateInfo.day }}</text>
<text class="date-price" v-if="dateInfo.price"
>¥{{ dateInfo.price }}</text
@@ -90,10 +90,12 @@ const props = defineProps({
required: true,
},
// 价格数据对象
// 价格数据数组
priceData: {
type: Object,
default: () => ({}),
type: Array,
default: () => [
{date: '', price: '-', stock: '0'}
],
},
// 默认选中日期
@@ -202,6 +204,16 @@ const getFirstDayOfMonth = (year, month) => {
return day === 0 ? 6 : day - 1; // 转换为周一开始 (0=周一, 6=周日)
};
// 获取指定日期的价格
const getPriceForDate = (dateStr) => {
if (!props.priceData || !Array.isArray(props.priceData)) {
return null;
}
const priceItem = props.priceData.find(item => item.date === dateStr);
return priceItem ? priceItem.price : null;
};
// 生成日历网格数据
const generateCalendarGrid = (year, month) => {
const daysInMonth = getDaysInMonth(year, month);
@@ -221,7 +233,7 @@ const generateCalendarGrid = (year, month) => {
grid.push({
date: dateStr,
day: day,
price: props.priceData[dateStr] || null,
price: getPriceForDate(dateStr),
disabled: isDateDisabled(dateStr),
selected: isDateSelected(dateStr),
inRange: isDateInRange(dateStr),
@@ -378,8 +390,8 @@ const handleRangeSelection = (dateInfo) => {
emit("range-select", {
startDate: rangeStart.value,
endDate: rangeEnd.value,
startPrice: props.priceData[rangeStart.value],
endPrice: props.priceData[rangeEnd.value],
startPrice: getPriceForDate(rangeStart.value),
endPrice: getPriceForDate(rangeEnd.value),
totalDays: daysBetween,
});
}