From 7f0c6dd2188b6bf8eacc4e75acb56d10afbff1a9 Mon Sep 17 00:00:00 2001 From: zsmj Date: Wed, 28 Sep 2022 13:52:26 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-80978=20fix:=20DynamicYearMonthPopup=20?= =?UTF-8?q?=E5=B7=A6=E5=8F=B3=E5=88=87=E6=8D=A2=E5=B9=B4=E4=BB=BD=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E9=BB=98=E8=AE=A4=E9=80=89=E4=B8=AD=E6=B6=88=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/widget/yearmonth/card.static.yearmonth.js | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/widget/yearmonth/card.static.yearmonth.js b/src/widget/yearmonth/card.static.yearmonth.js index 09ff4ac2f..251b5871c 100644 --- a/src/widget/yearmonth/card.static.yearmonth.js +++ b/src/widget/yearmonth/card.static.yearmonth.js @@ -9,13 +9,7 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, { var self = this; // 纵向排列月 var month = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; - var items = []; - items.push(month.slice(0, 2)); - items.push(month.slice(2, 4)); - items.push(month.slice(4, 6)); - items.push(month.slice(6, 8)); - items.push(month.slice(8, 10)); - items.push(month.slice(10, 12)); + var items = BI.chunk(month, 2); return BI.map(items, function (i, item) { return BI.map(item, function (j, td) { return { @@ -57,10 +51,7 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, { action: function () { var value = this.getValue(); self._checkMonthStatus(value); - self.setValue({ - year: value, - month: self.selectedMonth - }); + self._setYear(value); } }] }, { @@ -106,7 +97,8 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, { var o = this.options; var minDate = BI.parseDateTime(o.min, "%Y-%X-%d"), maxDate = BI.parseDateTime(o.max, "%Y-%X-%d"); var minYear = minDate.getFullYear(), maxYear = maxDate.getFullYear(); - var minMonth = 0; var maxMonth = 11; + var minMonth = 0; + var maxMonth = 11; minYear === year && (minMonth = minDate.getMonth()); maxYear === year && (maxMonth = maxDate.getMonth()); var yearInvalid = year < minYear || year > maxYear; @@ -116,6 +108,22 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, { }); }, + _setYear: function (year) { + var o = this.options; + + var dateVoid = BI.checkDateVoid(year, this.selectedMonth, 1, o.min, o.max); + + // 在切换年的时候,如果月份不在区间内了,取消选中 + if (BI.contains(["y", "m"], dateVoid[0])) { + this.selectedYear = year; + this.month.setValue(); + return; + } + + this.selectedYear = year; + this.month.setValue(this.selectedMonth); + }, + setMinDate: function (minDate) { if (this.options.min !== minDate) { this.options.min = minDate;