Blame view

src/components/date-picker/picker.vue 16.3 KB
17e1fcf1   梁灏   init DatePicker
1
  <template>
ecaf8d51   梁灏   Date add transfer...
2
      <div :class="[prefixCls]" v-clickoutside="handleClose">
531cd165   梁灏   support DatePicke...
3
          <div ref="reference" :class="[prefixCls + '-rel']">
e9dd4dab   梁灏   publish 0.9.11-rc-1
4
5
              <slot>
                  <i-input
4863a75d   Sergio Crisostomo   Correct logic whe...
6
                      :key="forceInputRerender"
acb79ba3   梁灏   fixed #433
7
                      :element-id="elementId"
e9dd4dab   梁灏   publish 0.9.11-rc-1
8
9
10
11
12
13
                      :class="[prefixCls + '-editor']"
                      :readonly="!editable || readonly"
                      :disabled="disabled"
                      :size="size"
                      :placeholder="placeholder"
                      :value="visualValue"
0460a1e8   梁灏   fixed #812
14
                      :name="name"
531cd165   梁灏   support DatePicke...
15
                      @on-input-change="handleInputChange"
e9dd4dab   梁灏   publish 0.9.11-rc-1
16
                      @on-focus="handleFocus"
030a522d   Sergio Crisostomo   make picker close...
17
                      @on-blur="handleBlur"
e9dd4dab   梁灏   publish 0.9.11-rc-1
18
                      @on-click="handleIconClick"
531cd165   梁灏   support DatePicke...
19
20
                      @mouseenter.native="handleInputMouseenter"
                      @mouseleave.native="handleInputMouseleave"
e55ba7a2   Sergio Crisostomo   Add week numbers
21
22
23
  
                      :icon="iconType"
                  ></i-input>
e9dd4dab   梁灏   publish 0.9.11-rc-1
24
25
              </slot>
          </div>
531cd165   梁灏   support DatePicke...
26
          <transition :name="transition">
ecaf8d51   梁灏   Date add transfer...
27
28
29
30
31
32
33
34
              <Drop
                  @click.native="handleTransferClick"
                  v-show="opened"
                  :class="{ [prefixCls + '-transfer']: transfer }"
                  :placement="placement"
                  ref="drop"
                  :data-transfer="transfer"
                  v-transfer-dom>
95eae081   Sergio Crisostomo   refactor Datepicker
35
36
37
                  <div>
                      <component
                          :is="panel"
46726afd   Sergio Crisostomo   Fix panels reset ...
38
                          ref="pickerPanel"
95eae081   Sergio Crisostomo   refactor Datepicker
39
40
41
42
43
44
45
                          :visible="visible"
                          :showTime="type === 'datetime' || type === 'datetimerange'"
                          :confirm="isConfirm"
                          :selectionMode="selectionMode"
                          :steps="steps"
                          :format="format"
                          :value="internalValue"
63bd0f7d   Sergio Crisostomo   Add start-date pr...
46
                          :start-date="startDate"
435bf781   Sergio Crisostomo   add split panel p...
47
                          :split-panels="splitPanels"
e55ba7a2   Sergio Crisostomo   Add week numbers
48
                          :show-week-numbers="showWeekNumbers"
b52e02e4   Sergio Crisostomo   Fix month|year pr...
49
                          :picker-type="type"
95eae081   Sergio Crisostomo   refactor Datepicker
50
  
79ac2457   Sergio Crisostomo   Allow DatePicker ...
51
52
                          :time-picker-options="timePickerOptions"
  
95eae081   Sergio Crisostomo   refactor Datepicker
53
54
55
56
57
58
59
60
61
                          v-bind="ownPickerProps"
  
                          @on-pick="onPick"
                          @on-pick-clear="handleClear"
                          @on-pick-success="onPickSuccess"
                          @on-pick-click="disableClickOutSide = true"
                          @on-selection-mode-change="onSelectionModeChange"
                      ></component>
                  </div>
531cd165   梁灏   support DatePicke...
62
63
              </Drop>
          </transition>
0f677893   梁灏   update DatePicker
64
      </div>
