gaoluyang
昨天 b64a0deae5b5d33f9e20671a68936b27f0b9b00b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<script lang="ts" setup>
import type { DictDataType } from '@vben/hooks';
 
import { onMounted, ref } from 'vue';
 
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
 
import { CalendarPanel, useCalendar } from '../components';
 
const {
  calendarDayMap,
  currentDate,
  fetchCalendar,
  holidaySet,
  loadHolidays,
  loading,
  watchMonth,
} = useCalendar();
 
const typeOptions = ref<DictDataType[]>([]);
const selectedType = ref<number>();
 
/** 查询当前月份的排班日历,按选中分类过滤 */
function doFetch() {
  if (selectedType.value === undefined) {
    return;
  }
  fetchCalendar({ calendarType: selectedType.value, queryType: 'TYPE' });
}
 
/** 点击左侧分类后切换并刷新日历 */
function onSelectType(value: number) {
  selectedType.value = value;
  doFetch();
}
 
/** 监听月份切换,重新加载当月排班 */
watchMonth(() => {
  if (selectedType.value !== undefined) {
    doFetch();
  }
});
 
onMounted(() => {
  // 假期列表与排班主数据并行加载,避免假期接口无权限或异常时阻断分类/排班加载
  void loadHolidays();
  typeOptions.value = getDictOptions(DICT_TYPE.MES_CAL_CALENDAR_TYPE, 'number');
  if (typeOptions.value.length > 0) {
    onSelectType(typeOptions.value[0]!.value as number);
  }
});
</script>
 
<template>
  <div class="flex">
    <!-- 左侧:班组类型选择 -->
    <div
      class="border-border mr-3 w-[150px] shrink-0 overflow-hidden rounded border"
    >
      <div
        v-for="item in typeOptions"
        :key="item.value as number"
        class="text-foreground border-border hover:bg-muted/50 cursor-pointer border-b px-4 py-2.5 text-sm transition-colors last:border-b-0"
        :class="
          selectedType === item.value
            ? 'bg-primary/10 text-primary font-medium'
            : ''
        "
        @click="onSelectType(item.value as number)"
      >
        {{ item.label }}
      </div>
    </div>
 
    <!-- 右侧:日历 -->
    <div class="flex-1">
      <CalendarPanel
        v-model:current-date="currentDate"
        :calendar-day-map="calendarDayMap"
        :holiday-set="holidaySet"
        :loading="loading"
      />
    </div>
  </div>
</template>