From f8553abcdde4d3d7d458832edb866110d48bb5d1 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 2 Apr 2026 10:03:50 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(mes):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=81=87=E6=9C=9F=E8=AE=BE=E7=BD=AE=E5=88=97=E8=A1=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=97=A5=E6=9C=9F=E8=8C=83=E5=9B=B4=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新假期设置列表接口,支持可选的开始和结束日期参数,优化前端日历组件的数据获取逻辑,提升用户体验。 --- src/api/mes/cal/holiday/index.ts | 6 +++--- src/views/mes/cal/holiday/index.vue | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) 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 }) => { // 非当前月日期,不处理(避免切换月份)