- useFavorites: 收藏管理 - useHistory: 播放历史 - useSettings: 用户设置 - useChannels: 频道数据获取和解析 - useGroups: 分组管理 - useChannelFilter: 频道过滤 - useDates: 日期列表 - usePrograms: 节目单管理 - useEvent: 键盘事件
48 lines
1022 B
JavaScript
48 lines
1022 B
JavaScript
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,
|
||
};
|
||
}
|