year-table.vue
2.37 KB
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
<template>
<div :class="classes">
<span
:class="getCellCls(cell)"
v-for="cell in cells"
@click="handleClick(cell)"
@mouseenter="handleMouseMove(cell)"
>
<em>{{ cell.date.getFullYear() }}</em>
</span>
</div>
</template>
<script>
import { clearHours } from '../util';
import { deepCopy } from '../../../utils/assist';
import mixin from './mixin';
import prefixCls from './prefixCls';
export default {
mixins: [ mixin ],
props: {/* in mixin */},
computed: {
classes() {
return [
`${prefixCls}`,
`${prefixCls}-year`
];
},
startYear() {
return Math.floor(this.tableDate.getFullYear() / 10) * 10;
},
cells () {
let cells = [];
const cell_tmpl = {
text: '',
selected: false,
disabled: false
};
const selectedDays = this.dates.filter(Boolean).map(date => clearHours(new Date(date.getFullYear(), 0, 1)));
const focusedDate = clearHours(new Date(this.focusedDate.getFullYear(), 0, 1));
for (let i = 0; i < 10; i++) {
const cell = deepCopy(cell_tmpl);
cell.date = new Date(this.startYear + i, 0, 1);
cell.disabled = typeof this.disabledDate === 'function' && this.disabledDate(cell.date) && this.selectionMode === 'year';
const day = clearHours(cell.date);
cell.selected = selectedDays.includes(day);
cell.focused = day === focusedDate;
cells.push(cell);
}
return cells;
}
},
methods: {
getCellCls (cell) {
return [
`${prefixCls}-cell`,
{
[`${prefixCls}-cell-selected`]: cell.selected,
[`${prefixCls}-cell-disabled`]: cell.disabled,
[`${prefixCls}-cell-focused`]: cell.focused,
[`${prefixCls}-cell-range`]: cell.range && !cell.start && !cell.end
}
];
},
}
};
</script>