[Doc] DatetimePicker: improve documentation (#747)

This commit is contained in:
neverland
2018-03-22 11:48:30 +08:00
committed by GitHub
parent 4810630215
commit 70fbdea35d
5 changed files with 123 additions and 38 deletions

View File

@@ -11,9 +11,10 @@
</template>
<script>
import create from '../utils/create';
import Picker from '../picker';
import create from '../utils/create';
const currentYear = new Date().getFullYear();
const isValidDate = date => Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime());
export default create({
@@ -42,16 +43,12 @@ export default create({
},
minDate: {
type: Date,
default() {
return new Date(new Date().getFullYear() - 10, 0, 1);
},
default: () => new Date(currentYear - 10, 0, 1),
validator: isValidDate
},
maxDate: {
type: Date,
default() {
return new Date(new Date().getFullYear() + 10, 11, 31);
},
default: () => new Date(currentYear + 10, 11, 31),
validator: isValidDate
},
minHour: {
@@ -77,6 +74,7 @@ export default create({
const isEqual = this.type === 'time' ? val === this.innerValue : val.valueOf() === this.innerValue.valueOf();
if (!isEqual) this.innerValue = val;
},
innerValue(val) {
this.updateColumnValue(val);
this.$emit('input', val);
@@ -104,7 +102,7 @@ export default create({
];
if (this.type === 'date') result.splice(3, 2);
if (this.type === 'date-year-month') result.splice(2, 3);
if (this.type === 'year-month') result.splice(2, 3);
return result;
},
columns() {
@@ -125,7 +123,7 @@ export default create({
methods: {
correctValue(value) {
// validate value
const isDateType = this.type.indexOf('date') > -1;
const isDateType = this.type !== 'time';
if (isDateType && !isValidDate(value)) {
value = this.minDate;
} else if (!value) {
@@ -241,7 +239,7 @@ export default create({
const month = this.getTrueValue(values[1]);
const maxDate = this.getMonthEndDay(year, month);
let date = this.getTrueValue(values[2]);
if (this.type === 'date-year-month') {
if (this.type === 'year-month') {
date = 1;
}
date = date > maxDate ? maxDate : date;
@@ -259,6 +257,7 @@ export default create({
},
updateColumnValue(value) {
console.log(value, this.type);
let values = [];
if (this.type === 'time') {
const currentValue = value.split(':');
@@ -278,7 +277,7 @@ export default create({
`0${value.getMinutes()}`.slice(-2)
);
}
if (this.type === 'date-year-month') {
if (this.type === 'year-month') {
values = values.slice(0, 2);
}
}