-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathmonth-calendar-panel.tsx
98 lines (92 loc) · 3.33 KB
/
month-calendar-panel.tsx
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
87
88
89
90
91
92
93
94
95
96
97
98
import { defineComponent, getCurrentInstance } from 'vue';
import type { SetupContext } from 'vue';
import { useNamespace } from '@devui/shared/utils';
import useMonthCalendarPanel from '../composables/use-month-calendar-panel';
import { datePickerProPanelProps, DatePickerProPanelProps, YearAndMonthItem } from '../date-picker-pro-types';
import { createI18nTranslate } from '../../../locale/create';
import { monthPickerHeight, yearItemHeight, monthCalendarItemHeight } from '../const';
import { VirtualList } from '../../../virtual-list';
export default defineComponent({
name: 'MonthCalendarPanel',
props: datePickerProPanelProps,
emits: ['selectedDate', 'changeRangeFocusType'],
setup(props: DatePickerProPanelProps, ctx: SetupContext) {
const app = getCurrentInstance();
const t = createI18nTranslate('DDatePickerPro', app);
const ns = useNamespace('date-picker-pro');
const {
yearScrollRef,
monthScrollRef,
yearList,
monthList,
handlerSelectYear,
handlerMonthScroll,
getMonthItemCls,
handlerSelectMonth,
} = useMonthCalendarPanel(props, ctx);
return () => {
const yearItemSlots = {
item: (year: YearAndMonthItem) => {
return (
<div
class={[ns.e('year-list-item'), year.active && ns.e('year-item-active')]}
key={year.year}
onClick={() => handlerSelectYear(year.year)}>
{year.year}
</div>
);
},
};
const monthItemSlots = {
item: (year: YearAndMonthItem) => {
return (
<div class={ns.e('table-month')}>
<div class={ns.e('table-month-title')}>{year.year + t('year')}</div>
<table class={ns.e('table-month-content')}>
<tbody>
{monthList.map((season: number[], seasonIndex: number) => (
<tr key={seasonIndex}>
{season.map((month: number) => (
<td
key={month}
class={getMonthItemCls(year.year, month)}
onClick={(e: MouseEvent) => {
e.preventDefault();
e.stopPropagation();
handlerSelectMonth(year.year, month);
}}>
<span>{t(`month${month}`) || 'm'}</span>
</td>
))}
</tr>
))}
</tbody>
</table>
</div>
);
},
};
return (
<div class={ns.e('month-calendar-panel')}>
<VirtualList
ref={yearScrollRef}
class={ns.e('year-list')}
data={yearList.value}
height={monthPickerHeight}
itemHeight={yearItemHeight}
v-slots={yearItemSlots}></VirtualList>
<div class={ns.e('month-wrapper')}>
<VirtualList
ref={monthScrollRef}
class={ns.e('month-list')}
data={yearList.value}
height={monthPickerHeight}
itemHeight={monthCalendarItemHeight}
v-slots={monthItemSlots}
onScroll={handlerMonthScroll}></VirtualList>
</div>
</div>
);
};
},
});