Blame view

src/components/date-picker/picker.vue 4 KB
17e1fcf1   梁灏   init DatePicker
1
  <template>
0f677893   梁灏   update DatePicker
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
      <div
          :class="[prefixCls]"
          v-clickoutside="handleClose"
          @mouseenter="handleMouseenter"
          @mouseleave="handleMouseleave">
          <i-input
              v-el:reference
              :class="[prefixCls + '-editor']"
              :readonly="!editable || readonly"
              :disabled="disabled"
              :size="size"
              :placeholder="placeholder"
              :value.sync="visualValue"
              @on-focus="handleFocus"
              @on-blur="handleBlur"
              @on-click="handleIconClick"
              :icon="iconType"></i-input>
          <Drop v-show="visible" :placement="placement" transition="slide-up" v-ref:drop>
              <div v-el:picker></div>
          </Drop>
      </div>
17e1fcf1   梁灏   init DatePicker
23
24
  </template>
  <script>
0f677893   梁灏   update DatePicker
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
      import Vue from 'vue';
      import iInput from '../../components/input/input.vue';
      import Drop from '../../components/select/dropdown.vue';
      import clickoutside from '../../directives/clickoutside';
      import { oneOf } from '../../utils/assist';
  
      const prefixCls = 'ivu-date-picker';
  
      const DEFAULT_FORMATS = {
          date: 'yyyy-MM-dd',
          month: 'yyyy-MM',
          datetime: 'yyyy-MM-dd HH:mm:ss',
          time: 'HH:mm:ss',
          timerange: 'HH:mm:ss',
          daterange: 'yyyy-MM-dd',
          datetimerange: 'yyyy-MM-dd HH:mm:ss'
      };
  
      const PLACEMENT_MAP = {
          left: 'bottom-start',
          center: 'bottom-center',
          right: 'bottom-end'
      };
  
17e1fcf1   梁灏   init DatePicker
49
      export default {
0f677893   梁灏   update DatePicker
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
          components: { iInput, Drop },
          directives: { clickoutside },
          props: {
              format: {
                  type: String
              },
              readonly: {
                  type: Boolean,
                  default: false
              },
              disabled: {
                  type: Boolean,
                  default: false
              },
              editable: {
                  type: Boolean,
                  default: true
              },
              size: {
                  validator (value) {
                      return oneOf(value, ['small', 'large']);
                  }
              },
              placeholder: {
                  type: String,
                  default: ''
              },
              align: {
                  validator (value) {
                      return oneOf(value, ['left', 'center', 'right']);
                  },
                  default: 'left'
              },
              options: {
                  type: Object
              }
          },
17e1fcf1   梁灏   init DatePicker
87
          data () {
0f677893   梁灏   update DatePicker
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
              return {
                  prefixCls: prefixCls,
                  showClose: false,
                  visualValue: '',
                  visible: false,
                  picker: null
              }
          },
          computed: {
              iconType () {
                  return this.showClose ? 'ios-close' : 'ios-calendar-outline';
              },
              placement () {
                  return PLACEMENT_MAP[this.align];
              }
          },
          methods: {
              handleClose () {
                  this.visible = false;
              },
              handleFocus () {
                  this.visible = true;
              },
              handleBlur () {
  
              },
              handleMouseenter () {
                  if (this.readonly || this.disabled) return;
                  if (this.visualValue) {
                      this.showClose = true;
                  }
              },
              handleMouseleave () {
                  this.showClose = false;
              },
              handleIconClick () {
  
              },
              showPicker () {
                  if (!this.picker) {
                      this.picker = new Vue(this.panel).$mount(this.$els.picker);
                  }
              }
          },
          watch: {
              visible (val) {
                  if (val) {
                      this.showPicker();
                      this.$refs.drop.update();
                  } else {
                      this.$refs.drop.destroy();
                  }
              }
17e1fcf1   梁灏   init DatePicker
141
          },
0f677893   梁灏   update DatePicker
142
143
144
145
146
          beforeDestroy () {
              if (this.picker) {
                  this.picker.$destroy();
              }
          }
17e1fcf1   梁灏   init DatePicker
147
148
      }
  </script>