From 4b79c55b778ca3474701fa8de46928d923c2c19c Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 9 May 2019 19:05:42 +0800 Subject: [PATCH 1/3] =?UTF-8?q?BI-43293=20feat:=20=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=AF=B9=E6=97=A5=E6=9C=9F=E6=8E=A7=E4=BB=B6=E7=9A=84=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/js/widget/date/demo.multidate_combo.js | 27 ++++--- src/widget/dynamicdate/dynamicdate.combo.js | 4 +- src/widget/dynamicdate/dynamicdate.trigger.js | 76 ++++++++++++++---- .../dynamicdatetime/dynamicdatetime.combo.js | 4 +- .../dynamicdatetime.trigger.js | 80 +++++++++++++++---- 5 files changed, 150 insertions(+), 41 deletions(-) diff --git a/demo/js/widget/date/demo.multidate_combo.js b/demo/js/widget/date/demo.multidate_combo.js index 6f40ce804..69262b9a8 100644 --- a/demo/js/widget/date/demo.multidate_combo.js +++ b/demo/js/widget/date/demo.multidate_combo.js @@ -20,15 +20,24 @@ Demo.Date = BI.inherit(BI.Widget, { ref: function () { self.datecombo = this; }, - width: 300 - // value: { - // type: 1, - // value: { - // year: 2018, - // month: 2, - // day: 23 - // } - // } + width: 300, + // format: "%Y-%X-%d", // yyyy-MM-dd + // format: "%Y/%X/%d", // yyyy/MM/dd + // format: "%Y-%x-%e", // yyyy-M-d + // format: "%Y/%x/%e", // yyyy/M/d + // format: "%X/%d/%Y", // MM/dd/yyyy + // format: "%X/%e/%y", // MM/d/yy + // format: "%X.%d.%Y", // MM.dd.yyyy + // format: "%X.%e.%Y", // MM.d.yyyy + // format: "%X-%e-%y", // MM.d.yyyy + value: { + type: 1, + value: { + year: 2018, + month: 2, + day: 23 + } + } }, { type: "bi.button", text: "getValue", diff --git a/src/widget/dynamicdate/dynamicdate.combo.js b/src/widget/dynamicdate/dynamicdate.combo.js index 473abc11c..bc814ad6f 100644 --- a/src/widget/dynamicdate/dynamicdate.combo.js +++ b/src/widget/dynamicdate/dynamicdate.combo.js @@ -10,7 +10,8 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, { baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius", height: 22, minDate: "1900-01-01", - maxDate: "2099-12-31" + maxDate: "2099-12-31", + format: "%Y-%X-%d" }, @@ -48,6 +49,7 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, { type: "bi.dynamic_date_trigger", min: opts.minDate, max: opts.maxDate, + format: opts.format, height: opts.height, value: opts.value, ref: function () { diff --git a/src/widget/dynamicdate/dynamicdate.trigger.js b/src/widget/dynamicdate/dynamicdate.trigger.js index 1b71e0492..e2f695457 100644 --- a/src/widget/dynamicdate/dynamicdate.trigger.js +++ b/src/widget/dynamicdate/dynamicdate.trigger.js @@ -4,14 +4,16 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { vgap: 2, yearLength: 4, yearMonthLength: 6, - yearFullMonthLength: 7 + yearFullMonthLength: 7, + compareFormat: "%Y-%X-%d" }, props: { extraCls: "bi-date-trigger", min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 - height: 24 + height: 24, + format: "" // 显示的日期格式化方式 }, _init: function () { @@ -22,9 +24,10 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { type: "bi.sign_editor", height: o.height, validationChecker: function (v) { - var date = v.match(/\d+/g); - self._autoAppend(v, date); - return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ + var formatStr = self._getStandardDateStr(v); + var date = formatStr.match(/\d+/g); + !BI.isKey(o.format) && self._autoAppend(v, date); + return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({ year: date[0] | 0, month: date[1] | 0, day: date[2] | 0 @@ -38,10 +41,11 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { allowBlank: true, watermark: BI.i18nText("BI-Basic_Unrestricted"), errorText: function () { - if (self.editor.isEditing()) { - return BI.i18nText("BI-Date_Trigger_Error_Text"); + 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"); } - return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + return str; }, title: function () { var storeValue = self.storeValue || {}; @@ -52,14 +56,14 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { var text = self._getText(value); var date = BI.getDate(); date = BI.DynamicDateHelper.getCalculation(value); - var dateStr = BI.print(date, "%Y-%X-%d"); + var dateStr = BI.print(date, self._getFormatString()); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); case BI.DynamicDateCombo.Static: default: if (BI.isNull(value) || BI.isNull(value.day)) { return ""; } - return BI.print(BI.getDate(value.year, (value.month - 1), value.day), "%Y-%X-%d"); + return BI.print(BI.getDate(value.year, (value.month - 1), value.day), self._getFormatString()); } } }); @@ -86,7 +90,8 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { } if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { - var date = value.split("-"); + var formatStr = self._getStandardDateStr(value); + var date = formatStr.match(/\d+/g); self.storeValue = { type: BI.DynamicDateCombo.Static, value: { @@ -121,6 +126,45 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { }); this.setValue(o.value); }, + + _getStandardDateStr: function (v) { + var c = this._const; + var result = [0, 1, 2]; + var formatArray = this._getFormatString().match(/%./g); + BI.each(formatArray, function (idx, v) { + switch (v) { + case "%Y": + case "%y": + result[0] = idx; + break; + case "%X": + case "%x": + result[1] = idx; + break; + case "%d": + case "%e": + default: + result[2] = idx; + break; + } + }); + var dateArray = v.match(/\d+/g); + var newArray = []; + BI.each(dateArray, function (idx) { + newArray[idx] = dateArray[result[idx]]; + }); + // 这边之所以不直接返回join结果是因为年的格式可能只有2位,所以需要format一下 + if(newArray.length === result.length && newArray[0].length === 2) { + return BI.print(BI.parseDateTime(newArray.join("-"), c.compareFormat), c.compareFormat); + } + // 这边format成-20-也没关系, 反正都是不合法的 + return newArray.join("-"); + }, + + _getFormatString: function () { + return this.options.format || this._const.compareFormat; + }, + _dateCheck: function (date) { return BI.print(BI.parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === date || BI.print(BI.parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date || @@ -150,19 +194,19 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { }, _yearCheck: function (v) { - var date = BI.print(BI.parseDateTime(v, "%Y-%X-%d"), "%Y-%X-%d"); + var date = BI.print(BI.parseDateTime(v, this._getFormatString()), this._const.compareFormat); return BI.print(BI.parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max; }, _monthCheck: function (v) { - var date = BI.parseDateTime(v, "%Y-%X-%d"); - var dateStr = BI.print(date, "%Y-%X-%d"); + var date = BI.parseDateTime(v, this._getFormatString()); + var dateStr = BI.print(date, this._const.compareFormat); return (date.getMonth() >= 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; }, _setInnerValue: function (date) { - var dateStr = BI.print(date, "%Y-%X-%d"); + var dateStr = BI.print(date, this._getFormatString()); this.editor.setState(dateStr); this.editor.setValue(dateStr); }, @@ -238,7 +282,7 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { this.editor.setState(""); this.editor.setValue(""); } else { - var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day), "%Y-%X-%d"); + var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day), this._getFormatString()); this.editor.setState(dateStr); this.editor.setValue(dateStr); } diff --git a/src/widget/dynamicdatetime/dynamicdatetime.combo.js b/src/widget/dynamicdatetime/dynamicdatetime.combo.js index 09536bed3..b410aea3e 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.combo.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.combo.js @@ -10,7 +10,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, { baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow", height: 22, minDate: "1900-01-01", - maxDate: "2099-12-31" + maxDate: "2099-12-31", + format: "%Y-%X-%d" }, @@ -48,6 +49,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, { type: "bi.dynamic_date_time_trigger", min: opts.minDate, max: opts.maxDate, + format: opts.format, height: opts.height, value: opts.value, ref: function () { diff --git a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js index 378a9628b..2df12beca 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js @@ -4,14 +4,16 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { vgap: 2, yearLength: 4, yearMonthLength: 6, - yearFullMonthLength: 7 + yearFullMonthLength: 7, + compareFormat: "%Y-%X-%d %H:%M:%S" }, props: { extraCls: "bi-date-time-trigger", min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 - height: 24 + height: 24, + format: "%Y-%X-%d %H:%M:%S" // 显示的日期格式化方式 }, _init: function () { @@ -22,9 +24,10 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { type: "bi.sign_editor", height: o.height, validationChecker: function (v) { - var date = v.match(/\d+/g); - self._autoAppend(v, date); - return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ + var formatStr = self._getStandardDateStr(v); + var date = formatStr.match(/\d+/g); + self._isDefaultDateFormat() && self._autoAppend(v, date); + return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({ year: date[0] | 0, month: date[1] | 0, day: date[2] | 0 @@ -38,10 +41,11 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { allowBlank: true, watermark: BI.i18nText("BI-Basic_Unrestricted"), errorText: function () { - if (self.editor.isEditing()) { - return BI.i18nText("BI-Basic_Date_Time_Error_Text"); + var str = ""; + if (self._isDefaultDateFormat()) { + str = self.editor.isEditing() ? BI.i18nText("BI-Basic_Date_Time_Error_Text") : BI.i18nText("BI-Year_Trigger_Invalid_Text"); } - return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + return str; }, title: function () { var storeValue = self.storeValue || {}; @@ -51,7 +55,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { case BI.DynamicDateCombo.Dynamic: var text = self._getText(value); var date = BI.DynamicDateHelper.getCalculation(value); - var dateStr = BI.print(date, "%Y-%x-%e %H:%M:%S"); + var dateStr = BI.print(date, o.format); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); case BI.DynamicDateCombo.Static: default: @@ -59,7 +63,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { return ""; } return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, - value.second || 0), "%Y-%X-%d %H:%M:%S"); + value.second || 0), o.format); } } }); @@ -86,7 +90,8 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { } if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { - var date = value.split(/-|\s|:/); + var formatStr = self._getStandardDateStr(value); + var date = formatStr.match(/\d+/g); self.storeValue = { type: BI.DynamicDateCombo.Static, value: { @@ -119,8 +124,55 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { }); this.setValue(o.value); }, + + _isDefaultDateFormat: function () { + return this.options.format === this._const.compareFormat; + }, + + _getStandardDateStr: function (v) { + var result = [0, 1, 2, 3, 4, 5]; + var formatArray = this.options.format.match(/%./g); + BI.each(formatArray, function (idx, v) { + switch (v) { + case "%Y": + case "%y": + result[0] = idx; + break; + case "%X": + case "%x": + result[1] = idx; + break; + case "%d": + case "%e": + result[2] = idx; + break; + case "%H": + case "%h": + result[3] = idx; + break; + case "%M": + case "%m": + result[4] = idx; + break; + case "%S": + case "%s": + default: + result[5] = idx; + break; + } + }); + var dateArray = v.match(/\d+/g); + var newArray = []; + BI.each(dateArray, function (idx) { + newArray[idx] = dateArray[result[idx]]; + }); + return newArray.slice(0, 3).join("-") + " " + newArray.slice(3).join(":"); + }, + _dateCheck: function (date) { - return BI.print(BI.parseDateTime(date, "%Y-%x-%d %H:%M:%S"), "%Y-%x-%d %H:%M:%S") === date || + var o = this.options; + return BI.print(BI.parseDateTime(date, o.format), o.format) === date || + BI.print(BI.parseDateTime(date, "%Y-%x-%d %H:%M:%S"), "%Y-%x-%d %H:%M:%S") === date || BI.print(BI.parseDateTime(date, "%Y-%X-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date || BI.print(BI.parseDateTime(date, "%Y-%x-%e %H:%M:%S"), "%Y-%x-%e %H:%M:%S") === date || BI.print(BI.parseDateTime(date, "%Y-%X-%e %H:%M:%S"), "%Y-%X-%e %H:%M:%S") === date || @@ -158,7 +210,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { }, _monthCheck: function (v) { - var date = BI.parseDateTime(v, "%Y-%X-%d"); + var date = BI.parseDateTime(v, this.options.format); var dateStr = BI.print(date, "%Y-%X-%d"); return (date.getMonth() > 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; @@ -242,7 +294,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { this.editor.setValue(""); } else { var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, - value.second || 0), "%Y-%X-%d %H:%M:%S"); + value.second || 0), this.options.format); this.editor.setState(dateStr); this.editor.setValue(dateStr); } From 857315e6912a05447772f5f5da002221ebcf81b8 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Fri, 10 May 2019 11:40:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?KERNEL-551=20feat:=20=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E5=92=8C=E6=97=B6=E9=97=B4=E6=8E=A7=E4=BB=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=8C=83=E5=9B=B4=E5=92=8C=E8=87=AA=E5=AE=9A=E4=B9=89=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 4 ++ src/core/func/date.js | 4 +- src/widget/dynamicdate/dynamicdate.combo.js | 2 +- .../dynamicdatetime/dynamicdatetime.combo.js | 2 +- .../dynamicdatetime.trigger.js | 60 ++++++++++--------- 5 files changed, 40 insertions(+), 32 deletions(-) diff --git a/changelog.md b/changelog.md index 3caf08032..75ef9bf55 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,8 @@ # 更新日志 +2.0(2019-05) +- 日期/时间/日期区间/时间区间支持自定义日期选择范围 +- 日期/时间/日期区间/时间区间支持自定义日期显示格式 + 2.0(2019-04) - 新增`bi.multi_tree_list_combo`控件, 此下拉树勾选节点时不会影响父子节点的勾选状态 - 新增`bi.multi_tree_insert_combo`控件, 此下拉树可以插入不存在的新值 diff --git a/src/core/func/date.js b/src/core/func/date.js index 690d868ac..14d1a39bb 100644 --- a/src/core/func/date.js +++ b/src/core/func/date.js @@ -171,8 +171,8 @@ _.extend(BI, { s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) s["%I"] = (ir < 10) ? ("0" + ir) : ir; // hour, range 01 to 12 (12h format) s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy; // day of the year (range 001 to 366) - s["%k"] = hr; // hour, range 0 to 23 (24h format) - s["%l"] = ir; // hour, range 1 to 12 (12h format) + s["%k"] = hr + ""; // hour, range 0 to 23 (24h format) + s["%l"] = ir + ""; // hour, range 1 to 12 (12h format) s["%X"] = (m < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12 s["%x"] = m + 1; // month, range 1 to 12 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 diff --git a/src/widget/dynamicdate/dynamicdate.combo.js b/src/widget/dynamicdate/dynamicdate.combo.js index bc814ad6f..e53ad57c5 100644 --- a/src/widget/dynamicdate/dynamicdate.combo.js +++ b/src/widget/dynamicdate/dynamicdate.combo.js @@ -11,7 +11,7 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, { height: 22, minDate: "1900-01-01", maxDate: "2099-12-31", - format: "%Y-%X-%d" + format: "" }, diff --git a/src/widget/dynamicdatetime/dynamicdatetime.combo.js b/src/widget/dynamicdatetime/dynamicdatetime.combo.js index b410aea3e..531e18f98 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.combo.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.combo.js @@ -11,7 +11,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, { height: 22, minDate: "1900-01-01", maxDate: "2099-12-31", - format: "%Y-%X-%d" + format: "" }, diff --git a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js index 2df12beca..819302b45 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js @@ -13,7 +13,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 height: 24, - format: "%Y-%X-%d %H:%M:%S" // 显示的日期格式化方式 + format: "" // 显示的日期格式化方式 }, _init: function () { @@ -26,7 +26,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { validationChecker: function (v) { var formatStr = self._getStandardDateStr(v); var date = formatStr.match(/\d+/g); - self._isDefaultDateFormat() && self._autoAppend(v, date); + !BI.isKey(o.format) && self._autoAppend(v, date); return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({ year: date[0] | 0, month: date[1] | 0, @@ -42,7 +42,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { watermark: BI.i18nText("BI-Basic_Unrestricted"), errorText: function () { var str = ""; - if (self._isDefaultDateFormat()) { + if (BI.isKey(o.format)) { str = self.editor.isEditing() ? BI.i18nText("BI-Basic_Date_Time_Error_Text") : BI.i18nText("BI-Year_Trigger_Invalid_Text"); } return str; @@ -55,7 +55,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { case BI.DynamicDateCombo.Dynamic: var text = self._getText(value); var date = BI.DynamicDateHelper.getCalculation(value); - var dateStr = BI.print(date, o.format); + var dateStr = BI.print(date, self._getFormatString()); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); case BI.DynamicDateCombo.Static: default: @@ -63,7 +63,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { return ""; } return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, - value.second || 0), o.format); + value.second || 0), self._getFormatString()); } } }); @@ -125,13 +125,10 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { this.setValue(o.value); }, - _isDefaultDateFormat: function () { - return this.options.format === this._const.compareFormat; - }, - _getStandardDateStr: function (v) { - var result = [0, 1, 2, 3, 4, 5]; - var formatArray = this.options.format.match(/%./g); + var result = []; + var hasSecond = false; + var formatArray = this._getFormatString().match(/%./g); BI.each(formatArray, function (idx, v) { switch (v) { case "%Y": @@ -146,33 +143,40 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { case "%e": result[2] = idx; break; - case "%H": - case "%h": - result[3] = idx; - break; - case "%M": - case "%m": - result[4] = idx; - break; case "%S": - case "%s": + hasSecond = true; + break; default: - result[5] = idx; break; } }); + var dateArray = v.match(/\d+/g); var newArray = []; - BI.each(dateArray, function (idx) { + // 处理乱序的年月日 + BI.each(dateArray.slice(0, 3), function (idx) { newArray[idx] = dateArray[result[idx]]; }); - return newArray.slice(0, 3).join("-") + " " + newArray.slice(3).join(":"); + // 拼接时分秒和pm + var suffixArray = dateArray.slice(3); + // hh:mm + if(suffixArray.length === 2 && !hasSecond) { + suffixArray.push("00"); + } + var suffixString = suffixArray.join(":"); + var dateString = newArray.slice(0, 3).join("-"); + if (BI.isNotEmptyString(suffixString)) { + dateString += " " + suffixString; + } + return dateString; + }, + + _getFormatString: function () { + return this.options.format || this._const.compareFormat; }, _dateCheck: function (date) { - var o = this.options; - return BI.print(BI.parseDateTime(date, o.format), o.format) === date || - BI.print(BI.parseDateTime(date, "%Y-%x-%d %H:%M:%S"), "%Y-%x-%d %H:%M:%S") === date || + return BI.print(BI.parseDateTime(date, "%Y-%x-%d %H:%M:%S"), "%Y-%x-%d %H:%M:%S") === date || BI.print(BI.parseDateTime(date, "%Y-%X-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date || BI.print(BI.parseDateTime(date, "%Y-%x-%e %H:%M:%S"), "%Y-%x-%e %H:%M:%S") === date || BI.print(BI.parseDateTime(date, "%Y-%X-%e %H:%M:%S"), "%Y-%X-%e %H:%M:%S") === date || @@ -217,7 +221,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { }, _setInnerValue: function (date) { - var dateStr = BI.print(date, "%Y-%X-%e %H:%M:%S"); + var dateStr = BI.print(date, this._getFormatString()); this.editor.setState(dateStr); this.editor.setValue(dateStr); }, @@ -294,7 +298,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { this.editor.setValue(""); } else { var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, - value.second || 0), this.options.format); + value.second || 0), this._getFormatString()); this.editor.setState(dateStr); this.editor.setValue(dateStr); } From 873dec27fa941248191d4c88151a2b316e3dd2b6 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Fri, 10 May 2019 11:40:57 +0800 Subject: [PATCH 3/3] update --- demo/js/widget/date/demo.multidate_combo.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/demo/js/widget/date/demo.multidate_combo.js b/demo/js/widget/date/demo.multidate_combo.js index 69262b9a8..604a4a4ae 100644 --- a/demo/js/widget/date/demo.multidate_combo.js +++ b/demo/js/widget/date/demo.multidate_combo.js @@ -51,6 +51,24 @@ Demo.Date = BI.inherit(BI.Widget, { self.datetimecombo = this; }, width: 300, + // format: "%Y-%X-%d %H:%M:%S", // yyyy-MM-dd HH:mm:ss + // format: "%Y/%X/%d %H:%M:%S", // yyyy/MM/dd HH:mm:ss + // format: "%Y-%X-%d %I:%M:%S", // yyyy-MM-dd hh:mm:ss + // format: "%Y/%X/%d %I:%M:%S", // yyyy/MM/dd hh:mm:ss + // format: "%Y-%X-%d %H:%M:%S %p", // yyyy-MM-dd HH:mm:ss a + // format: "Y/%X/%d %H:%M:%S %p", // yyyy/MM/dd HH:mm:ss a + // format: "%Y-%X-%d %I:%M:%S %p", // yyyy-MM-dd hh:mm:ss a + // format: "%Y/%X/%d %I:%M:%S %p", // yyyy/MM/dd hh:mm:ss a + // format: "%X/%d/%Y %I:%M:%S", // MM/dd/yyyy hh:mm:ss + // format: "%X/%d/%Y %H:%M:%S", // MM/dd/yyyy HH:mm:ss + // format: "%X/%d/%Y %I:%M:%S", // MM/dd/yyyy hh:mm:ss a + // format: "%X/%d/%Y %H:%M:%S %p", // MM/dd/yyyy HH:mm:ss a + // format: "%X/%d/%Y %I:%M:%S %p", // MM/dd/yyyy hh:mm:ss a + // format: "%X/%d/%Y %H:%M:%S %p", // MM/dd/yyyy HH:mm:ss a + // format: "%X/%d/%Y %l:%M %p", // MM/dd/yyyy h:mm a + // format: "%X-%d-%Y %k:%M %p", // MM/dd/yyyy H:mm a + // format: "%Y-%x-%e %l:%M", // yyyy-M-d h:mm + // format: "%Y-%x-%e %k:%M", // yyyy-M-d H:mm value: { type: 1, value: {