17e1fcf1
梁灏
init DatePicker
|
1
|
<template>
|
95eae081
Sergio Crisostomo
refactor Datepicker
|
2
|
<div :class="classes">
|
50637863
梁灏
update DatePicker
|
3
|
<div :class="[prefixCls + '-header']">
|
af6a7c48
Danny Spangenberg
weekStartDay did ...
|
4
5
6
|
<span v-for="day in headerDays" :key="day">
{{day}}
</span>
|
50637863
梁灏
update DatePicker
|
7
|
</div>
|
95eae081
Sergio Crisostomo
refactor Datepicker
|
8
9
|
<span
:class="getCellCls(cell)"
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
10
11
|
v-for="(cell, i) in readCells"
:key="String(cell.date) + i"
|
95eae081
Sergio Crisostomo
refactor Datepicker
|
12
13
14
|
@click="handleClick(cell)"
@mouseenter="handleMouseMove(cell)"
>
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
15
|
<em>{{ cell.desc }}</em>
|
95eae081
Sergio Crisostomo
refactor Datepicker
|
16
|
</span>
|
50637863
梁灏
update DatePicker
|
17
|
</div>
|
17e1fcf1
梁灏
init DatePicker
|
18
19
|
</template>
<script>
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
20
|
import { clearHours, isInRange } from '../util';
|
4ab11811
梁灏
some component su...
|
21
|
import Locale from '../../../mixins/locale';
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
22
|
import jsCalendar from 'js-calendar';
|
50637863
梁灏
update DatePicker
|
23
|
|
95eae081
Sergio Crisostomo
refactor Datepicker
|
24
25
|
import mixin from './mixin';
import prefixCls from './prefixCls';
|
50637863
梁灏
update DatePicker
|
26
|
|
0f677893
梁灏
update DatePicker
|
27
|
|
17e1fcf1
梁灏
init DatePicker
|
28
|
export default {
|
95eae081
Sergio Crisostomo
refactor Datepicker
|
29
30
|
mixins: [ Locale, mixin ],
|
0f677893
梁灏
update DatePicker
|
31
|
props: {
|
95eae081
Sergio Crisostomo
refactor Datepicker
|
32
|
/* more props in mixin */
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
33
34
35
36
|
showWeekNumbers: {
type: Boolean,
default: false
},
|
0f677893
梁灏
update DatePicker
|
37
|
},
|
17e1fcf1
梁灏
init DatePicker
|
38
|
data () {
|
0f677893
梁灏
update DatePicker
|
39
|
return {
|
fa3a666d
梁灏
update DatePicker
|
40
|
prefixCls: prefixCls,
|
b0893113
jingsam
add eslint
|
41
|
};
|
0f677893
梁灏
update DatePicker
|
42
|
},
|
0f677893
梁灏
update DatePicker
|
43
44
45
|
computed: {
classes () {
return [
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
46
47
48
49
|
`${prefixCls}`,
{
[`${prefixCls}-show-week-numbers`]: this.showWeekNumbers
}
|
b0893113
jingsam
add eslint
|
50
|
];
|
50637863
梁灏
update DatePicker
|
51
|
},
|
5ca5a6eb
Sergio Crisostomo
compute calendar ...
|
52
53
54
55
|
calendar(){
const weekStartDay = Number(this.t('i.datepicker.weekStartDay'));
return new jsCalendar.Generator({onlyDays: !this.showWeekNumbers, weekStart: weekStartDay});
},
|
af6a7c48
Danny Spangenberg
weekStartDay did ...
|
56
57
58
59
|
headerDays () {
const weekStartDay = Number(this.t('i.datepicker.weekStartDay'));
const translatedDays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'].map(item => {
return this.t('i.datepicker.weeks.' + item);
|
6850c1da
梁灏
Scroll add `heigh...
|
60
|
});
|
af6a7c48
Danny Spangenberg
weekStartDay did ...
|
61
|
const weekDays = translatedDays.splice(weekStartDay, 7 - weekStartDay).concat(translatedDays.splice(0, weekStartDay));
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
62
|
return this.showWeekNumbers ? [''].concat(weekDays) : weekDays;
|
af6a7c48
Danny Spangenberg
weekStartDay did ...
|
63
|
},
|
95eae081
Sergio Crisostomo
refactor Datepicker
|
64
65
66
|
readCells () {
const tableYear = this.tableDate.getFullYear();
const tableMonth = this.tableDate.getMonth();
|
50637863
梁灏
update DatePicker
|
67
|
const today = clearHours(new Date()); // timestamp of today
|
95eae081
Sergio Crisostomo
refactor Datepicker
|
68
69
70
71
|
const selectedDays = this.dates.filter(Boolean).map(clearHours); // timestamp of selected days
const [minDay, maxDay] = this.dates.map(clearHours);
const rangeStart = this.rangeState.from && clearHours(this.rangeState.from);
const rangeEnd = this.rangeState.to && clearHours(this.rangeState.to);
|
50637863
梁灏
update DatePicker
|
72
|
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
73
74
|
const isRange = this.selectionMode === 'range';
const disabledTestFn = typeof this.disabledDate === 'function' && this.disabledDate;
|
50637863
梁灏
update DatePicker
|
75
|
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
76
77
|
return this.calendar(tableYear, tableMonth, (cell) => {
const time = cell.date && clearHours(cell.date);
|
a781ad1a
Sergio Crisostomo
hide range and se...
|
78
|
const dateIsInCurrentMonth = cell.date && tableMonth === cell.date.getMonth();
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
79
80
81
|
return {
...cell,
type: time === today ? 'today' : cell.type,
|
a781ad1a
Sergio Crisostomo
hide range and se...
|
82
|
selected: dateIsInCurrentMonth && selectedDays.includes(time),
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
83
|
disabled: (cell.date && disabledTestFn) && disabledTestFn(new Date(time)),
|
a781ad1a
Sergio Crisostomo
hide range and se...
|
84
85
86
|
range: dateIsInCurrentMonth && isRange && isInRange(time, rangeStart, rangeEnd),
start: dateIsInCurrentMonth && isRange && time === minDay,
end: dateIsInCurrentMonth && isRange && time === maxDay
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
87
|
};
|
a1c88eba
Sergio Crisostomo
Correct showWeekN...
|
88
|
}).cells.slice(this.showWeekNumbers ? 8 : 0);
|
0f677893
梁灏
update DatePicker
|
89
|
}
|
17e1fcf1
梁灏
init DatePicker
|
90
|
},
|
0f677893
梁灏
update DatePicker
|
91
|
methods: {
|
0f677893
梁灏
update DatePicker
|
92
93
94
95
|
getCellCls (cell) {
return [
`${prefixCls}-cell`,
{
|
3cf7cfd1
梁灏
update DatePicker
|
96
|
[`${prefixCls}-cell-selected`]: cell.selected || cell.start || cell.end,
|
50637863
梁灏
update DatePicker
|
97
98
|
[`${prefixCls}-cell-disabled`]: cell.disabled,
[`${prefixCls}-cell-today`]: cell.type === 'today',
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
99
100
101
|
[`${prefixCls}-cell-prev-month`]: cell.type === 'prevMonth',
[`${prefixCls}-cell-next-month`]: cell.type === 'nextMonth',
[`${prefixCls}-cell-week-label`]: cell.type === 'weekLabel',
|
3cf7cfd1
梁灏
update DatePicker
|
102
|
[`${prefixCls}-cell-range`]: cell.range && !cell.start && !cell.end
|
0f677893
梁灏
update DatePicker
|
103
|
}
|
b0893113
jingsam
add eslint
|
104
|
];
|
50637863
梁灏
update DatePicker
|
105
106
|
},
|
0f677893
梁灏
update DatePicker
|
107
|
}
|
b0893113
jingsam
add eslint
|
108
109
|
};
</script>
|