Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions uview-ui/components/u-calendar/u-calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@
toolTip: {
type: String,
default: '选择日期'
},
//默认开始日期
defaultStartDate: {
type: String,
default: ''
},
//默认结束日期
defaultEndDate: {
type: String,
default: ''
}
},
data() {
Expand Down Expand Up @@ -333,6 +343,10 @@
formatNum: function(num) {
return num < 10 ? '0' + num : num + '';
},
//反向格式化数字
formatNumReverse: function (num) {
return num > 10 ? num : parseInt(num);
},
//一个月有多少天
getMonthDay(year, month) {
let days = new Date(year, month, 0).getDate();
Expand Down Expand Up @@ -386,6 +400,7 @@
this.weekday = this.getWeekday(this.year, this.month);
this.weekdayArr=this.generateArray(1,this.weekday)
this.showTitle = `${this.year}年${this.month}月`;
if (this.defaultStartDate) this.setDate(this.defaultStartDate, this.defaultEndDate)
if (this.isChange && this.mode == 'date') {
this.btnFix(true);
}
Expand Down Expand Up @@ -481,6 +496,20 @@
endWeek: endWeek
});
}
},
setDate(startDate, endDate = null) {
const defaultStartDateArr = startDate.split('-')
this.startYear = defaultStartDateArr[0]
this.startMonth = this.formatNumReverse(defaultStartDateArr[1])
this.startDay = this.formatNumReverse(defaultStartDateArr[2])
this.startDate = this.activeDate = `${this.startYear}-${this.startMonth}-${this.startDay}`
if (endDate) {
const defaultEndDateArr = endDate.split('-')
this.endYear = defaultEndDateArr[0]
this.endMonth = this.formatNumReverse(defaultEndDateArr[1])
this.endDay = this.formatNumReverse(defaultEndDateArr[2])
this.endDate = `${this.endYear}-${this.endMonth}-${this.endDay}`
}
}
}
};
Expand Down