Blame view

src/components/date-picker/base/year-table.vue 2.37 KB
17e1fcf1   梁灏   init DatePicker
1
  <template>
ca8e830c   Sergio Crisostomo   move files to sub...
2
3
4
5
6
7
8
9
10
      <div :class="classes">
          <span
              :class="getCellCls(cell)"
              v-for="cell in cells"
              @click="handleClick(cell)"
              @mouseenter="handleMouseMove(cell)"
          >
              <em>{{ cell.date.getFullYear() }}</em>
          </span>
c46f385a   梁灏   update DatePicker
11
      </div>
17e1fcf1   梁灏   init DatePicker
12
13
  </template>
  <script>
e8a990f5   Sergio Crisostomo   hide ranges in mo...
14
      import { clearHours } from '../util';
c46f385a   梁灏   update DatePicker
15
      import { deepCopy } from '../../../utils/assist';
ca8e830c   Sergio Crisostomo   move files to sub...
16
17
      import mixin from './mixin';
      import prefixCls from './prefixCls';
c46f385a   梁灏   update DatePicker
18
  
17e1fcf1   梁灏   init DatePicker
19
      export default {
ca8e830c   Sergio Crisostomo   move files to sub...
20
21
22
          mixins: [ mixin ],
  
          props: {/* in mixin */},
c46f385a   梁灏   update DatePicker
23
          computed: {
ca8e830c   Sergio Crisostomo   move files to sub...
24
              classes() {
c46f385a   梁灏   update DatePicker
25
26
27
                  return [
                      `${prefixCls}`,
                      `${prefixCls}-year`
b0893113   jingsam   :art: add eslint
28
                  ];
c46f385a   梁灏   update DatePicker
29
30
              },
              startYear() {
ca8e830c   Sergio Crisostomo   move files to sub...
31
                  return Math.floor(this.tableDate.getFullYear() / 10) * 10;
c46f385a   梁灏   update DatePicker
32
33
34
35
36
37
38
39
40
              },
              cells () {
                  let cells = [];
                  const cell_tmpl = {
                      text: '',
                      selected: false,
                      disabled: false
                  };
  
ca8e830c   Sergio Crisostomo   move files to sub...
41
                  const selectedDays = this.dates.filter(Boolean).map(date => clearHours(new Date(date.getFullYear(), 0, 1)));
75cb2998   Sergio Crisostomo   Add keyboard navi...
42
                  const focusedDate = clearHours(new Date(this.focusedDate.getFullYear(), 0, 1));
c46f385a   梁灏   update DatePicker
43
  
ca8e830c   Sergio Crisostomo   move files to sub...
44
45
46
47
                  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';
75cb2998   Sergio Crisostomo   Add keyboard navi...
48
49
50
                      const day = clearHours(cell.date);
                      cell.selected = selectedDays.includes(day);
                      cell.focused = day === focusedDate;
c46f385a   梁灏   update DatePicker
51
52
53
54
55
56
57
58
59
60
61
62
                      cells.push(cell);
                  }
  
                  return cells;
              }
          },
          methods: {
              getCellCls (cell) {
                  return [
                      `${prefixCls}-cell`,
                      {
                          [`${prefixCls}-cell-selected`]: cell.selected,
ca8e830c   Sergio Crisostomo   move files to sub...
63
                          [`${prefixCls}-cell-disabled`]: cell.disabled,
75cb2998   Sergio Crisostomo   Add keyboard navi...
64
                          [`${prefixCls}-cell-focused`]: cell.focused,
ca8e830c   Sergio Crisostomo   move files to sub...
65
                          [`${prefixCls}-cell-range`]: cell.range && !cell.start && !cell.end
c46f385a   梁灏   update DatePicker
66
                      }
b0893113   jingsam   :art: add eslint
67
                  ];
c46f385a   梁灏   update DatePicker
68
              },
c46f385a   梁灏   update DatePicker
69
          }
b0893113   jingsam   :art: add eslint
70
71
      };
  </script>