diff --git a/changelog.md b/changelog.md index 5185abbcf7..4506df6804 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2021-07) +- 优化了日期类型控件标红时的报错提示 - 支持虚拟dom - 修复了树控件节点未初始化时调用树的getValue始终为空的问题 diff --git a/src/widget/dynamicdate/dynamicdate.trigger.js b/src/widget/dynamicdate/dynamicdate.trigger.js index ae8fcda030..807d6e3a53 100644 --- a/src/widget/dynamicdate/dynamicdate.trigger.js +++ b/src/widget/dynamicdate/dynamicdate.trigger.js @@ -42,11 +42,25 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { vgap: c.vgap, allowBlank: true, watermark: BI.isKey(o.watermark) ? o.watermark : BI.i18nText("BI-Basic_Unrestricted"), - errorText: function () { + errorText: function (v) { var str = ""; if (!BI.isKey(o.format)) { - str = self.editor.isEditing() ? BI.i18nText("BI-Date_Trigger_Error_Text") : BI.i18nText("BI-Year_Trigger_Invalid_Text"); + if (!self._dateCheck(v)) { + str = self.editor.isEditing() ? BI.i18nText("BI-Date_Trigger_Error_Text") : BI.i18nText("BI-Year_Trigger_Invalid_Text"); + } else { + var start = BI.parseDateTime(o.min, "%Y-%X-%d"); + var end = BI.parseDateTime(o.max, "%Y-%X-%d"); + str = BI.i18nText("BI-Basic_Date_Range_Error", + start.getFullYear(), + start.getMonth() + 1, + start.getDate(), + end.getFullYear(), + end.getMonth() + 1, + end.getDate() + ); + } } + return str; }, title: BI.bind(this._getTitle, this) diff --git a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js index 53fd8ef6b7..6e23f36544 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js @@ -42,11 +42,25 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { vgap: c.vgap, allowBlank: true, watermark: BI.isKey(o.watermark) ? o.watermark : BI.i18nText("BI-Basic_Unrestricted"), - errorText: function () { + errorText: function (v) { var str = ""; if (!BI.isKey(o.format)) { - str = self.editor.isEditing() ? BI.i18nText("BI-Basic_Date_Time_Error_Text") : BI.i18nText("BI-Year_Trigger_Invalid_Text"); + if (!self._dateCheck(v)) { + str = self.editor.isEditing() ? BI.i18nText("BI-Date_Trigger_Error_Text") : BI.i18nText("BI-Year_Trigger_Invalid_Text"); + } else { + var start = BI.parseDateTime(o.min, "%Y-%X-%d"); + var end = BI.parseDateTime(o.max, "%Y-%X-%d"); + str = BI.i18nText("BI-Basic_Date_Range_Error", + start.getFullYear(), + start.getMonth() + 1, + start.getDate(), + end.getFullYear(), + end.getMonth() + 1, + end.getDate() + ); + } } + return str; }, title: BI.bind(this._getTitle, this) diff --git a/src/widget/year/trigger.year.js b/src/widget/year/trigger.year.js index 577e9c3172..545f422f5c 100644 --- a/src/widget/year/trigger.year.js +++ b/src/widget/year/trigger.year.js @@ -35,9 +35,18 @@ BI.DynamicYearTrigger = BI.inherit(BI.Trigger, { vgap: c.vgap, watermark: BI.i18nText("BI-Basic_Unrestricted"), allowBlank: true, - errorText: function () { + errorText: function (v) { + if (BI.isPositiveInteger(v)) { + var start = BI.parseDateTime(o.min, "%Y-%X-%d"); + var end = BI.parseDateTime(o.max, "%Y-%X-%d"); + + return BI.i18nText("BI-Basic_Year_Range_Error", + start.getFullYear(), + end.getFullYear()); + } + return BI.i18nText("BI-Year_Trigger_Invalid_Text"); - } + }, }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { self.fireEvent(BI.DynamicYearTrigger.EVENT_KEY_DOWN, arguments); diff --git a/src/widget/yearmonth/trigger.yearmonth.js b/src/widget/yearmonth/trigger.yearmonth.js index 0266d7aa45..021c52fe6c 100644 --- a/src/widget/yearmonth/trigger.yearmonth.js +++ b/src/widget/yearmonth/trigger.yearmonth.js @@ -78,7 +78,21 @@ BI.DynamicYearMonthTrigger = BI.inherit(BI.Trigger, { }, watermark: BI.i18nText("BI-Basic_Unrestricted"), errorText: function (v) { - return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + var year = isYear ? v : self.yearEditor.getValue(); + var month = isYear ? self.monthEditor.getValue() : v; + if (!BI.isPositiveInteger(year) || !BI.isPositiveInteger(month) || month > 12) { + return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + } + + var start = BI.parseDateTime(o.min, "%Y-%X-%d"); + var end = BI.parseDateTime(o.max, "%Y-%X-%d"); + + return BI.i18nText("BI-Basic_Year_Month_Range_Error", + start.getFullYear(), + start.getMonth() + 1, + end.getFullYear(), + end.getMonth() + 1 + ); }, hgap: c.hgap, vgap: c.vgap, diff --git a/src/widget/yearquarter/trigger.yearquarter.js b/src/widget/yearquarter/trigger.yearquarter.js index eb807eff27..2d4a3f06e2 100644 --- a/src/widget/yearquarter/trigger.yearquarter.js +++ b/src/widget/yearquarter/trigger.yearquarter.js @@ -75,12 +75,25 @@ BI.DynamicYearQuarterTrigger = BI.inherit(BI.Trigger, { return false; }, errorText: function (v) { - return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + var year = isYear ? v : self.yearEditor.getValue(); + var quarter = isYear ? self.quarterEditor.getValue() : v; + if (!BI.isPositiveInteger(year) || !BI.isPositiveInteger(quarter) || quarter > 4) { + return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + } + + var start = BI.parseDateTime(o.min, "%Y-%X-%d"); + var end = BI.parseDateTime(o.max, "%Y-%X-%d"); + + return BI.i18nText("BI-Basic_Year_Quarter_Range_Error", + start.getFullYear(), + BI.getQuarter(start), + end.getFullYear(), + BI.getQuarter(end) + ); }, watermark: BI.i18nText("BI-Basic_Unrestricted"), hgap: c.hgap, vgap: c.vgap, - title: "", allowBlank: true }); editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () {