From b01c235f1ab3a3a75416cfd11c08946a7c737bed Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Mon, 27 Jul 2020 12:14:17 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-35908=20&&=20REPORT-36013=20fix:=20?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=97=A5=E6=9C=9Fvalue=E4=B8=8D=E5=9C=A8min?= =?UTF-8?q?=E5=92=8Cmax=E4=B9=8B=E9=97=B4=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E7=81=B0=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 1 + src/case/calendar/calendar.js | 2 -- src/widget/date/calendar/picker.date.js | 47 +++++++++++++++++-------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/changelog.md b/changelog.md index ead4d92ef..cf2eccb14 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2020-07) +- 修复了日期类型控件设置一个不在minDate和maxDate之间的日期值时,面板灰化与翻页按钮状态不对的问题 - BI.OB的on方法返回一个解除监听的函数 - 修复了grid_view执行_unMount时不调用子组件的_unMount的问题 - combo新增belowMouse属性,允许popup在点击处弹出 diff --git a/src/case/calendar/calendar.js b/src/case/calendar/calendar.js index 9d2ed758b..56507ab34 100644 --- a/src/case/calendar/calendar.js +++ b/src/case/calendar/calendar.js @@ -23,8 +23,6 @@ BI.Calendar = BI.inherit(BI.Widget, { var self = this, o = this.options, log = {}, De = BI.getDate(); var mins = o.min.match(/\d+/g); var maxs = o.max.match(/\d+/g); - Y < (mins[0] | 0) && (Y = (mins[0] | 0)); - Y > (maxs[0] | 0) && (Y = (maxs[0] | 0)); De.setFullYear(Y, M, D); log.ymd = [De.getFullYear(), De.getMonth(), De.getDate()]; diff --git a/src/widget/date/calendar/picker.date.js b/src/widget/date/calendar/picker.date.js index 2d840b2b0..bf6abd378 100644 --- a/src/widget/date/calendar/picker.date.js +++ b/src/widget/date/calendar/picker.date.js @@ -136,49 +136,68 @@ BI.DatePicker = BI.inherit(BI.Widget, { if (!BI.contains(allowMonth, month)) { month = allowMonth[0]; } + return month; }, _getAllowMonths: function () { - var self = this, o = this.options; - var minDate = BI.parseDateTime(o.min, "%Y-%X-%d"); - var maxDate = BI.parseDateTime(o.max, "%Y-%X-%d"); - minDate.setDate(1); - maxDate.setDate(1); - var calcMin = BI.print(minDate, "%Y-%X-%d"); - var calcMax = BI.print(maxDate, "%Y-%X-%d"); + var obj = this._getCheckMinMaxDate(); + var year = this.year.getValue() || this._year; return BI.filter(BI.range(1, 13), function (idx, v) { - return !BI.checkDateVoid(self.year.getValue(), v, 1, calcMin, calcMax)[0]; + return !BI.checkDateVoid(year, v, 1, obj.min, obj.max)[0]; }); }, + // 上一年月不合法则灰化 _checkLeftValid: function () { - var o = this.options; - var minDate = BI.parseDateTime(o.min, "%Y-%X-%d"); - var valid = !(this._month <= (minDate.getMonth() + 1) && this._year <= minDate.getFullYear()); + var obj = this._getCheckMinMaxDate(); + var year = this._month === 1 ? this._year - 1 : this._year; + var month = this._month === 1 ? 12 : this.month - 1; + var valid = BI.isNull(BI.checkDateVoid(year, month, 1, obj.min, obj.max)[0]); this.left.setEnable(valid); return valid; }, + // 下一年月不合法则灰化 _checkRightValid: function () { - var o = this.options; - var maxDate = BI.parseDateTime(o.max, "%Y-%X-%d"); - var valid = !(this._month >= (maxDate.getMonth() + 1) && this._year >= maxDate.getFullYear()); + var obj = this._getCheckMinMaxDate(); + var year = this._month === 12 ? this._year + 1 : this._year; + var month = this._month === 12 ? 1 : this.month + 1; + var valid = BI.isNull(BI.checkDateVoid(year, month, 1, obj.min, obj.max)[0]); this.right.setEnable(valid); return valid; }, + _getCheckMinMaxDate() { + var o = this.options; + var minDate = BI.parseDateTime(o.min, "%Y-%X-%d"); + var maxDate = BI.parseDateTime(o.max, "%Y-%X-%d"); + minDate.setDate(1); + maxDate.setDate(1); + + return { + min: BI.print(minDate, "%Y-%X-%d"), + max: BI.print(maxDate, "%Y-%X-%d") + }; + }, + setMinDate: function (minDate) { this.options.min = minDate; this.year.setMinDate(minDate); + this._refreshMonth(); + this._checkLeftValid(); + this._checkRightValid(); }, setMaxDate: function (maxDate) { this.options.max = maxDate; this.year.setMaxDate(maxDate); + this._refreshMonth(); + this._checkLeftValid(); + this._checkRightValid(); }, setValue: function (ob) {