update DatePicker

update DatePicker
This commit is contained in:
梁灏 2016-12-15 23:29:31 +08:00
parent f46ebc38dc
commit e1874103ad
4 changed files with 37 additions and 9 deletions

View file

@ -103,7 +103,6 @@
}, },
watch: { watch: {
value (newVal) { value (newVal) {
console.log(12331)
if (!newVal) return; if (!newVal) return;
newVal = new Date(newVal); newVal = new Date(newVal);
if (!isNaN(newVal)) { if (!isNaN(newVal)) {

View file

@ -181,7 +181,6 @@
return { return {
prefixCls: prefixCls, prefixCls: prefixCls,
showClose: false, showClose: false,
visualValue: '',
visible: false, visible: false,
picker: null, picker: null,
internalValue: '' internalValue: ''
@ -226,7 +225,6 @@
TYPE_VALUE_RESOLVER_MAP['default'] TYPE_VALUE_RESOLVER_MAP['default']
).parser; ).parser;
const parsedValue = parser(value, this.format || DEFAULT_FORMATS[type]); const parsedValue = parser(value, this.format || DEFAULT_FORMATS[type]);
if (parsedValue) { if (parsedValue) {
if (this.picker) this.picker.value = parsedValue; if (this.picker) this.picker.value = parsedValue;
} }
@ -241,13 +239,36 @@
this.visible = false; this.visible = false;
}, },
handleFocus () { handleFocus () {
if (this.readonly) return;
this.visible = true; this.visible = true;
}, },
handleBlur () { handleBlur () {
}, },
handleInputChange (val) { handleInputChange (event) {
this.visualValue = val; const oldValue = this.visualValue;
const value = event.target.value;
let correctValue = '';
const format = this.format || DEFAULT_FORMATS[this.type];
const parsedDate = parseDate(value, format);
if (parsedDate instanceof Date) {
const options = this.options;
if (options.disabledDate && typeof options.disabledDate === 'function' && options.disabledDate(new Date(parsedDate))) {
correctValue = oldValue;
} else {
correctValue = formatDate(parsedDate, format);
}
} else {
correctValue = oldValue;
}
const correctDate = parseDate(correctValue, format);
this.visualValue = correctValue;
event.target.value = correctValue;
this.internalValue = correctDate;
}, },
handleInputMouseenter () { handleInputMouseenter () {
if (this.readonly || this.disabled) return; if (this.readonly || this.disabled) return;
@ -277,9 +298,10 @@
} }
this.picker.$on('on-pick', (date, visible = false) => { this.picker.$on('on-pick', (date, visible = false) => {
this.$emit('on-change', date); this.$emit('on-change', formatDate(date, this.format || DEFAULT_FORMATS[this.type]));
this.value = date; this.value = date;
this.visible = visible; this.visible = visible;
this.picker.value = date;
this.picker.resetView && this.picker.resetView(); this.picker.resetView && this.picker.resetView();
}); });

View file

@ -141,8 +141,8 @@
handleBlur () { handleBlur () {
this.$emit('on-blur'); this.$emit('on-blur');
}, },
handleChange () { handleChange (event) {
this.$emit('on-change', this.value); this.$emit('on-change', event);
}, },
resizeTextarea () { resizeTextarea () {
const autosize = this.autosize; const autosize = this.autosize;

View file

@ -3,7 +3,14 @@
<br> <br>
<row> <row>
<i-col span="4"> <i-col span="4">
<date-picker style="width:200px" placeholder="请选择日期" :value.sync="value" :options="options" @on-change="change" @on-open-change="change2" :format="format"></date-picker> <date-picker
style="width:200px"
placeholder="请选择日期"
:value.sync="value"
:options="options"
@on-change="change"
:format="format"
@on-open-change="change2"></date-picker>
</i-col> </i-col>
<i-col span="4"> <i-col span="4">
<date-picker type="year" style="width:200px" placeholder="请选择日期" :value.sync="value" :options="options"></date-picker> <date-picker type="year" style="width:200px" placeholder="请选择日期" :value.sync="value" :options="options"></date-picker>