mirror of
https://github.com/tenrok/vue2-datepicker.git
synced 2026-06-18 12:50:36 +03:00
refactor: optimize code
This commit is contained in:
+10
-20
@@ -256,20 +256,11 @@ export default {
|
|||||||
}
|
}
|
||||||
return this.value2date(this.value);
|
return this.value2date(this.value);
|
||||||
},
|
},
|
||||||
innerValueValid() {
|
|
||||||
if (!this.range && isValidDate(this.innerValue)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (this.range && isValidRangeDate(this.innerValue)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
text() {
|
text() {
|
||||||
if (this.userInput !== null) {
|
if (this.userInput !== null) {
|
||||||
return this.userInput;
|
return this.userInput;
|
||||||
}
|
}
|
||||||
if (!this.innerValueValid) {
|
if (!this.isValidValue(this.innerValue)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
const fmt = this.format;
|
const fmt = this.format;
|
||||||
@@ -279,7 +270,7 @@ export default {
|
|||||||
return this.formatDate(this.innerValue, fmt);
|
return this.formatDate(this.innerValue, fmt);
|
||||||
},
|
},
|
||||||
showClearIcon() {
|
showClearIcon() {
|
||||||
return !this.disabled && this.clearable && this.innerValueValid;
|
return !this.disabled && this.clearable && this.text;
|
||||||
},
|
},
|
||||||
locale() {
|
locale() {
|
||||||
if (isObject(this.lang)) {
|
if (isObject(this.lang)) {
|
||||||
@@ -355,6 +346,10 @@ export default {
|
|||||||
this.closePopup();
|
this.closePopup();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
isValidValue(value) {
|
||||||
|
const validate = this.range ? isValidRangeDate : isValidDate;
|
||||||
|
return validate(value);
|
||||||
|
},
|
||||||
handleSelectDate(val, type) {
|
handleSelectDate(val, type) {
|
||||||
if (this.confirm) {
|
if (this.confirm) {
|
||||||
this.currentValue = val;
|
this.currentValue = val;
|
||||||
@@ -402,15 +397,10 @@ export default {
|
|||||||
this.handleClear();
|
this.handleClear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let date = null;
|
const date = this.range
|
||||||
if (this.range) {
|
? text.split(this.rangeSeparator).map(v => this.parseDate(v, this.format))
|
||||||
date = text.split(this.rangeSeparator).map(v => this.parseDate(v, this.format));
|
: this.parseDate(text, this.format);
|
||||||
date = isValidRangeDate(date) ? date : null;
|
if (this.isValidValue(date)) {
|
||||||
} else {
|
|
||||||
date = this.parseDate(text, this.format);
|
|
||||||
date = isValidDate(date) ? date : null;
|
|
||||||
}
|
|
||||||
if (date !== null) {
|
|
||||||
this.emitValue(date);
|
this.emitValue(date);
|
||||||
this.blur();
|
this.blur();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user