From 7fa489476e7d5f00735178c84869f78599c645b7 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Fri, 10 May 2019 17:00:53 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-552=20feat:=20=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=8E=A7=E4=BB=B6=E5=85=81=E8=AE=B8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=98=AF=E5=90=A6=E5=8F=AF=E4=BB=A5=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/js/widget/date/demo.multidate_combo.js | 2 + src/widget/dynamicdate/dynamicdate.combo.js | 4 +- src/widget/dynamicdate/dynamicdate.trigger.js | 57 +++++++++++------- .../dynamicdatetime/dynamicdatetime.combo.js | 4 +- .../dynamicdatetime.trigger.js | 58 ++++++++++++------- src/widget/time/time.trigger.js | 3 +- 6 files changed, 85 insertions(+), 43 deletions(-) diff --git a/demo/js/widget/date/demo.multidate_combo.js b/demo/js/widget/date/demo.multidate_combo.js index 604a4a4aee..61b20892cc 100644 --- a/demo/js/widget/date/demo.multidate_combo.js +++ b/demo/js/widget/date/demo.multidate_combo.js @@ -21,6 +21,7 @@ Demo.Date = BI.inherit(BI.Widget, { self.datecombo = this; }, width: 300, + // allowEdit: false, // format: "%Y-%X-%d", // yyyy-MM-dd // format: "%Y/%X/%d", // yyyy/MM/dd // format: "%Y-%x-%e", // yyyy-M-d @@ -51,6 +52,7 @@ Demo.Date = BI.inherit(BI.Widget, { self.datetimecombo = this; }, width: 300, + // allowEdit: false, // 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 diff --git a/src/widget/dynamicdate/dynamicdate.combo.js b/src/widget/dynamicdate/dynamicdate.combo.js index e53ad57c50..b93cd63946 100644 --- a/src/widget/dynamicdate/dynamicdate.combo.js +++ b/src/widget/dynamicdate/dynamicdate.combo.js @@ -11,7 +11,8 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, { height: 22, minDate: "1900-01-01", maxDate: "2099-12-31", - format: "" + format: "", + allowEdit: true }, @@ -50,6 +51,7 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, { min: opts.minDate, max: opts.maxDate, format: opts.format, + allowEdit: opts.allowEdit, 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 e2f6954574..d896c45390 100644 --- a/src/widget/dynamicdate/dynamicdate.trigger.js +++ b/src/widget/dynamicdate/dynamicdate.trigger.js @@ -13,7 +13,8 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 height: 24, - format: "" // 显示的日期格式化方式 + format: "", // 显示的日期格式化方式 + allowEdit: true // 是否允许编辑 }, _init: function () { @@ -47,25 +48,7 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { } return str; }, - title: function () { - var storeValue = self.storeValue || {}; - var type = storeValue.type || BI.DynamicDateCombo.Static; - var value = storeValue.value; - switch (type) { - case BI.DynamicDateCombo.Dynamic: - var text = self._getText(value); - var date = BI.getDate(); - date = BI.DynamicDateHelper.getCalculation(value); - 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), self._getFormatString()); - } - } + title: BI.bind(this._getTitle, this) }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { self.fireEvent(BI.DynamicDateTrigger.EVENT_KEY_DOWN); @@ -124,9 +107,43 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { width: 24 }] }); + !o.allowEdit && BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: { + type: "bi.text", + title: BI.bind(this._getTitle, this) + }, + left: 0, + right: 24, + top: 0, + bottom: 0 + }] + }); this.setValue(o.value); }, + _getTitle: function () { + var storeValue = this.storeValue || {}; + var type = storeValue.type || BI.DynamicDateCombo.Static; + var value = storeValue.value; + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = this._getText(value); + var date = BI.getDate(); + date = BI.DynamicDateHelper.getCalculation(value); + var dateStr = BI.print(date, this._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), this._getFormatString()); + } + }, + _getStandardDateStr: function (v) { var c = this._const; var result = [0, 1, 2]; diff --git a/src/widget/dynamicdatetime/dynamicdatetime.combo.js b/src/widget/dynamicdatetime/dynamicdatetime.combo.js index 531e18f983..ee5e9429be 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.combo.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.combo.js @@ -11,7 +11,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, { height: 22, minDate: "1900-01-01", maxDate: "2099-12-31", - format: "" + format: "", + allowEdit: true }, @@ -49,6 +50,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, { type: "bi.dynamic_date_time_trigger", min: opts.minDate, max: opts.maxDate, + allowEdit: opts.allowEdit, format: opts.format, height: opts.height, value: opts.value, diff --git a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js index 819302b450..68e7463b19 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js @@ -13,7 +13,8 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 height: 24, - format: "" // 显示的日期格式化方式 + format: "", // 显示的日期格式化方式 + allowEdit: true // 是否允许编辑 }, _init: function () { @@ -47,25 +48,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { } return str; }, - title: function () { - var storeValue = self.storeValue || {}; - var type = storeValue.type || BI.DynamicDateCombo.Static; - var value = storeValue.value; - switch (type) { - case BI.DynamicDateCombo.Dynamic: - var text = self._getText(value); - var date = BI.DynamicDateHelper.getCalculation(value); - 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, value.hour || 0, value.minute || 0, - value.second || 0), self._getFormatString()); - } - } + title: BI.bind(this._getTitle, this) }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN); @@ -122,9 +105,44 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { width: 24 }] }); + + !o.allowEdit && BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: { + type: "bi.text", + title: BI.bind(this._getTitle, this) + }, + left: 0, + right: 24, + top: 0, + bottom: 0 + }] + }); this.setValue(o.value); }, + _getTitle: function () { + var storeValue = this.storeValue || {}; + var type = storeValue.type || BI.DynamicDateCombo.Static; + var value = storeValue.value; + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = this._getText(value); + var date = BI.DynamicDateHelper.getCalculation(value); + var dateStr = BI.print(date, this._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, value.hour || 0, value.minute || 0, + value.second || 0), this._getFormatString()); + } + }, + _getStandardDateStr: function (v) { var result = []; var hasSecond = false; diff --git a/src/widget/time/time.trigger.js b/src/widget/time/time.trigger.js index d8e99d368d..f61dfe7180 100644 --- a/src/widget/time/time.trigger.js +++ b/src/widget/time/time.trigger.js @@ -135,7 +135,8 @@ _getTitle: function () { var storeValue = this.storeValue || {}; - return BI.print(BI.getDate(storeValue.year, (storeValue.month - 1), storeValue.day), this._getFormatString()); + var date = BI.getDate(); + return BI.print(BI.getDate(date.getFullYear(), 0, 1, storeValue.hour, storeValue.minute, storeValue.second), this._getFormatString()); }, _getFormatString: function () {