Browse Source

Merge branch 'date'

# Conflicts:
#	changelog.md
es6
windy 6 years ago
parent
commit
64448c9edd
  1. 3
      changelog.md
  2. 45
      demo/js/widget/date/demo.multidate_combo.js
  3. 172
      dist/2.0/fineui.ie.js
  4. 172
      dist/2.0/fineui.js
  5. 172
      dist/bundle.ie.js
  6. 172
      dist/bundle.js
  7. 4
      dist/core.js
  8. 45
      dist/demo.js
  9. 172
      dist/fineui.ie.js
  10. 172
      dist/fineui.js
  11. 172
      dist/fineui_without_jquery_polyfill.js
  12. 4
      dist/utils.js
  13. 168
      dist/widget.js
  14. 4
      src/core/func/date.js
  15. 4
      src/widget/dynamicdate/dynamicdate.combo.js
  16. 76
      src/widget/dynamicdate/dynamicdate.trigger.js
  17. 4
      src/widget/dynamicdatetime/dynamicdatetime.combo.js
  18. 84
      src/widget/dynamicdatetime/dynamicdatetime.trigger.js

3
changelog.md

@ -1,5 +1,7 @@
# 更新日志 # 更新日志
2.0(2019-05) 2.0(2019-05)
- 日期/时间/日期区间/时间区间支持自定义日期选择范围
- 日期/时间/日期区间/时间区间支持自定义日期显示格式
- 增加less函数: 字体资源添加函数addFontRe和字体激活函数activeFont - 增加less函数: 字体资源添加函数addFontRe和字体激活函数activeFont
> @fontList: "dec", "report"; > @fontList: "dec", "report";
@ -9,7 +11,6 @@
以上即可使用自定义的dec,report字体和fineui的资源字体 以上即可使用自定义的dec,report字体和fineui的资源字体
2.0(2019-04) 2.0(2019-04)
- 新增`bi.multi_tree_list_combo`控件, 此下拉树勾选节点时不会影响父子节点的勾选状态 - 新增`bi.multi_tree_list_combo`控件, 此下拉树勾选节点时不会影响父子节点的勾选状态
- 新增`bi.multi_tree_insert_combo`控件, 此下拉树可以插入不存在的新值 - 新增`bi.multi_tree_insert_combo`控件, 此下拉树可以插入不存在的新值

45
demo/js/widget/date/demo.multidate_combo.js

