DatePicker: fix set initial value

pull/184/head
qingwei.li 2016-09-29 14:45:00 +08:00
parent 1cae9b35b3
commit 7de5306b27
4 changed files with 15 additions and 14 deletions

View File

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

View File

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

View File

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

View File

@ -24,9 +24,15 @@ export const merge = function(target) {
return target; return target;
}; };
export const formatDate = function(date, format) { export const toDate = function(date) {
date = new Date(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'); return dateUtil.format(date, format || 'yyyy-MM-dd');
}; };