Browse Source

REPORT-19859 fix: 年月控件支持最大最小日期限制

es6
windy 5 years ago
parent
commit
a258ba1cb2
  1. 27
      src/widget/yearmonth/card.static.yearmonth.js
  2. 12
      src/widget/yearmonth/combo.yearmonth.js
  3. 3
      src/widget/yearmonth/trigger.yearmonth.js

27
src/widget/yearmonth/card.static.yearmonth.js

@ -6,6 +6,7 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, {
}, },
_createMonths: function () { _createMonths: function () {
var self = this;
// 纵向排列月 // 纵向排列月
var month = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; var month = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12];
var items = []; var items = [];
@ -27,7 +28,10 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, {
height: 23, height: 23,
width: 38, width: 38,
value: td, value: td,
text: td text: td,
ref: function (_ref) {
self.monthMap[j === 0 ? i : i + 6] = _ref;
}
}; };
}); });
}); });
@ -35,10 +39,13 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, {
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
this.monthMap = {};
return { return {
type: "bi.vertical", type: "bi.vertical",
items: [{ items: [{
type: "bi.year_picker", type: "bi.year_picker",
min: o.min,
max: o.max,
ref: function () { ref: function () {
self.yearPicker = this; self.yearPicker = this;
}, },
@ -48,6 +55,7 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, {
eventName: BI.YearPicker.EVENT_CHANGE, eventName: BI.YearPicker.EVENT_CHANGE,
action: function () { action: function () {
var value = this.getValue(); var value = this.getValue();
self._checkMonthStatus(value);
self.setValue({ self.setValue({
year: value, year: value,
month: self.selectedMonth month: self.selectedMonth
@ -87,6 +95,23 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, {
}; };
}, },
mounted: function() {
this._checkMonthStatus(this.selectedYear);
},
_checkMonthStatus: function (year) {
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;
minYear === year && (minMonth = minDate.getMonth());
maxYear === year && (maxMonth = maxDate.getMonth());
var yearInvalid = year < minYear || year > maxYear;
BI.each(this.monthMap, function (month, obj) {
var monthInvalid = month < minMonth || month > maxMonth;
obj.setEnable(!yearInvalid && !monthInvalid);
});
},
getValue: function () { getValue: function () {
return { return {

12
src/widget/yearmonth/combo.yearmonth.js

@ -3,8 +3,8 @@ BI.DynamicYearMonthCombo = BI.inherit(BI.Single, {
props: { props: {
baseCls: "bi-year-month-combo bi-border bi-focus-shadow", baseCls: "bi-year-month-combo bi-border bi-focus-shadow",
behaviors: {}, behaviors: {},
min: "1900-01-01", // 最小日期 minDate: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 maxDate: "2099-12-31", // 最大日期
height: 22 height: 22
}, },
@ -15,8 +15,8 @@ BI.DynamicYearMonthCombo = BI.inherit(BI.Single, {
this.storeTriggerValue = ""; this.storeTriggerValue = "";
this.trigger = BI.createWidget({ this.trigger = BI.createWidget({
type: "bi.dynamic_year_month_trigger", type: "bi.dynamic_year_month_trigger",
min: o.min, min: o.minDate,
max: o.max, max: o.maxDate,
height: o.height, height: o.height,
value: o.value || "" value: o.value || ""
}); });
@ -100,8 +100,8 @@ BI.DynamicYearMonthCombo = BI.inherit(BI.Single, {
} }
}], }],
behaviors: o.behaviors, behaviors: o.behaviors,
min: o.min, min: o.minDate,
max: o.max max: o.maxDate
}, },
value: o.value || "" value: o.value || ""
} }

3
src/widget/yearmonth/trigger.yearmonth.js

@ -62,12 +62,13 @@ BI.DynamicYearMonthTrigger = BI.inherit(BI.Trigger, {
_createEditor: function (isYear) { _createEditor: function (isYear) {
var self = this, o = this.options, c = this._const; var self = this, o = this.options, c = this._const;
var minDate = BI.parseDateTime(o.min, "%Y-%X-%d");
var editor = BI.createWidget({ var editor = BI.createWidget({
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
if(isYear) { if(isYear) {
return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, v === minDate.getFullYear() ? minDate.getMonth() + 1 : 1, 1, o.min, o.max)[0]);
} }
return v === "" || ((BI.isPositiveInteger(v) && v >= 1 && v <= 12) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]); return v === "" || ((BI.isPositiveInteger(v) && v >= 1 && v <= 12) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]);
}, },

Loading…
Cancel
Save