Blame view

src/components/date-picker/picker/date-picker.js 1.29 KB
9b376832   Sergio Crisostomo   Add feature: allo...
1
  import Vue from 'vue';
17e1fcf1   梁灏   init DatePicker
2
3
4
5
6
7
8
9
10
11
12
  import Picker from '../picker.vue';
  import DatePanel from '../panel/date.vue';
  import DateRangePanel from '../panel/date-range.vue';
  
  const getPanel = function (type) {
      if (type === 'daterange' || type === 'datetimerange') {
          return DateRangePanel;
      }
      return DatePanel;
  };
  
0f677893   梁灏   update DatePicker
13
14
  import { oneOf } from '../../../utils/assist';
  
17e1fcf1   梁灏   init DatePicker
15
16
17
18
  export default {
      mixins: [Picker],
      props: {
          type: {
0f677893   梁灏   update DatePicker
19
              validator (value) {
e0cd7f90   梁灏   fixed #134
20
                  return oneOf(value, ['year', 'month', 'date', 'daterange', 'datetime', 'datetimerange']);
0f677893   梁灏   update DatePicker
21
              },
17e1fcf1   梁灏   init DatePicker
22
              default: 'date'
50637863   梁灏   update DatePicker
23
          },
c46f385a   梁灏   update DatePicker
24
          value: {}
17e1fcf1   梁灏   init DatePicker
25
      },
9ffdd6da   Sergio Crisostomo   Propagate type ch...
26
27
28
29
30
31
32
33
34
35
36
      watch: {
          type(value){
              const typeMap = {
                  year: 'year',
                  month: 'month',
                  date: 'day'
              };
              const validType = oneOf(value, Object.keys(typeMap));
              if (validType) this.Panel.selectionMode = typeMap[value];
          }
      },
50637863   梁灏   update DatePicker
37
      created () {
531cd165   梁灏   support DatePicke...
38
          if (!this.currentValue) {
50637863   梁灏   update DatePicker
39
              if (this.type === 'daterange' || this.type === 'datetimerange') {
531cd165   梁灏   support DatePicke...
40
                  this.currentValue = ['',''];
50637863   梁灏   update DatePicker
41
              } else {
531cd165   梁灏   support DatePicke...
42
                  this.currentValue = '';
50637863   梁灏   update DatePicker
43
44
45
              }
          }
  
9b376832   Sergio Crisostomo   Add feature: allo...
46
47
          const panel = getPanel(this.type);
          this.Panel = new Vue(panel);
17e1fcf1   梁灏   init DatePicker
48
      }
b0893113   jingsam   :art: add eslint
49
  };