Blame view

src/components/date-picker/base/month-table.vue 2.54 KB
95eae081   Sergio Crisostomo   refactor Datepicker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  <template>
      <div :class="classes">
          <span
              :class="getCellCls(cell)"
              v-for="cell in cells"
              @click="handleClick(cell)"
              @mouseenter="handleMouseMove(cell)"
  
          >
              <em>{{ cell.text }}</em>
          </span>
      </div>
  </template>
  <script>
e8a990f5   Sergio Crisostomo   hide ranges in mo...
15
      import { clearHours } from '../util';
95eae081   Sergio Crisostomo   refactor Datepicker
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
      import { deepCopy } from '../../../utils/assist';
      import Locale from '../../../mixins/locale';
      import mixin from './mixin';
      import prefixCls from './prefixCls';
  
      export default {
          mixins: [ Locale, mixin ],
          props: {/* in mixin */},
          computed: {
              classes() {
                  return [
                      `${prefixCls}`,
                      `${prefixCls}-month`
                  ];
              },
              cells () {
                  let cells = [];
                  const cell_tmpl = {
                      text: '',
                      selected: false,
                      disabled: false
                  };
  
                  const tableYear = this.tableDate.getFullYear();
95eae081   Sergio Crisostomo   refactor Datepicker
40
                  const selectedDays = this.dates.filter(Boolean).map(date => clearHours(new Date(date.getFullYear(), date.getMonth(), 1)));
75cb2998   Sergio Crisostomo   Add keyboard navi...
41
                  const focusedDate = clearHours(new Date(this.focusedDate.getFullYear(), this.focusedDate.getMonth(), 1));
95eae081   Sergio Crisostomo   refactor Datepicker
42
43
44
45
46
  
                  for (let i = 0; i < 12; i++) {
                      const cell = deepCopy(cell_tmpl);
                      cell.date = new Date(tableYear, i, 1);
                      cell.text = this.tCell(i + 1);
75cb2998   Sergio Crisostomo   Add keyboard navi...
47
                      const day = clearHours(cell.date);
95eae081   Sergio Crisostomo   refactor Datepicker
48
                      cell.disabled = typeof this.disabledDate === 'function' && this.disabledDate(cell.date) && this.selectionMode === 'month';
75cb2998   Sergio Crisostomo   Add keyboard navi...
49
50
                      cell.selected = selectedDays.includes(day);
                      cell.focused = day === focusedDate;
95eae081   Sergio Crisostomo   refactor Datepicker
51
52
53
54
55
56
57
58
59
60
61
62
63
                      cells.push(cell);
                  }
  
                  return cells;
              }
          },
          methods: {
              getCellCls (cell) {
                  return [
                      `${prefixCls}-cell`,
                      {
                          [`${prefixCls}-cell-selected`]: cell.selected,
                          [`${prefixCls}-cell-disabled`]: cell.disabled,
75cb2998   Sergio Crisostomo   Add keyboard navi...
64
                          [`${prefixCls}-cell-focused`]: cell.focused,
95eae081   Sergio Crisostomo   refactor Datepicker
65
66
67
68
69
70
71
72
73
74
                          [`${prefixCls}-cell-range`]: cell.range && !cell.start && !cell.end
                      }
                  ];
              },
              tCell (nr) {
                  return this.t(`i.datepicker.months.m${nr}`);
              }
          }
      };
  </script>