diff --git a/changelog.md b/changelog.md index 378f46e959..c5e29ff74b 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2019-11) +- 日期系列新增setMinDate和setMaxDate接口 - 修复了同步复选树设置节点默认open后, 叶子节点无法选中的问题 - 修复了连续多音字搜索可能导致结果异常或者标红异常的问题 - 新增BI.set(object, path, value)方法 diff --git a/src/case/calendar/calendar.js b/src/case/calendar/calendar.js index 71d267776a..9d2ed758b1 100644 --- a/src/case/calendar/calendar.js +++ b/src/case/calendar/calendar.js @@ -94,37 +94,10 @@ BI.Calendar = BI.inherit(BI.Widget, { vgap: 10 }] }); - var days = this._dateCreator(o.year, o.month - 1, o.day); - items = []; - items.push(days.slice(0, 7)); - items.push(days.slice(7, 14)); - items.push(days.slice(14, 21)); - items.push(days.slice(21, 28)); - items.push(days.slice(28, 35)); - items.push(days.slice(35, 42)); - - items = BI.map(items, function (i, item) { - return BI.map(item, function (j, td) { - var month = td.lastMonth ? o.month - 1 : (td.nextMonth ? o.month + 1 : o.month); - return BI.extend(td, { - type: "bi.calendar_date_item", - textAlign: "center", - whiteSpace: "normal", - once: false, - forceSelected: true, - height: 24, - value: o.year + "-" + month + "-" + td.text, - disabled: td.lastMonth || td.nextMonth || td.disabled, - lgap: 5, - rgap: 5 - // selected: td.currentDay - }); - }); - }); this.days = BI.createWidget({ type: "bi.button_group", - items: BI.createItems(items, {}), + items: BI.createItems(this._getItems(), {}), layouts: [BI.LogicFactory.createLogic("table", BI.extend({}, o.logic, { columns: 7, rows: 6, @@ -168,6 +141,57 @@ BI.Calendar = BI.inherit(BI.Widget, { return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; }, + _getItems: function () { + var o = this.options; + var days = this._dateCreator(o.year, o.month - 1, o.day); + var items = []; + items.push(days.slice(0, 7)); + items.push(days.slice(7, 14)); + items.push(days.slice(14, 21)); + items.push(days.slice(21, 28)); + items.push(days.slice(28, 35)); + items.push(days.slice(35, 42)); + + return BI.map(items, function (i, item) { + return BI.map(item, function (j, td) { + var month = td.lastMonth ? o.month - 1 : (td.nextMonth ? o.month + 1 : o.month); + return BI.extend(td, { + type: "bi.calendar_date_item", + textAlign: "center", + whiteSpace: "normal", + once: false, + forceSelected: true, + height: 24, + value: o.year + "-" + month + "-" + td.text, + disabled: td.lastMonth || td.nextMonth || td.disabled, + lgap: 5, + rgap: 5 + // selected: td.currentDay + }); + }); + }); + }, + + _populate: function() { + this.days.populate(this._getItems()); + }, + + setMinDate: function (minDate) { + var o = this.options; + if (BI.isNotEmptyString(o.min)) { + o.min = minDate; + this._populate(); + } + }, + + setMaxDate: function (maxDate) { + var o = this.options; + if (BI.isNotEmptyString(o.max)) { + o.max = maxDate; + this._populate(); + } + }, + setValue: function (ob) { this.days.setValue([ob.year + "-" + ob.month + "-" + ob.day]); }, diff --git a/src/case/calendar/calendar.year.js b/src/case/calendar/calendar.year.js index cd70532beb..2d9d968417 100644 --- a/src/case/calendar/calendar.year.js +++ b/src/case/calendar/calendar.year.js @@ -42,43 +42,11 @@ BI.YearCalendar = BI.inherit(BI.Widget, { BI.YearCalendar.superclass._init.apply(this, arguments); var self = this, o = this.options; this.currentYear = BI.getDate().getFullYear(); - var years = this._yearCreator(o.year || this.currentYear); - - // 纵向排列年 - var len = years.length, tyears = BI.makeArray(len, ""); - var map = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; - BI.each(years, function (i, y) { - tyears[i] = years[map[i]]; - }); - var items = []; - items.push(tyears.slice(0, 2)); - items.push(tyears.slice(2, 4)); - items.push(tyears.slice(4, 6)); - items.push(tyears.slice(6, 8)); - items.push(tyears.slice(8, 10)); - items.push(tyears.slice(10, 12)); - - items = BI.map(items, function (i, item) { - return BI.map(item, function (j, td) { - return BI.extend(td, { - type: "bi.text_item", - cls: "bi-list-item-select", - textAlign: "center", - whiteSpace: "normal", - once: false, - forceSelected: true, - height: 24, - width: 45, - value: td.text, - disabled: td.disabled - }); - }); - }); this.years = BI.createWidget({ type: "bi.button_group", behaviors: o.behaviors, - items: BI.createItems(items, {}), + items: BI.createItems(this._getItems(), {}), layouts: [BI.LogicFactory.createLogic("table", BI.extend({}, o.logic, { columns: 2, rows: 6, @@ -114,6 +82,63 @@ BI.YearCalendar = BI.inherit(BI.Widget, { return !!BI.checkDateVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0]; }, + _getItems: function () { + var o = this.options; + var years = this._yearCreator(o.year || this.currentYear); + + // 纵向排列年 + var len = years.length, tyears = BI.makeArray(len, ""); + var map = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; + BI.each(years, function (i, y) { + tyears[i] = years[map[i]]; + }); + + var items = []; + items.push(tyears.slice(0, 2)); + items.push(tyears.slice(2, 4)); + items.push(tyears.slice(4, 6)); + items.push(tyears.slice(6, 8)); + items.push(tyears.slice(8, 10)); + items.push(tyears.slice(10, 12)); + + return BI.map(items, function (i, item) { + return BI.map(item, function (j, td) { + return BI.extend(td, { + type: "bi.text_item", + cls: "bi-list-item-select", + textAlign: "center", + whiteSpace: "normal", + once: false, + forceSelected: true, + height: 24, + width: 45, + value: td.text, + disabled: td.disabled + }); + }); + }); + }, + + _populate: function () { + this.years.populate(this._getItems()); + }, + + setMinDate: function (minDate) { + var o = this.options; + if (BI.isNotEmptyString(o.min)) { + o.min = minDate; + this._populate(); + } + }, + + setMaxDate: function (maxDate) { + var o = this.options; + if (BI.isNotEmptyString(this.options.max)) { + o.max = maxDate; + this._populate(); + } + }, + setValue: function (val) { this.years.setValue([val]); }, diff --git a/src/widget/date/calendar/combo.year.date.js b/src/widget/date/calendar/combo.year.date.js index bfffa140cb..1d7f59bada 100644 --- a/src/widget/date/calendar/combo.year.date.js +++ b/src/widget/date/calendar/combo.year.date.js @@ -61,6 +61,14 @@ BI.YearDateCombo = BI.inherit(BI.Trigger, { }); }, + setMinDate: function (minDate) { + this.popup.setMinDate(minDate); + }, + + setMaxDate: function (maxDate) { + this.popup.setMaxDate(maxDate); + }, + 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 a964b28f92..de16ff01de 100644 --- a/src/widget/date/calendar/picker.date.js +++ b/src/widget/date/calendar/picker.date.js @@ -141,7 +141,13 @@ BI.DatePicker = BI.inherit(BI.Widget, { return valid; }, + setMinDate: function (minDate) { + this.year.setMinDate(minDate); + }, + setMaxDate: function (maxDate) { + this.year.setMaxDate(maxDate); + }, setValue: function (ob) { this._year = BI.parseInt(ob.year); diff --git a/src/widget/date/calendar/picker.year.js b/src/widget/date/calendar/picker.year.js index 076a7839dc..fafbe40dc2 100644 --- a/src/widget/date/calendar/picker.year.js +++ b/src/widget/date/calendar/picker.year.js @@ -104,6 +104,19 @@ BI.YearPicker = BI.inherit(BI.Widget, { return valid; }, + setMinDate: function (minDate) { + this.options.min = minDate; + this.year.setMinDate(minDate); + this._checkLeftValid(); + this._checkRightValid(); + }, + + setMaxDate: function (maxDate) { + this.options.max = maxDate; + this.year.setMaxDate(maxDate); + this._checkLeftValid(); + this._checkRightValid(); + }, setValue: function (v) { diff --git a/src/widget/date/calendar/popup.calendar.date.js b/src/widget/date/calendar/popup.calendar.date.js index 11ea19a45c..298fedd059 100644 --- a/src/widget/date/calendar/popup.calendar.date.js +++ b/src/widget/date/calendar/popup.calendar.date.js @@ -102,6 +102,36 @@ BI.DateCalendarPopup = BI.inherit(BI.Widget, { }); }, + _checkMin: function () { + var calendar = this.calendar.getSelectedCard(); + if (BI.isNotNull(calendar)) { + calendar.setMinDate(this.options.min); + } + }, + + _checkMax: function () { + var calendar = this.calendar.getSelectedCard(); + if (BI.isNotNull(calendar)) { + calendar.setMaxDate(this.options.max); + } + }, + + setMinDate: function (minDate) { + if (BI.isNotEmptyString(this.options.min)) { + this.options.min = minDate; + this.datePicker.setMinDate(minDate); + this._checkMin(); + } + }, + + setMaxDate: function (maxDate) { + if (BI.isNotEmptyString(this.options.max)) { + this.options.max = maxDate; + this.datePicker.setMaxDate(maxDate); + this._checkMax(); + } + }, + setValue: function (timeOb) { this.datePicker.setValue(timeOb); this.calendar.setSelect(BI.Calendar.getPageByDateJSON(timeOb)); diff --git a/src/widget/date/calendar/popup.year.js b/src/widget/date/calendar/popup.year.js index 15654c0043..63ef1f1b69 100644 --- a/src/widget/date/calendar/popup.year.js +++ b/src/widget/date/calendar/popup.year.js @@ -39,7 +39,7 @@ BI.YearPopup = BI.inherit(BI.Widget, { this.selectedYear = this._year = BI.getDate().getFullYear(); - var backBtn = BI.createWidget({ + this.backBtn = BI.createWidget({ type: "bi.icon_button", cls: "pre-page-h-font", width: 24, @@ -47,7 +47,7 @@ BI.YearPopup = BI.inherit(BI.Widget, { value: -1 }); - var preBtn = BI.createWidget({ + this.preBtn = BI.createWidget({ type: "bi.icon_button", cls: "next-page-h-font", width: 24, @@ -65,15 +65,15 @@ BI.YearPopup = BI.inherit(BI.Widget, { tab: { cls: "year-popup-navigation bi-high-light bi-split-top", height: 24, - items: [backBtn, preBtn] + items: [this.backBtn, this.preBtn] }, cardCreator: BI.bind(this._createYearCalendar, this), afterCardShow: function () { this.setValue(self.selectedYear); var calendar = this.getSelectedCard(); - backBtn.setEnable(!calendar.isFrontYear()); - preBtn.setEnable(!calendar.isFinalYear()); + calendar && self.backBtn.setEnable(!calendar.isFrontYear()); + calendar && self.preBtn.setEnable(!calendar.isFinalYear()); } }); @@ -88,6 +88,38 @@ BI.YearPopup = BI.inherit(BI.Widget, { } }, + _checkMin: function () { + var calendar = this.navigation.getSelectedCard(); + if (BI.isNotNull(calendar)) { + calendar.setMinDate(this.options.min); + this.backBtn.setEnable(!calendar.isFrontYear()); + this.preBtn.setEnable(!calendar.isFinalYear()); + } + }, + + _checkMax: function () { + var calendar = this.navigation.getSelectedCard(); + if (BI.isNotNull(calendar)) { + calendar.setMaxDate(this.options.max); + this.backBtn.setEnable(!calendar.isFrontYear()); + this.preBtn.setEnable(!calendar.isFinalYear()); + } + }, + + setMinDate: function (minDate) { + if (BI.isNotEmptyString(this.options.min)) { + this.options.min = minDate; + this._checkMin(); + } + }, + + setMaxDate: function (maxDate) { + if (BI.isNotEmptyString(this.options.max)) { + this.options.max = maxDate; + this._checkMax(); + } + }, + getValue: function () { return this.selectedYear; }, diff --git a/src/widget/dynamicdate/dynamicdate.combo.js b/src/widget/dynamicdate/dynamicdate.combo.js index af9ea5b769..7a2fedf6ca 100644 --- a/src/widget/dynamicdate/dynamicdate.combo.js +++ b/src/widget/dynamicdate/dynamicdate.combo.js @@ -190,6 +190,8 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, { listeners: [{ eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, action: function () { + self.popup.setMinDate(opts.minDate); + self.popup.setMaxDate(opts.maxDate); self.popup.setValue(self.storeValue); self.fireEvent(BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW); } @@ -267,6 +269,18 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, { }, + setMinDate: function (minDate) { + var o = this.options; + o.minDate = minDate; + this.trigger.setMinDate(minDate); + }, + + setMaxDate: function (maxDate) { + var o = this.options; + o.maxDate = maxDate; + this.trigger.setMaxDate(maxDate); + }, + setValue: function (v) { this.storeValue = v; this.trigger.setValue(v); diff --git a/src/widget/dynamicdate/dynamicdate.popup.js b/src/widget/dynamicdate/dynamicdate.popup.js index bb5e0e5fbb..b862db0fb0 100644 --- a/src/widget/dynamicdate/dynamicdate.popup.js +++ b/src/widget/dynamicdate/dynamicdate.popup.js @@ -171,6 +171,20 @@ BI.DynamicDatePopup = BI.inherit(BI.Widget, { return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, + setMinDate: function (minDate) { + if (this.options.min !== minDate) { + this.ymd.setMinDate(minDate); + } + this.options.min = minDate; + }, + + setMaxDate: function (maxDate) { + if (this.options.max !== maxDate) { + this.ymd.setMaxDate(maxDate); + } + this.options.max = maxDate; + }, + setValue: function (v) { this.storeValue = v; var self = this; diff --git a/src/widget/dynamicdate/dynamicdate.trigger.js b/src/widget/dynamicdate/dynamicdate.trigger.js index 5089ec9c35..3ec9d1c18d 100644 --- a/src/widget/dynamicdate/dynamicdate.trigger.js +++ b/src/widget/dynamicdate/dynamicdate.trigger.js @@ -318,6 +318,18 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { } }, + setMinDate: function (minDate) { + if (BI.isNotEmptyString(this.options.min)) { + this.options.min = minDate; + } + }, + + setMaxDate: function (maxDate) { + if (BI.isNotEmptyString(this.options.max)) { + this.options.max = maxDate; + } + }, + getKey: function () { return this.editor.getValue(); }, diff --git a/src/widget/dynamicdatetime/dynamicdatetime.combo.js b/src/widget/dynamicdatetime/dynamicdatetime.combo.js index 59bd8c3613..5572ecde53 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.combo.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.combo.js @@ -271,6 +271,18 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, { } }, + setMinDate: function (minDate) { + var o = this.options; + o.minDate = minDate; + this.trigger.setMinDate(minDate); + }, + + setMaxDate: function (maxDate) { + var o = this.options; + o.maxDate = maxDate; + this.trigger.setMaxDate(maxDate); + }, + setValue: function (v) { this.storeValue = v; this.trigger.setValue(v); diff --git a/src/widget/dynamicdatetime/dynamicdatetime.popup.js b/src/widget/dynamicdatetime/dynamicdatetime.popup.js index 2bdde53d4f..d8f943551d 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.popup.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.popup.js @@ -178,6 +178,20 @@ BI.DynamicDateTimePopup = BI.inherit(BI.Widget, { return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, + setMinDate: function (minDate) { + if (this.options.min !== minDate) { + this.ymd.setMinDate(minDate); + } + this.options.min = minDate; + }, + + setMaxDate: function (maxDate) { + if (this.options.max !== maxDate) { + this.ymd.setMaxDate(maxDate); + } + this.options.max = maxDate; + }, + setValue: function (v) { this.storeValue = v; var self = this; diff --git a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js index 297e3c09d7..53fd8ef6b7 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js @@ -310,6 +310,18 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { } }, + setMinDate: function (minDate) { + if (BI.isNotEmptyString(this.options.min)) { + this.options.min = minDate; + } + }, + + setMaxDate: function (maxDate) { + if (BI.isNotEmptyString(this.options.max)) { + this.options.max = maxDate; + } + }, + setValue: function (v) { var type, value, self = this; var date = BI.getDate(); diff --git a/src/widget/yearmonth/card.static.yearmonth.js b/src/widget/yearmonth/card.static.yearmonth.js index 3b6c8bb713..24a2f2ff4d 100644 --- a/src/widget/yearmonth/card.static.yearmonth.js +++ b/src/widget/yearmonth/card.static.yearmonth.js @@ -113,6 +113,22 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, { }); }, + setMinDate: function (minDate) { + if (this.options.min !== minDate) { + this.yearPicker.setMinDate(minDate); + this._checkMonthStatus(this.selectedYear); + } + this.options.min = minDate; + }, + + setMaxDate: function (maxDate) { + if (this.options.max !== maxDate) { + this.yearPicker.setMaxDate(maxDate); + this._checkMonthStatus(this.selectedYear); + } + this.options.max = maxDate; + }, + getValue: function () { return { year: this.selectedYear, diff --git a/src/widget/yearmonth/popup.yearmonth.js b/src/widget/yearmonth/popup.yearmonth.js index 0f4d2c81ee..d8559b1b7d 100644 --- a/src/widget/yearmonth/popup.yearmonth.js +++ b/src/widget/yearmonth/popup.yearmonth.js @@ -170,6 +170,20 @@ BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { }; }, + setMinDate: function (minDate) { + if (this.options.min !== minDate) { + this.year.setMinDate(minDate); + } + this.options.min = minDate; + }, + + setMaxDate: function (maxDate) { + if (this.options.max !== maxDate) { + this.year.setMaxDate(maxDate); + } + this.options.max = maxDate; + }, + setValue: function (v) { this.storeValue = v; var self = this;