From 3fab455e6e87f86c464afb349f398e73a9c8112f Mon Sep 17 00:00:00 2001 From: b2894lxlx <517289602@qq.com> Date: Sun, 26 Sep 2021 18:00:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=BB=98=E8=AE=A4=E8=B5=B7?= =?UTF-8?q?=E5=A7=8B=E6=97=A5=E6=9C=9F=EF=BC=9B=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=B5=B7=E5=A7=8B=E6=97=A5=E6=9C=9F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uview-ui/components/u-calendar/u-calendar.vue | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/uview-ui/components/u-calendar/u-calendar.vue b/uview-ui/components/u-calendar/u-calendar.vue index 2b301842..c2884948 100644 --- a/uview-ui/components/u-calendar/u-calendar.vue +++ b/uview-ui/components/u-calendar/u-calendar.vue @@ -224,6 +224,16 @@ toolTip: { type: String, default: '选择日期' + }, + //默认开始日期 + defaultStartDate: { + type: String, + default: '' + }, + //默认结束日期 + defaultEndDate: { + type: String, + default: '' } }, data() { @@ -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(); @@ -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); } @@ -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}` + } } } };