import { ref, computed } from "vue"; // 日期标签 const DAY_LABELS = ["今天", "明天", "后天"]; export function useDates() { const selectedDate = ref(""); // 生成日期列表(今天、明天、后天...) const dates = computed(() => { const list = []; const today = new Date(); for (let i = 0; i < 7; i++) { const date = new Date(today); date.setDate(today.getDate() + i); const value = date.toISOString().split("T")[0]; const day = `${date.getMonth() + 1}/${date.getDate()}`; const label = i < 3 ? DAY_LABELS[i] : `${date.getMonth() + 1}月${date.getDate()}日`; list.push({ value, day, label }); } return list; }); // 选择日期 function selectDate(dateValue) { selectedDate.value = dateValue; } // 初始化为今天 function initToday() { selectedDate.value = new Date().toISOString().split("T")[0]; } return { selectedDate, dates, selectDate, initToday, }; }