Browse Source

KERNEL-14092 refactor: widget/timeinterval

es6
Zhenfei.Li 2 years ago
parent
commit
a2ca12a140
  1. 6
      src/case/calendar/calendar.date.item.js
  2. 65
      src/case/calendar/calendar.js
  3. 52
      src/case/calendar/calendar.year.js
  4. 26
      src/core/logic/index.js
  5. 4
      src/widget/dynamicdate/dynamicdate.trigger.js
  6. 259
      src/widget/timeinterval/dateinterval.js
  7. 3
      src/widget/timeinterval/index.js
  8. 248
      src/widget/timeinterval/timeinterval.js
  9. 126
      src/widget/timeinterval/timeperiods.js

6
src/case/calendar/calendar.date.item.js

@ -1,9 +1,9 @@
import { shortcut } from "@/core";
import { BasicButton } from "@/base";
/** /**
* 专门为calendar的视觉加的button作为私有button,不能配置任何属性也不要用这个玩意 * 专门为calendar的视觉加的button作为私有button,不能配置任何属性也不要用这个玩意
*/ */
import { shortcut } from "@/core";
import { BasicButton } from "@/base";
@shortcut() @shortcut()
export class CalendarDateItem extends BasicButton { export class CalendarDateItem extends BasicButton {
props() { props() {

65
src/case/calendar/calendar.js

@ -1,13 +1,42 @@
import { shortcut, Widget, getDate, each, range, extend, isLeapYear, Date, StartOfWeek, checkDateVoid, map, createWidget, createItems, LogicFactory, Controller, getShortDayName, getOffsetDate, isNotEmptyString, parseInt } from "@/core";
/** /**
* Created by GUY on 2015/8/28. * Created by GUY on 2015/8/28.
* @class BI.Calendar * @class Calendar
* @extends BI.Widget * @extends Widget
*/ */
import { shortcut, Widget, getDate, each, range, extend, isLeapYear, Date, StartOfWeek, checkDateVoid, map, createWidget, createItems, LogicFactory, Controller, getShortDayName, getOffsetDate, isNotEmptyString, parseInt } from "@/core";
@shortcut() @shortcut()
export class Calendar extends Widget { export class Calendar extends Widget {
static xtype = "bi.calendar"; static xtype = "bi.calendar";
static getPageByDateJSON (json) {
const year = getDate().getFullYear();
const month = getDate().getMonth();
let page = (json.year - year) * 12;
page += json.month - 1 - month;
return page;
}
static getDateJSONByPage (v) {
const months = getDate().getMonth();
let page = v;
// 对当前page做偏移,使到当前年初
page = page + months;
let year = parseInt(page / 12);
if (page < 0 && page % 12 !== 0) {
year--;
}
const month = page >= 0 ? (page % 12) : ((12 + page % 12) % 12);
return {
year: getDate().getFullYear() + year,
month: month + 1,
};
}
_defaultConfig () { _defaultConfig () {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
@ -222,33 +251,3 @@ export class Calendar extends Widget {
}; };
} }
} }
extend(Calendar, {
getPageByDateJSON (json) {
const year = getDate().getFullYear();
const month = getDate().getMonth();
let page = (json.year - year) * 12;
page += json.month - 1 - month;
return page;
},
getDateJSONByPage (v) {
const months = getDate().getMonth();
let page = v;
// 对当前page做偏移,使到当前年初
page = page + months;
let year = parseInt(page / 12);
if (page < 0 && page % 12 !== 0) {
year--;
}
const month = page >= 0 ? (page % 12) : ((12 + page % 12) % 12);
return {
year: getDate().getFullYear() + year,
month: month + 1,
};
},
});

52
src/case/calendar/calendar.year.js

@ -1,12 +1,33 @@
import { shortcut, Widget, extend, parseDateTime, range, checkDateVoid, print, getDate, each, createWidget, createItems, LogicFactory, Controller, makeArray, map, isNotEmptyString } from "@/core";
/** /**
* Created by GUY on 2015/8/28. * Created by GUY on 2015/8/28.
* @class BI.YearCalendar * @class YearCalendar
* @extends BI.Widget * @extends Widget
*/ */
import { shortcut, Widget, extend, parseDateTime, range, checkDateVoid, print, getDate, each, createWidget, createItems, LogicFactory, Controller, makeArray, map, isNotEmptyString } from "@/core";
@shortcut() @shortcut()
export class YearCalendar extends Widget { export class YearCalendar extends Widget {
static xtype = "bi.year_calendar"; static xtype = "bi.year_calendar";
static INTERVAL = 12;
// 获取显示的第一年
static getStartYear (year) {
const cur = getDate().getFullYear();
return year - ((year - cur + 3) % YearCalendar.INTERVAL + 12) % YearCalendar.INTERVAL;
}
static getEndYear (year) {
return YearCalendar.getStartYear(year) + YearCalendar.INTERVAL - 1;
}
static getPageByYear (year) {
const cur = getDate().getFullYear();
year = YearCalendar.getStartYear(year);
return (year - cur + 3) / YearCalendar.INTERVAL;
}
_defaultConfig () { _defaultConfig () {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
@ -150,28 +171,3 @@ export class YearCalendar extends Widget {
return this.years.getValue()[0]; return this.years.getValue()[0];
} }
} }
// 类方法
extend(YearCalendar, {
INTERVAL: 12,
// 获取显示的第一年
getStartYear (year) {
const cur = getDate().getFullYear();
return year - ((year - cur + 3) % YearCalendar.INTERVAL + 12) % YearCalendar.INTERVAL;
},
getEndYear (year) {
return YearCalendar.getStartYear(year) + YearCalendar.INTERVAL - 1;
},
getPageByYear (year) {
const cur = getDate().getFullYear();
year = YearCalendar.getStartYear(year);
return (year - cur + 3) / YearCalendar.INTERVAL;
},
});

26
src/core/logic/index.js

@ -1,3 +1,5 @@
import { map, isWidget } from "../2.base";
import { Direction } from "../constant";
import { Logic } from "./logic"; import { Logic } from "./logic";
import { VerticalLayoutLogic, HorizontalLayoutLogic, TableLayoutLogic, HorizontalFillLayoutLogic } from "./logic.layout"; import { VerticalLayoutLogic, HorizontalLayoutLogic, TableLayoutLogic, HorizontalFillLayoutLogic } from "./logic.layout";
@ -33,21 +35,21 @@ export const LogicFactory = {
createLogicTypeByDirection (direction) { createLogicTypeByDirection (direction) {
switch (direction) { switch (direction) {
case BI.Direction.Top: case Direction.Top:
case BI.Direction.Bottom: case Direction.Bottom:
case BI.Direction.Custom: case Direction.Custom:
return BI.LogicFactory.Type.Vertical; return LogicFactory.Type.Vertical;
case BI.Direction.Left: case Direction.Left:
case BI.Direction.Right: case Direction.Right:
return BI.LogicFactory.Type.Horizontal; return LogicFactory.Type.Horizontal;
default: default:
} }
}, },
createLogicItemsByDirection (direction) { createLogicItemsByDirection (direction) {
let items = Array.prototype.slice.call(arguments, 1); let items = Array.prototype.slice.call(arguments, 1);
items = BI.map(items, (i, item) => { items = map(items, (i, item) => {
if (BI.isWidget(item)) { if (isWidget(item)) {
return { return {
el: item, el: item,
width: item.options.width, width: item.options.width,
@ -58,13 +60,13 @@ export const LogicFactory = {
return item; return item;
}); });
switch (direction) { switch (direction) {
case BI.Direction.Bottom: case Direction.Bottom:
items.reverse(); items.reverse();
break; break;
case BI.Direction.Right: case Direction.Right:
items.reverse(); items.reverse();
break; break;
case BI.Direction.Custom: case Direction.Custom:
items = items.slice(1); items = items.slice(1);
break; break;
default: default:

4
src/widget/dynamicdate/dynamicdate.trigger.js

@ -303,16 +303,16 @@ export class DynamicDateTrigger extends Trigger {
} }
setValue(v) { setValue(v) {
let type, value; let type, value, text;
let date = getDate(); let date = getDate();
this.storeValue = v; this.storeValue = v;
if (isNotNull(v)) { if (isNotNull(v)) {
type = v.type || DynamicDateCombo.Static; type = v.type || DynamicDateCombo.Static;
value = v.value || v; value = v.value || v;
} }
const text = this._getText(value);
switch (type) { switch (type) {
case DynamicDateCombo.Dynamic: case DynamicDateCombo.Dynamic:
text = this._getText(value);
date = DynamicDateHelper.getCalculation(value); date = DynamicDateHelper.getCalculation(value);
this._setInnerValue(date, text); this._setInnerValue(date, text);
break; break;

259
src/widget/timeinterval/dateinterval.js

@ -1,27 +1,39 @@
/** import { shortcut, extend, createWidget, i18nText, print, parseDateTime, checkDateVoid, checkDateLegal, isNotNull } from "@/core";
* Created by Baron on 2015/10/19. import { Single, Label, Bubbles } from "@/base";
*/ import { DynamicDateCombo } from "../dynamicdate";
BI.DateInterval = BI.inherit(BI.Single, {
constants: { @shortcut()
export class DateInterval extends Single {
static xtype = "bi.date_interval"
constants = {
height: 24, height: 24,
width: 24, width: 24,
lgap: 15, lgap: 15,
offset: 0, offset: 0,
timeErrorCls: "time-error" timeErrorCls: "time-error",
}, };
_defaultConfig: function () {
var conf = BI.DateInterval.superclass._defaultConfig.apply(this, arguments); static EVENT_VALID = "EVENT_VALID"
return BI.extend(conf, { static EVENT_ERROR = "EVENT_ERROR"
static EVENT_CHANGE = "EVENT_CHANGE"
static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW"
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
extraCls: "bi-date-interval", extraCls: "bi-date-interval",
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31", maxDate: "2099-12-31",
height: 24, height: 24,
supportDynamic: true, supportDynamic: true,
}); });
}, }
render: function () { render() {
var self = this, o = this.options; const o = this.options;
o.value = o.value || {}; o.value = o.value || {};
this.left = this._createCombo(o.value.start, o.watermark?.start); this.left = this._createCombo(o.value.start, o.watermark?.start);
this.right = this._createCombo(o.value.end, o.watermark?.end); this.right = this._createCombo(o.value.end, o.watermark?.end);
@ -30,164 +42,177 @@ BI.DateInterval = BI.inherit(BI.Single, {
type: "bi.horizontal_fill", type: "bi.horizontal_fill",
columnSize: ["fill", "", "fill"], columnSize: ["fill", "", "fill"],
items: [{ items: [{
el: self.left el: this.left,
}, { }, {
el: { el: {
type: "bi.label", type: Label.xtype,
height: o.height, height: o.height,
hgap: 5, hgap: 5,
text: "-", text: "-",
ref: function (_ref) { ref: _ref => {
self.label = _ref; this.label = _ref;
} },
} },
}, { }, {
el: self.right el: this.right,
}] }],
}; };
}, }
_createCombo: function (v, watermark) { _createCombo(v, watermark) {
var self = this, o = this.options; const o = this.options;
var combo = BI.createWidget({ const combo = createWidget({
type: "bi.dynamic_date_combo", type: DynamicDateCombo.xtype,
supportDynamic: o.supportDynamic, supportDynamic: o.supportDynamic,
minDate: o.minDate, minDate: o.minDate,
maxDate: o.maxDate, maxDate: o.maxDate,
simple: o.simple, simple: o.simple,
behaviors: o.behaviors, behaviors: o.behaviors,
watermark: watermark, watermark,
value: v, value: v,
height: o.height, height: o.height,
listeners: [{ listeners: [{
eventName: BI.DynamicDateCombo.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW, eventName: DynamicDateCombo.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW,
action: function () { action: () => {
self.fireEvent(BI.DateInterval.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW); this.fireEvent(DateInterval.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW);
} },
}] }],
}); });
combo.on(BI.DynamicDateCombo.EVENT_ERROR, function () { combo.on(DynamicDateCombo.EVENT_ERROR, () => {
self._clearTitle(); this._clearTitle();
BI.Bubbles.hide("error"); Bubbles.hide("error");
self.element.removeClass(self.constants.timeErrorCls); this.element.removeClass(this.constants.timeErrorCls);
self.fireEvent(BI.DateInterval.EVENT_ERROR); this.fireEvent(DateInterval.EVENT_ERROR);
}); });
combo.on(BI.DynamicDateCombo.EVENT_VALID, function () { combo.on(DynamicDateCombo.EVENT_VALID, () => {
BI.Bubbles.hide("error"); Bubbles.hide("error");
var smallDate = self.left.getKey(), bigDate = self.right.getKey(); const smallDate = this.left.getKey(),
if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { bigDate = this.right.getKey();
self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); if (this._check(smallDate, bigDate) && this._compare(smallDate, bigDate)) {
self.element.addClass(self.constants.timeErrorCls); this._setTitle(i18nText("BI-Time_Interval_Error_Text"));
BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { this.element.addClass(this.constants.timeErrorCls);
offsetStyle: "center" Bubbles.show("error", i18nText("BI-Time_Interval_Error_Text"), this, {
offsetStyle: "center",
}); });
self.fireEvent(BI.DateInterval.EVENT_ERROR); this.fireEvent(DateInterval.EVENT_ERROR);
} else { } else {
self._clearTitle(); this._clearTitle();
self.element.removeClass(self.constants.timeErrorCls); this.element.removeClass(this.constants.timeErrorCls);
} }
}); });
combo.on(BI.DynamicDateCombo.EVENT_FOCUS, function () { combo.on(DynamicDateCombo.EVENT_FOCUS, () => {
BI.Bubbles.hide("error"); Bubbles.hide("error");
var smallDate = self.left.getKey(), bigDate = self.right.getKey(); const smallDate = this.left.getKey(),
if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { bigDate = this.right.getKey();
self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); if (this._check(smallDate, bigDate) && this._compare(smallDate, bigDate)) {
self.element.addClass(self.constants.timeErrorCls); this._setTitle(i18nText("BI-Time_Interval_Error_Text"));
BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { this.element.addClass(this.constants.timeErrorCls);
offsetStyle: "center" Bubbles.show("error", i18nText("BI-Time_Interval_Error_Text"), this, {
offsetStyle: "center",
}); });
self.fireEvent(BI.DateInterval.EVENT_ERROR); this.fireEvent(DateInterval.EVENT_ERROR);
} else { } else {
self._clearTitle(); this._clearTitle();
self.element.removeClass(self.constants.timeErrorCls); this.element.removeClass(this.constants.timeErrorCls);
} }
}); });
// combo.on(BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW, function () { // combo.on(DynamicDateCombo.EVENT_BEFORE_POPUPVIEW, () => {
// self.left.hidePopupView(); // this.left.hidePopupView();
// self.right.hidePopupView(); // this.right.hidePopupView();
// }); // });
combo.on(BI.DynamicDateCombo.EVENT_CONFIRM, function () { combo.on(DynamicDateCombo.EVENT_CONFIRM, () => {
BI.Bubbles.hide("error"); Bubbles.hide("error");
var smallDate = self.left.getKey(), bigDate = self.right.getKey(); const smallDate = this.left.getKey(),
if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { bigDate = this.right.getKey();
self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); if (this._check(smallDate, bigDate) && this._compare(smallDate, bigDate)) {
self.element.addClass(self.constants.timeErrorCls); this._setTitle(i18nText("BI-Time_Interval_Error_Text"));
self.fireEvent(BI.DateInterval.EVENT_ERROR); this.element.addClass(this.constants.timeErrorCls);
}else{ this.fireEvent(DateInterval.EVENT_ERROR);
self._clearTitle(); } else {
self.element.removeClass(self.constants.timeErrorCls); this._clearTitle();
self.fireEvent(BI.DateInterval.EVENT_CHANGE); this.element.removeClass(this.constants.timeErrorCls);
this.fireEvent(DateInterval.EVENT_CHANGE);
} }
}); });
return combo; return combo;
}, }
_dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === date || _dateCheck(date) {
BI.print(BI.parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date || return print(parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === date ||
BI.print(BI.parseDateTime(date, "%Y-%x-%e"), "%Y-%x-%e") === date || print(parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date ||
BI.print(BI.parseDateTime(date, "%Y-%X-%e"), "%Y-%X-%e") === date; print(parseDateTime(date, "%Y-%x-%e"), "%Y-%x-%e") === date ||
}, print(parseDateTime(date, "%Y-%X-%e"), "%Y-%X-%e") === date;
_checkVoid: function (obj) { }
var o = this.options;
return !BI.checkDateVoid(obj.year, obj.month, obj.day, o.minDate, o.maxDate)[0]; _checkVoid(obj) {
}, const o = this.options;
_check: function (smallDate, bigDate) {
var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); return !checkDateVoid(obj.year, obj.month, obj.day, o.minDate, o.maxDate)[0];
return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ }
_check(smallDate, bigDate) {
const smallObj = smallDate.match(/\d+/g),
bigObj = bigDate.match(/\d+/g);
return this._dateCheck(smallDate) && checkDateLegal(smallDate) && this._checkVoid({
year: smallObj[0], year: smallObj[0],
month: smallObj[1], month: smallObj[1],
day: smallObj[2] day: smallObj[2],
}) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ }) && this._dateCheck(bigDate) && checkDateLegal(bigDate) && this._checkVoid({
year: bigObj[0], year: bigObj[0],
month: bigObj[1], month: bigObj[1],
day: bigObj[2] day: bigObj[2],
}); });
}, }
_compare: function (smallDate, bigDate) {
smallDate = BI.print(BI.parseDateTime(smallDate, "%Y-%X-%d"), "%Y-%X-%d"); _compare(smallDate, bigDate) {
bigDate = BI.print(BI.parseDateTime(bigDate, "%Y-%X-%d"), "%Y-%X-%d"); smallDate = print(parseDateTime(smallDate, "%Y-%X-%d"), "%Y-%X-%d");
return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; bigDate = print(parseDateTime(bigDate, "%Y-%X-%d"), "%Y-%X-%d");
},
_setTitle: function (v) { return isNotNull(smallDate) && isNotNull(bigDate) && smallDate > bigDate;
}
_setTitle(v) {
this.left.setTitle(v); this.left.setTitle(v);
this.right.setTitle(v); this.right.setTitle(v);
this.label.setTitle(v); this.label.setTitle(v);
}, }
_clearTitle: function () {
_clearTitle() {
this.left.setTitle(""); this.left.setTitle("");
this.right.setTitle(""); this.right.setTitle("");
this.label.setTitle(""); this.label.setTitle("");
}, }
setMinDate: function (minDate) { setMinDate(minDate) {
var o = this.options; const o = this.options;
o.minDate = minDate; o.minDate = minDate;
this.left.setMinDate(minDate); this.left.setMinDate(minDate);
this.right.setMinDate(minDate); this.right.setMinDate(minDate);
}, }
setMaxDate: function (maxDate) { setMaxDate(maxDate) {
var o = this.options; const o = this.options;
o.maxDate = maxDate; o.maxDate = maxDate;
this.left.setMaxDate(maxDate); this.left.setMaxDate(maxDate);
this.right.setMaxDate(maxDate); this.right.setMaxDate(maxDate);
}, }
setValue: function (date) { setValue(date) {
date = date || {}; date = date || {};
this.left.setValue(date.start); this.left.setValue(date.start);
this.right.setValue(date.end); this.right.setValue(date.end);
}, }
getValue: function () {
return {start: this.left.getValue(), end: this.right.getValue()}; getValue() {
} return {
}); start: this.left.getValue(),
BI.DateInterval.EVENT_VALID = "EVENT_VALID"; end: this.right.getValue(),
BI.DateInterval.EVENT_ERROR = "EVENT_ERROR"; };
BI.DateInterval.EVENT_CHANGE = "EVENT_CHANGE"; }
BI.DateInterval.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW"; }
BI.shortcut("bi.date_interval", BI.DateInterval);

3
src/widget/timeinterval/index.js

@ -0,0 +1,3 @@
export { DateInterval } from "./dateinterval";
export { TimeInterval } from "./timeinterval";
export { TimePeriods } from "./timeperiods";

248
src/widget/timeinterval/timeinterval.js

@ -1,27 +1,37 @@
/** import { shortcut, extend, createWidget, i18nText, print, parseDateTime, checkDateVoid, checkDateLegal, isNotNull } from "@/core";
* Created by Baron on 2015/10/19. import { Single, Label, Bubbles } from "@/base";
*/ import { DynamicDateTimeCombo } from "../dynamicdatetime";
BI.TimeInterval = BI.inherit(BI.Single, {
constants: { @shortcut()
export class TimeInterval extends Single {
static xtype = "bi.time_interval"
constants = {
height: 24, height: 24,
width: 24, width: 24,
lgap: 15, lgap: 15,
offset: 0, offset: 0,
timeErrorCls: "time-error" timeErrorCls: "time-error",
}, };
_defaultConfig: function () {
var conf = BI.TimeInterval.superclass._defaultConfig.apply(this, arguments); static EVENT_VALID = "EVENT_VALID"
return BI.extend(conf, { static EVENT_ERROR = "EVENT_ERROR"
static EVENT_CHANGE = "EVENT_CHANGE"
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
extraCls: "bi-time-interval", extraCls: "bi-time-interval",
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31", maxDate: "2099-12-31",
height: 24, height: 24,
supportDynamic: true supportDynamic: true,
}); });
}, }
render: function () { render() {
var self = this, o = this.options; const o = this.options;
o.value = o.value || {}; o.value = o.value || {};
this.left = this._createCombo(o.value.start, o.watermark?.start); this.left = this._createCombo(o.value.start, o.watermark?.start);
this.right = this._createCombo(o.value.end, o.watermark?.end); this.right = this._createCombo(o.value.end, o.watermark?.end);
@ -30,158 +40,172 @@ BI.TimeInterval = BI.inherit(BI.Single, {
type: "bi.horizontal_fill", type: "bi.horizontal_fill",
columnSize: ["fill", "", "fill"], columnSize: ["fill", "", "fill"],
items: [{ items: [{
el: self.left el: this.left,
}, { }, {
el: { el: {
type: "bi.label", type: Label.xtype,
height: o.height, height: o.height,
hgap: 5, hgap: 5,
text: "-", text: "-",
ref: function (_ref) { ref: _ref => {
self.label = _ref; this.label = _ref;
} },
} },
}, { }, {
el: self.right el: this.right,
}] }],
}; };
}, }
_createCombo: function (v, watermark) { _createCombo(v, watermark) {
var self = this, o = this.options; const o = this.options;
var combo = BI.createWidget({ const combo = createWidget({
type: "bi.dynamic_date_time_combo", type: DynamicDateTimeCombo.xtype,
simple: o.simple, simple: o.simple,
supportDynamic: o.supportDynamic, supportDynamic: o.supportDynamic,
minDate: o.minDate, minDate: o.minDate,
maxDate: o.maxDate, maxDate: o.maxDate,
behaviors: o.behaviors, behaviors: o.behaviors,
watermark: watermark, watermark,
value: v, value: v,
height: o.height, height: o.height,
}); });
combo.on(BI.DynamicDateTimeCombo.EVENT_ERROR, function () { combo.on(DynamicDateTimeCombo.EVENT_ERROR, () => {
self._clearTitle(); this._clearTitle();
BI.Bubbles.hide("error"); Bubbles.hide("error");
self.element.removeClass(self.constants.timeErrorCls); this.element.removeClass(this.constants.timeErrorCls);
self.fireEvent(BI.TimeInterval.EVENT_ERROR); this.fireEvent(TimeInterval.EVENT_ERROR);
}); });
combo.on(BI.DynamicDateTimeCombo.EVENT_VALID, function () { combo.on(DynamicDateTimeCombo.EVENT_VALID, () => {
BI.Bubbles.hide("error"); Bubbles.hide("error");
var smallDate = self.left.getKey(), bigDate = self.right.getKey(); const smallDate = this.left.getKey(),
if (self.left.isValid() && self.right.isValid() && self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { bigDate = this.right.getKey();
self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); if (this.left.isValid() && this.right.isValid() && this._check(smallDate, bigDate) && this._compare(smallDate, bigDate)) {
self.element.addClass(self.constants.timeErrorCls); this._setTitle(i18nText("BI-Time_Interval_Error_Text"));
BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { this.element.addClass(this.constants.timeErrorCls);
offsetStyle: "center" Bubbles.show("error", i18nText("BI-Time_Interval_Error_Text"), this, {
offsetStyle: "center",
}); });
self.fireEvent(BI.TimeInterval.EVENT_ERROR); this.fireEvent(TimeInterval.EVENT_ERROR);
} else { } else {
self._clearTitle(); this._clearTitle();
self.element.removeClass(self.constants.timeErrorCls); this.element.removeClass(this.constants.timeErrorCls);
} }
}); });
combo.on(BI.DynamicDateTimeCombo.EVENT_FOCUS, function () { combo.on(DynamicDateTimeCombo.EVENT_FOCUS, () => {
BI.Bubbles.hide("error"); Bubbles.hide("error");
var smallDate = self.left.getKey(), bigDate = self.right.getKey(); const smallDate = this.left.getKey(),
if (self.left.isValid() && self.right.isValid() && self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { bigDate = this.right.getKey();
self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); if (this.left.isValid() && this.right.isValid() && this._check(smallDate, bigDate) && this._compare(smallDate, bigDate)) {
self.element.addClass(self.constants.timeErrorCls); this._setTitle(i18nText("BI-Time_Interval_Error_Text"));
BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { this.element.addClass(this.constants.timeErrorCls);
offsetStyle: "center" Bubbles.show("error", i18nText("BI-Time_Interval_Error_Text"), this, {
offsetStyle: "center",
}); });
self.fireEvent(BI.TimeInterval.EVENT_ERROR); this.fireEvent(TimeInterval.EVENT_ERROR);
} else { } else {
self._clearTitle(); this._clearTitle();
self.element.removeClass(self.constants.timeErrorCls); this.element.removeClass(this.constants.timeErrorCls);
} }
}); });
// 不知道干啥的,先注释掉 // 不知道干啥的,先注释掉
// combo.on(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW, function () { // combo.on(DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW, () => {
// self.left.hidePopupView(); // this.left.hidePopupView();
// self.right.hidePopupView(); // this.right.hidePopupView();
// }); // });
combo.on(BI.DynamicDateTimeCombo.EVENT_CONFIRM, function () { combo.on(DynamicDateTimeCombo.EVENT_CONFIRM, () => {
BI.Bubbles.hide("error"); Bubbles.hide("error");
var smallDate = self.left.getKey(), bigDate = self.right.getKey(); const smallDate = this.left.getKey(),
if (self.left.isValid() && self.right.isValid() && self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { bigDate = this.right.getKey();
self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); if (this.left.isValid() && this.right.isValid() && this._check(smallDate, bigDate) && this._compare(smallDate, bigDate)) {
self.element.addClass(self.constants.timeErrorCls); this._setTitle(i18nText("BI-Time_Interval_Error_Text"));
self.fireEvent(BI.TimeInterval.EVENT_ERROR); this.element.addClass(this.constants.timeErrorCls);
}else{ this.fireEvent(TimeInterval.EVENT_ERROR);
self._clearTitle(); } else {
self.element.removeClass(self.constants.timeErrorCls); this._clearTitle();
self.fireEvent(BI.TimeInterval.EVENT_CHANGE); this.element.removeClass(this.constants.timeErrorCls);
this.fireEvent(TimeInterval.EVENT_CHANGE);
} }
}); });
return combo; return combo;
}, }
_dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%x-%d %H:%M:%S"), "%Y-%x-%d %H:%M:%S") === date || _dateCheck(date) {
BI.print(BI.parseDateTime(date, "%Y-%X-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date || return print(parseDateTime(date, "%Y-%x-%d %H:%M:%S"), "%Y-%x-%d %H:%M:%S") === date ||
BI.print(BI.parseDateTime(date, "%Y-%x-%e %H:%M:%S"), "%Y-%x-%e %H:%M:%S") === date || print(parseDateTime(date, "%Y-%X-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date ||
BI.print(BI.parseDateTime(date, "%Y-%X-%e %H:%M:%S"), "%Y-%X-%e %H:%M:%S") === date; print(parseDateTime(date, "%Y-%x-%e %H:%M:%S"), "%Y-%x-%e %H:%M:%S") === date ||
}, print(parseDateTime(date, "%Y-%X-%e %H:%M:%S"), "%Y-%X-%e %H:%M:%S") === date;
_checkVoid: function (obj) { }
var o = this.options;
return !BI.checkDateVoid(obj.year, obj.month, obj.day, o.minDate, o.maxDate)[0]; _checkVoid(obj) {
}, const o = this.options;
_check: function (smallDate, bigDate) {
var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); return !checkDateVoid(obj.year, obj.month, obj.day, o.minDate, o.maxDate)[0];
return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ }
_check(smallDate, bigDate) {
const smallObj = smallDate.match(/\d+/g),
bigObj = bigDate.match(/\d+/g);
return this._dateCheck(smallDate) && checkDateLegal(smallDate) && this._checkVoid({
year: smallObj[0], year: smallObj[0],
month: smallObj[1], month: smallObj[1],
day: smallObj[2] day: smallObj[2],
}) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ }) && this._dateCheck(bigDate) && checkDateLegal(bigDate) && this._checkVoid({
year: bigObj[0], year: bigObj[0],
month: bigObj[1], month: bigObj[1],
day: bigObj[2] day: bigObj[2],
}); });
}, }
_compare: function (smallDate, bigDate) {
smallDate = BI.print(BI.parseDateTime(smallDate, "%Y-%X-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S"); _compare(smallDate, bigDate) {
bigDate = BI.print(BI.parseDateTime(bigDate, "%Y-%X-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S"); smallDate = print(parseDateTime(smallDate, "%Y-%X-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S");
return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; bigDate = print(parseDateTime(bigDate, "%Y-%X-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S");
},
_setTitle: function (v) { return isNotNull(smallDate) && isNotNull(bigDate) && smallDate > bigDate;
}
_setTitle(v) {
this.left.setTitle(v); this.left.setTitle(v);
this.right.setTitle(v); this.right.setTitle(v);
this.label.setTitle(v); this.label.setTitle(v);
}, }
_clearTitle: function () {
_clearTitle() {
this.left.setTitle(""); this.left.setTitle("");
this.right.setTitle(""); this.right.setTitle("");
this.label.setTitle(""); this.label.setTitle("");
}, }
setMinDate: function (minDate) { setMinDate(minDate) {
var o = this.options; const o = this.options;
o.minDate = minDate; o.minDate = minDate;
this.left.setMinDate(minDate); this.left.setMinDate(minDate);
this.right.setMinDate(minDate); this.right.setMinDate(minDate);
}, }
setMaxDate: function (maxDate) { setMaxDate(maxDate) {
var o = this.options; const o = this.options;
o.maxDate = maxDate; o.maxDate = maxDate;
this.left.setMaxDate(maxDate); this.left.setMaxDate(maxDate);
this.right.setMaxDate(maxDate); this.right.setMaxDate(maxDate);
}, }
setValue: function (date) { setValue(date) {
date = date || {}; date = date || {};
this.left.setValue(date.start); this.left.setValue(date.start);
this.right.setValue(date.end); this.right.setValue(date.end);
}, }
getValue: function () {
return {start: this.left.getValue(), end: this.right.getValue()}; getValue() {
} return {
}); start: this.left.getValue(),
BI.TimeInterval.EVENT_VALID = "EVENT_VALID"; end: this.right.getValue(),
BI.TimeInterval.EVENT_ERROR = "EVENT_ERROR"; };
BI.TimeInterval.EVENT_CHANGE = "EVENT_CHANGE"; }
BI.shortcut("bi.time_interval", BI.TimeInterval); }

126
src/widget/timeinterval/timeperiods.js

@ -1,92 +1,90 @@
/** import { shortcut, extend } from "@/core";
* 时间区间 import { Single, Label } from "@/base";
* qcc import { TimeCombo } from "../time";
* 2019/2/28
*/
!(function () { @shortcut()
BI.TimePeriods = BI.inherit(BI.Single, { export class TimePeriods extends Single {
constants: { static xtype = "bi.time_periods"
height: 24,
width: 24, props = {
hgap: 15,
offset: -15
},
props: {
extraCls: "bi-time-interval", extraCls: "bi-time-interval",
value: {} value: {},
}, };
render: function () { static EVENT_CONFIRM = "EVENT_CONFIRM"
var self = this, o = this.options; static EVENT_CHANGE = "EVENT_CHANGE"
render() {
const o = this.options;
return { return {
type: "bi.horizontal_fill", type: "bi.horizontal_fill",
columnSize: ["fill", "", "fill"], columnSize: ["fill", "", "fill"],
items: [{ items: [{
el: BI.extend({ el: extend({
ref: function (_ref) { ref: _ref => {
self.left = _ref; this.left = _ref;
} },
}, this._createCombo(o.value.start, o.watermark?.start)) }, this._createCombo(o.value.start, o.watermark?.start)),
}, { }, {
el: { el: {
type: "bi.label", type: Label.xtype,
height: o.height, height: o.height,
hgap: 5, hgap: 5,
text: "-", text: "-",
ref: function (_ref) { ref: _ref => {
self.label = _ref; this.label = _ref;
} },
} },
}, { }, {
el: BI.extend({ el: extend({
ref: function (_ref) { ref: _ref => {
self.right = _ref; this.right = _ref;
}
}, this._createCombo(o.value.end, o.watermark?.end))
}]
};
}, },
}, this._createCombo(o.value.end, o.watermark?.end)),
}],
};
}
_createCombo(v, watermark) {
const o = this.options;
_createCombo: function (v, watermark) {
var self = this;
var o = this.options;
return { return {
type: "bi.time_combo", type: TimeCombo.xtype,
value: v, value: v,
height: o.height, height: o.height,
watermark: watermark, watermark,
listeners: [{ listeners: [{
eventName: BI.TimeCombo.EVENT_BEFORE_POPUPVIEW, eventName: TimeCombo.EVENT_BEFORE_POPUPVIEW,
action: function () { action: () => {
self.left.hidePopupView(); this.left.hidePopupView();
self.right.hidePopupView(); this.right.hidePopupView();
} },
}, { }, {
eventName: BI.TimeCombo.EVENT_CHANGE, eventName: TimeCombo.EVENT_CHANGE,
action: function () { action: () => {
self.fireEvent(BI.TimePeriods.EVENT_CHANGE); this.fireEvent(TimePeriods.EVENT_CHANGE);
} },
}, { }, {
eventName: BI.TimeCombo.EVENT_CONFIRM, eventName: TimeCombo.EVENT_CONFIRM,
action: function () { action: () => {
self.fireEvent(BI.TimePeriods.EVENT_CONFIRM); this.fireEvent(TimePeriods.EVENT_CONFIRM);
}
}]
};
}, },
}],
};
}
setValue: function (date) { setValue(date) {
date = date || {}; date = date || {};
this.left.setValue(date.start); this.left.setValue(date.start);
this.right.setValue(date.end); this.right.setValue(date.end);
},
getValue: function () {
return {start: this.left.getValue(), end: this.right.getValue()};
} }
});
BI.TimePeriods.EVENT_CONFIRM = "EVENT_CONFIRM"; getValue() {
BI.TimePeriods.EVENT_CHANGE = "EVENT_CHANGE"; return {
BI.shortcut("bi.time_periods", BI.TimePeriods); start: this.left.getValue(),
})(); end: this.right.getValue(),
};
}
}

Loading…
Cancel
Save