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 () {
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
39
|
const weekStartDay = Number(this.t('i.datepicker.weekStartDay'));
|
0f677893
梁灏
update DatePicker
|
40
|
return {
|
fa3a666d
梁灏
update DatePicker
|
41
|
prefixCls: prefixCls,
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
42
|
calendar: new jsCalendar.Generator({onlyDays: !this.showWeekNumbers, weekStart: weekStartDay})
|
b0893113
jingsam
add eslint
|
43
|
};
|
0f677893
梁灏
update DatePicker
|
44
|
},
|
0f677893
梁灏
update DatePicker
|
45
46
47
|
computed: {
classes () {
return [
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
48
49
50
51
|
`${prefixCls}`,
{
[`${prefixCls}-show-week-numbers`]: this.showWeekNumbers
}
|
b0893113
jingsam
add eslint
|
52
|
];
|
50637863
梁灏
update DatePicker
|
53
|
},
|
af6a7c48
Danny Spangenberg
weekStartDay did ...
|
54
55
56
57
|
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...
|
58
|
});
|
af6a7c48
Danny Spangenberg
weekStartDay did ...
|
59
|
const weekDays = translatedDays.splice(weekStartDay, 7 - weekStartDay).concat(translatedDays.splice(0, weekStartDay));
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
60
|
return this.showWeekNumbers ? [''].concat(weekDays) : weekDays;
|
af6a7c48
Danny Spangenberg
weekStartDay did ...
|
61
|
},
|
95eae081
Sergio Crisostomo
refactor Datepicker
|
62
63
64
|
readCells () {
const tableYear = this.tableDate.getFullYear();
const tableMonth = this.tableDate.getMonth();
|
50637863
梁灏
update DatePicker
|
65
|
const today = clearHours(new Date()); // timestamp of today
|
95eae081
Sergio Crisostomo
refactor Datepicker
|
66
67
68
69
|
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
|
70
|
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
71
72
|
const isRange = this.selectionMode === 'range';
const disabledTestFn = typeof this.disabledDate === 'function' && this.disabledDate;
|
50637863
梁灏
update DatePicker
|
73
|
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
74
75
76
77
78
79
80
81
82
83
84
|
return this.calendar(tableYear, tableMonth, (cell) => {
const time = cell.date && clearHours(cell.date);
return {
...cell,
type: time === today ? 'today' : cell.type,
selected: selectedDays.includes(time),
disabled: (cell.date && disabledTestFn) && disabledTestFn(new Date(time)),
range: isRange && isInRange(time, rangeStart, rangeEnd),
start: isRange && time === minDay,
end: isRange && time === maxDay
};
|
5426dcf9
Sergio Crisostomo
fix specs, fix me...
|
85
|
}).cells;
|
0f677893
梁灏
update DatePicker
|
86
|
}
|
17e1fcf1
梁灏
init DatePicker
|
87
|
},
|
0f677893
梁灏
update DatePicker
|
88
|
methods: {
|
0f677893
梁灏
update DatePicker
|
89
90
91
92
|
getCellCls (cell) {
return [
`${prefixCls}-cell`,
{
|
3cf7cfd1
梁灏
update DatePicker
|
93
|
[`${prefixCls}-cell-selected`]: cell.selected || cell.start || cell.end,
|
50637863
梁灏
update DatePicker
|
94
95
|
[`${prefixCls}-cell-disabled`]: cell.disabled,
[`${prefixCls}-cell-today`]: cell.type === 'today',
|
e55ba7a2
Sergio Crisostomo
Add week numbers
|
96
97
98
|
[`${prefixCls}-cell-prev-month`]: cell.type === 'prevMonth',
[`${prefixCls}-cell-next-month`]: cell.type === 'nextMonth',
[`${prefixCls}-cell-week-label`]: cell.type === 'weekLabel',
|
3cf7cfd1
梁灏
update DatePicker
|
99
|
[`${prefixCls}-cell-range`]: cell.range && !cell.start && !cell.end
|
0f677893
梁灏
update DatePicker
|
100
|
}
|
b0893113
jingsam
add eslint
|
101
|
];
|
50637863
梁灏
update DatePicker
|
102
103
|
},
|
0f677893
梁灏
update DatePicker
|
104
|
}
|
b0893113
jingsam
add eslint
|
105
106
|
};
</script>
|