diff --git a/changelog.md b/changelog.md index 84ab48568..f2618763c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,6 @@ # 更新日志 2.0(2020-07) -- 修复date_picker最大值最小值判断问题 +- 修复date_picker最大值最小值与面板展示判断问题 - 复选下拉树和下拉列表添加showView和hideVIew方法 - number_editor支持自动检测数值与范围是否合法 - 修复了颜色选择器设置值为null的时候,trigger和popup表现不一致的问题 diff --git a/src/widget/date/calendar/combo.month.date.js b/src/widget/date/calendar/combo.month.date.js index fef307866..cbdb552dc 100644 --- a/src/widget/date/calendar/combo.month.date.js +++ b/src/widget/date/calendar/combo.month.date.js @@ -23,6 +23,7 @@ BI.MonthDateCombo = BI.inherit(BI.Trigger, { this.popup = BI.createWidget({ type: "bi.month_popup", + allowMonths: o.allowMonths, behaviors: o.behaviors }); @@ -55,6 +56,10 @@ BI.MonthDateCombo = BI.inherit(BI.Trigger, { }); }, + populate: function () { + this.combo.populate.apply(this.combo, arguments); + }, + setValue: function (v) { this.trigger.setValue(v); this.popup.setValue(v); diff --git a/src/widget/date/calendar/picker.date.js b/src/widget/date/calendar/picker.date.js index 58e98588f..06b556ed3 100644 --- a/src/widget/date/calendar/picker.date.js +++ b/src/widget/date/calendar/picker.date.js @@ -6,7 +6,7 @@ BI.DatePicker = BI.inherit(BI.Widget, { _defaultConfig: function () { var conf = BI.DatePicker.superclass._defaultConfig.apply(this, arguments); - + return BI.extend(conf, { baseCls: "bi-date-picker", height: 40, @@ -76,13 +76,14 @@ BI.DatePicker = BI.inherit(BI.Widget, { this.year.on(BI.YearDateCombo.EVENT_CHANGE, function () { self.setValue({ year: self.year.getValue(), - month: self.month.getValue(), + month: self._refreshMonth() }); self.fireEvent(BI.DatePicker.EVENT_CHANGE); }); this.month = BI.createWidget({ type: "bi.month_date_combo", behaviors: o.behaviors, + allowMonths: this._getAllowMonths() }); this.month.on(BI.MonthDateCombo.EVENT_CHANGE, function () { self.setValue({ @@ -128,12 +129,29 @@ BI.DatePicker = BI.inherit(BI.Widget, { }); }, + _refreshMonth: function () { + var month = this.month.getValue(); + this.month.populate(this._getAllowMonths()); + var allowMonth = this._getAllowMonths(); + if (!BI.contains(allowMonth, month)) { + month = allowMonth[0]; + } + return month; + }, + + _getAllowMonths: function () { + var self = this, o = this.options; + return BI.filter(BI.range(1, 13), function (idx, v) { + return !BI.checkDateVoid(self.year.getValue(), v, 1, o.min, o.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()); this.left.setEnable(valid); - + return valid; }, @@ -142,7 +160,7 @@ BI.DatePicker = BI.inherit(BI.Widget, { var maxDate = BI.parseDateTime(o.max, "%Y-%X-%d"); var valid = !(this._month >= (maxDate.getMonth() + 1) && this._year >= maxDate.getFullYear()); this.right.setEnable(valid); - + return valid; }, diff --git a/src/widget/date/calendar/popup.month.js b/src/widget/date/calendar/popup.month.js index 658642b21..251511e77 100644 --- a/src/widget/date/calendar/popup.month.js +++ b/src/widget/date/calendar/popup.month.js @@ -18,6 +18,35 @@ BI.MonthPopup = BI.inherit(BI.Widget, { BI.MonthPopup.superclass._init.apply(this, arguments); var self = this, o = this.options; + this.month = BI.createWidget({ + type: "bi.button_group", + element: this, + behaviors: o.behaviors, + items: BI.createItems(this._getItems(o.allowMonths), {}), + layouts: [BI.LogicFactory.createLogic("table", BI.extend({ + dynamic: true + }, { + columns: 2, + rows: 6, + columnSize: [1 / 2, 1 / 2], + rowSize: 25 + })), { + type: "bi.center_adapt", + vgap: 1, + hgap: 2 + }], + value: o.value + }); + + this.month.on(BI.Controller.EVENT_CHANGE, function (type) { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + if (type === BI.Events.CLICK) { + self.fireEvent(BI.MonthPopup.EVENT_CHANGE); + } + }); + }, + + _getItems: function(m) { // 纵向排列月 var month = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; var items = []; @@ -39,37 +68,17 @@ BI.MonthPopup = BI.inherit(BI.Widget, { height: 23, width: 38, value: td, - text: td + text: td, + disabled: !BI.contains(m, td) }; }); }); - this.month = BI.createWidget({ - type: "bi.button_group", - element: this, - behaviors: o.behaviors, - items: BI.createItems(items, {}), - layouts: [BI.LogicFactory.createLogic("table", BI.extend({ - dynamic: true - }, { - columns: 2, - rows: 6, - columnSize: [1 / 2, 1 / 2], - rowSize: 25 - })), { - type: "bi.center_adapt", - vgap: 1, - hgap: 2 - }], - value: o.value - }); + return items; + }, - this.month.on(BI.Controller.EVENT_CHANGE, function (type) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if (type === BI.Events.CLICK) { - self.fireEvent(BI.MonthPopup.EVENT_CHANGE); - } - }); + populate: function(months) { + this.month.populate(this._getItems(months)); }, getValue: function () {