From ff42bd22dbbfd428b280b26d2522965d6020846d Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 28 Nov 2019 15:47:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?KERNEL-2278=20&&=20BI-56459:=20=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E7=B3=BB=E5=88=97=E6=96=B0=E5=A2=9EsetMinDate?= =?UTF-8?q?=E5=92=8CsetMaxDate=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/case/calendar/calendar.js | 80 ++++++++++------ src/case/calendar/calendar.year.js | 91 ++++++++++++------- src/widget/date/calendar/combo.year.date.js | 8 ++ src/widget/date/calendar/picker.date.js | 6 ++ src/widget/date/calendar/picker.year.js | 13 +++ .../date/calendar/popup.calendar.date.js | 30 ++++++ src/widget/date/calendar/popup.year.js | 42 ++++++++- src/widget/dynamicdate/dynamicdate.combo.js | 14 +++ src/widget/dynamicdate/dynamicdate.popup.js | 14 +++ src/widget/dynamicdate/dynamicdate.trigger.js | 12 +++ .../dynamicdatetime/dynamicdatetime.combo.js | 12 +++ .../dynamicdatetime/dynamicdatetime.popup.js | 14 +++ .../dynamicdatetime.trigger.js | 12 +++ src/widget/yearmonth/card.static.yearmonth.js | 16 ++++ src/widget/yearmonth/popup.yearmonth.js | 14 +++ 15 files changed, 312 insertions(+), 66 deletions(-) diff --git a/src/case/calendar/calendar.js b/src/case/calendar/calendar.js index 71d267776..9d2ed758b 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 cd70532be..2d9d96841 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 bfffa140c..1d7f59bad 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 a964b28f9..de16ff01d 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 076a7839d..fafbe40dc 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 11ea19a45..298fedd05 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 15654c004..63ef1f1b6 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 af9ea5b76..7a2fedf6c 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 bb5e0e5fb..b862db0fb 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 5089ec9c3..3ec9d1c18 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 59bd8c361..5572ecde5 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 2bdde53d4..d8f943551 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 297e3c09d..53fd8ef6b 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 3b6c8bb71..24a2f2ff4 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 0f4d2c81e..d8559b1b7 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; From 9891e6be9474996f355a301a53920583f4f11e33 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 28 Nov 2019 15:55:52 +0800 Subject: [PATCH 2/2] changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 378f46e95..c5e29ff74 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2019-11) +- 日期系列新增setMinDate和setMaxDate接口 - 修复了同步复选树设置节点默认open后, 叶子节点无法选中的问题 - 修复了连续多音字搜索可能导致结果异常或者标红异常的问题 - 新增BI.set(object, path, value)方法