@ -20,15 +20,24 @@ Demo.Date = BI.inherit(BI.Widget, {
ref: function () { ref: function () {
self.datecombo = this; self.datecombo = this;
}, },
width: 300 width: 300,
// value: { // format: "%Y-%X-%d", // yyyy-MM-dd
// type: 1, // format: "%Y/%X/%d", // yyyy/MM/dd
// value: { // format: "%Y-%x-%e", // yyyy-M-d
// year: 2018, // format: "%Y/%x/%e", // yyyy/M/d
// month: 2, // format: "%X/%d/%Y", // MM/dd/yyyy
// day: 23 // 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", type: "bi.button",
text: "getValue", text: "getValue",
@ -42,6 +51,24 @@ Demo.Date = BI.inherit(BI.Widget, {
self.datetimecombo = this; self.datetimecombo = this;
}, },
width: 300, 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: { value: {
type: 1, type: 1,
value: { value: {

172
dist/2.0/fineui.ie.js vendored

@ -18039,8 +18039,8 @@ _.extend(BI, {
s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) 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["%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["%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["%k"] = hr + ""; // hour, range 0 to 23 (24h format)
s["%l"] = ir; // hour, range 1 to 12 (12h 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 < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12
s["%x"] = m + 1; // month, range 1 to 12 s["%x"] = m + 1; // month, range 1 to 12
s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
@ -62703,7 +62703,8 @@ BI.extend(BI.DynamicDateCard, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -62741,6 +62742,7 @@ BI.extend(BI.DynamicDateCard, {
type: "bi.dynamic_date_trigger", type: "bi.dynamic_date_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -63325,14 +63327,16 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d"
}, },
props: { props: {
extraCls: "bi-date-trigger", extraCls: "bi-date-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -63343,9 +63347,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -63359,10 +63364,11 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Date_Trigger_Error_Text"); 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 () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -63373,14 +63379,14 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
var text = self._getText(value); var text = self._getText(value);
var date = BI.getDate(); var date = BI.getDate();
date = BI.DynamicDateHelper.getCalculation(value); 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); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
if (BI.isNull(value) || BI.isNull(value.day)) { if (BI.isNull(value) || BI.isNull(value.day)) {
return ""; 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());
} }
} }
}); });
@ -63407,7 +63413,8 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -63442,6 +63449,45 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}); });
this.setValue(o.value); 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) { _dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === 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 || BI.print(BI.parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date ||
@ -63471,19 +63517,19 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}, },
_yearCheck: function (v) { _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; return BI.print(BI.parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
}, },
_monthCheck: function (v) { _monthCheck: function (v) {
var date = BI.parseDateTime(v, "%Y-%X-%d"); var date = BI.parseDateTime(v, this._getFormatString());
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._const.compareFormat);
return (date.getMonth() >= 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _setInnerValue: function (date) {
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -63559,7 +63605,7 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
this.editor.setState(""); this.editor.setState("");
this.editor.setValue(""); this.editor.setValue("");
} else { } 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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }
@ -63598,7 +63644,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -63636,6 +63683,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
type: "bi.dynamic_date_time_trigger", type: "bi.dynamic_date_time_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -64330,14 +64378,16 @@ BI.extend(BI.DynamicDateTimeSelect, {
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d %H:%M:%S"
}, },
props: { props: {
extraCls: "bi-date-time-trigger", extraCls: "bi-date-time-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -64348,9 +64398,10 @@ BI.extend(BI.DynamicDateTimeSelect, {
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -64364,10 +64415,11 @@ BI.extend(BI.DynamicDateTimeSelect, {
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Basic_Date_Time_Error_Text"); 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 BI.i18nText("BI-Year_Trigger_Invalid_Text"); return str;
}, },
title: function () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -64377,7 +64429,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
case BI.DynamicDateCombo.Dynamic: case BI.DynamicDateCombo.Dynamic:
var text = self._getText(value); var text = self._getText(value);
var date = BI.DynamicDateHelper.getCalculation(value); var date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, "%Y-%x-%e %H:%M:%S"); var dateStr = BI.print(date, self._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
@ -64385,7 +64437,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
return ""; return "";
} }
return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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), self._getFormatString());
} }
} }
}); });
@ -64412,7 +64464,8 @@ BI.extend(BI.DynamicDateTimeSelect, {
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -64445,6 +64498,57 @@ BI.extend(BI.DynamicDateTimeSelect, {
}); });
this.setValue(o.value); this.setValue(o.value);
}, },
_getStandardDateStr: function (v) {
var result = [];
var hasSecond = false;
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":
result[2] = idx;
break;
case "%S":
hasSecond = true;
break;
default:
break;
}
});
var dateArray = v.match(/\d+/g);
var newArray = [];
// 处理乱序的年月日
BI.each(dateArray.slice(0, 3), function (idx) {
newArray[idx] = dateArray[result[idx]];
});
// 拼接时分秒和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) { _dateCheck: function (date) {
return 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-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date ||
@ -64484,14 +64588,14 @@ BI.extend(BI.DynamicDateTimeSelect, {
}, },
_monthCheck: function (v) { _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"); var dateStr = BI.print(date, "%Y-%X-%d");
return (date.getMonth() > 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -64568,7 +64672,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
this.editor.setValue(""); this.editor.setValue("");
} else { } else {
var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }

172
dist/2.0/fineui.js vendored

@ -18039,8 +18039,8 @@ _.extend(BI, {
s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) 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["%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["%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["%k"] = hr + ""; // hour, range 0 to 23 (24h format)
s["%l"] = ir; // hour, range 1 to 12 (12h 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 < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12
s["%x"] = m + 1; // month, range 1 to 12 s["%x"] = m + 1; // month, range 1 to 12
s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
@ -63107,7 +63107,8 @@ BI.extend(BI.DynamicDateCard, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -63145,6 +63146,7 @@ BI.extend(BI.DynamicDateCard, {
type: "bi.dynamic_date_trigger", type: "bi.dynamic_date_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -63729,14 +63731,16 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d"
}, },
props: { props: {
extraCls: "bi-date-trigger", extraCls: "bi-date-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -63747,9 +63751,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -63763,10 +63768,11 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Date_Trigger_Error_Text"); 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 () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -63777,14 +63783,14 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
var text = self._getText(value); var text = self._getText(value);
var date = BI.getDate(); var date = BI.getDate();
date = BI.DynamicDateHelper.getCalculation(value); 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); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
if (BI.isNull(value) || BI.isNull(value.day)) { if (BI.isNull(value) || BI.isNull(value.day)) {
return ""; 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());
} }
} }
}); });
@ -63811,7 +63817,8 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -63846,6 +63853,45 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}); });
this.setValue(o.value); 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) { _dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === 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 || BI.print(BI.parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date ||
@ -63875,19 +63921,19 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}, },
_yearCheck: function (v) { _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; return BI.print(BI.parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
}, },
_monthCheck: function (v) { _monthCheck: function (v) {
var date = BI.parseDateTime(v, "%Y-%X-%d"); var date = BI.parseDateTime(v, this._getFormatString());
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._const.compareFormat);
return (date.getMonth() >= 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _setInnerValue: function (date) {
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -63963,7 +64009,7 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
this.editor.setState(""); this.editor.setState("");
this.editor.setValue(""); this.editor.setValue("");
} else { } 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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }
@ -64002,7 +64048,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -64040,6 +64087,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
type: "bi.dynamic_date_time_trigger", type: "bi.dynamic_date_time_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -64734,14 +64782,16 @@ BI.extend(BI.DynamicDateTimeSelect, {
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d %H:%M:%S"
}, },
props: { props: {
extraCls: "bi-date-time-trigger", extraCls: "bi-date-time-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -64752,9 +64802,10 @@ BI.extend(BI.DynamicDateTimeSelect, {
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -64768,10 +64819,11 @@ BI.extend(BI.DynamicDateTimeSelect, {
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Basic_Date_Time_Error_Text"); 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 BI.i18nText("BI-Year_Trigger_Invalid_Text"); return str;
}, },
title: function () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -64781,7 +64833,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
case BI.DynamicDateCombo.Dynamic: case BI.DynamicDateCombo.Dynamic:
var text = self._getText(value); var text = self._getText(value);
var date = BI.DynamicDateHelper.getCalculation(value); var date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, "%Y-%x-%e %H:%M:%S"); var dateStr = BI.print(date, self._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
@ -64789,7 +64841,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
return ""; return "";
} }
return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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), self._getFormatString());
} }
} }
}); });
@ -64816,7 +64868,8 @@ BI.extend(BI.DynamicDateTimeSelect, {
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -64849,6 +64902,57 @@ BI.extend(BI.DynamicDateTimeSelect, {
}); });
this.setValue(o.value); this.setValue(o.value);
}, },
_getStandardDateStr: function (v) {
var result = [];
var hasSecond = false;
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":
result[2] = idx;
break;
case "%S":
hasSecond = true;
break;
default:
break;
}
});
var dateArray = v.match(/\d+/g);
var newArray = [];
// 处理乱序的年月日
BI.each(dateArray.slice(0, 3), function (idx) {
newArray[idx] = dateArray[result[idx]];
});
// 拼接时分秒和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) { _dateCheck: function (date) {
return 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-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date ||
@ -64888,14 +64992,14 @@ BI.extend(BI.DynamicDateTimeSelect, {
}, },
_monthCheck: function (v) { _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"); var dateStr = BI.print(date, "%Y-%X-%d");
return (date.getMonth() > 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -64972,7 +65076,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
this.editor.setValue(""); this.editor.setValue("");
} else { } else {
var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }

172
dist/bundle.ie.js vendored

@ -18039,8 +18039,8 @@ _.extend(BI, {
s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) 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["%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["%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["%k"] = hr + ""; // hour, range 0 to 23 (24h format)
s["%l"] = ir; // hour, range 1 to 12 (12h 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 < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12
s["%x"] = m + 1; // month, range 1 to 12 s["%x"] = m + 1; // month, range 1 to 12
s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
@ -62703,7 +62703,8 @@ BI.extend(BI.DynamicDateCard, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -62741,6 +62742,7 @@ BI.extend(BI.DynamicDateCard, {
type: "bi.dynamic_date_trigger", type: "bi.dynamic_date_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -63325,14 +63327,16 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d"
}, },
props: { props: {
extraCls: "bi-date-trigger", extraCls: "bi-date-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -63343,9 +63347,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -63359,10 +63364,11 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Date_Trigger_Error_Text"); 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 () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -63373,14 +63379,14 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
var text = self._getText(value); var text = self._getText(value);
var date = BI.getDate(); var date = BI.getDate();
date = BI.DynamicDateHelper.getCalculation(value); 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); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
if (BI.isNull(value) || BI.isNull(value.day)) { if (BI.isNull(value) || BI.isNull(value.day)) {
return ""; 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());
} }
} }
}); });
@ -63407,7 +63413,8 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -63442,6 +63449,45 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}); });
this.setValue(o.value); 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) { _dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === 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 || BI.print(BI.parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date ||
@ -63471,19 +63517,19 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}, },
_yearCheck: function (v) { _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; return BI.print(BI.parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
}, },
_monthCheck: function (v) { _monthCheck: function (v) {
var date = BI.parseDateTime(v, "%Y-%X-%d"); var date = BI.parseDateTime(v, this._getFormatString());
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._const.compareFormat);
return (date.getMonth() >= 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _setInnerValue: function (date) {
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -63559,7 +63605,7 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
this.editor.setState(""); this.editor.setState("");
this.editor.setValue(""); this.editor.setValue("");
} else { } 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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }
@ -63598,7 +63644,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -63636,6 +63683,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
type: "bi.dynamic_date_time_trigger", type: "bi.dynamic_date_time_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -64330,14 +64378,16 @@ BI.extend(BI.DynamicDateTimeSelect, {
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d %H:%M:%S"
}, },
props: { props: {
extraCls: "bi-date-time-trigger", extraCls: "bi-date-time-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -64348,9 +64398,10 @@ BI.extend(BI.DynamicDateTimeSelect, {
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -64364,10 +64415,11 @@ BI.extend(BI.DynamicDateTimeSelect, {
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Basic_Date_Time_Error_Text"); 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 BI.i18nText("BI-Year_Trigger_Invalid_Text"); return str;
}, },
title: function () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -64377,7 +64429,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
case BI.DynamicDateCombo.Dynamic: case BI.DynamicDateCombo.Dynamic:
var text = self._getText(value); var text = self._getText(value);
var date = BI.DynamicDateHelper.getCalculation(value); var date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, "%Y-%x-%e %H:%M:%S"); var dateStr = BI.print(date, self._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
@ -64385,7 +64437,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
return ""; return "";
} }
return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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), self._getFormatString());
} }
} }
}); });
@ -64412,7 +64464,8 @@ BI.extend(BI.DynamicDateTimeSelect, {
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -64445,6 +64498,57 @@ BI.extend(BI.DynamicDateTimeSelect, {
}); });
this.setValue(o.value); this.setValue(o.value);
}, },
_getStandardDateStr: function (v) {
var result = [];
var hasSecond = false;
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":
result[2] = idx;
break;
case "%S":
hasSecond = true;
break;
default:
break;
}
});
var dateArray = v.match(/\d+/g);
var newArray = [];
// 处理乱序的年月日
BI.each(dateArray.slice(0, 3), function (idx) {
newArray[idx] = dateArray[result[idx]];
});
// 拼接时分秒和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) { _dateCheck: function (date) {
return 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-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date ||
@ -64484,14 +64588,14 @@ BI.extend(BI.DynamicDateTimeSelect, {
}, },
_monthCheck: function (v) { _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"); var dateStr = BI.print(date, "%Y-%X-%d");
return (date.getMonth() > 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -64568,7 +64672,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
this.editor.setValue(""); this.editor.setValue("");
} else { } else {
var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }

172
dist/bundle.js vendored

@ -18039,8 +18039,8 @@ _.extend(BI, {
s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) 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["%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["%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["%k"] = hr + ""; // hour, range 0 to 23 (24h format)
s["%l"] = ir; // hour, range 1 to 12 (12h 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 < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12
s["%x"] = m + 1; // month, range 1 to 12 s["%x"] = m + 1; // month, range 1 to 12
s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
@ -63107,7 +63107,8 @@ BI.extend(BI.DynamicDateCard, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -63145,6 +63146,7 @@ BI.extend(BI.DynamicDateCard, {
type: "bi.dynamic_date_trigger", type: "bi.dynamic_date_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -63729,14 +63731,16 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d"
}, },
props: { props: {
extraCls: "bi-date-trigger", extraCls: "bi-date-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -63747,9 +63751,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -63763,10 +63768,11 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Date_Trigger_Error_Text"); 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 () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -63777,14 +63783,14 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
var text = self._getText(value); var text = self._getText(value);
var date = BI.getDate(); var date = BI.getDate();
date = BI.DynamicDateHelper.getCalculation(value); 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); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
if (BI.isNull(value) || BI.isNull(value.day)) { if (BI.isNull(value) || BI.isNull(value.day)) {
return ""; 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());
} }
} }
}); });
@ -63811,7 +63817,8 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -63846,6 +63853,45 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}); });
this.setValue(o.value); 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) { _dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === 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 || BI.print(BI.parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date ||
@ -63875,19 +63921,19 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}, },
_yearCheck: function (v) { _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; return BI.print(BI.parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
}, },
_monthCheck: function (v) { _monthCheck: function (v) {
var date = BI.parseDateTime(v, "%Y-%X-%d"); var date = BI.parseDateTime(v, this._getFormatString());
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._const.compareFormat);
return (date.getMonth() >= 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _setInnerValue: function (date) {
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -63963,7 +64009,7 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
this.editor.setState(""); this.editor.setState("");
this.editor.setValue(""); this.editor.setValue("");
} else { } 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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }
@ -64002,7 +64048,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -64040,6 +64087,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
type: "bi.dynamic_date_time_trigger", type: "bi.dynamic_date_time_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -64734,14 +64782,16 @@ BI.extend(BI.DynamicDateTimeSelect, {
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d %H:%M:%S"
}, },
props: { props: {
extraCls: "bi-date-time-trigger", extraCls: "bi-date-time-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -64752,9 +64802,10 @@ BI.extend(BI.DynamicDateTimeSelect, {
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -64768,10 +64819,11 @@ BI.extend(BI.DynamicDateTimeSelect, {
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Basic_Date_Time_Error_Text"); 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 BI.i18nText("BI-Year_Trigger_Invalid_Text"); return str;
}, },
title: function () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -64781,7 +64833,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
case BI.DynamicDateCombo.Dynamic: case BI.DynamicDateCombo.Dynamic:
var text = self._getText(value); var text = self._getText(value);
var date = BI.DynamicDateHelper.getCalculation(value); var date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, "%Y-%x-%e %H:%M:%S"); var dateStr = BI.print(date, self._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
@ -64789,7 +64841,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
return ""; return "";
} }
return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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), self._getFormatString());
} }
} }
}); });
@ -64816,7 +64868,8 @@ BI.extend(BI.DynamicDateTimeSelect, {
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -64849,6 +64902,57 @@ BI.extend(BI.DynamicDateTimeSelect, {
}); });
this.setValue(o.value); this.setValue(o.value);
}, },
_getStandardDateStr: function (v) {
var result = [];
var hasSecond = false;
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":
result[2] = idx;
break;
case "%S":
hasSecond = true;
break;
default:
break;
}
});
var dateArray = v.match(/\d+/g);
var newArray = [];
// 处理乱序的年月日
BI.each(dateArray.slice(0, 3), function (idx) {
newArray[idx] = dateArray[result[idx]];
});
// 拼接时分秒和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) { _dateCheck: function (date) {
return 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-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date ||
@ -64888,14 +64992,14 @@ BI.extend(BI.DynamicDateTimeSelect, {
}, },
_monthCheck: function (v) { _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"); var dateStr = BI.print(date, "%Y-%X-%d");
return (date.getMonth() > 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -64972,7 +65076,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
this.editor.setValue(""); this.editor.setValue("");
} else { } else {
var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }

4
dist/core.js vendored

@ -18039,8 +18039,8 @@ _.extend(BI, {
s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) 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["%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["%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["%k"] = hr + ""; // hour, range 0 to 23 (24h format)
s["%l"] = ir; // hour, range 1 to 12 (12h 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 < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12
s["%x"] = m + 1; // month, range 1 to 12 s["%x"] = m + 1; // month, range 1 to 12
s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59

45
dist/demo.js vendored

@ -8861,15 +8861,24 @@ Demo.Date = BI.inherit(BI.Widget, {
ref: function () { ref: function () {
self.datecombo = this; self.datecombo = this;
}, },
width: 300 width: 300,
// value: { // format: "%Y-%X-%d", // yyyy-MM-dd
// type: 1, // format: "%Y/%X/%d", // yyyy/MM/dd
// value: { // format: "%Y-%x-%e", // yyyy-M-d
// year: 2018, // format: "%Y/%x/%e", // yyyy/M/d
// month: 2, // format: "%X/%d/%Y", // MM/dd/yyyy
// day: 23 // 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", type: "bi.button",
text: "getValue", text: "getValue",
@ -8883,6 +8892,24 @@ Demo.Date = BI.inherit(BI.Widget, {
self.datetimecombo = this; self.datetimecombo = this;
}, },
width: 300, 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: { value: {
type: 1, type: 1,
value: { value: {

172
dist/fineui.ie.js vendored

@ -18284,8 +18284,8 @@ _.extend(BI, {
s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) 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["%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["%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["%k"] = hr + ""; // hour, range 0 to 23 (24h format)
s["%l"] = ir; // hour, range 1 to 12 (12h 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 < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12
s["%x"] = m + 1; // month, range 1 to 12 s["%x"] = m + 1; // month, range 1 to 12
s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
@ -62948,7 +62948,8 @@ BI.extend(BI.DynamicDateCard, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -62986,6 +62987,7 @@ BI.extend(BI.DynamicDateCard, {
type: "bi.dynamic_date_trigger", type: "bi.dynamic_date_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -63570,14 +63572,16 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d"
}, },
props: { props: {
extraCls: "bi-date-trigger", extraCls: "bi-date-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -63588,9 +63592,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -63604,10 +63609,11 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Date_Trigger_Error_Text"); 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 () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -63618,14 +63624,14 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
var text = self._getText(value); var text = self._getText(value);
var date = BI.getDate(); var date = BI.getDate();
date = BI.DynamicDateHelper.getCalculation(value); 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); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
if (BI.isNull(value) || BI.isNull(value.day)) { if (BI.isNull(value) || BI.isNull(value.day)) {
return ""; 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());
} }
} }
}); });
@ -63652,7 +63658,8 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -63687,6 +63694,45 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}); });
this.setValue(o.value); 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) { _dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === 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 || BI.print(BI.parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date ||
@ -63716,19 +63762,19 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}, },
_yearCheck: function (v) { _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; return BI.print(BI.parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
}, },
_monthCheck: function (v) { _monthCheck: function (v) {
var date = BI.parseDateTime(v, "%Y-%X-%d"); var date = BI.parseDateTime(v, this._getFormatString());
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._const.compareFormat);
return (date.getMonth() >= 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _setInnerValue: function (date) {
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -63804,7 +63850,7 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
this.editor.setState(""); this.editor.setState("");
this.editor.setValue(""); this.editor.setValue("");
} else { } 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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }
@ -63843,7 +63889,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -63881,6 +63928,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
type: "bi.dynamic_date_time_trigger", type: "bi.dynamic_date_time_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -64575,14 +64623,16 @@ BI.extend(BI.DynamicDateTimeSelect, {
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d %H:%M:%S"
}, },
props: { props: {
extraCls: "bi-date-time-trigger", extraCls: "bi-date-time-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -64593,9 +64643,10 @@ BI.extend(BI.DynamicDateTimeSelect, {
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -64609,10 +64660,11 @@ BI.extend(BI.DynamicDateTimeSelect, {
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Basic_Date_Time_Error_Text"); 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 BI.i18nText("BI-Year_Trigger_Invalid_Text"); return str;
}, },
title: function () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -64622,7 +64674,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
case BI.DynamicDateCombo.Dynamic: case BI.DynamicDateCombo.Dynamic:
var text = self._getText(value); var text = self._getText(value);
var date = BI.DynamicDateHelper.getCalculation(value); var date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, "%Y-%x-%e %H:%M:%S"); var dateStr = BI.print(date, self._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
@ -64630,7 +64682,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
return ""; return "";
} }
return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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), self._getFormatString());
} }
} }
}); });
@ -64657,7 +64709,8 @@ BI.extend(BI.DynamicDateTimeSelect, {
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -64690,6 +64743,57 @@ BI.extend(BI.DynamicDateTimeSelect, {
}); });
this.setValue(o.value); this.setValue(o.value);
}, },
_getStandardDateStr: function (v) {
var result = [];
var hasSecond = false;
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":
result[2] = idx;
break;
case "%S":
hasSecond = true;
break;
default:
break;
}
});
var dateArray = v.match(/\d+/g);
var newArray = [];
// 处理乱序的年月日
BI.each(dateArray.slice(0, 3), function (idx) {
newArray[idx] = dateArray[result[idx]];
});
// 拼接时分秒和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) { _dateCheck: function (date) {
return 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-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date ||
@ -64729,14 +64833,14 @@ BI.extend(BI.DynamicDateTimeSelect, {
}, },
_monthCheck: function (v) { _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"); var dateStr = BI.print(date, "%Y-%X-%d");
return (date.getMonth() > 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -64813,7 +64917,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
this.editor.setValue(""); this.editor.setValue("");
} else { } else {
var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }

172
dist/fineui.js vendored

@ -18284,8 +18284,8 @@ _.extend(BI, {
s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) 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["%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["%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["%k"] = hr + ""; // hour, range 0 to 23 (24h format)
s["%l"] = ir; // hour, range 1 to 12 (12h 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 < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12
s["%x"] = m + 1; // month, range 1 to 12 s["%x"] = m + 1; // month, range 1 to 12
s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
@ -63352,7 +63352,8 @@ BI.extend(BI.DynamicDateCard, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -63390,6 +63391,7 @@ BI.extend(BI.DynamicDateCard, {
type: "bi.dynamic_date_trigger", type: "bi.dynamic_date_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -63974,14 +63976,16 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d"
}, },
props: { props: {
extraCls: "bi-date-trigger", extraCls: "bi-date-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -63992,9 +63996,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -64008,10 +64013,11 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Date_Trigger_Error_Text"); 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 () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -64022,14 +64028,14 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
var text = self._getText(value); var text = self._getText(value);
var date = BI.getDate(); var date = BI.getDate();
date = BI.DynamicDateHelper.getCalculation(value); 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); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
if (BI.isNull(value) || BI.isNull(value.day)) { if (BI.isNull(value) || BI.isNull(value.day)) {
return ""; 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());
} }
} }
}); });
@ -64056,7 +64062,8 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -64091,6 +64098,45 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}); });
this.setValue(o.value); 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) { _dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === 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 || BI.print(BI.parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date ||
@ -64120,19 +64166,19 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}, },
_yearCheck: function (v) { _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; return BI.print(BI.parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
}, },
_monthCheck: function (v) { _monthCheck: function (v) {
var date = BI.parseDateTime(v, "%Y-%X-%d"); var date = BI.parseDateTime(v, this._getFormatString());
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._const.compareFormat);
return (date.getMonth() >= 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _setInnerValue: function (date) {
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -64208,7 +64254,7 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
this.editor.setState(""); this.editor.setState("");
this.editor.setValue(""); this.editor.setValue("");
} else { } 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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }
@ -64247,7 +64293,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -64285,6 +64332,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
type: "bi.dynamic_date_time_trigger", type: "bi.dynamic_date_time_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -64979,14 +65027,16 @@ BI.extend(BI.DynamicDateTimeSelect, {
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d %H:%M:%S"
}, },
props: { props: {
extraCls: "bi-date-time-trigger", extraCls: "bi-date-time-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -64997,9 +65047,10 @@ BI.extend(BI.DynamicDateTimeSelect, {
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -65013,10 +65064,11 @@ BI.extend(BI.DynamicDateTimeSelect, {
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Basic_Date_Time_Error_Text"); 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 BI.i18nText("BI-Year_Trigger_Invalid_Text"); return str;
}, },
title: function () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -65026,7 +65078,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
case BI.DynamicDateCombo.Dynamic: case BI.DynamicDateCombo.Dynamic:
var text = self._getText(value); var text = self._getText(value);
var date = BI.DynamicDateHelper.getCalculation(value); var date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, "%Y-%x-%e %H:%M:%S"); var dateStr = BI.print(date, self._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
@ -65034,7 +65086,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
return ""; return "";
} }
return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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), self._getFormatString());
} }
} }
}); });
@ -65061,7 +65113,8 @@ BI.extend(BI.DynamicDateTimeSelect, {
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -65094,6 +65147,57 @@ BI.extend(BI.DynamicDateTimeSelect, {
}); });
this.setValue(o.value); this.setValue(o.value);
}, },
_getStandardDateStr: function (v) {
var result = [];
var hasSecond = false;
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":
result[2] = idx;
break;
case "%S":
hasSecond = true;
break;
default:
break;
}
});
var dateArray = v.match(/\d+/g);
var newArray = [];
// 处理乱序的年月日
BI.each(dateArray.slice(0, 3), function (idx) {
newArray[idx] = dateArray[result[idx]];
});
// 拼接时分秒和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) { _dateCheck: function (date) {
return 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-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date ||
@ -65133,14 +65237,14 @@ BI.extend(BI.DynamicDateTimeSelect, {
}, },
_monthCheck: function (v) { _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"); var dateStr = BI.print(date, "%Y-%X-%d");
return (date.getMonth() > 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -65217,7 +65321,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
this.editor.setValue(""); this.editor.setValue("");
} else { } else {
var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }

172
dist/fineui_without_jquery_polyfill.js vendored

@ -17785,8 +17785,8 @@ _.extend(BI, {
s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) 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["%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["%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["%k"] = hr + ""; // hour, range 0 to 23 (24h format)
s["%l"] = ir; // hour, range 1 to 12 (12h 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 < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12
s["%x"] = m + 1; // month, range 1 to 12 s["%x"] = m + 1; // month, range 1 to 12
s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
@ -45744,7 +45744,8 @@ BI.extend(BI.DynamicDateCard, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -45782,6 +45783,7 @@ BI.extend(BI.DynamicDateCard, {
type: "bi.dynamic_date_trigger", type: "bi.dynamic_date_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -46366,14 +46368,16 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d"
}, },
props: { props: {
extraCls: "bi-date-trigger", extraCls: "bi-date-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -46384,9 +46388,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -46400,10 +46405,11 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Date_Trigger_Error_Text"); 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 () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -46414,14 +46420,14 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
var text = self._getText(value); var text = self._getText(value);
var date = BI.getDate(); var date = BI.getDate();
date = BI.DynamicDateHelper.getCalculation(value); 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); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
if (BI.isNull(value) || BI.isNull(value.day)) { if (BI.isNull(value) || BI.isNull(value.day)) {
return ""; 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());
} }
} }
}); });
@ -46448,7 +46454,8 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -46483,6 +46490,45 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}); });
this.setValue(o.value); 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) { _dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === 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 || BI.print(BI.parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date ||
@ -46512,19 +46558,19 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}, },
_yearCheck: function (v) { _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; return BI.print(BI.parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
}, },
_monthCheck: function (v) { _monthCheck: function (v) {
var date = BI.parseDateTime(v, "%Y-%X-%d"); var date = BI.parseDateTime(v, this._getFormatString());
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._const.compareFormat);
return (date.getMonth() >= 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _setInnerValue: function (date) {
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -46600,7 +46646,7 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
this.editor.setState(""); this.editor.setState("");
this.editor.setValue(""); this.editor.setValue("");
} else { } 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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }
@ -46639,7 +46685,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -46677,6 +46724,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
type: "bi.dynamic_date_time_trigger", type: "bi.dynamic_date_time_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -47371,14 +47419,16 @@ BI.extend(BI.DynamicDateTimeSelect, {
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d %H:%M:%S"
}, },
props: { props: {
extraCls: "bi-date-time-trigger", extraCls: "bi-date-time-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -47389,9 +47439,10 @@ BI.extend(BI.DynamicDateTimeSelect, {
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -47405,10 +47456,11 @@ BI.extend(BI.DynamicDateTimeSelect, {
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Basic_Date_Time_Error_Text"); 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 BI.i18nText("BI-Year_Trigger_Invalid_Text"); return str;
}, },
title: function () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -47418,7 +47470,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
case BI.DynamicDateCombo.Dynamic: case BI.DynamicDateCombo.Dynamic:
var text = self._getText(value); var text = self._getText(value);
var date = BI.DynamicDateHelper.getCalculation(value); var date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, "%Y-%x-%e %H:%M:%S"); var dateStr = BI.print(date, self._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
@ -47426,7 +47478,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
return ""; return "";
} }
return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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), self._getFormatString());
} }
} }
}); });
@ -47453,7 +47505,8 @@ BI.extend(BI.DynamicDateTimeSelect, {
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -47486,6 +47539,57 @@ BI.extend(BI.DynamicDateTimeSelect, {
}); });
this.setValue(o.value); this.setValue(o.value);
}, },
_getStandardDateStr: function (v) {
var result = [];
var hasSecond = false;
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":
result[2] = idx;
break;
case "%S":
hasSecond = true;
break;
default:
break;
}
});
var dateArray = v.match(/\d+/g);
var newArray = [];
// 处理乱序的年月日
BI.each(dateArray.slice(0, 3), function (idx) {
newArray[idx] = dateArray[result[idx]];
});
// 拼接时分秒和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) { _dateCheck: function (date) {
return 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-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date ||
@ -47525,14 +47629,14 @@ BI.extend(BI.DynamicDateTimeSelect, {
}, },
_monthCheck: function (v) { _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"); var dateStr = BI.print(date, "%Y-%X-%d");
return (date.getMonth() > 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -47609,7 +47713,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
this.editor.setValue(""); this.editor.setValue("");
} else { } else {
var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }

4
dist/utils.js vendored

@ -10753,8 +10753,8 @@ _.extend(BI, {
s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) 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["%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["%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["%k"] = hr + ""; // hour, range 0 to 23 (24h format)
s["%l"] = ir; // hour, range 1 to 12 (12h 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 < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12
s["%x"] = m + 1; // month, range 1 to 12 s["%x"] = m + 1; // month, range 1 to 12
s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59

168
dist/widget.js vendored

@ -2710,7 +2710,8 @@ BI.extend(BI.DynamicDateCard, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -2748,6 +2749,7 @@ BI.extend(BI.DynamicDateCard, {
type: "bi.dynamic_date_trigger", type: "bi.dynamic_date_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -3332,14 +3334,16 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d"
}, },
props: { props: {
extraCls: "bi-date-trigger", extraCls: "bi-date-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -3350,9 +3354,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -3366,10 +3371,11 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Date_Trigger_Error_Text"); 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 () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -3380,14 +3386,14 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
var text = self._getText(value); var text = self._getText(value);
var date = BI.getDate(); var date = BI.getDate();
date = BI.DynamicDateHelper.getCalculation(value); 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); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
if (BI.isNull(value) || BI.isNull(value.day)) { if (BI.isNull(value) || BI.isNull(value.day)) {
return ""; 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());
} }
} }
}); });
@ -3414,7 +3420,8 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -3449,6 +3456,45 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}); });
this.setValue(o.value); 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) { _dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === 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 || BI.print(BI.parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date ||
@ -3478,19 +3524,19 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
}, },
_yearCheck: function (v) { _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; return BI.print(BI.parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
}, },
_monthCheck: function (v) { _monthCheck: function (v) {
var date = BI.parseDateTime(v, "%Y-%X-%d"); var date = BI.parseDateTime(v, this._getFormatString());
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._const.compareFormat);
return (date.getMonth() >= 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _setInnerValue: function (date) {
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -3566,7 +3612,7 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger
this.editor.setState(""); this.editor.setState("");
this.editor.setValue(""); this.editor.setValue("");
} else { } 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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }
@ -3605,7 +3651,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -3643,6 +3690,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
type: "bi.dynamic_date_time_trigger", type: "bi.dynamic_date_time_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {
@ -4337,14 +4385,16 @@ BI.extend(BI.DynamicDateTimeSelect, {
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d %H:%M:%S"
}, },
props: { props: {
extraCls: "bi-date-time-trigger", extraCls: "bi-date-time-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -4355,9 +4405,10 @@ BI.extend(BI.DynamicDateTimeSelect, {
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -4371,10 +4422,11 @@ BI.extend(BI.DynamicDateTimeSelect, {
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Basic_Date_Time_Error_Text"); 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 BI.i18nText("BI-Year_Trigger_Invalid_Text"); return str;
}, },
title: function () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -4384,7 +4436,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
case BI.DynamicDateCombo.Dynamic: case BI.DynamicDateCombo.Dynamic:
var text = self._getText(value); var text = self._getText(value);
var date = BI.DynamicDateHelper.getCalculation(value); var date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, "%Y-%x-%e %H:%M:%S"); var dateStr = BI.print(date, self._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
@ -4392,7 +4444,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
return ""; return "";
} }
return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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), self._getFormatString());
} }
} }
}); });
@ -4419,7 +4471,8 @@ BI.extend(BI.DynamicDateTimeSelect, {
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -4452,6 +4505,57 @@ BI.extend(BI.DynamicDateTimeSelect, {
}); });
this.setValue(o.value); this.setValue(o.value);
}, },
_getStandardDateStr: function (v) {
var result = [];
var hasSecond = false;
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":
result[2] = idx;
break;
case "%S":
hasSecond = true;
break;
default:
break;
}
});
var dateArray = v.match(/\d+/g);
var newArray = [];
// 处理乱序的年月日
BI.each(dateArray.slice(0, 3), function (idx) {
newArray[idx] = dateArray[result[idx]];
});
// 拼接时分秒和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) { _dateCheck: function (date) {
return 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-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date ||
@ -4491,14 +4595,14 @@ BI.extend(BI.DynamicDateTimeSelect, {
}, },
_monthCheck: function (v) { _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"); var dateStr = BI.print(date, "%Y-%X-%d");
return (date.getMonth() > 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -4575,7 +4679,7 @@ BI.extend(BI.DynamicDateTimeSelect, {
this.editor.setValue(""); this.editor.setValue("");
} else { } else {
var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }

4
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["%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["%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["%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["%k"] = hr + ""; // hour, range 0 to 23 (24h format)
s["%l"] = ir; // hour, range 1 to 12 (12h 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 < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12
s["%x"] = m + 1; // month, range 1 to 12 s["%x"] = m + 1; // month, range 1 to 12
s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59

4
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", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow bi-border-radius",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -48,6 +49,7 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, {
type: "bi.dynamic_date_trigger", type: "bi.dynamic_date_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {

76
src/widget/dynamicdate/dynamicdate.trigger.js

@ -4,14 +4,16 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, {
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d"
}, },
props: { props: {
extraCls: "bi-date-trigger", extraCls: "bi-date-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -22,9 +24,10 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, {
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -38,10 +41,11 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, {
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Date_Trigger_Error_Text"); 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 () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -52,14 +56,14 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, {
var text = self._getText(value); var text = self._getText(value);
var date = BI.getDate(); var date = BI.getDate();
date = BI.DynamicDateHelper.getCalculation(value); 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); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
if (BI.isNull(value) || BI.isNull(value.day)) { if (BI.isNull(value) || BI.isNull(value.day)) {
return ""; 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())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -121,6 +126,45 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, {
}); });
this.setValue(o.value); 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) { _dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === 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 || 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) { _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; return BI.print(BI.parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
}, },
_monthCheck: function (v) { _monthCheck: function (v) {
var date = BI.parseDateTime(v, "%Y-%X-%d"); var date = BI.parseDateTime(v, this._getFormatString());
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._const.compareFormat);
return (date.getMonth() >= 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _setInnerValue: function (date) {
var dateStr = BI.print(date, "%Y-%X-%d"); var dateStr = BI.print(date, this._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -238,7 +282,7 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, {
this.editor.setState(""); this.editor.setState("");
this.editor.setValue(""); this.editor.setValue("");
} else { } 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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }

4
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", baseCls: "bi-dynamic-date-combo bi-border bi-focus-shadow",
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31" maxDate: "2099-12-31",
format: ""
}, },
@ -48,6 +49,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
type: "bi.dynamic_date_time_trigger", type: "bi.dynamic_date_time_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {

84
src/widget/dynamicdatetime/dynamicdatetime.trigger.js

@ -4,14 +4,16 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
vgap: 2, vgap: 2,
yearLength: 4, yearLength: 4,
yearMonthLength: 6, yearMonthLength: 6,
yearFullMonthLength: 7 yearFullMonthLength: 7,
compareFormat: "%Y-%X-%d %H:%M:%S"
}, },
props: { props: {
extraCls: "bi-date-time-trigger", extraCls: "bi-date-time-trigger",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24 height: 24,
format: "" // 显示的日期格式化方式
}, },
_init: function () { _init: function () {
@ -22,9 +24,10 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
type: "bi.sign_editor", type: "bi.sign_editor",
height: o.height, height: o.height,
validationChecker: function (v) { validationChecker: function (v) {
var date = v.match(/\d+/g); var formatStr = self._getStandardDateStr(v);
self._autoAppend(v, date); var date = formatStr.match(/\d+/g);
return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ !BI.isKey(o.format) && self._autoAppend(v, date);
return self._dateCheck(formatStr) && BI.checkDateLegal(formatStr) && self._checkVoid({
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0
@ -38,10 +41,11 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
allowBlank: true, allowBlank: true,
watermark: BI.i18nText("BI-Basic_Unrestricted"), watermark: BI.i18nText("BI-Basic_Unrestricted"),
errorText: function () { errorText: function () {
if (self.editor.isEditing()) { var str = "";
return BI.i18nText("BI-Basic_Date_Time_Error_Text"); 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 BI.i18nText("BI-Year_Trigger_Invalid_Text"); return str;
}, },
title: function () { title: function () {
var storeValue = self.storeValue || {}; var storeValue = self.storeValue || {};
@ -51,7 +55,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
case BI.DynamicDateCombo.Dynamic: case BI.DynamicDateCombo.Dynamic:
var text = self._getText(value); var text = self._getText(value);
var date = BI.DynamicDateHelper.getCalculation(value); var date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, "%Y-%x-%e %H:%M:%S"); var dateStr = BI.print(date, self._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static: case BI.DynamicDateCombo.Static:
default: default:
@ -59,7 +63,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
return ""; return "";
} }
return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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), self._getFormatString());
} }
} }
}); });
@ -86,7 +90,8 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
} }
if (BI.isNotEmptyString(value) && !BI.isEqual(self.storeTriggerValue, self.getKey())) { 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 = { self.storeValue = {
type: BI.DynamicDateCombo.Static, type: BI.DynamicDateCombo.Static,
value: { value: {
@ -119,6 +124,57 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
}); });
this.setValue(o.value); this.setValue(o.value);
}, },
_getStandardDateStr: function (v) {
var result = [];
var hasSecond = false;
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":
result[2] = idx;
break;
case "%S":
hasSecond = true;
break;
default:
break;
}
});
var dateArray = v.match(/\d+/g);
var newArray = [];
// 处理乱序的年月日
BI.each(dateArray.slice(0, 3), function (idx) {
newArray[idx] = dateArray[result[idx]];
});
// 拼接时分秒和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) { _dateCheck: function (date) {
return 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-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date ||
@ -158,14 +214,14 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
}, },
_monthCheck: function (v) { _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"); var dateStr = BI.print(date, "%Y-%X-%d");
return (date.getMonth() > 0 && (BI.print(BI.parseDateTime(v, "%Y-%X"), "%Y-%X") === v || 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; BI.print(BI.parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max;
}, },
_setInnerValue: function (date) { _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.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
}, },
@ -242,7 +298,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
this.editor.setValue(""); this.editor.setValue("");
} else { } else {
var dateStr = BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, 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._getFormatString());
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }

Loading…
Cancel
Save