Browse Source

DatePicker: fix set initial value

qingwei.li 8 years ago
parent
commit
7de5306b27

+ 1 - 1
packages/date-picker/src/basic/date-table.vue

@@ -30,7 +30,7 @@
   </table>
 </template>
 
-<script type="text/ecmascript-6">
+<script>
   import { $t, getFirstDayOfMonth, getDayCountOfMonth, getWeekNumber, getStartDateOfMonth, DAY_DURATION } from '../util';
   import { hasClass } from 'wind-dom/src/class';
   import Vue from 'vue';

+ 3 - 3
packages/date-picker/src/panel/date-range.vue

@@ -129,7 +129,7 @@
 </template>
 
 <script type="text/ecmascript-6">
-  import { nextMonth, prevMonth, $t, formatDate, parseDate } from '../util';
+  import { nextMonth, prevMonth, toDate, $t, formatDate, parseDate } from '../util';
 
   export default {
     computed: {
@@ -292,8 +292,8 @@
           this.minDate = null;
           this.maxDate = null;
         } else if (Array.isArray(newVal)) {
-          this.minDate = newVal[0];
-          this.maxDate = newVal[1];
+          this.minDate = toDate(newVal[0]);
+          this.maxDate = toDate(newVal[1]);
         }
       }
     },

+ 3 - 8
packages/date-picker/src/picker.vue

@@ -290,9 +290,7 @@ export default {
       const type = this.type;
 
       if (HAVE_TRIGGER_TYPES.indexOf(type) !== -1) {
-        if (!this.pickerVisible) {
-          this.showPicker();
-        }
+        this.pickerVisible = !this.pickerVisible;
       }
       this.$emit('focus', this);
     },
@@ -451,7 +449,7 @@ export default {
           this.$emit('input', date);
 
           if (!visible) {
-            this.pickerVisible = this.picker.visible = false;
+            this.pickerVisible = this.picker.visible = !this.picker.visible;
           }
           this.picker.resetView && this.picker.resetView();
         });
@@ -467,10 +465,7 @@ export default {
       }
 
       this.$nextTick(() => {
-        if (this.popper) {
-          this.popper.update();
-          return;
-        }
+        if (this.popper) return;
 
         this.popper = new Popper(this.$refs.reference, this.picker.$el, {
           gpuAcceleration: false,

+ 8 - 2
packages/date-picker/src/util/index.js

@@ -24,9 +24,15 @@ export const merge = function(target) {
   return target;
 };
 
-export const formatDate = function(date, format) {
+export const toDate = function(date) {
   date = new Date(date);
-  if (isNaN(date.getTime())) return '';
+  if (isNaN(date.getTime())) return null;
+  return date;
+};
+
+export const formatDate = function(date, format) {
+  date = toDate(date);
+  if (!date) return '';
   return dateUtil.format(date, format || 'yyyy-MM-dd');
 };