17e1fcf1   梁灏   init DatePicker
65
66
  </template>
  <script>
95eae081   Sergio Crisostomo   refactor Datepicker
67
68
  
  
0f677893   梁灏   update DatePicker
69
70
71
      import iInput from '../../components/input/input.vue';
      import Drop from '../../components/select/dropdown.vue';
      import clickoutside from '../../directives/clickoutside';
ecaf8d51   梁灏   Date add transfer...
72
      import TransferDom from '../../directives/transfer-dom';
0f677893   梁灏   update DatePicker
73
      import { oneOf } from '../../utils/assist';
2fb29fae   Sergio Crisostomo   export utilities ...
74
      import { DEFAULT_FORMATS, TYPE_VALUE_RESOLVER_MAP } from './util';
cd78c9c4   梁灏   some comps suppor...
75
      import Emitter from '../../mixins/emitter';
0f677893   梁灏   update DatePicker
76
77
78
  
      const prefixCls = 'ivu-date-picker';
  
34867ff9   Sergio Crisostomo   normalise empty i...
79
80
      const isEmptyArray = val => val.reduce((isEmpty, str) => isEmpty && !str || (typeof str === 'string' && str.trim() === ''), true);
  
17e1fcf1   梁灏   init DatePicker
81
      export default {
21dad188   梁灏   prevent dispatch ...
82
          name: 'CalendarPicker',
cd78c9c4   梁灏   some comps suppor...
83
          mixins: [ Emitter ],
0f677893   梁灏   update DatePicker
84
          components: { iInput, Drop },
ecaf8d51   梁灏   Date add transfer...
85
          directives: { clickoutside, TransferDom },
0f677893   梁灏   update DatePicker
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
          props: {
              format: {
                  type: String
              },
              readonly: {
                  type: Boolean,
                  default: false
              },
              disabled: {
                  type: Boolean,
                  default: false
              },
              editable: {
                  type: Boolean,
                  default: true
              },
fe44201b   梁灏   DatePicker add cl...
102
103
104
105
              clearable: {
                  type: Boolean,
                  default: true
              },
b9041a0d   梁灏   DatePicker add co...
106
107
108
109
              confirm: {
                  type: Boolean,
                  default: false
              },
e9dd4dab   梁灏   publish 0.9.11-rc-1
110
111
112
113
              open: {
                  type: Boolean,
                  default: null
              },
95eae081   Sergio Crisostomo   refactor Datepicker
114
115
116
117
              multiple: {
                  type: Boolean,
                  default: false
              },
79ac2457   Sergio Crisostomo   Allow DatePicker ...
118
119
120
121
              timePickerOptions: {
                  default: () => ({}),
                  type: Object,
              },
435bf781   Sergio Crisostomo   add split panel p...
122
123
124
125
              splitPanels: {
                  type: Boolean,
                  default: false
              },
e55ba7a2   Sergio Crisostomo   Add week numbers
126
127
128
129
              showWeekNumbers: {
                  type: Boolean,
                  default: false
              },
63bd0f7d   Sergio Crisostomo   Add start-date pr...
130
131
132
              startDate: {
                  type: Date
              },
0f677893   梁灏   update DatePicker
133
134
              size: {
                  validator (value) {
f00a037c   梁灏   some Components's...
135
                      return oneOf(value, ['small', 'large', 'default']);
0f677893   梁灏   update DatePicker
136
137
138
139
140
141
                  }
              },
              placeholder: {
                  type: String,
                  default: ''
              },
68e9b100   梁灏   update DatePicker
142
              placement: {
0f677893   梁灏   update DatePicker
143
                  validator (value) {
68e9b100   梁灏   update DatePicker
144
                      return oneOf(value, ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end']);
0f677893   梁灏   update DatePicker
145
                  },
68e9b100   梁灏   update DatePicker
146
                  default: 'bottom-start'
0f677893   梁灏   update DatePicker
147
              },
ecaf8d51   梁灏   Date add transfer...
148
149
150
              transfer: {
                  type: Boolean,
                  default: false
0460a1e8   梁灏   fixed #812
151
152
153
              },
              name: {
                  type: String
acb79ba3   梁灏   fixed #433
154
155
156
              },
              elementId: {
                  type: String
95eae081   Sergio Crisostomo   refactor Datepicker
157
158
159
160
161
162
              },
              steps: {
                  type: Array,
                  default: () => []
              },
              value: {
8878e4a3   Sergio Crisostomo   Remove validator ...
163
                  type: [Date, String, Array]
4863a75d   Sergio Crisostomo   Correct logic whe...
164
165
166
167
              },
              options: {
                  type: Object,
                  default: () => ({})
0f677893   梁灏   update DatePicker
168
169
              }
          },
95eae081   Sergio Crisostomo   refactor Datepicker
170
          data(){
34867ff9   Sergio Crisostomo   normalise empty i...
171
172
              const isRange = this.type.includes('range');
              const emptyArray = isRange ? [null, null] : [null];
4a1734b7   Sergio Crisostomo   fix time and time...
173
174
              const initialValue = isEmptyArray((isRange ? this.value : [this.value]) || []) ? emptyArray : this.parseDate(this.value);
  
0f677893   梁灏   update DatePicker
175
176
177
              return {
                  prefixCls: prefixCls,
                  showClose: false,
0f677893   梁灏   update DatePicker
178
                  visible: false,
34867ff9   Sergio Crisostomo   normalise empty i...
179
                  internalValue: initialValue,
531cd165   梁灏   support DatePicke...
180
                  disableClickOutSide: false,    // fixed when click a date,trigger clickoutside to close picker
95eae081   Sergio Crisostomo   refactor Datepicker
181
                  disableCloseUnderTransfer: false,  // transfer 模式下,点击Drop也会触发关闭,
4863a75d   Sergio Crisostomo   Correct logic whe...
182
183
                  selectionMode: this.onSelectionModeChange(this.type),
                  forceInputRerender: 1
b0893113   jingsam   :art: add eslint
184
              };
0f677893   梁灏   update DatePicker
185
186
          },
          computed: {
b42322fe   Sergio Crisostomo   Pass Strings to @...
187
              publicVModelValue(){
d07b4f33   Sergio Crisostomo   fix logic for mul...
188
                  if (this.multiple){
8f6aeda4   Sergio Crisostomo   Fix parser and fo...
189
                      return this.internalValue.slice();
d07b4f33   Sergio Crisostomo   fix logic for mul...
190
191
                  } else {
                      const isRange = this.type.includes('range');
57f0582b   Sergio Crisostomo   Pass correct argu...
192
193
194
                      let val = this.internalValue.map(date => date instanceof Date ? new Date(date) : (date || ''));
  
                      if (this.type.match(/^time/)) val = val.map(this.formatDate);
8f6aeda4   Sergio Crisostomo   Fix parser and fo...
195
                      return (isRange || this.multiple) ? val : val[0];
d07b4f33   Sergio Crisostomo   fix logic for mul...
196
                  }
95eae081   Sergio Crisostomo   refactor Datepicker
197
              },
b42322fe   Sergio Crisostomo   Pass Strings to @...
198
199
200
              publicStringValue(){
                  const {formatDate, publicVModelValue, type} = this;
                  if (type.match(/^time/)) return publicVModelValue;
2332ac9b   Sergio Crisostomo   Fix error in form...
201
                  if (this.multiple) return formatDate(publicVModelValue);
b42322fe   Sergio Crisostomo   Pass Strings to @...
202
203
                  return Array.isArray(publicVModelValue) ? publicVModelValue.map(formatDate) : formatDate(publicVModelValue);
              },
e9dd4dab   梁灏   publish 0.9.11-rc-1
204
205
206
              opened () {
                  return this.open === null ? this.visible : this.open;
              },
0f677893   梁灏   update DatePicker
207
              iconType () {
9d844d53   梁灏   fixed Layout bug
208
                  let icon = 'ios-calendar-outline';
456877a1   梁灏   update TimePicker
209
                  if (this.type === 'time' || this.type === 'timerange') icon = 'ios-clock-outline';
9d844d53   梁灏   fixed Layout bug
210
211
                  if (this.showClose) icon = 'ios-close';
                  return icon;
0f677893   梁灏   update DatePicker
212
              },
d20fe0ee   梁灏   update DatePicker
213
              transition () {
95eae081   Sergio Crisostomo   refactor Datepicker
214
215
                  const bottomPlaced = this.placement.match(/^bottom/);
                  return bottomPlaced ? 'slide-up' : 'slide-down';
d20fe0ee   梁灏   update DatePicker
216
              },
95eae081   Sergio Crisostomo   refactor Datepicker
217
              visualValue() {
2fb29fae   Sergio Crisostomo   export utilities ...
218
                  return this.formatDate(this.internalValue);
95eae081   Sergio Crisostomo   refactor Datepicker
219
220
              },
              isConfirm(){
d07b4f33   Sergio Crisostomo   fix logic for mul...
221
                  return this.confirm || this.type === 'datetime' || this.type === 'datetimerange' || this.multiple;
0f677893   梁灏   update DatePicker
222
223
224
              }
          },
          methods: {
95eae081   Sergio Crisostomo   refactor Datepicker
225
              onSelectionModeChange(type){
95eae081   Sergio Crisostomo   refactor Datepicker
226
                  if (type.match(/^date/)) type = 'date';
46726afd   Sergio Crisostomo   Fix panels reset ...
227
228
                  this.selectionMode = oneOf(type, ['year', 'month', 'date', 'time']) && type;
                  return this.selectionMode;
95eae081   Sergio Crisostomo   refactor Datepicker
229
              },
ecaf8d51   梁灏   Date add transfer...
230
231
232
233
              // 开启 transfer 时,点击 Drop 即会关闭,这里不让其关闭
              handleTransferClick () {
                  if (this.transfer) this.disableCloseUnderTransfer = true;
              },
0f677893   梁灏   update DatePicker
234
              handleClose () {
ecaf8d51   梁灏   Date add transfer...
235
236
237
238
                  if (this.disableCloseUnderTransfer) {
                      this.disableCloseUnderTransfer = false;
                      return false;
                  }
1b7aefea   梁灏   update Picker
239
                  if (this.open !== null) return;
95eae081   Sergio Crisostomo   refactor Datepicker
240
  
762c8ddf   梁灏   update DatePicker
241
                  this.visible = false;
68e9b100   梁灏   update DatePicker
242
                  this.disableClickOutSide = false;
0f677893   梁灏   update DatePicker
243
244
              },
              handleFocus () {
e1874103   梁灏   update DatePicker
245
                  if (this.readonly) return;
0f677893   梁灏   update DatePicker
246
                  this.visible = true;
6017ed75   Sergio Crisostomo   update scroll whe...
247
                  this.$refs.pickerPanel.onToggleVisibility(true);
0f677893   梁灏   update DatePicker
248
              },
030a522d   Sergio Crisostomo   make picker close...
249
250
              handleBlur () {
                  this.visible = false;
46726afd   Sergio Crisostomo   Fix panels reset ...
251
                  this.onSelectionModeChange(this.type);
c2b7fed0   Sergio Crisostomo   Reset panel selec...
252
                  this.internalValue = this.internalValue.slice(); // trigger panel watchers to reset views
46726afd   Sergio Crisostomo   Fix panels reset ...
253
                  this.reset();
6017ed75   Sergio Crisostomo   update scroll whe...
254
255
                  this.$refs.pickerPanel.onToggleVisibility(false);
  
46726afd   Sergio Crisostomo   Fix panels reset ...
256
257
258
              },
              reset(){
                  this.$refs.pickerPanel.reset && this.$refs.pickerPanel.reset();
030a522d   Sergio Crisostomo   make picker close...
259
              },
e1874103   梁灏   update DatePicker
260
              handleInputChange (event) {
4863a75d   Sergio Crisostomo   Correct logic whe...
261
                  const isArrayValue = this.type.includes('range') || this.multiple;
e1874103   梁灏   update DatePicker
262
                  const oldValue = this.visualValue;
95eae081   Sergio Crisostomo   refactor Datepicker
263
                  const newValue = event.target.value;
4863a75d   Sergio Crisostomo   Correct logic whe...
264
265
266
267
268
269
                  const newDate = this.parseDate(newValue);
                  const disabledDateFn =
                      this.options &&
                      typeof this.options.disabledDate === 'function' &&
                      this.options.disabledDate;
                  const valueToTest = isArrayValue ? newDate : newDate[0];
d9ff845f   Sergio Crisostomo   Emit input event ...
270
                  const isDisabled = disabledDateFn && disabledDateFn(valueToTest);
72f225e9   Sergio Crisostomo   Fix date manual i...
271
                  const isValidDate = newDate.reduce((valid, date) => valid && date instanceof Date, true);
e1874103   梁灏   update DatePicker
272
  
72f225e9   Sergio Crisostomo   Fix date manual i...
273
                  if (newValue !== oldValue && !isDisabled && isValidDate) {
95eae081   Sergio Crisostomo   refactor Datepicker
274
                      this.emitChange();
4863a75d   Sergio Crisostomo   Correct logic whe...
275
276
277
                      this.internalValue = newDate;
                  } else {
                      this.forceInputRerender++;
7c5ccdab   梁灏   update DatePicker
278
                  }
c46f385a   梁灏   update DatePicker
279
280
              },
              handleInputMouseenter () {
0f677893   梁灏   update DatePicker
281
                  if (this.readonly || this.disabled) return;
fe44201b   梁灏   DatePicker add cl...
282
                  if (this.visualValue && this.clearable) {
0f677893   梁灏   update DatePicker
283
284
285
                      this.showClose = true;
                  }
              },
c46f385a   梁灏   update DatePicker
286
              handleInputMouseleave () {
0f677893   梁灏   update DatePicker
287
288
289
                  this.showClose = false;
              },
              handleIconClick () {
7b7178f1   梁灏   fixed #528
290
291
                  if (this.showClose) {
                      this.handleClear();
f1f0206c   Aresn   fixed Date bug
292
                  } else if (!this.disabled) {
7b7178f1   梁灏   fixed #528
293
294
                      this.handleFocus();
                  }
b9041a0d   梁灏   DatePicker add co...
295
296
              },
              handleClear () {
c46f385a   梁灏   update DatePicker
297
                  this.visible = false;
95eae081   Sergio Crisostomo   refactor Datepicker
298
                  this.internalValue = this.internalValue.map(() => null);
d20fe0ee   梁灏   update DatePicker
299
                  this.$emit('on-clear');
cd78c9c4   梁灏   some comps suppor...
300
                  this.dispatch('FormItem', 'on-form-change', '');
95eae081   Sergio Crisostomo   refactor Datepicker
301
                  this.emitChange();
46726afd   Sergio Crisostomo   Fix panels reset ...
302
                  this.reset();
9d844d53   梁灏   fixed Layout bug
303
  
95eae081   Sergio Crisostomo   refactor Datepicker
304
305
306
307
                  setTimeout(
                      () => this.onSelectionModeChange(this.type),
                      500 // delay to improve dropdown close visual effect
                  );
344131a7   梁灏   update DatePicker
308
              },
95eae081   Sergio Crisostomo   refactor Datepicker
309
              emitChange () {
fc0c4c78   梁灏   fixed #494
310
                  this.$nextTick(() => {
b42322fe   Sergio Crisostomo   Pass Strings to @...
311
312
                      this.$emit('on-change', this.publicStringValue);
                      this.dispatch('FormItem', 'on-form-change', this.publicStringValue);
fc0c4c78   梁灏   fixed #494
313
                  });
21dad188   梁灏   prevent dispatch ...
314
              },
8f6aeda4   Sergio Crisostomo   Fix parser and fo...
315
              parseDate(val) {
95eae081   Sergio Crisostomo   refactor Datepicker
316
                  const isRange = this.type.includes('range');
456877a1   梁灏   update TimePicker
317
                  const type = this.type;
95eae081   Sergio Crisostomo   refactor Datepicker
318
                  const parser = (
456877a1   梁灏   update TimePicker
319
                      TYPE_VALUE_RESOLVER_MAP[type] ||
699a9dc8   梁灏   update DatePicker
320
                      TYPE_VALUE_RESOLVER_MAP['default']
95eae081   Sergio Crisostomo   refactor Datepicker
321
                  ).parser;
2fb29fae   Sergio Crisostomo   export utilities ...
322
323
                  const format = this.format || DEFAULT_FORMATS[type];
                  const multipleParser = TYPE_VALUE_RESOLVER_MAP['multiple'].parser;
699a9dc8   梁灏   update DatePicker
324
  
95eae081   Sergio Crisostomo   refactor Datepicker
325
                  if (val && type === 'time' && !(val instanceof Date)) {
2fb29fae   Sergio Crisostomo   export utilities ...
326
327
328
                      val = parser(val, format);
                  } else if (this.multiple && val) {
                      val = multipleParser(val, format);
4863a75d   Sergio Crisostomo   Correct logic whe...
329
                  } else if (isRange) {
95eae081   Sergio Crisostomo   refactor Datepicker
330
331
332
                      if (!val){
                          val = [null, null];
                      } else {
283b90aa   Sergio Crisostomo   Fix daterange man...
333
334
                          if (typeof val === 'string') {
                              val = parser(val, format);
4a1734b7   Sergio Crisostomo   fix time and time...
335
336
                          } else if (type === 'timerange') {
                              val = parser(val, format);
283b90aa   Sergio Crisostomo   Fix daterange man...
337
338
339
340
                          } else {
                              val = val.map(date => new Date(date)); // try to parse
                              val = val.map(date => isNaN(date.getTime()) ? null : date); // check if parse passed
                          }
95eae081   Sergio Crisostomo   refactor Datepicker
341
                      }
8f6aeda4   Sergio Crisostomo   Fix parser and fo...
342
                  } else if (typeof val === 'string' && type.indexOf('time') !== 0){
72f225e9   Sergio Crisostomo   Fix date manual i...
343
                      val = parser(val, format) || null;
95eae081   Sergio Crisostomo   refactor Datepicker
344
                  }
2fb29fae   Sergio Crisostomo   export utilities ...
345
346
  
                  return (isRange || this.multiple) ? (val || []) : [val];
95eae081   Sergio Crisostomo   refactor Datepicker
347
              },
8f6aeda4   Sergio Crisostomo   Fix parser and fo...
348
              formatDate(value){
8f6aeda4   Sergio Crisostomo   Fix parser and fo...
349
                  const format = DEFAULT_FORMATS[this.type];
2fb29fae   Sergio Crisostomo   export utilities ...
350
351
352
353
354
355
356
357
358
359
360
  
                  if (this.multiple) {
                      const formatter = TYPE_VALUE_RESOLVER_MAP.multiple.formatter;
                      return formatter(value, this.format || format);
                  } else {
                      const {formatter} = (
                          TYPE_VALUE_RESOLVER_MAP[this.type] ||
                          TYPE_VALUE_RESOLVER_MAP['default']
                      );
                      return formatter(value, this.format || format);
                  }
8f6aeda4   Sergio Crisostomo   Fix parser and fo...
361
              },
95eae081   Sergio Crisostomo   refactor Datepicker
362
              onPick(dates, visible = false) {
d07b4f33   Sergio Crisostomo   fix logic for mul...
363
                  if (this.multiple){
88d24200   Sergio Crisostomo   Fix date toggle i...
364
365
                      const pickedTimeStamp = dates.getTime();
                      const indexOfPickedDate = this.internalValue.findIndex(date => date && date.getTime() === pickedTimeStamp);
d07b4f33   Sergio Crisostomo   fix logic for mul...
366
                      const allDates = [...this.internalValue, dates].filter(Boolean);
88d24200   Sergio Crisostomo   Fix date toggle i...
367
                      const timeStamps = allDates.map(date => date.getTime()).filter((ts, i, arr) => arr.indexOf(ts) === i && i !== indexOfPickedDate); // filter away duplicates
d07b4f33   Sergio Crisostomo   fix logic for mul...
368
                      this.internalValue = timeStamps.map(ts => new Date(ts));
95eae081   Sergio Crisostomo   refactor Datepicker
369
370
                  } else {
                      this.internalValue = Array.isArray(dates) ? dates : [dates];
0fd13696   梁灏   fixed DatePicker ...
371
                  }
95eae081   Sergio Crisostomo   refactor Datepicker
372
373
374
375
376
377
378
379
  
                  if (!this.isConfirm) this.onSelectionModeChange(this.type); // reset the selectionMode
                  if (!this.isConfirm) this.visible = visible;
                  this.emitChange();
              },
              onPickSuccess(){
                  this.visible = false;
                  this.$emit('on-ok');
46726afd   Sergio Crisostomo   Fix panels reset ...
380
                  this.reset();
e55ba7a2   Sergio Crisostomo   Add week numbers
381
              },
0f677893   梁灏   update DatePicker
382
383
          },
          watch: {
95eae081   Sergio Crisostomo   refactor Datepicker
384
385
              visible (state) {
                  if (state === false){
0f677893   梁灏   update DatePicker
386
                      this.$refs.drop.destroy();
030a522d   Sergio Crisostomo   make picker close...
387
388
                      const input = this.$el.querySelector('input');
                      if (input) input.blur();
c46f385a   梁灏   update DatePicker
389
                  }
65ce6ced   Sergio Crisostomo   keep `this.$refs....
390
                  this.$refs.drop.update();
95eae081   Sergio Crisostomo   refactor Datepicker
391
                  this.$emit('on-open-change', state);
c46f385a   梁灏   update DatePicker
392
              },
95eae081   Sergio Crisostomo   refactor Datepicker
393
              value(val) {
8f6aeda4   Sergio Crisostomo   Fix parser and fo...
394
                  this.internalValue = this.parseDate(val);
0dd7b94a   梁灏   update TimePicker
395
  
d20fe0ee   梁灏   update DatePicker
396
397
              },
              open (val) {
95eae081   Sergio Crisostomo   refactor Datepicker
398
399
400
401
                  this.visible = val === true;
              },
              type(type){
                  this.onSelectionModeChange(type);
8f6aeda4   Sergio Crisostomo   Fix parser and fo...
402
              },
b42322fe   Sergio Crisostomo   Pass Strings to @...
403
              publicVModelValue(now, before){
8f6aeda4   Sergio Crisostomo   Fix parser and fo...
404
405
                  const newValue = JSON.stringify(now);
                  const oldValue = JSON.stringify(before);
d9ff845f   Sergio Crisostomo   Emit input event ...
406
407
                  const shouldEmitInput = newValue !== oldValue || typeof now !== typeof before;
                  if (shouldEmitInput) this.$emit('input', now); // to update v-model
8f6aeda4   Sergio Crisostomo   Fix parser and fo...
408
              },
e9dd4dab   梁灏   publish 0.9.11-rc-1
409
          },
531cd165   梁灏   support DatePicke...
410
          mounted () {
d9ff845f   Sergio Crisostomo   Emit input event ...
411
              const initialValue = this.value;
b42322fe   Sergio Crisostomo   Pass Strings to @...
412
              const parsedValue = this.publicVModelValue;
d9ff845f   Sergio Crisostomo   Emit input event ...
413
              if (typeof initialValue !== typeof parsedValue || JSON.stringify(initialValue) !== JSON.stringify(parsedValue)){
b42322fe   Sergio Crisostomo   Pass Strings to @...
414
                  this.$emit('input', this.publicVModelValue); // to update v-model
d9ff845f   Sergio Crisostomo   Emit input event ...
415
              }
d20fe0ee   梁灏   update DatePicker
416
              if (this.open !== null) this.visible = this.open;
0f677893   梁灏   update DatePicker
417
          }
b0893113   jingsam   :art: add eslint
418
419
      };
  </script>