|
@@ -22,13 +22,9 @@
|
|
|
<tr v-for="row in rows" :key="row">
|
|
|
<td v-for="date in dateList.slice((row - 1) * 7, (row - 1) * 7 + 7)" :key="date.value">
|
|
|
<div
|
|
|
- class="calendar-date hand"
|
|
|
- :class="{
|
|
|
- 'calendar-date--grey': date.month !== showDate.month,
|
|
|
- 'calendar-date--today': date.value === currentDate.value
|
|
|
- }"
|
|
|
+ :class="date.month == showDate.month ? 'calendar-date hand' : 'calendar-date--grey'"
|
|
|
:style="getStyle(date)"
|
|
|
- @click="handleChangeCurrent(date.dayjs)"
|
|
|
+ @click="handleChangeCurrent(date)"
|
|
|
>
|
|
|
<span>{{ date.date }}</span>
|
|
|
</div>
|
|
@@ -69,6 +65,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
format: "YYYY-MM-DD",
|
|
|
disabled: false
|
|
|
});
|
|
|
+const emits = defineEmits(['updateCalendar', 'change']);
|
|
|
const sevenDay: Array<string> = ["日", "一", "二", "三", "四", "五", "六"];
|
|
|
const dateList = ref<CalendarDate[]>([]);
|
|
|
|
|
@@ -81,10 +78,8 @@ const getCalendarDate = (dayjs: Dayjs): CalendarDate => {
|
|
|
dayjs: dayjs
|
|
|
};
|
|
|
};
|
|
|
-// 选中的日期
|
|
|
-const currentDate = ref<CalendarDate>(getCalendarDate(dayjs()));
|
|
|
// 当前日历展示的日期
|
|
|
-const showDate = ref<CalendarDate>(currentDate.value);
|
|
|
+const showDate = ref<CalendarDate>(getCalendarDate(dayjs()));
|
|
|
|
|
|
// 获取日期列表,6*7天
|
|
|
const rows = 6;
|
|
@@ -100,38 +95,47 @@ const getDateList = (): Array<CalendarDate> => {
|
|
|
|
|
|
const nextMonth = (number: number) => {
|
|
|
showDate.value = getCalendarDate(showDate.value.dayjs.add(number, "month"));
|
|
|
+ emits('updateCalendar', showDate.value);
|
|
|
dateList.value = getDateList();
|
|
|
};
|
|
|
const nextYear = (number: number) => {
|
|
|
showDate.value = getCalendarDate(showDate.value.dayjs.add(number, "year"));
|
|
|
+ emits('updateCalendar', showDate.value);
|
|
|
dateList.value = getDateList();
|
|
|
};
|
|
|
|
|
|
// 修改选中日期
|
|
|
-const emit = defineEmits(["change"]);
|
|
|
-const handleChangeCurrent = (dayjs: Dayjs) => {
|
|
|
+const handleChangeCurrent = (date) => {
|
|
|
if (props.disabled) return;
|
|
|
- currentDate.value = getCalendarDate(dayjs);
|
|
|
- showDate.value = currentDate.value;
|
|
|
+ showDate.value = getCalendarDate(date.dayjs);
|
|
|
+ emits("change", showDate.value);
|
|
|
dateList.value = getDateList();
|
|
|
- emit("change", currentDate.value);
|
|
|
};
|
|
|
|
|
|
// 给不同颜色赋值
|
|
|
const getStyle = (date) => {
|
|
|
- let style = { backgroundColor: '' }
|
|
|
+ let style = { backgroundColor: '', color: '' }
|
|
|
+ const day = date.year+ '-' + (date.month + 1) + '-' + date.date;
|
|
|
for (let i = 0; i < props.dotDays.length; i++) {
|
|
|
- if (props.dotDays[i].date === date.value) {
|
|
|
+ if (props.dotDays[i].date === day) {
|
|
|
style.backgroundColor = props.dotDays[i].color;
|
|
|
+ style.color = props.dotDays[i].color === '#409eff' ? '#fff' : '#000'
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ if (showDate.value.value === date.value) {
|
|
|
+ // 当前选中日期
|
|
|
+ style.backgroundColor = '#474747';
|
|
|
+ style.color = '#fff'
|
|
|
+ }
|
|
|
return style;
|
|
|
}
|
|
|
|
|
|
// 选择今天
|
|
|
const handleSelectToday = () => {
|
|
|
- currentDate.value = getCalendarDate(dayjs());
|
|
|
+ showDate.value = getCalendarDate(dayjs());
|
|
|
+ emits('updateCalendar', showDate.value);
|
|
|
+ dateList.value = getDateList();
|
|
|
};
|
|
|
onMounted(() => {
|
|
|
if (props.current) {
|