diff --git a/src/api/mes/cal/holiday/index.ts b/src/api/mes/cal/holiday/index.ts index 503d3964e..45c066983 100644 --- a/src/api/mes/cal/holiday/index.ts +++ b/src/api/mes/cal/holiday/index.ts @@ -11,9 +11,9 @@ export interface CalHolidayVO { // MES 假期设置 API export const CalHolidayApi = { - // 查询所有假期设置列表 - getHolidayList: async () => { - return await request.get({ url: `/mes/cal/holiday/list` }) + // 查询假期设置列表(支持可选日期范围过滤) + getHolidayList: async (params?: { startDay?: string; endDay?: string }) => { + return await request.get({ url: `/mes/cal/holiday/list`, params }) }, // 根据日期查询假期设置 diff --git a/src/views/mes/cal/holiday/index.vue b/src/views/mes/cal/holiday/index.vue index b2f69d21c..4adcf7e48 100644 --- a/src/views/mes/cal/holiday/index.vue +++ b/src/views/mes/cal/holiday/index.vue @@ -47,11 +47,16 @@ const message = useMessage() const currentDate = ref(new Date()) const holidaySet = ref(new Set()) // 节假日日期集合 const formRef = ref() +const lastFetchedMonth = ref('') // 用于避免同月重复请求 -/** 获取假期列表 */ +/** 获取假期列表(按当前日历可见范围过滤) */ const getList = async () => { holidaySet.value.clear() - const list = await CalHolidayApi.getHolidayList() + // 计算日历组件可见范围:当月 ± 1 月(el-calendar 会显示上月末和下月初) + const current = dayjs(currentDate.value) + const startDay = current.subtract(1, 'month').startOf('month').format('YYYY-MM-DD 00:00:00') + const endDay = current.add(1, 'month').endOf('month').format('YYYY-MM-DD 23:59:59') + const list = await CalHolidayApi.getHolidayList({ startDay, endDay }) if (list) { list.forEach((item: CalHolidayVO) => { // 后端返回的 day 为时间戳(long),格式化为 yyyy-MM-dd @@ -61,8 +66,17 @@ const getList = async () => { } }) } + lastFetchedMonth.value = current.format('YYYY-MM') } +/** 监听月份切换,重新加载可见范围内的数据 */ +watch(currentDate, (newDate) => { + const newMonth = dayjs(newDate).format('YYYY-MM') + if (newMonth !== lastFetchedMonth.value) { + getList() + } +}) + /** 点击日期 */ const onClickDay = (data: { type: string; day: string }) => { // 非当前月日期,不处理(避免切换月份)