Browse Source

无jira refact:widget的xtype换下

es6
Treecat 1 year ago
parent
commit
de22cfdcf9
  1. 99
      src/widget/collapse/collapse.js
  2. 17
      src/widget/date/calendar/combo.month.date.js
  3. 17
      src/widget/date/calendar/combo.year.date.js
  4. 80
      src/widget/date/calendar/picker.date.js
  5. 58
      src/widget/date/calendar/picker.year.js
  6. 81
      src/widget/date/calendar/popup.calendar.date.js
  7. 87
      src/widget/date/calendar/popup.month.js
  8. 30
      src/widget/date/calendar/popup.year.js
  9. 31
      src/widget/date/calendar/trigger.triangle.date.js
  10. 58
      src/widget/datepane/card.static.datepane.js
  11. 291
      src/widget/datepane/datepane.js
  12. 49
      src/widget/datetime/datetime.combo.js
  13. 89
      src/widget/datetime/datetime.popup.js
  14. 35
      src/widget/datetime/datetime.trigger.js
  15. 100
      src/widget/datetimepane/card.static.datetimepane.js
  16. 297
      src/widget/datetimepane/datetimepane.js
  17. 14
      src/widget/downlist/combo.downlist.js
  18. 110
      src/widget/downlist/group.downlist.js
  19. 10
      src/widget/downlist/index.js
  20. 238
      src/widget/downlist/item.downlist.js
  21. 251
      src/widget/downlist/item.downlistgroup.js
  22. 580
      src/widget/downlist/popup.downlist.js
  23. 75
      src/widget/dynamicdate/dynamicdate.caculate.js
  24. 481
      src/widget/dynamicdate/dynamicdate.card.js
  25. 468
      src/widget/dynamicdate/dynamicdate.combo.js
  26. 137
      src/widget/dynamicdate/dynamicdate.param.item.js
  27. 288
      src/widget/dynamicdate/dynamicdate.popup.js
  28. 156
      src/widget/dynamicdate/dynamicdate.trigger.js
  29. 480
      src/widget/dynamicdatetime/dynamicdatetime.combo.js
  30. 320
      src/widget/dynamicdatetime/dynamicdatetime.popup.js
  31. 249
      src/widget/dynamicdatetime/dynamicdatetime.timeselect.js
  32. 211
      src/widget/dynamicdatetime/dynamicdatetime.trigger.js
  33. 93
      src/widget/editor/editor.search.js
  34. 4
      src/widget/editor/editor.search.small.js
  35. 41
      src/widget/editor/editor.text.js
  36. 4
      src/widget/editor/editor.text.small.js
  37. 4
      src/widget/intervalslider/index.js
  38. 151
      src/widget/intervalslider/intervalslider.js
  39. 86
      src/widget/intervalslider/model.accuratecalculation.js
  40. 6
      src/widget/multilayerdownlist/combo.downlist.js
  41. 38
      src/widget/multilayerdownlist/popup.downlist.js
  42. 78
      src/widget/multilayerselecttree/multilayerselecttree.combo.js
  43. 14
      src/widget/multilayerselecttree/multilayerselecttree.insert.search.pane.js
  44. 42
      src/widget/multilayerselecttree/multilayerselecttree.leveltree.js
  45. 12
      src/widget/multilayerselecttree/multilayerselecttree.popup.js
  46. 41
      src/widget/multilayerselecttree/multilayerselecttree.trigger.js
  47. 68
      src/widget/multilayersingletree/multilayersingletree.combo.js
  48. 14
      src/widget/multilayersingletree/multilayersingletree.insert.search.pane.js
  49. 37
      src/widget/multilayersingletree/multilayersingletree.leveltree.js
  50. 12
      src/widget/multilayersingletree/multilayersingletree.popup.js
  51. 41
      src/widget/multilayersingletree/multilayersingletree.trigger.js
  52. 3
      src/widget/multiselect/check/multiselect.check.pane.js
  53. 22
      src/widget/multiselect/check/multiselect.display.js
  54. 50
      src/widget/multiselect/loader.js
  55. 124
      src/widget/multiselect/multiselect.combo.js
  56. 112
      src/widget/multiselect/multiselect.combo.nobar.js
  57. 173
      src/widget/multiselect/multiselect.insert.combo.js
  58. 155
      src/widget/multiselect/multiselect.insert.combo.nobar.js
  59. 56
      src/widget/multiselect/multiselect.insert.trigger.js
  60. 60
      src/widget/multiselect/multiselect.loader.js
  61. 76
      src/widget/multiselect/multiselect.loader.nobar.js
  62. 36
      src/widget/multiselect/multiselect.popup.view.js
  63. 34
      src/widget/multiselect/multiselect.popup.view.nobar.js
  64. 57
      src/widget/multiselect/multiselect.trigger.js
  65. 14
      src/widget/multiselect/search/multiselect.search.insert.pane.js
  66. 16
      src/widget/multiselect/search/multiselect.search.loader.js
  67. 13
      src/widget/multiselect/search/multiselect.search.pane.js
  68. 8
      src/widget/multiselect/trigger/button.checkselected.js
  69. 11
      src/widget/multiselect/trigger/editor.multiselect.js
  70. 24
      src/widget/multiselect/trigger/editor/editor.patch.js
  71. 37
      src/widget/multiselect/trigger/searcher.multiselect.insert.js
  72. 28
      src/widget/multiselect/trigger/searcher.multiselect.js
  73. 25
      src/widget/multiselect/trigger/switcher.checkselected.js
  74. 53
      src/widget/multiselectlist/multiselectlist.insert.js
  75. 53
      src/widget/multiselectlist/multiselectlist.insert.nobar.js
  76. 24
      src/widget/multiselectlist/multiselectlist.js
  77. 17
      src/widget/multiselecttree/multiselecttree.js
  78. 3
      src/widget/multiselecttree/multiselecttree.popup.js

99
src/widget/collapse/collapse.js

@ -1,11 +1,23 @@
import { shortcut, Widget, map, extend, isFunction, contains, each, isKey, isNotEmptyArray } from "@/core"; import {
VerticalLayout,
shortcut,
Widget,
map,
extend,
isFunction,
contains,
each,
isKey,
isNotEmptyArray
} from "@/core";
import { ArrowNode } from "@/case";
import { Expander } from "@/base"; import { Expander } from "@/base";
@shortcut() @shortcut()
export class Collapse extends Widget { export class Collapse extends Widget {
static xtype = "bi.collapse" static xtype = "bi.collapse";
static EVENT_EXPAND = "EVENT_EXPAND" static EVENT_EXPAND = "EVENT_EXPAND";
props = { props = {
baseCls: "bi-collapse", baseCls: "bi-collapse",
@ -30,10 +42,9 @@ export class Collapse extends Widget {
this.expanders = {}; this.expanders = {};
return { return {
type: "bi.vertical", type: VerticalLayout.xtype,
cls: collapseCls, cls: collapseCls,
items: this._getItems(this.options.items), items: this._getItems(this.options.items),
}; };
} }
@ -44,46 +55,58 @@ export class Collapse extends Widget {
const isActive = contains(this._getCurrentValue(o.value), item.value); const isActive = contains(this._getCurrentValue(o.value), item.value);
const cls = o.ghost || index === 0 ? "" : "bi-border-top"; const cls = o.ghost || index === 0 ? "" : "bi-border-top";
const el = extend({ const el = extend(
type: "bi.arrow_group_node", {
height: 30, type: ArrowNode.xtype,
text: item.text, height: 30,
value: item.value, text: item.text,
open: isActive, value: item.value,
}, item.el); open: isActive,
const popup = extend({
animation: o.openMotion.animation,
animationDuring: o.openMotion.animationDuring,
}, item.popup);
return extend({
type: "bi.expander",
cls,
isDefaultInit: o.isDefaultInit,
trigger: o.trigger,
listeners: [{
eventName: Expander.EVENT_EXPAND,
action: () => {
this._hideOtherExpander(item.value);
this.fireEvent(Collapse.EVENT_EXPAND, item.value);
},
}],
}, item, {
el,
popup,
ref: _ref => {
isFunction(item.ref) && item.ref(_ref);
this.expanders[item.value] = _ref;
}, },
}); item.el
);
const popup = extend(
{
animation: o.openMotion.animation,
animationDuring: o.openMotion.animationDuring,
},
item.popup
);
return extend(
{
type: Expander.xtype,
cls,
isDefaultInit: o.isDefaultInit,
trigger: o.trigger,
listeners: [
{
eventName: Expander.EVENT_EXPAND,
action: () => {
this._hideOtherExpander(item.value);
this.fireEvent(Collapse.EVENT_EXPAND, item.value);
},
}
],
},
item,
{
el,
popup,
ref: _ref => {
isFunction(item.ref) && item.ref(_ref);
this.expanders[item.value] = _ref;
},
}
);
}); });
} }
_hideOtherExpander(expandKey) { _hideOtherExpander(expandKey) {
if (this.options.accordion) { if (this.options.accordion) {
each(this.expanders, (key, expander) => { each(this.expanders, (key, expander) => {
key !== (`${expandKey}`) && expander.hideView(); key !== `${expandKey}` && expander.hideView();
}); });
} }
} }

17
src/widget/date/calendar/combo.month.date.js

@ -1,6 +1,7 @@
import { shortcut, extend, createWidget } from "@/core"; import { DateTriangleTrigger } from "./trigger.triangle.date";
import { Trigger, Combo } from "@/base";
import { MonthPopup } from "./popup.month"; import { MonthPopup } from "./popup.month";
import { Combo, Trigger } from "@/base";
import { VerticalLayout, shortcut, extend, createWidget } from "@/core";
/** /**
* 日期控件中的月份下拉框 * 日期控件中的月份下拉框
@ -11,9 +12,9 @@ import { MonthPopup } from "./popup.month";
*/ */
@shortcut() @shortcut()
export class MonthDateCombo extends Trigger { export class MonthDateCombo extends Trigger {
static xtype = "bi.month_date_combo" static xtype = "bi.month_date_combo";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() { _defaultConfig() {
return extend(super._defaultConfig(...arguments), { return extend(super._defaultConfig(...arguments), {
@ -28,11 +29,11 @@ export class MonthDateCombo extends Trigger {
const o = this.options; const o = this.options;
this.trigger = createWidget({ this.trigger = createWidget({
type: "bi.date_triangle_trigger", type: DateTriangleTrigger.xtype,
}); });
this.popup = createWidget({ this.popup = createWidget({
type: "bi.month_popup", type: MonthPopup.xtype,
allowMonths: o.allowMonths, allowMonths: o.allowMonths,
behaviors: o.behaviors, behaviors: o.behaviors,
}); });
@ -44,7 +45,7 @@ export class MonthDateCombo extends Trigger {
}); });
this.combo = createWidget({ this.combo = createWidget({
type: "bi.combo", type: Combo.xtype,
offsetStyle: "center", offsetStyle: "center",
container: o.container, container: o.container,
element: this, element: this,
@ -55,7 +56,7 @@ export class MonthDateCombo extends Trigger {
minWidth: 100, minWidth: 100,
stopPropagation: false, stopPropagation: false,
el: { el: {
type: "bi.vertical", type: VerticalLayout.xtype,
hgap: 6, hgap: 6,
vgap: 5, vgap: 5,
items: [this.popup], items: [this.popup],

17
src/widget/date/calendar/combo.year.date.js

@ -1,6 +1,7 @@
import { shortcut, extend, createWidget } from "@/core"; import { DateTriangleTrigger } from "./trigger.triangle.date";
import { Trigger, Combo } from "@/base";
import { YearPopup } from "./popup.year"; import { YearPopup } from "./popup.year";
import { Combo, Trigger } from "@/base";
import { shortcut, extend, createWidget } from "@/core";
/** /**
* 年份下拉框 * 年份下拉框
@ -11,10 +12,10 @@ import { YearPopup } from "./popup.year";
*/ */
@shortcut() @shortcut()
export class YearDateCombo extends Trigger { export class YearDateCombo extends Trigger {
static xtype = "bi.year_date_combo" static xtype = "bi.year_date_combo";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW" static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
_defaultConfig() { _defaultConfig() {
return extend(super._defaultConfig(...arguments), { return extend(super._defaultConfig(...arguments), {
@ -32,11 +33,11 @@ export class YearDateCombo extends Trigger {
const o = this.options; const o = this.options;
this.trigger = createWidget({ this.trigger = createWidget({
type: "bi.date_triangle_trigger", type: DateTriangleTrigger.xtype,
}); });
this.popup = createWidget({ this.popup = createWidget({
type: "bi.year_popup", type: YearPopup.xtype,
behaviors: o.behaviors, behaviors: o.behaviors,
min: o.min, min: o.min,
max: o.max, max: o.max,
@ -50,7 +51,7 @@ export class YearDateCombo extends Trigger {
}); });
this.combo = createWidget({ this.combo = createWidget({
type: "bi.combo", type: Combo.xtype,
offsetStyle: "center", offsetStyle: "center",
element: this, element: this,
container: o.container, container: o.container,

80
src/widget/date/calendar/picker.date.js

@ -1,7 +1,23 @@
import { shortcut, Widget, extend, createWidget, contains, isNull, getDate, filter, range, checkDateVoid, parseDateTime, parseInt, print } from "@/core";
import { IconButton } from "@/base"; import { IconButton } from "@/base";
import { YearDateCombo } from "./combo.year.date"; import { YearDateCombo } from "./combo.year.date";
import { MonthDateCombo } from "./combo.month.date"; import { MonthDateCombo } from "./combo.month.date";
import {
HTapeLayout,
CenterAdaptLayout,
shortcut,
Widget,
extend,
createWidget,
contains,
isNull,
getDate,
filter,
range,
checkDateVoid,
parseDateTime,
parseInt,
print
} from "@/core";
/** /**
* Created by GUY on 2015/9/7. * Created by GUY on 2015/9/7.
@ -10,10 +26,10 @@ import { MonthDateCombo } from "./combo.month.date";
*/ */
@shortcut() @shortcut()
export class DatePicker extends Widget { export class DatePicker extends Widget {
static xtype = "bi.date_picker" static xtype = "bi.date_picker";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW" static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW";
_defaultConfig() { _defaultConfig() {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
@ -32,7 +48,7 @@ export class DatePicker extends Widget {
this._year = getDate().getFullYear(); this._year = getDate().getFullYear();
this._month = getDate().getMonth() + 1; this._month = getDate().getMonth() + 1;
this.left = createWidget({ this.left = createWidget({
type: "bi.icon_button", type: IconButton.xtype,
cls: "pre-page-h-font", cls: "pre-page-h-font",
width: 24, width: 24,
height: 24, height: 24,
@ -40,13 +56,13 @@ export class DatePicker extends Widget {
this.left.on(IconButton.EVENT_CHANGE, () => { this.left.on(IconButton.EVENT_CHANGE, () => {
if (this._month === 1) { if (this._month === 1) {
this.setValue({ this.setValue({
year: (this.year.getValue() - 1) || (getDate().getFullYear() - 1), year: this.year.getValue() - 1 || getDate().getFullYear() - 1,
month: 12, month: 12,
}); });
} else { } else {
this.setValue({ this.setValue({
year: this.year.getValue() || getDate().getFullYear(), year: this.year.getValue() || getDate().getFullYear(),
month: (this.month.getValue() - 1) || getDate().getMonth(), month: this.month.getValue() - 1 || getDate().getMonth(),
}); });
} }
this.fireEvent(DatePicker.EVENT_CHANGE); this.fireEvent(DatePicker.EVENT_CHANGE);
@ -55,7 +71,7 @@ export class DatePicker extends Widget {
}); });
this.right = createWidget({ this.right = createWidget({
type: "bi.icon_button", type: IconButton.xtype,
cls: "next-page-h-font", cls: "next-page-h-font",
width: 24, width: 24,
height: 24, height: 24,
@ -64,13 +80,13 @@ export class DatePicker extends Widget {
this.right.on(IconButton.EVENT_CHANGE, () => { this.right.on(IconButton.EVENT_CHANGE, () => {
if (this._month === 12) { if (this._month === 12) {
this.setValue({ this.setValue({
year: (this.year.getValue() + 1) || (getDate().getFullYear() + 1), year: this.year.getValue() + 1 || getDate().getFullYear() + 1,
month: 1, month: 1,
}); });
} else { } else {
this.setValue({ this.setValue({
year: this.year.getValue() || getDate().getFullYear(), year: this.year.getValue() || getDate().getFullYear(),
month: (this.month.getValue() + 1) || (getDate().getMonth() + 2), month: this.month.getValue() + 1 || getDate().getMonth() + 2,
}); });
} }
this.fireEvent(DatePicker.EVENT_CHANGE); this.fireEvent(DatePicker.EVENT_CHANGE);
@ -79,7 +95,7 @@ export class DatePicker extends Widget {
}); });
this.year = createWidget({ this.year = createWidget({
type: "bi.year_date_combo", type: YearDateCombo.xtype,
behaviors: o.behaviors, behaviors: o.behaviors,
min: o.min, min: o.min,
max: o.max, max: o.max,
@ -95,7 +111,7 @@ export class DatePicker extends Widget {
this.fireEvent(DatePicker.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW); this.fireEvent(DatePicker.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW);
}); });
this.month = createWidget({ this.month = createWidget({
type: "bi.month_date_combo", type: MonthDateCombo.xtype,
behaviors: o.behaviors, behaviors: o.behaviors,
allowMonths: this._getAllowMonths(), allowMonths: this._getAllowMonths(),
}); });
@ -111,27 +127,31 @@ export class DatePicker extends Widget {
}); });
createWidget({ createWidget({
type: "bi.htape", type: HTapeLayout.xtype,
element: this, element: this,
items: [{ items: [
el: { {
type: "bi.center_adapt", el: {
items: [this.left], type: CenterAdaptLayout.xtype,
items: [this.left],
},
width: 24,
}, },
width: 24, {
}, { el: {
el: { type: CenterAdaptLayout.xtype,
type: "bi.center_adapt", hgap: 10,
hgap: 10, items: [this.year, this.month],
items: [this.year, this.month], },
}, },
}, { {
el: { el: {
type: "bi.center_adapt", type: CenterAdaptLayout.xtype,
items: [this.right], items: [this.right],
},
width: 24,
}, },
width: 24, ],
}],
}); });
this.setValue({ this.setValue({
year: this._year, year: this._year,
@ -147,7 +167,7 @@ export class DatePicker extends Widget {
month = defaultMonth || allowMonth[0]; month = defaultMonth || allowMonth[0];
} }
this.month.setValue(month); this.month.setValue(month);
return month; return month;
} }

58
src/widget/date/calendar/picker.year.js

@ -1,17 +1,17 @@
import { shortcut, Widget, extend, createWidget, getDate, parseDateTime } from "@/core";
import { IconButton } from "@/base";
import { YearDateCombo } from "./combo.year.date"; import { YearDateCombo } from "./combo.year.date";
import { HTapeLayout, CenterAdaptLayout, shortcut, Widget, extend, createWidget, getDate, parseDateTime } from "@/core";
import { IconButton } from "@/base";
@shortcut() @shortcut()
export class YearPicker extends Widget { export class YearPicker extends Widget {
static xtype = "bi.year_picker" static xtype = "bi.year_picker";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW" static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
_defaultConfig() { _defaultConfig() {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, { return extend(conf, {
baseCls: "bi-year-picker", baseCls: "bi-year-picker",
behaviors: {}, behaviors: {},
@ -53,7 +53,7 @@ export class YearPicker extends Widget {
}); });
this.year = createWidget({ this.year = createWidget({
type: "bi.year_date_combo", type: YearDateCombo.xtype,
min: o.min, min: o.min,
behaviors: o.behaviors, behaviors: o.behaviors,
max: o.max, max: o.max,
@ -68,26 +68,32 @@ export class YearPicker extends Widget {
}); });
createWidget({ createWidget({
type: "bi.htape", type: HTapeLayout.xtype,
element: this, element: this,
items: [{ items: [
el: { {
type: "bi.center_adapt", el: {
items: [this.left], type: CenterAdaptLayout.xtype,
items: [this.left],
},
width: 25,
}, },
width: 25, {
}, { type: CenterAdaptLayout.xtype,
type: "bi.center_adapt", items: [
items: [{ {
el: this.year, el: this.year,
}], },
}, { ],
el: {
type: "bi.center_adapt",
items: [this.right],
}, },
width: 25, {
}], el: {
type: CenterAdaptLayout.xtype,
items: [this.right],
},
width: 25,
},
],
}); });
this.setValue(this._year); this.setValue(this._year);
} }
@ -96,7 +102,7 @@ export class YearPicker extends Widget {
const o = this.options; const o = this.options;
const valid = this._year > parseDateTime(o.min, "%Y-%X-%d").getFullYear(); const valid = this._year > parseDateTime(o.min, "%Y-%X-%d").getFullYear();
this.left.setEnable(valid); this.left.setEnable(valid);
return valid; return valid;
} }
@ -104,7 +110,7 @@ export class YearPicker extends Widget {
const o = this.options; const o = this.options;
const valid = this._year < parseDateTime(o.max, "%Y-%X-%d").getFullYear(); const valid = this._year < parseDateTime(o.max, "%Y-%X-%d").getFullYear();
this.right.setEnable(valid); this.right.setEnable(valid);
return valid; return valid;
} }

81
src/widget/date/calendar/popup.calendar.date.js

@ -1,7 +1,18 @@
import { shortcut, Widget, createWidget, bind, getDate, each, isNotEmptyString } from "@/core";
import { Navigation } from "@/base";
import { Calendar } from "@/case"; import { Calendar } from "@/case";
import { DatePicker } from "./picker.date"; import { DatePicker } from "./picker.date";
import { Navigation } from "@/base";
import {
VerticalLayout,
AbsoluteLayout,
Layout,
shortcut,
Widget,
createWidget,
bind,
getDate,
each,
isNotEmptyString
} from "@/core";
/** /**
* Created by GUY on 2015/9/7. * Created by GUY on 2015/9/7.
@ -10,7 +21,7 @@ import { DatePicker } from "./picker.date";
*/ */
@shortcut() @shortcut()
export class DateCalendarPopup extends Widget { export class DateCalendarPopup extends Widget {
static xtype = "bi.date_calendar_popup" static xtype = "bi.date_calendar_popup";
props = { props = {
baseCls: "bi-date-calendar-popup", baseCls: "bi-date-calendar-popup",
@ -19,14 +30,13 @@ export class DateCalendarPopup extends Widget {
selectedTime: null, selectedTime: null,
}; };
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW" static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW";
_createNav(v) { _createNav(v) {
const date = Calendar.getDateJSONByPage(v); const date = Calendar.getDateJSONByPage(v);
const calendar = createWidget({ const calendar = createWidget({
type: "bi.calendar", type: Calendar.xtype,
logic: { logic: {
dynamic: true, dynamic: true,
}, },
@ -37,7 +47,7 @@ export class DateCalendarPopup extends Widget {
// BI-45616 此处为确定当前应该展示哪个年月对应的Calendar, day不是关键数据, 给1号就可 // BI-45616 此处为确定当前应该展示哪个年月对应的Calendar, day不是关键数据, 给1号就可
day: 1, day: 1,
}); });
return calendar; return calendar;
} }
@ -54,7 +64,7 @@ export class DateCalendarPopup extends Widget {
day: this._day, day: this._day,
}; };
this.datePicker = createWidget({ this.datePicker = createWidget({
type: "bi.date_picker", type: DatePicker.xtype,
behaviors: o.behaviors, behaviors: o.behaviors,
min: o.min, min: o.min,
max: o.max, max: o.max,
@ -65,13 +75,11 @@ export class DateCalendarPopup extends Widget {
logic: { logic: {
dynamic: true, dynamic: true,
}, },
type: "bi.navigation", type: Navigation.xtype,
tab: this.datePicker, tab: this.datePicker,
cardCreator: bind(this._createNav, this), cardCreator: bind(this._createNav, this),
afterCardCreated () { afterCardCreated() {},
},
afterCardShow: () => { afterCardShow: () => {
this.calendar.setValue(this.selectedTime); this.calendar.setValue(this.selectedTime);
@ -94,26 +102,33 @@ export class DateCalendarPopup extends Widget {
this.fireEvent(DateCalendarPopup.EVENT_CHANGE); this.fireEvent(DateCalendarPopup.EVENT_CHANGE);
}); });
return [{ return [
type: "bi.vertical", {
items: [{ type: VerticalLayout.xtype,
el: this.calendar, items: [
hgap: 12, {
bgap: 7, el: this.calendar,
}], hgap: 12,
}, { bgap: 7,
type: "bi.absolute", }
items: [{ ],
el: { },
type: "bi.layout", {
cls: "bi-split-top", type: AbsoluteLayout.xtype,
}, items: [
height: 1, {
top: 40, el: {
left: 0, type: Layout.xtype,
right: 0, cls: "bi-split-top",
}], },
}]; height: 1,
top: 40,
left: 0,
right: 0,
}
],
}
];
} }
_checkMin() { _checkMin() {

87
src/widget/date/calendar/popup.month.js

@ -1,4 +1,20 @@
import { shortcut, Widget, extend, Controller, createWidget, Events, createItems, toPix, map, contains, getDate, LogicFactory, parseInt } from "@/core"; import { ButtonGroup, TextItem } from "@/base";
import {
CenterAdaptLayout,
shortcut,
Widget,
extend,
Controller,
createWidget,
Events,
createItems,
toPix,
map,
contains,
getDate,
LogicFactory,
parseInt
} from "@/core";
/** /**
* 月份展示面板 * 月份展示面板
@ -9,9 +25,9 @@ import { shortcut, Widget, extend, Controller, createWidget, Events, createItems
*/ */
@shortcut() @shortcut()
export class MonthPopup extends Widget { export class MonthPopup extends Widget {
static xtype = "bi.month_popup" static xtype = "bi.month_popup";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() { _defaultConfig() {
return extend(super._defaultConfig(...arguments), { return extend(super._defaultConfig(...arguments), {
@ -27,21 +43,30 @@ export class MonthPopup extends Widget {
this.selectedMonth = getDate().getMonth() + 1; this.selectedMonth = getDate().getMonth() + 1;
this.month = createWidget({ this.month = createWidget({
type: "bi.button_group", type: ButtonGroup.xtype,
element: this, element: this,
behaviors: o.behaviors, behaviors: o.behaviors,
items: createItems(this._getItems(o.allowMonths), {}), items: createItems(this._getItems(o.allowMonths), {}),
layouts: [LogicFactory.createLogic("table", extend({ layouts: [
dynamic: true, LogicFactory.createLogic(
}, { "table",
columns: 2, extend(
rows: 6, {
columnSize: [1 / 2, 1 / 2], dynamic: true,
rowSize: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + 1, },
})), { {
type: "bi.center_adapt", columns: 2,
vgap: 2, rows: 6,
}], columnSize: [1 / 2, 1 / 2],
rowSize: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + 1,
}
)
),
{
type: CenterAdaptLayout.xtype,
vgap: 2,
}
],
value: o.value, value: o.value,
}); });
@ -66,21 +91,23 @@ export class MonthPopup extends Widget {
items.push(month.slice(6, 8)); items.push(month.slice(6, 8));
items.push(month.slice(8, 10)); items.push(month.slice(8, 10));
items.push(month.slice(10, 12)); items.push(month.slice(10, 12));
items = map(items, (i, item) => map(item, (j, td) => { items = map(items, (i, item) =>
return { map(item, (j, td) => {
type: "bi.text_item", return {
cls: "bi-border-radius bi-list-item-select", type: TextItem.xtype,
textAlign: "center", cls: "bi-border-radius bi-list-item-select",
whiteSpace: "nowrap", textAlign: "center",
once: false, whiteSpace: "nowrap",
forceSelected: true, once: false,
height: toPix(BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, 1), forceSelected: true,
width: 30, height: toPix(BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, 1),
value: td, width: 30,
text: td, value: td,
disabled: !contains(m, td), text: td,
}; disabled: !contains(m, td),
})); };
})
);
Widget.popContext(); Widget.popContext();
return items; return items;

30
src/widget/date/calendar/popup.year.js

@ -1,6 +1,18 @@
import { shortcut, Widget, extend, createWidget, isKey, Controller, bind, isNotNull, isNotEmptyString, getDate, parseInt } from "@/core";
import { Navigation } from "@/base";
import { YearCalendar } from "@/case"; import { YearCalendar } from "@/case";
import { IconButton, Navigation } from "@/base";
import {
shortcut,
Widget,
extend,
createWidget,
isKey,
Controller,
bind,
isNotNull,
isNotEmptyString,
getDate,
parseInt
} from "@/core";
/** /**
* 年份展示面板 * 年份展示面板
@ -11,9 +23,9 @@ import { YearCalendar } from "@/case";
*/ */
@shortcut() @shortcut()
export class YearPopup extends Widget { export class YearPopup extends Widget {
static xtype = "bi.year_popup" static xtype = "bi.year_popup";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() { _defaultConfig() {
return extend(super._defaultConfig(...arguments), { return extend(super._defaultConfig(...arguments), {
@ -29,7 +41,7 @@ export class YearPopup extends Widget {
y = this._year; y = this._year;
const calendar = createWidget({ const calendar = createWidget({
type: "bi.year_calendar", type: YearCalendar.xtype,
behaviors: o.behaviors, behaviors: o.behaviors,
min: o.min, min: o.min,
max: o.max, max: o.max,
@ -39,7 +51,7 @@ export class YearPopup extends Widget {
year: y + v * 12, year: y + v * 12,
}); });
calendar.setValue(this._year); calendar.setValue(this._year);
return calendar; return calendar;
} }
@ -50,7 +62,7 @@ export class YearPopup extends Widget {
this.selectedYear = this._year = getDate().getFullYear(); this.selectedYear = this._year = getDate().getFullYear();
this.backBtn = createWidget({ this.backBtn = createWidget({
type: "bi.icon_button", type: IconButton.xtype,
cls: "pre-page-h-font", cls: "pre-page-h-font",
width: 24, width: 24,
height: 24, height: 24,
@ -58,7 +70,7 @@ export class YearPopup extends Widget {
}); });
this.preBtn = createWidget({ this.preBtn = createWidget({
type: "bi.icon_button", type: IconButton.xtype,
cls: "next-page-h-font", cls: "next-page-h-font",
width: 24, width: 24,
height: 24, height: 24,
@ -66,7 +78,7 @@ export class YearPopup extends Widget {
}); });
this.navigation = createWidget({ this.navigation = createWidget({
type: "bi.navigation", type: Navigation.xtype,
element: this, element: this,
single: true, single: true,
logic: { logic: {

31
src/widget/date/calendar/trigger.triangle.date.js

@ -1,5 +1,5 @@
import { shortcut, extend, createWidget } from "@/core"; import { Label, IconLabel, Trigger } from "@/base";
import { Trigger } from "@/base"; import { VerticalAdaptLayout, shortcut, extend, createWidget } from "@/core";
/** /**
* 日期控件中的年份或月份trigger * 日期控件中的年份或月份trigger
@ -10,7 +10,7 @@ import { Trigger } from "@/base";
*/ */
@shortcut() @shortcut()
export class DateTriangleTrigger extends Trigger { export class DateTriangleTrigger extends Trigger {
static xtype = "bi.date_triangle_trigger" static xtype = "bi.date_triangle_trigger";
_const = { _const = {
height: 24, height: 24,
@ -30,7 +30,7 @@ export class DateTriangleTrigger extends Trigger {
const o = this.options, const o = this.options,
c = this._const; c = this._const;
this.text = createWidget({ this.text = createWidget({
type: "bi.label", type: Label.xtype,
cls: "list-item-text", cls: "list-item-text",
textAlign: "right", textAlign: "right",
text: o.text, text: o.text,
@ -39,15 +39,18 @@ export class DateTriangleTrigger extends Trigger {
}); });
createWidget({ createWidget({
type: "bi.vertical_adapt", type: VerticalAdaptLayout.xtype,
element: this, element: this,
items: [{ items: [
el: this.text, {
rgap: 5, el: this.text,
}, { rgap: 5,
type: "bi.icon_label", },
width: 16, {
}], type: IconLabel.xtype,
width: 16,
}
],
}); });
} }
@ -67,7 +70,5 @@ export class DateTriangleTrigger extends Trigger {
return this.item.getText(); return this.item.getText();
} }
getKey() { getKey() {}
}
} }

58
src/widget/datepane/card.static.datepane.js

@ -1,18 +1,31 @@
import { shortcut, Widget, extend, createWidget, bind, isNull, each, isNotEmptyString, getDate, getMonthDays } from "@/core";
import { DatePicker, DateCalendarPopup } from "../date/calendar"; import { DatePicker, DateCalendarPopup } from "../date/calendar";
import { Calendar } from "@/case";
import { Navigation } from "@/base"; import { Navigation } from "@/base";
import {
VTapeLayout,
AbsoluteLayout,
Layout,
shortcut,
Widget,
extend,
createWidget,
bind,
isNull,
each,
isNotEmptyString,
getDate,
getMonthDays
} from "@/core";
import { Calendar } from "@/case";
@shortcut() @shortcut()
export class StaticDatePaneCard extends Widget { export class StaticDatePaneCard extends Widget {
static xtype = "bi.static_date_pane_card"; static xtype = "bi.static_date_pane_card";
static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW";
"EVENT_BEFORE_YEAR_MONTH_POPUPVIEW";
_defaultConfig() { _defaultConfig() {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, { return extend(conf, {
baseCls: "bi-date-pane", baseCls: "bi-date-pane",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
@ -35,16 +48,14 @@ export class StaticDatePaneCard extends Widget {
}; };
this.datePicker = createWidget({ this.datePicker = createWidget({
type: "bi.date_picker", type: DatePicker.xtype,
behaviors: o.behaviors, behaviors: o.behaviors,
min: o.min, min: o.min,
max: o.max, max: o.max,
}); });
this.datePicker.on(DatePicker.EVENT_CHANGE, () => { this.datePicker.on(DatePicker.EVENT_CHANGE, () => {
const value = this.datePicker.getValue(); const value = this.datePicker.getValue();
const monthDay = getMonthDays( const monthDay = getMonthDays(getDate(value.year, value.month - 1, 1));
getDate(value.year, value.month - 1, 1)
);
let day = this.selectedTime.day || 0; let day = this.selectedTime.day || 0;
if (day > monthDay) { if (day > monthDay) {
day = monthDay; day = monthDay;
@ -54,27 +65,20 @@ export class StaticDatePaneCard extends Widget {
month: value.month, month: value.month,
}; };
day !== 0 && (this.selectedTime.day = day); day !== 0 && (this.selectedTime.day = day);
this.calendar.setSelect( this.calendar.setSelect(Calendar.getPageByDateJSON(this.selectedTime));
Calendar.getPageByDateJSON(this.selectedTime)
);
this.calendar.setValue(this.selectedTime); this.calendar.setValue(this.selectedTime);
day !== 0 && this.fireEvent(DateCalendarPopup.EVENT_CHANGE); day !== 0 && this.fireEvent(DateCalendarPopup.EVENT_CHANGE);
}); });
this.datePicker.on( this.datePicker.on(DatePicker.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW, () => {
DatePicker.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW, this.fireEvent(StaticDatePaneCard.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW);
() => { });
this.fireEvent(
StaticDatePaneCard.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW
);
}
);
this.calendar = createWidget({ this.calendar = createWidget({
direction: "custom", direction: "custom",
// logic: { // logic: {
// dynamic: false // dynamic: false
// }, // },
type: "bi.navigation", type: Navigation.xtype,
tab: this.datePicker, tab: this.datePicker,
cardCreator: bind(this._createNav, this), cardCreator: bind(this._createNav, this),
}); });
@ -87,7 +91,7 @@ export class StaticDatePaneCard extends Widget {
this.setValue(o.selectedTime); this.setValue(o.selectedTime);
createWidget({ createWidget({
type: "bi.vtape", type: VTapeLayout.xtype,
element: this, element: this,
items: [ items: [
{ {
@ -100,12 +104,12 @@ export class StaticDatePaneCard extends Widget {
}); });
createWidget({ createWidget({
type: "bi.absolute", type: AbsoluteLayout.xtype,
element: this, element: this,
items: [ items: [
{ {
el: { el: {
type: "bi.layout", type: Layout.xtype,
cls: "bi-split-top", cls: "bi-split-top",
}, },
height: 1, height: 1,
@ -120,7 +124,7 @@ export class StaticDatePaneCard extends Widget {
_createNav(v) { _createNav(v) {
const date = Calendar.getDateJSONByPage(v); const date = Calendar.getDateJSONByPage(v);
const calendar = createWidget({ const calendar = createWidget({
type: "bi.calendar", type: Calendar.xtype,
logic: { logic: {
dynamic: false, dynamic: false,
}, },
@ -130,13 +134,13 @@ export class StaticDatePaneCard extends Widget {
month: date.month, month: date.month,
day: this.selectedTime.day, day: this.selectedTime.day,
}); });
return calendar; return calendar;
} }
_getNewCurrentDate() { _getNewCurrentDate() {
const today = getDate(); const today = getDate();
return { return {
year: today.getFullYear(), year: today.getFullYear(),
month: today.getMonth() + 1, month: today.getMonth() + 1,

291
src/widget/datepane/datepane.js

@ -1,6 +1,20 @@
import { shortcut, Widget, createItems, i18nText, isEmptyObject, isNull, isEmptyString, isNotEmptyObject, getDate } from "@/core"; import {
import { ButtonGroup, TextButton } from "@/base"; VTapeLayout,
import { DynamicDateHelper, DynamicDateCombo, DynamicDatePopup } from "../dynamicdate"; CenterLayout,
shortcut,
Widget,
createItems,
i18nText,
isEmptyObject,
isNull,
isEmptyString,
isNotEmptyObject,
getDate
} from "@/core";
import { LinearSegment } from "@/case";
import { Tab, TextButton, ButtonGroup } from "@/base";
import { StaticDatePaneCard } from "./card.static.datepane";
import { DynamicDateCard, DynamicDateHelper, DynamicDateCombo, DynamicDatePopup } from "../dynamicdate";
@shortcut() @shortcut()
export class DynamicDatePane extends Widget { export class DynamicDatePane extends Widget {
@ -16,140 +30,167 @@ export class DynamicDatePane extends Widget {
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31", maxDate: "2099-12-31",
supportDynamic: true, supportDynamic: true,
} };
render() { render() {
const o = this.options; const o = this.options;
return { return {
type: "bi.vtape", type: VTapeLayout.xtype,
items: [{ items: [
el: { {
type: "bi.linear_segment", el: {
invisible: !o.supportDynamic, type: LinearSegment.xtype,
cls: "bi-split-bottom", invisible: !o.supportDynamic,
height: 30, cls: "bi-split-bottom",
items: createItems([{ height: 30,
text: i18nText("BI-Multi_Date_YMD"), items: createItems(
value: DynamicDatePane.Static, [
}, { {
text: i18nText("BI-Basic_Dynamic_Title"), text: i18nText("BI-Multi_Date_YMD"),
value: DynamicDatePane.Dynamic, value: DynamicDatePane.Static,
}], { },
textAlign: "center", {
}), text: i18nText("BI-Basic_Dynamic_Title"),
listeners: [{ value: DynamicDatePane.Dynamic,
eventName: ButtonGroup.EVENT_CHANGE, }
action: () => { ],
let date; {
const value = this.switcher.getValue()[0]; textAlign: "center",
this.dateTab.setSelect(value);
switch (value) {
case DynamicDatePane.Static:
date = DynamicDateHelper.getCalculation(this.dynamicPane.getValue());
this.ymd.setValue({
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
});
break;
case DynamicDatePane.Dynamic:
this.dynamicPane.setValue({
year: 0,
});
break;
default:
break;
} }
this.fireEvent(DynamicDatePane.EVENT_CHANGE); ),
}, listeners: [
}], {
ref: _ref => { eventName: ButtonGroup.EVENT_CHANGE,
this.switcher = _ref;
},
},
height: o.supportDynamic ? 30 : 0,
}, {
type: "bi.tab",
ref: _ref => {
this.dateTab = _ref;
},
showIndex: DynamicDatePane.Static,
cardCreator: v => {
switch (v) {
case DynamicDatePane.Static:
return {
type: "bi.static_date_pane_card",
min: o.minDate,
max: o.maxDate,
behaviors: o.behaviors,
listeners: [{
eventName: "EVENT_CHANGE",
action: () => { action: () => {
let date;
const value = this.switcher.getValue()[0];
this.dateTab.setSelect(value);
switch (value) {
case DynamicDatePane.Static:
date = DynamicDateHelper.getCalculation(this.dynamicPane.getValue());
this.ymd.setValue({
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
});
break;
case DynamicDatePane.Dynamic:
this.dynamicPane.setValue({
year: 0,
});
break;
default:
break;
}
this.fireEvent(DynamicDatePane.EVENT_CHANGE); this.fireEvent(DynamicDatePane.EVENT_CHANGE);
}, },
}, { }
eventName: "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW", ],
action: () => { ref: _ref => {
this.fireEvent(DynamicDatePane.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW); this.switcher = _ref;
}, },
}], },
ref: _ref => { height: o.supportDynamic ? 30 : 0,
this.ymd = _ref; },
}, {
}; type: Tab.xtype,
case DynamicDatePane.Dynamic: ref: _ref => {
default: this.dateTab = _ref;
return { },
type: "bi.vtape", showIndex: DynamicDatePane.Static,
items: [{ cardCreator: v => {
type: "bi.dynamic_date_card", switch (v) {
case DynamicDatePane.Static:
return {
type: StaticDatePaneCard.xtype,
min: o.minDate, min: o.minDate,
max: o.maxDate, max: o.maxDate,
behaviors: o.behaviors,
listeners: [
{
eventName: "EVENT_CHANGE",
action: () => {
this.fireEvent(DynamicDatePane.EVENT_CHANGE);
},
},
{
eventName: "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW",
action: () => {
this.fireEvent(DynamicDatePane.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW);
},
}
],
ref: _ref => { ref: _ref => {
this.dynamicPane = _ref; this.ymd = _ref;
}, },
}, { };
el: { case DynamicDatePane.Dynamic:
type: "bi.center", default:
items: [{ return {
type: "bi.text_button", type: VTapeLayout.xtype,
cls: "bi-high-light bi-border-top", items: [
shadow: true, {
text: i18nText("BI-Basic_Clear"), type: DynamicDateCard.xtype,
textHeight: 23, min: o.minDate,
listeners: [{ max: o.maxDate,
eventName: TextButton.EVENT_CHANGE, ref: _ref => {
action: () => { this.dynamicPane = _ref;
this.setValue(); },
this.fireEvent(DynamicDatePane.EVENT_CHANGE); },
}, {
}], el: {
}, { type: CenterLayout.xtype,
type: "bi.text_button", items: [
cls: "bi-border-left bi-high-light bi-border-top", {
textHeight: 23, type: TextButton.xtype,
shadow: true, cls: "bi-high-light bi-border-top",
text: i18nText("BI-Basic_OK"), shadow: true,
listeners: [{ text: i18nText("BI-Basic_Clear"),
eventName: TextButton.EVENT_CHANGE, textHeight: 23,
action: () => { listeners: [
const type = this.dateTab.getSelect(); {
if (type === DynamicDateCombo.Dynamic) { eventName: TextButton.EVENT_CHANGE,
this.dynamicPane.checkValidation(true) && this.fireEvent(DynamicDatePopup.EVENT_CHANGE); action: () => {
} else { this.setValue();
this.fireEvent(DynamicDatePane.EVENT_CHANGE); this.fireEvent(DynamicDatePane.EVENT_CHANGE);
},
}
],
},
{
type: TextButton.xtype,
cls: "bi-border-left bi-high-light bi-border-top",
textHeight: 23,
shadow: true,
text: i18nText("BI-Basic_OK"),
listeners: [
{
eventName: TextButton.EVENT_CHANGE,
action: () => {
const type = this.dateTab.getSelect();
if (type === DynamicDateCombo.Dynamic) {
this.dynamicPane.checkValidation(true) &&
this.fireEvent(
DynamicDatePopup.EVENT_CHANGE
);
} else {
this.fireEvent(DynamicDatePane.EVENT_CHANGE);
}
},
}
],
} }
}, ],
}], },
}], height: 24,
}, }
height: 24, ],
}], };
}; }
} },
}, }
}], ],
}; };
} }
@ -212,7 +253,7 @@ export class DynamicDatePane extends Widget {
getValue() { getValue() {
const type = this.dateTab.getSelect(); const type = this.dateTab.getSelect();
return { return {
type, type,
value: type === DynamicDatePane.Static ? this.dateTab.getValue() : this.dynamicPane.getValue(), value: type === DynamicDatePane.Static ? this.dateTab.getValue() : this.dynamicPane.getValue(),

49
src/widget/datetime/datetime.combo.js

@ -1,10 +1,11 @@
import { shortcut, extend, getDate, isNotNull, createWidget } from "@/core"; import { DateTimeTrigger } from "./datetime.trigger";
import { Single, Combo, IconButton } from "@/base";
import { DateTimePopup } from "./datetime.popup"; import { DateTimePopup } from "./datetime.popup";
import { Combo, IconButton, Single } from "@/base";
import { HTapeLayout, shortcut, extend, getDate, isNotNull, createWidget } from "@/core";
@shortcut() @shortcut()
export class DateTimeCombo extends Single { export class DateTimeCombo extends Single {
static xtype = "bi.date_time_combo" static xtype = "bi.date_time_combo";
constants = { constants = {
popupHeight: 290, popupHeight: 290,
@ -14,14 +15,16 @@ export class DateTimeCombo extends Single {
iconWidth: 24, iconWidth: 24,
}; };
static EVENT_CANCEL = "EVENT_CANCEL" static EVENT_CANCEL = "EVENT_CANCEL";
static EVENT_CONFIRM = "EVENT_CONFIRM" static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW" static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
_defaultConfig(conf) { _defaultConfig(conf) {
return extend(super._defaultConfig(...arguments), { return extend(super._defaultConfig(...arguments), {
baseCls: `bi-date-time-combo bi-focus-shadow ${conf.simple ? "bi-border-bottom" : "bi-border bi-border-radius"}`, baseCls: `bi-date-time-combo bi-focus-shadow ${
conf.simple ? "bi-border-bottom" : "bi-border bi-border-radius"
}`,
width: 200, width: 200,
height: 24, height: 24,
minDate: "1900-01-01", minDate: "1900-01-01",
@ -33,16 +36,18 @@ export class DateTimeCombo extends Single {
super._init(...arguments); super._init(...arguments);
const opts = this.options; const opts = this.options;
const date = getDate(); const date = getDate();
this.storeValue = isNotNull(opts.value) ? opts.value : { this.storeValue = isNotNull(opts.value)
year: date.getFullYear(), ? opts.value
month: date.getMonth() + 1, : {
day: date.getDate(), year: date.getFullYear(),
hour: date.getHours(), month: date.getMonth() + 1,
minute: date.getMinutes(), day: date.getDate(),
second: date.getSeconds(), hour: date.getHours(),
}; minute: date.getMinutes(),
second: date.getSeconds(),
};
this.trigger = createWidget({ this.trigger = createWidget({
type: "bi.date_time_trigger", type: DateTimeTrigger.xtype,
height: opts.height, height: opts.height,
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
@ -50,7 +55,7 @@ export class DateTimeCombo extends Single {
}); });
this.popup = createWidget({ this.popup = createWidget({
type: "bi.date_time_popup", type: DateTimePopup.xtype,
behaviors: opts.behaviors, behaviors: opts.behaviors,
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
@ -70,7 +75,7 @@ export class DateTimeCombo extends Single {
this.fireEvent(DateTimeCombo.EVENT_CONFIRM); this.fireEvent(DateTimeCombo.EVENT_CONFIRM);
}); });
this.combo = createWidget({ this.combo = createWidget({
type: "bi.combo", type: Combo.xtype,
container: opts.container, container: opts.container,
toggle: false, toggle: false,
isNeedAdjustHeight: false, isNeedAdjustHeight: false,
@ -83,7 +88,7 @@ export class DateTimeCombo extends Single {
stopPropagation: false, stopPropagation: false,
}, },
// DEC-4250 和复选下拉一样,点击不收起 // DEC-4250 和复选下拉一样,点击不收起
hideChecker (e) { hideChecker(e) {
return triggerBtn.element.find(e.target).length === 0; return triggerBtn.element.find(e.target).length === 0;
}, },
}); });
@ -93,7 +98,7 @@ export class DateTimeCombo extends Single {
}); });
const triggerBtn = createWidget({ const triggerBtn = createWidget({
type: "bi.icon_button", type: IconButton.xtype,
cls: "bi-trigger-icon-button date-font", cls: "bi-trigger-icon-button date-font",
width: this.constants.iconWidth, width: this.constants.iconWidth,
height: opts.height, height: opts.height,
@ -107,7 +112,7 @@ export class DateTimeCombo extends Single {
}); });
createWidget({ createWidget({
type: "bi.htape", type: HTapeLayout.xtype,
columnSize: ["", this.constants.iconWidth], columnSize: ["", this.constants.iconWidth],
element: this, element: this,
items: [this.combo, triggerBtn], items: [this.combo, triggerBtn],

89
src/widget/datetime/datetime.popup.js

@ -1,14 +1,26 @@
import { shortcut, Widget, extend, createWidget, i18nText, isNull, getDate } from "@/core";
import { TextButton } from "@/base"; import { TextButton } from "@/base";
import { DateCalendarPopup } from "../date/calendar"; import { DateCalendarPopup } from "../date/calendar";
import {
GridLayout,
VTapeLayout,
CenterAdaptLayout,
shortcut,
Widget,
extend,
createWidget,
i18nText,
isNull,
getDate
} from "@/core";
import { DynamicDateTimeSelect } from "../dynamicdatetime";
@shortcut() @shortcut()
export class DateTimePopup extends Widget { export class DateTimePopup extends Widget {
static xtype = "bi.date_time_popup" static xtype = "bi.date_time_popup";
static BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE" static BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE";
static BUTTON_CANCEL_EVENT_CHANGE = "BUTTON_CANCEL_EVENT_CHANGE" static BUTTON_CANCEL_EVENT_CHANGE = "BUTTON_CANCEL_EVENT_CHANGE";
static CALENDAR_EVENT_CHANGE = "CALENDAR_EVENT_CHANGE" static CALENDAR_EVENT_CHANGE = "CALENDAR_EVENT_CHANGE";
_defaultConfig() { _defaultConfig() {
return extend(super._defaultConfig(...arguments), { return extend(super._defaultConfig(...arguments), {
@ -22,7 +34,7 @@ export class DateTimePopup extends Widget {
super._init(...arguments); super._init(...arguments);
const opts = this.options; const opts = this.options;
this.cancelButton = createWidget({ this.cancelButton = createWidget({
type: "bi.text_button", type: TextButton.xtype,
cls: "multidate-popup-button bi-border-top bi-border-right", cls: "multidate-popup-button bi-border-top bi-border-right",
shadow: true, shadow: true,
text: i18nText("BI-Basic_Cancel"), text: i18nText("BI-Basic_Cancel"),
@ -32,7 +44,7 @@ export class DateTimePopup extends Widget {
}); });
this.okButton = createWidget({ this.okButton = createWidget({
type: "bi.text_button", type: TextButton.xtype,
cls: "multidate-popup-button bi-border-top", cls: "multidate-popup-button bi-border-top",
shadow: true, shadow: true,
text: i18nText("BI-Basic_OK"), text: i18nText("BI-Basic_OK"),
@ -42,7 +54,7 @@ export class DateTimePopup extends Widget {
}); });
this.dateCombo = createWidget({ this.dateCombo = createWidget({
type: "bi.date_calendar_popup", type: DateCalendarPopup.xtype,
behaviors: opts.behaviors, behaviors: opts.behaviors,
min: this.options.min, min: this.options.min,
max: this.options.max, max: this.options.max,
@ -52,32 +64,36 @@ export class DateTimePopup extends Widget {
}); });
this.dateButton = createWidget({ this.dateButton = createWidget({
type: "bi.grid", type: GridLayout.xtype,
items: [ items: [[this.cancelButton, this.okButton]],
[this.cancelButton, this.okButton]
],
}); });
createWidget({ createWidget({
element: this, element: this,
type: "bi.vtape", type: VTapeLayout.xtype,
items: [{ items: [
el: this.dateCombo, {
}, { el: this.dateCombo,
el: {
type: "bi.center_adapt",
cls: "bi-split-top",
items: [{
type: "bi.dynamic_date_time_select",
ref: _ref => {
this.timeSelect = _ref;
},
}],
}, },
height: 50, {
}, { el: {
el: this.dateButton, type: CenterAdaptLayout.xtype,
height: 30, cls: "bi-split-top",
}], items: [
{
type: DynamicDateTimeSelect.xtype,
ref: _ref => {
this.timeSelect = _ref;
},
}
],
},
height: 50,
},
{
el: this.dateButton,
height: 30,
}
],
}); });
this.setValue(opts.value); this.setValue(opts.value);
} }
@ -112,10 +128,13 @@ export class DateTimePopup extends Widget {
} }
getValue() { getValue() {
return extend({ return extend(
year: this.dateCombo.getValue().year, {
month: this.dateCombo.getValue().month, year: this.dateCombo.getValue().year,
day: this.dateCombo.getValue().day, month: this.dateCombo.getValue().month,
}, this.timeSelect.getValue()); day: this.dateCombo.getValue().day,
},
this.timeSelect.getValue()
);
} }
} }

35
src/widget/datetime/datetime.trigger.js

@ -1,19 +1,9 @@
import { import { Label, Trigger } from "@/base";
shortcut, import { HTapeLayout, shortcut, extend, createWidget, isNull, getDate, print } from "@/core";
extend,
createWidget,
isNull,
getDate,
print
} from "@/core";
import {
Trigger
} from "@/base";
@shortcut() @shortcut()
export class DateTimeTrigger extends Trigger { export class DateTimeTrigger extends Trigger {
static xtype = "bi.date_time_trigger" static xtype = "bi.date_time_trigger";
_const = { _const = {
hgap: 4, hgap: 4,
@ -35,7 +25,7 @@ export class DateTimeTrigger extends Trigger {
const o = this.options, const o = this.options,
c = this._const; c = this._const;
this.text = createWidget({ this.text = createWidget({
type: "bi.label", type: Label.xtype,
textAlign: "left", textAlign: "left",
height: o.height, height: o.height,
width: o.width, width: o.width,
@ -43,14 +33,17 @@ export class DateTimeTrigger extends Trigger {
}); });
createWidget({ createWidget({
type: "bi.htape", type: HTapeLayout.xtype,
element: this, element: this,
items: [{ items: [
el: this.text, {
}, { el: this.text,
el: createWidget(), },
width: this._const.iconWidth, {
}], el: createWidget(),
width: this._const.iconWidth,
}
],
}); });
this.setValue(o.value); this.setValue(o.value);
} }

100
src/widget/datetimepane/card.static.datetimepane.js

@ -1,18 +1,32 @@
import { shortcut, Widget, extend, getDate, createWidget, bind, isNull, each, isNotEmptyString, getMonthDays } from "@/core";
import { DatePicker, DateCalendarPopup } from "../date/calendar"; import { DatePicker, DateCalendarPopup } from "../date/calendar";
import { Calendar } from "@/case";
import { Navigation } from "@/base"; import { Navigation } from "@/base";
import {
VTapeLayout,
AbsoluteLayout,
Layout,
shortcut,
Widget,
extend,
getDate,
createWidget,
bind,
isNull,
each,
isNotEmptyString,
getMonthDays
} from "@/core";
import { Calendar } from "@/case";
import { DynamicDateTimeSelect } from "../dynamicdatetime/dynamicdatetime.timeselect"; import { DynamicDateTimeSelect } from "../dynamicdatetime/dynamicdatetime.timeselect";
@shortcut() @shortcut()
export class StaticDateTimePaneCard extends Widget { export class StaticDateTimePaneCard extends Widget {
static xtype = "bi.static_date_time_pane_card" static xtype = "bi.static_date_time_pane_card";
static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW" static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW";
_defaultConfig() { _defaultConfig() {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, { return extend(conf, {
baseCls: "bi-date-time-pane", baseCls: "bi-date-time-pane",
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
@ -35,7 +49,7 @@ export class StaticDateTimePaneCard extends Widget {
}; };
this.datePicker = createWidget({ this.datePicker = createWidget({
type: "bi.date_picker", type: DatePicker.xtype,
behaviors: o.behaviors, behaviors: o.behaviors,
min: o.min, min: o.min,
max: o.max, max: o.max,
@ -66,7 +80,7 @@ export class StaticDateTimePaneCard extends Widget {
// logic: { // logic: {
// dynamic: false // dynamic: false
// }, // },
type: "bi.navigation", type: Navigation.xtype,
tab: this.datePicker, tab: this.datePicker,
cardCreator: bind(this._createNav, this), cardCreator: bind(this._createNav, this),
}); });
@ -78,44 +92,52 @@ export class StaticDateTimePaneCard extends Widget {
}); });
createWidget({ createWidget({
type: "bi.vtape", type: VTapeLayout.xtype,
element: this, element: this,
hgap: 10, hgap: 10,
items: [{ items: [
el: this.datePicker, {
height: 40, el: this.datePicker,
}, this.calendar, { height: 40,
el: { },
type: "bi.dynamic_date_time_select", this.calendar,
cls: "bi-split-top", {
ref: _ref => { el: {
this.timeSelect = _ref; type: DynamicDateTimeSelect.xtype,
}, cls: "bi-split-top",
listeners: [{ ref: (_ref) => {
eventName: DynamicDateTimeSelect.EVENT_CONFIRM, this.timeSelect = _ref;
action: () => {
this.selectedTime = extend(this.calendar.getValue(), this.timeSelect.getValue());
this.fireEvent("EVENT_CHANGE");
}, },
}], listeners: [
{
eventName: DynamicDateTimeSelect.EVENT_CONFIRM,
action: () => {
this.selectedTime = extend(this.calendar.getValue(), this.timeSelect.getValue());
this.fireEvent("EVENT_CHANGE");
},
},
],
},
height: 40,
}, },
height: 40, ],
}],
}); });
createWidget({ createWidget({
type: "bi.absolute", type: AbsoluteLayout.xtype,
element: this, element: this,
items: [{ items: [
el: { {
type: "bi.layout", el: {
cls: "bi-split-top", type: Layout.xtype,
cls: "bi-split-top",
},
height: 1,
top: 40,
left: 0,
right: 0,
}, },
height: 1, ],
top: 40,
left: 0,
right: 0,
}],
}); });
this.setValue(o.selectedTime); this.setValue(o.selectedTime);
} }
@ -123,7 +145,7 @@ export class StaticDateTimePaneCard extends Widget {
_createNav(v) { _createNav(v) {
const date = Calendar.getDateJSONByPage(v); const date = Calendar.getDateJSONByPage(v);
const calendar = createWidget({ const calendar = createWidget({
type: "bi.calendar", type: Calendar.xtype,
logic: { logic: {
dynamic: false, dynamic: false,
}, },
@ -133,13 +155,13 @@ export class StaticDateTimePaneCard extends Widget {
month: date.month, month: date.month,
day: this.selectedTime.day, day: this.selectedTime.day,
}); });
return calendar; return calendar;
} }
_getNewCurrentDate() { _getNewCurrentDate() {
const today = getDate(); const today = getDate();
return { return {
year: today.getFullYear(), year: today.getFullYear(),
month: today.getMonth() + 1, month: today.getMonth() + 1,

297
src/widget/datetimepane/datetimepane.js

@ -1,17 +1,31 @@
import { shortcut, Widget, createItems, i18nText, isNull, isEmptyObject, isEmptyString, isNotEmptyObject, getDate } from "@/core"; import {
import { ButtonGroup, TextButton } from "@/base"; VTapeLayout,
CenterLayout,
shortcut,
Widget,
createItems,
i18nText,
isNull,
isEmptyObject,
isEmptyString,
isNotEmptyObject,
getDate
} from "@/core";
import { LinearSegment } from "@/case";
import { Tab, TextButton, ButtonGroup } from "@/base";
import { StaticDateTimePaneCard } from "./card.static.datetimepane";
import { DynamicDateCard, DynamicDateCombo, DynamicDateHelper } from "../dynamicdate";
import { DynamicDatePane } from "../datepane"; import { DynamicDatePane } from "../datepane";
import { DynamicDateCombo, DynamicDateHelper } from "../dynamicdate";
@shortcut() @shortcut()
export class DynamicDateTimePane extends Widget { export class DynamicDateTimePane extends Widget {
static xtype = "bi.dynamic_date_time_pane" static xtype = "bi.dynamic_date_time_pane";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW" static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW";
static Static = 1 static Static = 1;
static Dynamic = 2 static Dynamic = 2;
props = { props = {
baseCls: "bi-dynamic-date-pane", baseCls: "bi-dynamic-date-pane",
@ -22,136 +36,163 @@ export class DynamicDateTimePane extends Widget {
render() { render() {
const o = this.options; const o = this.options;
return { return {
type: "bi.vtape", type: VTapeLayout.xtype,
items: [{ items: [
el: { {
type: "bi.linear_segment", el: {
invisible: !o.supportDynamic, type: LinearSegment.xtype,
cls: "bi-split-bottom", invisible: !o.supportDynamic,
height: 30, cls: "bi-split-bottom",
items: createItems([{ height: 30,
text: i18nText("BI-Multi_Date_YMD"), items: createItems(
value: DynamicDateTimePane.Static, [
}, { {
text: i18nText("BI-Basic_Dynamic_Title"), text: i18nText("BI-Multi_Date_YMD"),
value: DynamicDateTimePane.Dynamic, value: DynamicDateTimePane.Static,
}], { },
textAlign: "center", {
}), text: i18nText("BI-Basic_Dynamic_Title"),
listeners: [{ value: DynamicDateTimePane.Dynamic,
eventName: ButtonGroup.EVENT_CHANGE, }
action: () => { ],
const value = this.switcher.getValue()[0]; {
let date; textAlign: "center",
this.dateTab.setSelect(value);
switch (value) {
case DynamicDateTimePane.Static:
date = DynamicDateHelper.getCalculation(this.dynamicPane.getValue());
this.ymd.setValue({
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
});
break;
case DynamicDateTimePane.Dynamic:
this.dynamicPane.setValue({
year: 0,
});
break;
default:
break;
} }
this.fireEvent(DynamicDateTimePane.EVENT_CHANGE); ),
}, listeners: [
}], {
ref: _ref => { eventName: ButtonGroup.EVENT_CHANGE,
this.switcher = _ref;
},
},
height: o.supportDynamic ? 30 : 0,
}, {
type: "bi.tab",
ref: _ref => {
this.dateTab = _ref;
},
showIndex: DynamicDateTimePane.Static,
cardCreator: v => {
switch (v) {
case DynamicDateTimePane.Static:
return {
type: "bi.static_date_time_pane_card",
min: o.minDate,
max: o.maxDate,
behaviors: o.behaviors,
listeners: [{
eventName: "EVENT_CHANGE",
action: () => { action: () => {
const value = this.switcher.getValue()[0];
let date;
this.dateTab.setSelect(value);
switch (value) {
case DynamicDateTimePane.Static:
date = DynamicDateHelper.getCalculation(this.dynamicPane.getValue());
this.ymd.setValue({
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
});
break;
case DynamicDateTimePane.Dynamic:
this.dynamicPane.setValue({
year: 0,
});
break;
default:
break;
}
this.fireEvent(DynamicDateTimePane.EVENT_CHANGE); this.fireEvent(DynamicDateTimePane.EVENT_CHANGE);
}, },
}, { }
eventName: "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW", ],
action: () => { ref: _ref => {
this.fireEvent(DynamicDateTimePane.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW); this.switcher = _ref;
}, },
}], },
ref: _ref => { height: o.supportDynamic ? 30 : 0,
this.ymd = _ref; },
}, {
}; type: Tab.xtype,
case DynamicDateTimePane.Dynamic: ref: _ref => {
default: this.dateTab = _ref;
return { },
type: "bi.vtape", showIndex: DynamicDateTimePane.Static,
items: [{ cardCreator: v => {
type: "bi.dynamic_date_card", switch (v) {
case DynamicDateTimePane.Static:
return {
type: StaticDateTimePaneCard.xtype,
min: o.minDate, min: o.minDate,
max: o.maxDate, max: o.maxDate,
behaviors: o.behaviors,
listeners: [
{
eventName: "EVENT_CHANGE",
action: () => {
this.fireEvent(DynamicDateTimePane.EVENT_CHANGE);
},
},
{
eventName: "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW",
action: () => {
this.fireEvent(DynamicDateTimePane.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW);
},
}
],
ref: _ref => { ref: _ref => {
this.dynamicPane = _ref; this.ymd = _ref;
}, },
}, { };
el: { case DynamicDateTimePane.Dynamic:
type: "bi.center", default:
items: [{ return {
type: "bi.text_button", type: VTapeLayout.xtype,
cls: "bi-high-light bi-border-top", items: [
shadow: true, {
text: i18nText("BI-Basic_Clear"), type: DynamicDateCard.xtype,
textHeight: 23, min: o.minDate,
listeners: [{ max: o.maxDate,
eventName: TextButton.EVENT_CHANGE, ref: _ref => {
action: () => { this.dynamicPane = _ref;
this.setValue(); },
this.fireEvent(DynamicDatePane.EVENT_CHANGE); },
}, {
}], el: {
}, { type: CenterLayout.xtype,
type: "bi.text_button", items: [
cls: "bi-border-left bi-high-light bi-border-top", {
textHeight: 23, type: TextButton.xtype,
shadow: true, cls: "bi-high-light bi-border-top",
text: i18nText("BI-Basic_OK"), shadow: true,
listeners: [{ text: i18nText("BI-Basic_Clear"),
eventName: TextButton.EVENT_CHANGE, textHeight: 23,
action: () => { listeners: [
const type = this.dateTab.getSelect(); {
if (type === DynamicDateCombo.Dynamic) { eventName: TextButton.EVENT_CHANGE,
this.dynamicPane.checkValidation(true) && this.fireEvent(DynamicDatePane.EVENT_CHANGE); action: () => {
} else { this.setValue();
this.fireEvent(DynamicDatePane.EVENT_CHANGE); this.fireEvent(DynamicDatePane.EVENT_CHANGE);
},
}
],
},
{
type: TextButton.xtype,
cls: "bi-border-left bi-high-light bi-border-top",
textHeight: 23,
shadow: true,
text: i18nText("BI-Basic_OK"),
listeners: [
{
eventName: TextButton.EVENT_CHANGE,
action: () => {
const type = this.dateTab.getSelect();
if (type === DynamicDateCombo.Dynamic) {
this.dynamicPane.checkValidation(true) &&
this.fireEvent(
DynamicDatePane.EVENT_CHANGE
);
} else {
this.fireEvent(DynamicDatePane.EVENT_CHANGE);
}
},
}
],
} }
}, ],
}], },
}], height: 24,
}, }
height: 24, ],
}], };
}; }
} },
}, }
}], ],
}; };
} }

14
src/widget/downlist/combo.downlist.js

@ -3,7 +3,6 @@ import { DownListPopup } from "./popup.downlist";
import { Combo } from "@/base"; import { Combo } from "@/base";
import { IconTrigger } from "@/case"; import { IconTrigger } from "@/case";
function transformItems(items) { function transformItems(items) {
if (!items) return items; if (!items) return items;
let result = cloneDeep(items); let result = cloneDeep(items);
@ -26,7 +25,7 @@ function transformItems(items) {
} }
}); });
}); });
return result; return result;
} }
@ -93,21 +92,14 @@ export class DownListCombo extends Widget {
{ {
eventName: DownListPopup.EVENT_CHANGE, eventName: DownListPopup.EVENT_CHANGE,
action: value => { action: value => {
this.fireEvent( this.fireEvent(DownListCombo.EVENT_CHANGE, value);
DownListCombo.EVENT_CHANGE,
value
);
this.downlistcombo.hideView(); this.downlistcombo.hideView();
}, },
}, },
{ {
eventName: DownListPopup.EVENT_SON_VALUE_CHANGE, eventName: DownListPopup.EVENT_SON_VALUE_CHANGE,
action: (value, fatherValue) => { action: (value, fatherValue) => {
this.fireEvent( this.fireEvent(DownListCombo.EVENT_SON_VALUE_CHANGE, value, fatherValue);
DownListCombo.EVENT_SON_VALUE_CHANGE,
value,
fatherValue
);
this.downlistcombo.hideView(); this.downlistcombo.hideView();
}, },
} }

110
src/widget/downlist/group.downlist.js

@ -1,62 +1,56 @@
import { import { ButtonTree } from "@/base";
shortcut, import { VerticalLayout, shortcut, Widget, extend, createWidget, Controller, Events } from "@/core";
Widget,
extend,
createWidget,
Controller,
Events
} from "@/core";
@shortcut() @shortcut()
export class DownListGroup extends Widget { export class DownListGroup extends Widget {
static xtype = "bi.down_list_group"; static xtype = "bi.down_list_group";
constants = { iconCls: "check-mark-ha-font" }; constants = { iconCls: "check-mark-ha-font" };
static EVENT_CHANGE = "EVENT_CHANGE"; static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() { _defaultConfig() {
return extend(super._defaultConfig(...arguments), { return extend(super._defaultConfig(...arguments), {
baseCls: "bi-down-list-group", baseCls: "bi-down-list-group",
items: [ items: [
{ {
el: {}, el: {},
} }
], ],
}); });
} }
_init() { _init() {
super._init(...arguments); super._init(...arguments);
const o = this.options; const o = this.options;
this.downlistgroup = createWidget({ this.downlistgroup = createWidget({
element: this, element: this,
type: "bi.button_tree", type: ButtonTree.xtype,
items: o.items, items: o.items,
chooseType: 0, // 0单选,1多选 chooseType: 0, // 0单选,1多选
layouts: [ layouts: [
{ {
type: "bi.vertical", type: VerticalLayout.xtype,
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
} }
], ],
value: o.value, value: o.value,
}); });
this.downlistgroup.on(Controller.EVENT_CHANGE, (type, ...args) => { this.downlistgroup.on(Controller.EVENT_CHANGE, (type, ...args) => {
this.fireEvent(Controller.EVENT_CHANGE, type, ...args); this.fireEvent(Controller.EVENT_CHANGE, type, ...args);
if (type === Events.CLICK) { if (type === Events.CLICK) {
this.fireEvent(DownListGroup.EVENT_CHANGE, type, ...args); this.fireEvent(DownListGroup.EVENT_CHANGE, type, ...args);
} }
}); });
} }
getValue() { getValue() {
return this.downlistgroup.getValue(); return this.downlistgroup.getValue();
} }
setValue(v) { setValue(v) {
this.downlistgroup.setValue(v); this.downlistgroup.setValue(v);
} }
} }

10
src/widget/downlist/index.js

@ -1,5 +1,5 @@
export { DownListGroup } from "./group.downlist"; export { DownListGroup } from "./group.downlist";
export { DownListItem } from "./item.downlist"; export { DownListItem } from "./item.downlist";
export { DownListGroupItem } from "./item.downlistgroup"; export { DownListGroupItem } from "./item.downlistgroup";
export { DownListPopup } from "./popup.downlist"; export { DownListPopup } from "./popup.downlist";
export { DownListCombo } from "./combo.downlist"; export { DownListCombo } from "./combo.downlist";

238
src/widget/downlist/item.downlist.js

@ -1,125 +1,121 @@
import { shortcut, extend, createWidget, isPlainObject, LogicFactory, Direction } from "@/core"; import { Label, Icon, BasicButton } from "@/base";
import { BasicButton } from "@/base"; import { CenterAdaptLayout, shortcut, extend, createWidget, isPlainObject, LogicFactory, Direction } from "@/core";
@shortcut() @shortcut()
export class DownListItem extends BasicButton { export class DownListItem extends BasicButton {
static xtype = "bi.down_list_item"; static xtype = "bi.down_list_item";
static EVENT_CHANGE = "EVENT_CHANGE"; static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() { _defaultConfig() {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, { return extend(conf, {
baseCls: "bi-down-list-item bi-list-item-active", baseCls: "bi-down-list-item bi-list-item-active",
cls: "", cls: "",
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
logic: { logic: {
dynamic: true, dynamic: true,
}, },
selected: false, selected: false,
iconHeight: null, iconHeight: null,
iconWidth: null, iconWidth: null,
textHgap: 0, textHgap: 0,
textVgap: 0, textVgap: 0,
textLgap: 0, textLgap: 0,
textRgap: 0, textRgap: 0,
}); });
} }
_init() { _init() {
super._init(...arguments); super._init(...arguments);
const o = this.options; const o = this.options;
this.text = createWidget({ this.text = createWidget({
type: "bi.label", type: Label.xtype,
cls: "list-item-text", cls: "list-item-text",
textAlign: "left", textAlign: "left",
hgap: o.textHgap, hgap: o.textHgap,
vgap: o.textVgap, vgap: o.textVgap,
lgap: o.textLgap, lgap: o.textLgap,
rgap: o.textRgap, rgap: o.textRgap,
text: o.text, text: o.text,
value: o.value, value: o.value,
keyword: o.keyword, keyword: o.keyword,
height: o.height, height: o.height,
}); });
const icon = isPlainObject(o.icon) const icon = isPlainObject(o.icon)
? o.icon ? o.icon
: { : {
type: "bi.icon", type: Icon.xtype,
width: o.iconWidth, width: o.iconWidth,
height: o.iconHeight, height: o.iconHeight,
}; };
this.icon = createWidget({ this.icon = createWidget({
type: "bi.center_adapt", type: CenterAdaptLayout.xtype,
width: 36, width: 36,
height: o.height, height: o.height,
items: [ items: [
{ {
el: icon, el: icon,
} }
], ],
}); });
createWidget( createWidget(
extend( extend(
{ {
element: this, element: this,
}, },
LogicFactory.createLogic( LogicFactory.createLogic(
LogicFactory.createLogicTypeByDirection(Direction.Left), LogicFactory.createLogicTypeByDirection(Direction.Left),
extend(o.logic, { extend(o.logic, {
items: LogicFactory.createLogicItemsByDirection( items: LogicFactory.createLogicItemsByDirection(Direction.Left, this.icon, this.text),
Direction.Left, })
this.icon, )
this.text )
), );
}) }
)
) setValue() {
); if (!this.isReadOnly()) {
} this.text.setValue(...arguments);
}
setValue() { }
if (!this.isReadOnly()) {
this.text.setValue(...arguments); getValue() {
} return this.text.getValue();
} }
getValue() { setText() {
return this.text.getValue(); this.text.setText(...arguments);
} }
setText() { getText() {
this.text.setText(...arguments); return this.text.getText();
} }
getText() { doClick() {
return this.text.getText(); super.doClick(...arguments);
} if (this.isValid()) {
this.fireEvent(DownListItem.EVENT_CHANGE, this.getValue(), this);
doClick() { }
super.doClick(...arguments); }
if (this.isValid()) {
this.fireEvent(DownListItem.EVENT_CHANGE, this.getValue(), this); doRedMark() {
} this.text.doRedMark(...arguments);
} }
doRedMark() { unRedMark() {
this.text.doRedMark(...arguments); this.text.unRedMark(...arguments);
} }
unRedMark() { doHighLight() {
this.text.unRedMark(...arguments); this.text.doHighLight(...arguments);
} }
doHighLight() { unHighLight() {
this.text.doHighLight(...arguments); this.text.unHighLight(...arguments);
} }
unHighLight() {
this.text.unHighLight(...arguments);
}
} }

251
src/widget/downlist/item.downlistgroup.js

@ -1,4 +1,7 @@
import { Label, IconButton, BasicButton } from "@/base";
import { import {
CenterAdaptLayout,
HorizontalFillLayout,
shortcut, shortcut,
extend, extend,
createWidget, createWidget,
@ -10,132 +13,130 @@ import {
first, first,
BlankSplitChar BlankSplitChar
} from "@/core"; } from "@/core";
import { BasicButton } from "@/base";
@shortcut() @shortcut()
export class DownListGroupItem extends BasicButton { export class DownListGroupItem extends BasicButton {
static xtype = "bi.down_list_group_item"; static xtype = "bi.down_list_group_item";
static EVENT_CHANGE = "EVENT_CHANGE"; static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() { _defaultConfig() {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, { return extend(conf, {
baseCls: `${conf.baseCls || ""} bi-down-list-group-item`, baseCls: `${conf.baseCls || ""} bi-down-list-group-item`,
logic: { logic: {
dynamic: false, dynamic: false,
}, },
// invalid: true, // invalid: true,
iconCls1: "dot-e-font", iconCls1: "dot-e-font",
icon: "", icon: "",
iconCls2: "pull-right-e-font", iconCls2: "pull-right-e-font",
}); });
} }
render() { render() {
const o = this.options; const o = this.options;
this.text = createWidget({ this.text = createWidget({
type: "bi.label", type: Label.xtype,
cls: "list-group-item-text", cls: "list-group-item-text",
textAlign: "left", textAlign: "left",
text: o.text, text: o.text,
value: o.value, value: o.value,
height: o.height, height: o.height,
}); });
if (isPlainObject(o.icon)) { if (isPlainObject(o.icon)) {
this.icon1 = createWidget({ this.icon1 = createWidget({
width: 36, width: 36,
height: o.height, height: o.height,
type: "bi.center_adapt", type: CenterAdaptLayout.xtype,
items: [o.icon], items: [o.icon],
}); });
} else { } else {
this.icon1 = createWidget({ this.icon1 = createWidget({
type: "bi.icon_button", type: IconButton.xtype,
cls: o.iconCls1, cls: o.iconCls1,
width: 36, width: 36,
height: o.height, height: o.height,
iconHeight: o.iconHeight, iconHeight: o.iconHeight,
iconWidth: 36, iconWidth: 36,
disableSelected: true, disableSelected: true,
selected: this._digest(o.value), selected: this._digest(o.value),
}); });
} }
this.icon2 = createWidget({ this.icon2 = createWidget({
type: "bi.icon_button", type: IconButton.xtype,
cls: o.iconCls2, cls: o.iconCls2,
width: 24, width: 24,
forceNotSelected: true, forceNotSelected: true,
}); });
this.element.hover( this.element.hover(
() => { () => {
if (this.isEnabled()) { if (this.isEnabled()) {
this.hover(); this.hover();
} }
}, },
() => { () => {
if (this.isEnabled()) { if (this.isEnabled()) {
this.dishover(); this.dishover();
} }
} }
); );
return { return {
type: "bi.horizontal_fill", type: HorizontalFillLayout.xtype,
columnSize: [36, "fill", 24], columnSize: [36, "fill", 24],
items: [this.icon1, this.text, this.icon2], items: [this.icon1, this.text, this.icon2],
}; };
} }
_getLevel() { _getLevel() {
const child = first(this.options.childValues); const child = first(this.options.childValues);
return isNotNull(child) ? (`${child}`).split(BlankSplitChar).length : 0; return isNotNull(child) ? `${child}`.split(BlankSplitChar).length : 0;
} }
_digest(v) { _digest(v) {
const o = this.options; const o = this.options;
v = isArray(v) ? v : [v]; v = isArray(v) ? v : [v];
const level = this._getLevel(); const level = this._getLevel();
return any(v, (idx, value) => contains( return any(v, (idx, value) =>
o.childValues, contains(o.childValues, `${value}`.split(BlankSplitChar).slice(0, level).join(BlankSplitChar))
(`${value}`).split(BlankSplitChar).slice(0, level).join(BlankSplitChar) );
)); }
}
hover() {
hover() { super.hover(...arguments);
super.hover(...arguments); this.icon1.element.addClass("hover");
this.icon1.element.addClass("hover"); this.icon2.element.addClass("hover");
this.icon2.element.addClass("hover"); }
}
dishover() {
dishover() { super.dishover(...arguments);
super.dishover(...arguments); this.icon1.element.removeClass("hover");
this.icon1.element.removeClass("hover"); this.icon2.element.removeClass("hover");
this.icon2.element.removeClass("hover"); }
}
doClick() {
doClick() { super.doClick(...arguments);
super.doClick(...arguments); if (this.isValid()) {
if (this.isValid()) { this.fireEvent(DownListGroupItem.EVENT_CHANGE, this.getValue());
this.fireEvent(DownListGroupItem.EVENT_CHANGE, this.getValue()); }
} }
}
doRedMark() {
doRedMark() { this.text.doRedMark(...arguments);
this.text.doRedMark(...arguments); }
}
unRedMark() {
unRedMark() { this.text.unRedMark(...arguments);
this.text.unRedMark(...arguments); }
}
setValue(v) {
setValue(v) { this.icon1.setSelected && this.icon1.setSelected(this._digest(v));
this.icon1.setSelected && this.icon1.setSelected(this._digest(v)); }
}
} }

580
src/widget/downlist/popup.downlist.js

@ -1,4 +1,7 @@
import { ButtonTree, Pane } from "@/base";
import { import {
VerticalLayout,
Layout,
shortcut, shortcut,
extend, extend,
createWidget, createWidget,
@ -13,320 +16,315 @@ import {
some, some,
deepClone deepClone
} from "@/core"; } from "@/core";
import { Pane, ButtonTree } from "@/base"; import { DownListGroup } from "./group.downlist";
@shortcut() @shortcut()
export class DownListPopup extends Pane { export class DownListPopup extends Pane {
static xtype = "bi.down_list_popup"; static xtype = "bi.down_list_popup";
constants = { constants = {
nextIcon: "pull-right-e-font", nextIcon: "pull-right-e-font",
height: 24, height: 24,
iconHeight: 12, iconHeight: 12,
iconWidth: 12, iconWidth: 12,
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
border: 1, border: 1,
}; };
static EVENT_CHANGE = "EVENT_CHANGE"; static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE"; static EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE";
_defaultConfig() { _defaultConfig() {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, {
baseCls: "bi-down-list-popup",
items: [],
chooseType: Selection.Multi,
});
}
_init() { return extend(conf, {
super._init(...arguments); baseCls: "bi-down-list-popup",
this.singleValues = []; items: [],
this.childValueMap = {}; chooseType: Selection.Multi,
this.fatherValueMap = {}; });
this.items = []; }
const o = this.options,
children = this._createPopupItems(o.items);
this.popup = createWidget({
type: "bi.button_tree",
items: createItems(
children,
{},
{
adjustLength: -2,
}
),
layouts: [
{
type: "bi.vertical",
hgap: this.constants.hgap,
vgap: this.constants.vgap,
}
],
value: this._digest(o.value),
chooseType: o.chooseType,
});
this.popup.on(ButtonTree.EVENT_CHANGE, (value, object) => { _init() {
let changedValue = value; super._init(...arguments);
if (isNotNull(this.childValueMap[value])) { this.singleValues = [];
changedValue = this.childValueMap[value]; this.childValueMap = {};
this.fireEvent( this.fatherValueMap = {};
DownListPopup.EVENT_SON_VALUE_CHANGE, this.items = [];
changedValue, const o = this.options,
this.fatherValueMap[value] children = this._createPopupItems(o.items);
); this.popup = createWidget({
} else { type: ButtonTree.xtype,
this.fireEvent(DownListPopup.EVENT_CHANGE, changedValue, object); items: createItems(
} children,
{},
{
adjustLength: -2,
}
),
layouts: [
{
type: VerticalLayout.xtype,
hgap: this.constants.hgap,
vgap: this.constants.vgap,
}
],
value: this._digest(o.value),
chooseType: o.chooseType,
});
if (!contains(this.singleValues, changedValue)) { this.popup.on(ButtonTree.EVENT_CHANGE, (value, object) => {
const item = this.getValue(); let changedValue = value;
const result = []; if (isNotNull(this.childValueMap[value])) {
each(item, (i, valueObject) => { changedValue = this.childValueMap[value];
if (valueObject.value !== changedValue) { this.fireEvent(DownListPopup.EVENT_SON_VALUE_CHANGE, changedValue, this.fatherValueMap[value]);
result.push(valueObject); } else {
} this.fireEvent(DownListPopup.EVENT_CHANGE, changedValue, object);
}); }
this.setValue(result);
}
});
createWidget({ if (!contains(this.singleValues, changedValue)) {
type: "bi.vertical", const item = this.getValue();
element: this, const result = [];
items: [this.popup], each(item, (i, valueObject) => {
vgap: 5, if (valueObject.value !== changedValue) {
}); result.push(valueObject);
} }
});
this.setValue(result);
}
});
_createPopupItems(items) { createWidget({
const result = []; type: VerticalLayout.xtype,
// 不能修改populate进来的item的引用 element: this,
each(items, (i, it) => { items: [this.popup],
const item_done = { vgap: 5,
type: "bi.down_list_group", });
items: [], }
};
const storeItem = []; _createPopupItems(items) {
const result = [];
// 不能修改populate进来的item的引用
each(items, (i, it) => {
const item_done = {
type: DownListGroup.xtype,
items: [],
};
each(it, (i, sourceItem) => { const storeItem = [];
const item = extend({}, sourceItem);
if (isNotEmptyArray(sourceItem.children) && !isEmpty(sourceItem.el)) {
item.type = "bi.combo_group";
// popup未初始化返回的是options中的value, 在经过buttontree的getValue concat之后,无法区分值来自options
// 还是item自身, 这边控制defaultInit为true来避免这个问题
item.isDefaultInit = true;
item.cls = "down-list-group";
item.trigger = "hover";
item.isNeedAdjustWidth = false;
item.el = sourceItem.el;
item.el.title = sourceItem.el.title || sourceItem.el.text;
item.el.type = "bi.down_list_group_item";
item.el.logic = {
dynamic: true,
};
item.el.height =
sourceItem.el.height || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT;
item.el.iconCls2 = this.constants.nextIcon;
item.popup = {
lgap: 1,
el: {
type: "bi.button_tree",
chooseType: 0,
layouts: [
{
type: "bi.vertical",
}
],
},
innerVgap: 5,
maxHeight: 378,
};
this._createChildren(item, sourceItem);
} else {
item.type = sourceItem.type || "bi.down_list_item";
item.title = sourceItem.title || sourceItem.text;
item.textRgap = 10;
item.isNeedAdjustWidth = false;
item.logic = {
dynamic: true,
};
}
const el_done = {};
el_done.el = item;
item_done.items.push(el_done);
storeItem.push(item);
});
if (this._isGroup(item_done.items)) {
each(item_done.items, (i, item) => {
this.singleValues.push(item.el.value);
});
}
result.push(item_done); each(it, (i, sourceItem) => {
this.items.push(storeItem); const item = extend({}, sourceItem);
if (this._needSpliter(i, items.length)) { if (isNotEmptyArray(sourceItem.children) && !isEmpty(sourceItem.el)) {
const spliter_container = createWidget({ item.type = "bi.combo_group";
type: "bi.vertical", // popup未初始化返回的是options中的value, 在经过buttontree的getValue concat之后,无法区分值来自options
items: [ // 还是item自身, 这边控制defaultInit为true来避免这个问题
{ item.isDefaultInit = true;
el: { item.cls = "down-list-group";
type: "bi.layout", item.trigger = "hover";
cls: "bi-down-list-spliter bi-split-top cursor-pointer", item.isNeedAdjustWidth = false;
height: 0, item.el = sourceItem.el;
}, item.el.title = sourceItem.el.title || sourceItem.el.text;
} item.el.type = "bi.down_list_group_item";
], item.el.logic = {
cls: "bi-down-list-spliter-container cursor-pointer", dynamic: true,
vgap: 5, };
hgap: 12, item.el.height = sourceItem.el.height || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT;
}); item.el.iconCls2 = this.constants.nextIcon;
result.push(spliter_container); item.popup = {
} lgap: 1,
}); el: {
type: ButtonTree.xtype,
return result; chooseType: 0,
} layouts: [
{
type: VerticalLayout.xtype,
}
],
},
innerVgap: 5,
maxHeight: 378,
};
this._createChildren(item, sourceItem);
} else {
item.type = sourceItem.type || "bi.down_list_item";
item.title = sourceItem.title || sourceItem.text;
item.textRgap = 10;
item.isNeedAdjustWidth = false;
item.logic = {
dynamic: true,
};
}
const el_done = {};
el_done.el = item;
item_done.items.push(el_done);
storeItem.push(item);
});
if (this._isGroup(item_done.items)) {
each(item_done.items, (i, item) => {
this.singleValues.push(item.el.value);
});
}
_createChildren(targetItem, sourceItem) { result.push(item_done);
targetItem.el.childValues = []; this.items.push(storeItem);
targetItem.items = targetItem.children = []; if (this._needSpliter(i, items.length)) {
each(sourceItem.children, (i, child) => { const spliter_container = createWidget({
const item = extend({}, child); type: VerticalLayout.xtype,
const fatherValue = deepClone(targetItem.el.value); items: [
const childValue = deepClone(item.value); {
this.singleValues.push(item.value); el: {
item.type = item.type || "bi.down_list_item"; type: Layout.xtype,
item.extraCls = " child-down-list-item"; cls: "bi-down-list-spliter bi-split-top cursor-pointer",
item.title = item.title || item.text; height: 0,
item.textRgap = 10; },
item.isNeedAdjustWidth = false; }
item.logic = { ],
dynamic: true, cls: "bi-down-list-spliter-container cursor-pointer",
}; vgap: 5,
item.father = fatherValue; hgap: 12,
item.childValue = item.value; });
this.fatherValueMap[this._createChildValue(fatherValue, childValue)] = result.push(spliter_container);
fatherValue; }
this.childValueMap[this._createChildValue(fatherValue, childValue)] = });
childValue;
item.value = this._createChildValue(fatherValue, childValue);
targetItem.el.childValues.push(item.value);
targetItem.items.push(item);
});
}
_isGroup(i) { return result;
return i.length > 1; }
}
_needSpliter(i, itemLength) { _createChildren(targetItem, sourceItem) {
return i < itemLength - 1; targetItem.el.childValues = [];
} targetItem.items = targetItem.children = [];
each(sourceItem.children, (i, child) => {
const item = extend({}, child);
const fatherValue = deepClone(targetItem.el.value);
const childValue = deepClone(item.value);
this.singleValues.push(item.value);
item.type = item.type || "bi.down_list_item";
item.extraCls = " child-down-list-item";
item.title = item.title || item.text;
item.textRgap = 10;
item.isNeedAdjustWidth = false;
item.logic = {
dynamic: true,
};
item.father = fatherValue;
item.childValue = item.value;
this.fatherValueMap[this._createChildValue(fatherValue, childValue)] = fatherValue;
this.childValueMap[this._createChildValue(fatherValue, childValue)] = childValue;
item.value = this._createChildValue(fatherValue, childValue);
targetItem.el.childValues.push(item.value);
targetItem.items.push(item);
});
}
_createChildValue(fatherValue, childValue) { _isGroup(i) {
return fatherValue + BI.BlankSplitChar + childValue; return i.length > 1;
} }
_digest(valueItem) { _needSpliter(i, itemLength) {
const valueArray = []; return i < itemLength - 1;
each(valueItem, (i, item) => { }
let value;
if (isNotNull(item.childValue)) {
value = this._createChildValue(item.value, item.childValue);
} else {
value = item.value;
}
valueArray.push(value);
});
return valueArray;
}
_checkValues(values) { _createChildValue(fatherValue, childValue) {
const value = []; return fatherValue + BI.BlankSplitChar + childValue;
each(this.items, (idx, itemGroup) => { }
each(itemGroup, (id, item) => {
if (isNotNull(item.children)) {
const childValues = map(item.children, "value");
const v = joinValue(childValues, values[idx]);
if (isNotEmptyString(v)) {
value.push(v);
}
} else {
if (item.value === values[idx][0]) {
value.push(values[idx][0]);
}
}
});
});
return value;
function joinValue(sources, targets) { _digest(valueItem) {
let value = ""; const valueArray = [];
some(sources, (idx, s) => some(targets, (id, t) => { each(valueItem, (i, item) => {
if (s === t) { let value;
value = s; if (isNotNull(item.childValue)) {
value = this._createChildValue(item.value, item.childValue);
return true; } else {
} value = item.value;
})); }
valueArray.push(value);
return value; });
}
}
populate(items) { return valueArray;
super.populate(...arguments); }
this.items = [];
this.childValueMap = {};
this.fatherValueMap = {};
this.singleValues = [];
const children = this._createPopupItems(items);
const popupItem = createItems(
children,
{},
{
adjustLength: -2,
}
);
this.popup.populate(popupItem);
}
setValue(valueItem) { _checkValues(values) {
this.popup.setValue(this._digest(valueItem)); const value = [];
} each(this.items, (idx, itemGroup) => {
each(itemGroup, (id, item) => {
if (isNotNull(item.children)) {
const childValues = map(item.children, "value");
const v = joinValue(childValues, values[idx]);
if (isNotEmptyString(v)) {
value.push(v);
}
} else {
if (item.value === values[idx][0]) {
value.push(values[idx][0]);
}
}
});
});
_getValue() { return value;
const v = [];
each(this.popup.getAllButtons(), (i, item) => {
i % 2 === 0 && v.push(item.getValue());
});
return v;
}
getValue() { function joinValue(sources, targets) {
const result = []; let value = "";
const values = this._checkValues(this._getValue()); some(sources, (idx, s) =>
each(values, (i, value) => { some(targets, (id, t) => {
const valueItem = {}; if (s === t) {
if (isNotNull(this.childValueMap[value])) { value = s;
const fartherValue = this.fatherValueMap[value];
valueItem.childValue = this.childValueMap[value]; return true;
valueItem.value = fartherValue; }
} else { })
valueItem.value = value; );
}
result.push(valueItem); return value;
}); }
}
return result;
} populate(items) {
super.populate(...arguments);
this.items = [];
this.childValueMap = {};
this.fatherValueMap = {};
this.singleValues = [];
const children = this._createPopupItems(items);
const popupItem = createItems(
children,
{},
{
adjustLength: -2,
}
);
this.popup.populate(popupItem);
}
setValue(valueItem) {
this.popup.setValue(this._digest(valueItem));
}
_getValue() {
const v = [];
each(this.popup.getAllButtons(), (i, item) => {
i % 2 === 0 && v.push(item.getValue());
});
return v;
}
getValue() {
const result = [];
const values = this._checkValues(this._getValue());
each(values, (i, value) => {
const valueItem = {};
if (isNotNull(this.childValueMap[value])) {
const fartherValue = this.fatherValueMap[value];
valueItem.childValue = this.childValueMap[value];
valueItem.value = fartherValue;
} else {
valueItem.value = value;
}
result.push(valueItem);
});
return result;
}
} }

75
src/widget/dynamicdate/dynamicdate.caculate.js

@ -1,53 +1,86 @@
import { isNotNull, parseInt, getDate, i18nText, size, getOffsetQuarter, getOffsetMonth, getOffsetDate, getLastDateOfMonth, getWeekStartDate, getWeekEndDate, getQuarterStartDate, getQuarterEndDate, print } from "@/core"; import {
isNotNull,
parseInt,
getDate,
i18nText,
size,
getOffsetQuarter,
getOffsetMonth,
getOffsetDate,
getLastDateOfMonth,
getWeekStartDate,
getWeekEndDate,
getQuarterStartDate,
getQuarterEndDate,
print
} from "@/core";
import { DynamicDateCard } from "./dynamicdate.card"; import { DynamicDateCard } from "./dynamicdate.card";
export const DynamicDateHelper = { export const DynamicDateHelper = {
getCalculation (obj) { getCalculation(obj) {
const date = getDate(); const date = getDate();
return this.getCalculationByDate(date, obj); return this.getCalculationByDate(date, obj);
}, },
getDescription (obj) { getDescription(obj) {
let value = ""; let value = "";
let endText = ""; let endText = "";
if (isNotNull(obj.year)) { if (isNotNull(obj.year)) {
if (parseInt(obj.year) !== 0) { if (parseInt(obj.year) !== 0) {
value += Math.abs(obj.year) + i18nText("BI-Basic_Year") + (obj.year < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.year) +
i18nText("BI-Basic_Year") +
(obj.year < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
endText = getPositionText(i18nText("BI-Basic_Year"), obj.position); endText = getPositionText(i18nText("BI-Basic_Year"), obj.position);
} }
if (isNotNull(obj.quarter)) { if (isNotNull(obj.quarter)) {
if (parseInt(obj.quarter) !== 0) { if (parseInt(obj.quarter) !== 0) {
value += Math.abs(obj.quarter) + i18nText("BI-Basic_Single_Quarter") + (obj.quarter < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.quarter) +
i18nText("BI-Basic_Single_Quarter") +
(obj.quarter < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
endText = getPositionText(i18nText("BI-Basic_Single_Quarter"), obj.position); endText = getPositionText(i18nText("BI-Basic_Single_Quarter"), obj.position);
} }
if (isNotNull(obj.month)) { if (isNotNull(obj.month)) {
if (parseInt(obj.month) !== 0) { if (parseInt(obj.month) !== 0) {
value += Math.abs(obj.month) + i18nText("BI-Basic_Month") + (obj.month < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.month) +
i18nText("BI-Basic_Month") +
(obj.month < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
endText = getPositionText(i18nText("BI-Basic_Month"), obj.position); endText = getPositionText(i18nText("BI-Basic_Month"), obj.position);
} }
if (isNotNull(obj.week)) { if (isNotNull(obj.week)) {
if (parseInt(obj.week) !== 0) { if (parseInt(obj.week) !== 0) {
value += Math.abs(obj.week) + i18nText("BI-Basic_Week") + (obj.week < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.week) +
i18nText("BI-Basic_Week") +
(obj.week < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
endText = getPositionText(i18nText("BI-Basic_Week"), obj.position); endText = getPositionText(i18nText("BI-Basic_Week"), obj.position);
} }
if (isNotNull(obj.day)) { if (isNotNull(obj.day)) {
if (parseInt(obj.day) !== 0) { if (parseInt(obj.day) !== 0) {
value += Math.abs(obj.day) + i18nText("BI-Basic_Day") + (obj.day < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.day) +
i18nText("BI-Basic_Day") +
(obj.day < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
endText = size(obj) === 1 ? getPositionText(i18nText("BI-Basic_Month"), obj.position) : ""; endText = size(obj) === 1 ? getPositionText(i18nText("BI-Basic_Month"), obj.position) : "";
} }
if (isNotNull(obj.workDay) && parseInt(obj.workDay) !== 0) { if (isNotNull(obj.workDay) && parseInt(obj.workDay) !== 0) {
value += Math.abs(obj.workDay) + i18nText("BI-Basic_Work_Day") + (obj.workDay < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.workDay) +
i18nText("BI-Basic_Work_Day") +
(obj.workDay < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
return value + endText; return value + endText;
function getPositionText (baseText, position) { function getPositionText(baseText, position) {
switch (position) { switch (position) {
case DynamicDateCard.OFFSET.BEGIN: case DynamicDateCard.OFFSET.BEGIN:
return baseText + i18nText("BI-Basic_Begin_Start"); return baseText + i18nText("BI-Basic_Begin_Start");
@ -60,9 +93,9 @@ export const DynamicDateHelper = {
} }
}, },
getCalculationByDate (date, obj) { getCalculationByDate(date, obj) {
if (isNotNull(obj.year)) { if (isNotNull(obj.year)) {
date = getDate((date.getFullYear() + parseInt(obj.year)), date.getMonth(), date.getDate()); date = getDate(date.getFullYear() + parseInt(obj.year), date.getMonth(), date.getDate());
} }
if (isNotNull(obj.quarter)) { if (isNotNull(obj.quarter)) {
date = getOffsetQuarter(date, parseInt(obj.quarter)); date = getOffsetQuarter(date, parseInt(obj.quarter));
@ -97,23 +130,29 @@ export const DynamicDateHelper = {
return getDate(date.getFullYear(), date.getMonth(), date.getDate()); return getDate(date.getFullYear(), date.getMonth(), date.getDate());
}, },
getBeginDate (date, obj) { getBeginDate(date, obj) {
if (isNotNull(obj.day)) { if (isNotNull(obj.day)) {
return obj.position === DynamicDateCard.OFFSET.BEGIN ? getDate(date.getFullYear(), date.getMonth(), 1) : getDate(date.getFullYear(), date.getMonth(), (getLastDateOfMonth(date)).getDate()); return obj.position === DynamicDateCard.OFFSET.BEGIN
? getDate(date.getFullYear(), date.getMonth(), 1)
: getDate(date.getFullYear(), date.getMonth(), getLastDateOfMonth(date).getDate());
} }
if (isNotNull(obj.week)) { if (isNotNull(obj.week)) {
return obj.position === DynamicDateCard.OFFSET.BEGIN ? getWeekStartDate(date) : getWeekEndDate(date); return obj.position === DynamicDateCard.OFFSET.BEGIN ? getWeekStartDate(date) : getWeekEndDate(date);
} }
if (isNotNull(obj.month)) { if (isNotNull(obj.month)) {
return obj.position === DynamicDateCard.OFFSET.BEGIN ? getDate(date.getFullYear(), date.getMonth(), 1) : getDate(date.getFullYear(), date.getMonth(), (getLastDateOfMonth(date)).getDate()); return obj.position === DynamicDateCard.OFFSET.BEGIN
? getDate(date.getFullYear(), date.getMonth(), 1)
: getDate(date.getFullYear(), date.getMonth(), getLastDateOfMonth(date).getDate());
} }
if (isNotNull(obj.quarter)) { if (isNotNull(obj.quarter)) {
return obj.position === DynamicDateCard.OFFSET.BEGIN ? getQuarterStartDate(date) : getQuarterEndDate(date); return obj.position === DynamicDateCard.OFFSET.BEGIN ? getQuarterStartDate(date) : getQuarterEndDate(date);
} }
if (isNotNull(obj.year)) { if (isNotNull(obj.year)) {
return obj.position === DynamicDateCard.OFFSET.BEGIN ? getDate(date.getFullYear(), 0, 1) : getDate(date.getFullYear(), 11, 31); return obj.position === DynamicDateCard.OFFSET.BEGIN
? getDate(date.getFullYear(), 0, 1)
: getDate(date.getFullYear(), 11, 31);
} }
return date; return date;
}, },
}; };

481
src/widget/dynamicdate/dynamicdate.card.js

@ -1,12 +1,33 @@
import { shortcut, Widget, i18nText, createItems, each, isNotNull, map, has, bind, last, extend, checkDateVoid, isNull, isNotEmptyString, parseDateTime, any } from "@/core"; import {
import { ButtonGroup, Bubbles } from "@/base"; VerticalLayout,
import { MultiSelectItem } from "@/case"; FloatLeftLayout,
VerticalAdaptLayout,
shortcut,
Widget,
i18nText,
createItems,
each,
isNotNull,
map,
has,
bind,
last,
extend,
checkDateVoid,
isNull,
isNotEmptyString,
parseDateTime,
any
} from "@/core";
import { Label, ButtonGroup, Bubbles } from "@/base";
import { MultiSelectItem, TextValueCombo } from "@/case";
import { DynamicDateParamItem } from "./dynamicdate.param.item";
import { DynamicDateHelper } from "./dynamicdate.caculate"; import { DynamicDateHelper } from "./dynamicdate.caculate";
@shortcut() @shortcut()
export class DynamicDateCard extends Widget { export class DynamicDateCard extends Widget {
static xtype = "bi.dynamic_date_card"; static xtype = "bi.dynamic_date_card";
static TYPE = { static TYPE = {
YEAR: 1, YEAR: 1,
QUARTER: 2, QUARTER: 2,
@ -27,132 +48,168 @@ export class DynamicDateCard extends Widget {
render() { render() {
this.position = DynamicDateCard.OFFSET.CURRENT; this.position = DynamicDateCard.OFFSET.CURRENT;
return { return {
type: "bi.vertical", type: VerticalLayout.xtype,
items: [{ items: [
el: { {
type: "bi.label", el: {
text: i18nText("BI-Multi_Date_Relative_Current_Time"), type: Label.xtype,
textAlign: "left", text: i18nText("BI-Multi_Date_Relative_Current_Time"),
lgap: 10, textAlign: "left",
}, lgap: 10,
tgap: 10, },
bgap: 5, tgap: 10,
}, { bgap: 5,
type: "bi.button_group",
ref: _ref => {
this.checkgroup = _ref;
}, },
chooseType: ButtonGroup.CHOOSE_TYPE_MULTI, {
lgap: 4, type: ButtonGroup.xtype,
value: [DynamicDateCard.TYPE.YEAR], ref: _ref => {
items: createItems([{ this.checkgroup = _ref;
text: i18nText("BI-Basic_Year"),
value: DynamicDateCard.TYPE.YEAR,
}, {
text: i18nText("BI-Basic_Single_Quarter"),
value: DynamicDateCard.TYPE.QUARTER,
}, {
text: i18nText("BI-Basic_Month"),
value: DynamicDateCard.TYPE.MONTH,
}, {
text: i18nText("BI-Basic_Week"),
value: DynamicDateCard.TYPE.WEEK,
}, {
text: i18nText("BI-Basic_Day"),
value: DynamicDateCard.TYPE.DAY,
}], {
type: "bi.multi_select_item",
logic: {
dynamic: true,
}, },
iconWrapperWidth: 26, chooseType: ButtonGroup.CHOOSE_TYPE_MULTI,
}), lgap: 4,
layouts: [{ value: [DynamicDateCard.TYPE.YEAR],
type: "bi.left", items: createItems(
rgap: 4, [
}], {
listeners: [{ text: i18nText("BI-Basic_Year"),
eventName: ButtonGroup.EVENT_CHANGE, value: DynamicDateCard.TYPE.YEAR,
action: () => { },
const value = this.checkgroup.getValue(); {
if (value.length !== 0) { text: i18nText("BI-Basic_Single_Quarter"),
this.workDayBox.setSelected(false); value: DynamicDateCard.TYPE.QUARTER,
} },
{
const plainValue = {}; text: i18nText("BI-Basic_Month"),
each(this.resultPane.getAllButtons(), (idx, button) => { value: DynamicDateCard.TYPE.MONTH,
const value = button.getValue(); },
if (isNotNull(value.dateType)) { {
plainValue[value.dateType] = { text: i18nText("BI-Basic_Week"),
value: value.value, value: DynamicDateCard.TYPE.WEEK,
offset: value.offset, },
}; {
} text: i18nText("BI-Basic_Day"),
}); value: DynamicDateCard.TYPE.DAY,
this.resultPane.populate(this._getParamJson(map(this.checkgroup.getValue(), (idx, v) => {
const obj = {
dateType: v,
};
if (has(plainValue, v)) {
obj.value = plainValue[v].value;
obj.offset = plainValue[v].offset;
} }
],
return obj; {
}))); type: MultiSelectItem.xtype,
this.position = DynamicDateCard.OFFSET.CURRENT; logic: {
this.fireEvent("EVENT_CHANGE"); dynamic: true,
}, },
}], iconWrapperWidth: 26,
}, { }
type: "bi.vertical_adapt", ),
lgap: 2, layouts: [
items: [{ {
el: { type: FloatLeftLayout.xtype,
type: "bi.multi_select_item", rgap: 4,
iconWrapperWidth: 26, }
ref: _ref => { ],
this.workDayBox = _ref; listeners: [
}, {
logic: { eventName: ButtonGroup.EVENT_CHANGE,
dynamic: true,
},
text: i18nText("BI-Basic_Work_Day"),
value: DynamicDateCard.TYPE.WORK_DAY,
listeners: [{
eventName: MultiSelectItem.EVENT_CHANGE,
action: () => { action: () => {
if (this.workDayBox.isSelected()) { const value = this.checkgroup.getValue();
this.checkgroup.setValue(); if (value.length !== 0) {
this.workDayBox.setSelected(false);
} }
this.resultPane.populate(this.workDayBox.isSelected() ? this._getParamJson([{
dateType: DynamicDateCard.TYPE.WORK_DAY, const plainValue = {};
}]) : []); each(this.resultPane.getAllButtons(), (idx, button) => {
const value = button.getValue();
if (isNotNull(value.dateType)) {
plainValue[value.dateType] = {
value: value.value,
offset: value.offset,
};
}
});
this.resultPane.populate(
this._getParamJson(
map(this.checkgroup.getValue(), (idx, v) => {
const obj = {
dateType: v,
};
if (has(plainValue, v)) {
obj.value = plainValue[v].value;
obj.offset = plainValue[v].offset;
}
return obj;
})
)
);
this.position = DynamicDateCard.OFFSET.CURRENT; this.position = DynamicDateCard.OFFSET.CURRENT;
this.fireEvent("EVENT_CHANGE"); this.fireEvent("EVENT_CHANGE");
}, },
}], }
}, ],
}],
ref: _ref => {
this.workDay = _ref;
}, },
}, { {
type: "bi.button_group", type: VerticalAdaptLayout.xtype,
items: this._getParamJson([{ lgap: 2,
dateType: DynamicDateCard.TYPE.YEAR, items: [
}]), {
ref: _ref => { el: {
this.resultPane = _ref; type: MultiSelectItem.xtype,
iconWrapperWidth: 26,
ref: _ref => {
this.workDayBox = _ref;
},
logic: {
dynamic: true,
},
text: i18nText("BI-Basic_Work_Day"),
value: DynamicDateCard.TYPE.WORK_DAY,
listeners: [
{
eventName: MultiSelectItem.EVENT_CHANGE,
action: () => {
if (this.workDayBox.isSelected()) {
this.checkgroup.setValue();
}
this.resultPane.populate(
this.workDayBox.isSelected()
? this._getParamJson([
{
dateType: DynamicDateCard.TYPE.WORK_DAY,
}
])
: []
);
this.position = DynamicDateCard.OFFSET.CURRENT;
this.fireEvent("EVENT_CHANGE");
},
}
],
},
}
],
ref: _ref => {
this.workDay = _ref;
},
}, },
layouts: [{ {
type: "bi.vertical", type: ButtonGroup.xtype,
bgap: 10, items: this._getParamJson([
hgap: 10, {
}], dateType: DynamicDateCard.TYPE.YEAR,
}], }
]),
ref: _ref => {
this.resultPane = _ref;
},
layouts: [
{
type: VerticalLayout.xtype,
bgap: 10,
hgap: 10,
}
],
}
],
}; };
} }
@ -160,22 +217,25 @@ export class DynamicDateCard extends Widget {
const items = map(values, (idx, value) => { const items = map(values, (idx, value) => {
return { return {
el: { el: {
type: "bi.dynamic_date_param_item", type: DynamicDateParamItem.xtype,
validationChecker: bind(this._checkDate, this), validationChecker: bind(this._checkDate, this),
dateType: value.dateType, dateType: value.dateType,
value: value.value, value: value.value,
offset: value.offset, offset: value.offset,
listeners: [{ listeners: [
eventName: "EVENT_CHANGE", {
action: () => { eventName: "EVENT_CHANGE",
this.fireEvent("EVENT_CHANGE"); action: () => {
}, this.fireEvent("EVENT_CHANGE");
}, { },
eventName: "EVENT_INPUT_CHANGE",
action () {
Bubbles.hide("dynamic-date-error");
}, },
}], {
eventName: "EVENT_INPUT_CHANGE",
action() {
Bubbles.hide("dynamic-date-error");
},
}
],
}, },
tgap: idx === 0 ? 5 : 0, tgap: idx === 0 ? 5 : 0,
}; };
@ -185,7 +245,7 @@ export class DynamicDateCard extends Widget {
const comboItems = this._getText(DynamicDateCard.TYPE.MONTH); const comboItems = this._getText(DynamicDateCard.TYPE.MONTH);
comboItems[0].text = i18nText("BI-Basic_Empty"); comboItems[0].text = i18nText("BI-Basic_Empty");
items.push({ items.push({
type: "bi.text_value_combo", type: TextValueCombo.xtype,
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
items: comboItems, items: comboItems,
container: null, container: null,
@ -193,19 +253,25 @@ export class DynamicDateCard extends Widget {
ref: _ref => { ref: _ref => {
this.textValueCombo = _ref; this.textValueCombo = _ref;
}, },
listeners: [{ listeners: [
eventName: "EVENT_CHANGE", {
action: () => { eventName: "EVENT_CHANGE",
this.position = this.textValueCombo.getValue()[0]; action: () => {
this.textValueCombo.setValue(this.position); this.position = this.textValueCombo.getValue()[0];
this.fireEvent("EVENT_CHANGE"); this.textValueCombo.setValue(this.position);
}, this.fireEvent("EVENT_CHANGE");
}], },
}
],
}); });
} else { } else {
if (values.length !== 0 && last(values).dateType !== DynamicDateCard.TYPE.DAY && last(values).dateType !== DynamicDateCard.TYPE.WORK_DAY) { if (
values.length !== 0 &&
last(values).dateType !== DynamicDateCard.TYPE.DAY &&
last(values).dateType !== DynamicDateCard.TYPE.WORK_DAY
) {
items.push({ items.push({
type: "bi.text_value_combo", type: TextValueCombo.xtype,
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
container: null, container: null,
items: this._getText(last(values).dateType), items: this._getText(last(values).dateType),
@ -213,14 +279,16 @@ export class DynamicDateCard extends Widget {
ref: _ref => { ref: _ref => {
this.textValueCombo = _ref; this.textValueCombo = _ref;
}, },
listeners: [{ listeners: [
eventName: "EVENT_CHANGE", {
action: () => { eventName: "EVENT_CHANGE",
this.position = this.textValueCombo.getValue()[0]; action: () => {
this.textValueCombo.setValue(this.position); this.position = this.textValueCombo.getValue()[0];
this.fireEvent("EVENT_CHANGE"); this.textValueCombo.setValue(this.position);
}, this.fireEvent("EVENT_CHANGE");
}], },
}
],
}); });
} }
} }
@ -238,50 +306,66 @@ export class DynamicDateCard extends Widget {
_getText(lastValue) { _getText(lastValue) {
switch (lastValue) { switch (lastValue) {
case DynamicDateCard.TYPE.YEAR: case DynamicDateCard.TYPE.YEAR:
return [{ return [
text: i18nText("BI-Basic_Current_Day"), {
value: DynamicDateCard.OFFSET.CURRENT, text: i18nText("BI-Basic_Current_Day"),
}, { value: DynamicDateCard.OFFSET.CURRENT,
text: i18nText("BI-Basic_Year_Begin"), },
value: DynamicDateCard.OFFSET.BEGIN, {
}, { text: i18nText("BI-Basic_Year_Begin"),
text: i18nText("BI-Basic_Year_End"), value: DynamicDateCard.OFFSET.BEGIN,
value: DynamicDateCard.OFFSET.END, },
}]; {
text: i18nText("BI-Basic_Year_End"),
value: DynamicDateCard.OFFSET.END,
}
];
case DynamicDateCard.TYPE.QUARTER: case DynamicDateCard.TYPE.QUARTER:
return [{ return [
text: i18nText("BI-Basic_Current_Day"), {
value: DynamicDateCard.OFFSET.CURRENT, text: i18nText("BI-Basic_Current_Day"),
}, { value: DynamicDateCard.OFFSET.CURRENT,
text: i18nText("BI-Basic_Quarter_Begin"), },
value: DynamicDateCard.OFFSET.BEGIN, {
}, { text: i18nText("BI-Basic_Quarter_Begin"),
text: i18nText("BI-Basic_Quarter_End"), value: DynamicDateCard.OFFSET.BEGIN,
value: DynamicDateCard.OFFSET.END, },
}]; {
text: i18nText("BI-Basic_Quarter_End"),
value: DynamicDateCard.OFFSET.END,
}
];
case DynamicDateCard.TYPE.MONTH: case DynamicDateCard.TYPE.MONTH:
return [{ return [
text: i18nText("BI-Basic_Current_Day"), {
value: DynamicDateCard.OFFSET.CURRENT, text: i18nText("BI-Basic_Current_Day"),
}, { value: DynamicDateCard.OFFSET.CURRENT,
text: i18nText("BI-Basic_Month_Begin"), },
value: DynamicDateCard.OFFSET.BEGIN, {
}, { text: i18nText("BI-Basic_Month_Begin"),
text: i18nText("BI-Basic_Month_End"), value: DynamicDateCard.OFFSET.BEGIN,
value: DynamicDateCard.OFFSET.END, },
}]; {
text: i18nText("BI-Basic_Month_End"),
value: DynamicDateCard.OFFSET.END,
}
];
case DynamicDateCard.TYPE.WEEK: case DynamicDateCard.TYPE.WEEK:
default: default:
return [{ return [
text: i18nText("BI-Basic_Current_Day"), {
value: DynamicDateCard.OFFSET.CURRENT, text: i18nText("BI-Basic_Current_Day"),
}, { value: DynamicDateCard.OFFSET.CURRENT,
text: i18nText("BI-Basic_Week_Begin"), },
value: DynamicDateCard.OFFSET.BEGIN, {
}, { text: i18nText("BI-Basic_Week_Begin"),
text: i18nText("BI-Basic_Week_End"), value: DynamicDateCard.OFFSET.BEGIN,
value: DynamicDateCard.OFFSET.END, },
}]; {
text: i18nText("BI-Basic_Week_End"),
value: DynamicDateCard.OFFSET.END,
}
];
} }
} }
@ -297,22 +381,22 @@ export class DynamicDateCard extends Widget {
const valueMap = {}; const valueMap = {};
switch (value.dateType) { switch (value.dateType) {
case DynamicDateCard.TYPE.YEAR: case DynamicDateCard.TYPE.YEAR:
valueMap.year = (value.offset === 0 ? -value.value : +value.value); valueMap.year = value.offset === 0 ? -value.value : +value.value;
break; break;
case DynamicDateCard.TYPE.QUARTER: case DynamicDateCard.TYPE.QUARTER:
valueMap.quarter = (value.offset === 0 ? -value.value : +value.value); valueMap.quarter = value.offset === 0 ? -value.value : +value.value;
break; break;
case DynamicDateCard.TYPE.MONTH: case DynamicDateCard.TYPE.MONTH:
valueMap.month = (value.offset === 0 ? -value.value : +value.value); valueMap.month = value.offset === 0 ? -value.value : +value.value;
break; break;
case DynamicDateCard.TYPE.WEEK: case DynamicDateCard.TYPE.WEEK:
valueMap.week = (value.offset === 0 ? -value.value : +value.value); valueMap.week = value.offset === 0 ? -value.value : +value.value;
break; break;
case DynamicDateCard.TYPE.DAY: case DynamicDateCard.TYPE.DAY:
valueMap.day = (value.offset === 0 ? -value.value : +value.value); valueMap.day = value.offset === 0 ? -value.value : +value.value;
break; break;
case DynamicDateCard.TYPE.WORK_DAY: case DynamicDateCard.TYPE.WORK_DAY:
valueMap.workDay = (value.offset === 0 ? -value.value : +value.value); valueMap.workDay = value.offset === 0 ? -value.value : +value.value;
break; break;
default: default:
break; break;
@ -320,7 +404,7 @@ export class DynamicDateCard extends Widget {
if (isNull(value.dateType)) { if (isNull(value.dateType)) {
valueMap.position = this.position || DynamicDateCard.OFFSET.CURRENT; valueMap.position = this.position || DynamicDateCard.OFFSET.CURRENT;
} }
return valueMap; return valueMap;
} }
@ -382,7 +466,7 @@ export class DynamicDateCard extends Widget {
} }
if (this.workDayBox.isSelected()) { if (this.workDayBox.isSelected()) {
const value = buttons[0].getValue(); const value = buttons[0].getValue();
valueMap.workDay = (value.offset === 0 ? -value.value : +value.value); valueMap.workDay = value.offset === 0 ? -value.value : +value.value;
} }
return valueMap; return valueMap;
@ -393,7 +477,8 @@ export class DynamicDateCard extends Widget {
const start = parseDateTime(o.min, "%Y-%X-%d"); const start = parseDateTime(o.min, "%Y-%X-%d");
const end = parseDateTime(o.max, "%Y-%X-%d"); const end = parseDateTime(o.max, "%Y-%X-%d");
return i18nText("BI-Basic_Date_Range_Error", return i18nText(
"BI-Basic_Date_Range_Error",
start.getFullYear(), start.getFullYear(),
start.getMonth() + 1, start.getMonth() + 1,
start.getDate(), start.getDate(),

468
src/widget/dynamicdate/dynamicdate.combo.js

@ -1,33 +1,45 @@
import { shortcut, getDate, toPix, isEqual, isNotEmptyString, isEmptyString, isNotNull, isNotEmptyObject, checkDateVoid } from "@/core"; import {
import { Single, Combo } from "@/base"; AbsoluteLayout,
HorizontalFillLayout,
shortcut,
getDate,
toPix,
isEqual,
isNotEmptyString,
isEmptyString,
isNotNull,
isNotEmptyObject,
checkDateVoid,
} from "@/core";
import { Combo, IconButton, Single } from "@/base";
import { DynamicDateTrigger } from "./dynamicdate.trigger"; import { DynamicDateTrigger } from "./dynamicdate.trigger";
import { DynamicDatePopup } from "./dynamicdate.popup"; import { DynamicDatePopup } from "./dynamicdate.popup";
@shortcut() @shortcut()
export class DynamicDateCombo extends Single { export class DynamicDateCombo extends Single {
static xtype = "bi.dynamic_date_combo" static xtype = "bi.dynamic_date_combo";
static EVENT_KEY_DOWN = "EVENT_KEY_DOWN" static EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
static EVENT_CONFIRM = "EVENT_CONFIRM" static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_FOCUS = "EVENT_FOCUS" static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR" static EVENT_BLUR = "EVENT_BLUR";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_VALID = "EVENT_VALID" static EVENT_VALID = "EVENT_VALID";
static EVENT_ERROR = "EVENT_ERROR" static EVENT_ERROR = "EVENT_ERROR";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW" static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW" static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW";
static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW" static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW";
static Static = 1; static Static = 1;
static Dynamic = 2; static Dynamic = 2;
constants = { constants = {
popupHeight: 259, popupHeight: 259,
popupWidth: 270, popupWidth: 270,
comboAdjustHeight: 1, comboAdjustHeight: 1,
border: 1, border: 1,
iconWidth: 24, iconWidth: 24,
} };
props = { props = {
baseCls: "bi-dynamic-date-combo", baseCls: "bi-dynamic-date-combo",
@ -56,200 +68,222 @@ export class DynamicDateCombo extends Single {
const border = opts.simple ? 1 : 2; const border = opts.simple ? 1 : 2;
return { return {
type: "bi.absolute", type: AbsoluteLayout.xtype,
items: [{ items: [
el: { {
type: "bi.combo",
cls: `${opts.simple ? "bi-border-bottom" : "bi-border bi-border-radius"} bi-focus-shadow`,
container: opts.container,
ref: _ref => {
this.combo = _ref;
},
toggle: false,
isNeedAdjustHeight: opts.isNeedAdjustHeight,
isNeedAdjustWidth: opts.isNeedAdjustWidth,
destroyWhenHide: true,
el: { el: {
type: "bi.horizontal_fill", type: Combo.xtype,
columnSize: [this.constants.iconWidth, "fill"], cls: `${opts.simple ? "bi-border-bottom" : "bi-border bi-border-radius"} bi-focus-shadow`,
height: toPix(opts.height, border), container: opts.container,
items: [{ ref: (_ref) => {
el: { this.combo = _ref;
type: "bi.icon_button", },
cls: "bi-trigger-icon-button date-change-h-font", toggle: false,
width: toPix(opts.height, border), isNeedAdjustHeight: opts.isNeedAdjustHeight,
height: toPix(opts.height, border), isNeedAdjustWidth: opts.isNeedAdjustWidth,
ref: _ref => { destroyWhenHide: true,
this.changeIcon = _ref; el: {
}, type: HorizontalFillLayout.xtype,
}, columnSize: [this.constants.iconWidth, "fill"],
}, {
type: "bi.dynamic_date_trigger",
simple: opts.simple,
min: opts.minDate,
max: opts.maxDate,
format: opts.format,
allowEdit: opts.allowEdit,
watermark: opts.watermark,
iconWidth: toPix(opts.height, border),
height: toPix(opts.height, border), height: toPix(opts.height, border),
value: opts.value, items: [
ref: _ref => { {
this.trigger = _ref; el: {
}, type: IconButton.xtype,
listeners: [{ cls: "bi-trigger-icon-button date-change-h-font",
eventName: DynamicDateTrigger.EVENT_KEY_DOWN, width: toPix(opts.height, border),
action: (...args) => { height: toPix(opts.height, border),
if (this.combo.isViewVisible()) { ref: (_ref) => {
this.combo.hideView(); this.changeIcon = _ref;
}
this.fireEvent(DynamicDateCombo.EVENT_KEY_DOWN, ...args);
},
}, {
eventName: DynamicDateTrigger.EVENT_STOP,
action: () => {
if (!this.combo.isViewVisible()) {
this.combo.showView();
}
},
}, {
eventName: DynamicDateTrigger.EVENT_FOCUS,
action: () => {
this.storeTriggerValue = this.trigger.getKey();
if (!this.combo.isViewVisible()) {
this.combo.showView();
}
this.fireEvent(DynamicDateCombo.EVENT_FOCUS);
},
}, {
eventName: DynamicDateTrigger.EVENT_BLUR,
action: () => {
this.fireEvent(DynamicDateCombo.EVENT_BLUR);
},
}, {
eventName: DynamicDateTrigger.EVENT_ERROR,
action: () => {
this.storeValue = {
type: DynamicDateCombo.Static,
value: {
year: date.getFullYear(),
month: date.getMonth() + 1,
}, },
}; },
this.combo.element.addClass("error");
this.fireEvent(DynamicDateCombo.EVENT_ERROR);
},
}, {
eventName: DynamicDateTrigger.EVENT_VALID,
action: () => {
this.storeValue = this.trigger.getValue();
this.combo.element.removeClass("error");
this.fireEvent(DynamicDateCombo.EVENT_VALID);
},
}, {
eventName: DynamicDateTrigger.EVENT_CHANGE,
action: () => {
this.fireEvent(DynamicDateCombo.EVENT_CHANGE);
},
}, {
eventName: DynamicDateTrigger.EVENT_CONFIRM,
action: () => {
const dateStore = this.storeTriggerValue;
const dateObj = this.trigger.getKey();
if (this.combo.isViewVisible() || isEqual(dateObj, dateStore)) {
return;
}
if (isNotEmptyString(dateObj) && !isEqual(dateObj, dateStore)) {
this.storeValue = this.trigger.getValue();
this.setValue(this.trigger.getValue());
} else if (isEmptyString(dateObj)) {
this.storeValue = null;
this.trigger.setValue();
}
this._checkDynamicValue(this.storeValue);
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM);
},
}],
}],
},
adjustLength: this.constants.comboAdjustHeight,
popup: {
el: {
type: "bi.dynamic_date_popup",
width: opts.isNeedAdjustWidth ? opts.width : undefined,
supportDynamic: opts.supportDynamic,
behaviors: opts.behaviors,
min: opts.minDate,
max: opts.maxDate,
ref: _ref => {
this.popup = _ref;
},
listeners: [{
eventName: DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE,
action: () => {
this.setValue();
this.combo.hideView();
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM);
}, },
}, { {
eventName: DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE, type: DynamicDateTrigger.xtype,
action: () => { simple: opts.simple,
const date = getDate(); min: opts.minDate,
this.setValue({ max: opts.maxDate,
type: DynamicDateCombo.Static, format: opts.format,
value: { allowEdit: opts.allowEdit,
year: date.getFullYear(), watermark: opts.watermark,
month: date.getMonth() + 1, iconWidth: toPix(opts.height, border),
day: date.getDate(), height: toPix(opts.height, border),
value: opts.value,
ref: (_ref) => {
this.trigger = _ref;
},
listeners: [
{
eventName: DynamicDateTrigger.EVENT_KEY_DOWN,
action: (...args) => {
if (this.combo.isViewVisible()) {
this.combo.hideView();
}
this.fireEvent(DynamicDateCombo.EVENT_KEY_DOWN, ...args);
},
}, },
}); {
this.combo.hideView(); eventName: DynamicDateTrigger.EVENT_STOP,
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM); action: () => {
}, if (!this.combo.isViewVisible()) {
}, { this.combo.showView();
eventName: DynamicDatePopup.BUTTON_OK_EVENT_CHANGE, }
action: () => { },
const value = this.popup.getValue(); },
if (this._checkValue(value)) { {
this.setValue(value); eventName: DynamicDateTrigger.EVENT_FOCUS,
} action: () => {
this.combo.hideView(); this.storeTriggerValue = this.trigger.getKey();
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM); if (!this.combo.isViewVisible()) {
this.combo.showView();
}
this.fireEvent(DynamicDateCombo.EVENT_FOCUS);
},
},
{
eventName: DynamicDateTrigger.EVENT_BLUR,
action: () => {
this.fireEvent(DynamicDateCombo.EVENT_BLUR);
},
},
{
eventName: DynamicDateTrigger.EVENT_ERROR,
action: () => {
this.storeValue = {
type: DynamicDateCombo.Static,
value: {
year: date.getFullYear(),
month: date.getMonth() + 1,
},
};
this.combo.element.addClass("error");
this.fireEvent(DynamicDateCombo.EVENT_ERROR);
},
},
{
eventName: DynamicDateTrigger.EVENT_VALID,
action: () => {
this.storeValue = this.trigger.getValue();
this.combo.element.removeClass("error");
this.fireEvent(DynamicDateCombo.EVENT_VALID);
},
},
{
eventName: DynamicDateTrigger.EVENT_CHANGE,
action: () => {
this.fireEvent(DynamicDateCombo.EVENT_CHANGE);
},
},
{
eventName: DynamicDateTrigger.EVENT_CONFIRM,
action: () => {
const dateStore = this.storeTriggerValue;
const dateObj = this.trigger.getKey();
if (this.combo.isViewVisible() || isEqual(dateObj, dateStore)) {
return;
}
if (isNotEmptyString(dateObj) && !isEqual(dateObj, dateStore)) {
this.storeValue = this.trigger.getValue();
this.setValue(this.trigger.getValue());
} else if (isEmptyString(dateObj)) {
this.storeValue = null;
this.trigger.setValue();
}
this._checkDynamicValue(this.storeValue);
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM);
},
},
],
}, },
}, { ],
eventName: DynamicDatePopup.EVENT_CHANGE, },
action: () => { adjustLength: this.constants.comboAdjustHeight,
this.setValue(this.popup.getValue()); popup: {
this.combo.hideView(); el: {
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM); type: DynamicDatePopup.xtype,
width: opts.isNeedAdjustWidth ? opts.width : undefined,
supportDynamic: opts.supportDynamic,
behaviors: opts.behaviors,
min: opts.minDate,
max: opts.maxDate,
ref: (_ref) => {
this.popup = _ref;
}, },
}, { listeners: [
eventName: DynamicDatePopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW, {
eventName: DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE,
action: () => {
this.setValue();
this.combo.hideView();
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM);
},
},
{
eventName: DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE,
action: () => {
const date = getDate();
this.setValue({
type: DynamicDateCombo.Static,
value: {
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
},
});
this.combo.hideView();
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM);
},
},
{
eventName: DynamicDatePopup.BUTTON_OK_EVENT_CHANGE,
action: () => {
const value = this.popup.getValue();
if (this._checkValue(value)) {
this.setValue(value);
}
this.combo.hideView();
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM);
},
},
{
eventName: DynamicDatePopup.EVENT_CHANGE,
action: () => {
this.setValue(this.popup.getValue());
this.combo.hideView();
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM);
},
},
{
eventName: DynamicDatePopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW,
action: () => {
this.fireEvent(DynamicDateCombo.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW);
},
},
],
},
},
// // DEC-4250 和复选下拉一样,点击triggerBtn不默认收起
// hideChecker: function (e) {
// return self.triggerBtn.element.find(e.target).length === 0;
// },
listeners: [
{
eventName: Combo.EVENT_BEFORE_POPUPVIEW,
action: () => { action: () => {
this.fireEvent(DynamicDateCombo.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW); this.popup.setMinDate(opts.minDate);
this.popup.setMaxDate(opts.maxDate);
this.popup.setValue(this.storeValue);
this.fireEvent(DynamicDateCombo.EVENT_BEFORE_POPUPVIEW);
}, },
}], },
}, ],
}, },
// // DEC-4250 和复选下拉一样,点击triggerBtn不默认收起 top: 0,
// hideChecker: function (e) { left: 0,
// return self.triggerBtn.element.find(e.target).length === 0; right: 0,
// }, bottom: 0,
listeners: [{
eventName: Combo.EVENT_BEFORE_POPUPVIEW,
action: () => {
this.popup.setMinDate(opts.minDate);
this.popup.setMaxDate(opts.maxDate);
this.popup.setValue(this.storeValue);
this.fireEvent(DynamicDateCombo.EVENT_BEFORE_POPUPVIEW);
},
}],
}, },
top: 0, ],
left: 0,
right: 0,
bottom: 0,
}],
}; };
} }
@ -263,16 +297,16 @@ export class DynamicDateCombo extends Single {
type = v.type; type = v.type;
} }
switch (type) { switch (type) {
case DynamicDateCombo.Dynamic: case DynamicDateCombo.Dynamic:
this.changeIcon.setVisible(true); this.changeIcon.setVisible(true);
// this.comboWrapper.attr("items")[0].width = o.height - this.options.simple ? 1 : 2; // this.comboWrapper.attr("items")[0].width = o.height - this.options.simple ? 1 : 2;
// this.comboWrapper.resize(); // this.comboWrapper.resize();
break; break;
default: default:
// this.comboWrapper.attr("items")[0].width = 0; // this.comboWrapper.attr("items")[0].width = 0;
// this.comboWrapper.resize(); // this.comboWrapper.resize();
this.changeIcon.setVisible(false); this.changeIcon.setVisible(false);
break; break;
} }
} }
@ -280,20 +314,18 @@ export class DynamicDateCombo extends Single {
const o = this.options; const o = this.options;
let value; let value;
switch (v.type) { switch (v.type) {
case DynamicDateCombo.Dynamic: case DynamicDateCombo.Dynamic:
return isNotEmptyObject(v.value); return isNotEmptyObject(v.value);
case DynamicDateCombo.Static: case DynamicDateCombo.Static:
value = v.value || {}; value = v.value || {};
return !checkDateVoid(value.year, value.month, value.day, o.minDate, o.maxDate)[0]; return !checkDateVoid(value.year, value.month, value.day, o.minDate, o.maxDate)[0];
default: default:
return true; return true;
} }
} }
_defaultState() { _defaultState() {}
}
setMinDate(minDate) { setMinDate(minDate) {
const o = this.options; const o = this.options;

137
src/widget/dynamicdate/dynamicdate.param.item.js

@ -1,19 +1,20 @@
import { shortcut, Widget, toPix, isNaturalNumber, i18nText } from "@/core"; import { HTapeLayout, shortcut, Widget, toPix, isNaturalNumber, i18nText } from "@/core";
import { DynamicDateCard } from "./dynamicdate.card";
import { SignEditor, TextValueCombo } from "@/case"; import { SignEditor, TextValueCombo } from "@/case";
import { Label } from "@/base";
import { DynamicDateCard } from "./dynamicdate.card";
@shortcut() @shortcut()
export class DynamicDateParamItem extends Widget { export class DynamicDateParamItem extends Widget {
static xtype = "bi.dynamic_date_param_item" static xtype = "bi.dynamic_date_param_item";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_INPUT_CHANGE = "EVENT_INPUT_CHANGE" static EVENT_INPUT_CHANGE = "EVENT_INPUT_CHANGE";
props() { props() {
return { return {
baseCls: "bi-dynamic-date-param-item", baseCls: "bi-dynamic-date-param-item",
dateType: DynamicDateCard.TYPE.YEAR, dateType: DynamicDateCard.TYPE.YEAR,
validationChecker () { validationChecker() {
return true; return true;
}, },
value: 0, value: 0,
@ -24,67 +25,79 @@ export class DynamicDateParamItem extends Widget {
render() { render() {
const o = this.options; const o = this.options;
return { return {
type: "bi.htape", type: HTapeLayout.xtype,
items: [{ items: [
el: { {
type: "bi.sign_editor", el: {
cls: "bi-border bi-focus-shadow bi-border-radius", type: SignEditor.xtype,
height: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 2), cls: "bi-border bi-focus-shadow bi-border-radius",
validationChecker (v) { height: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 2),
return isNaturalNumber(v); validationChecker(v) {
}, return isNaturalNumber(v);
value: o.value,
ref: _ref => {
this.editor = _ref;
},
errorText () {
return i18nText("BI-Please_Input_Natural_Number");
},
allowBlank: false,
listeners: [{
eventName: SignEditor.EVENT_CONFIRM,
action: () => {
this.fireEvent(DynamicDateParamItem.EVENT_CHANGE);
}, },
}, { value: o.value,
eventName: SignEditor.EVENT_CHANGE, ref: _ref => {
action: () => { this.editor = _ref;
this.fireEvent(DynamicDateParamItem.EVENT_INPUT_CHANGE);
}, },
}], errorText() {
}, return i18nText("BI-Please_Input_Natural_Number");
width: 60, },
}, { allowBlank: false,
el: { listeners: [
type: "bi.label", {
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, eventName: SignEditor.EVENT_CONFIRM,
text: this._getText(), action: () => {
this.fireEvent(DynamicDateParamItem.EVENT_CHANGE);
},
},
{
eventName: SignEditor.EVENT_CHANGE,
action: () => {
this.fireEvent(DynamicDateParamItem.EVENT_INPUT_CHANGE);
},
}
],
},
width: 60,
}, },
width: o.dateType === DynamicDateCard.TYPE.WORK_DAY ? 60 : 20, {
}, { el: {
type: "bi.text_value_combo", type: Label.xtype,
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
items: [{ text: this._getText(),
text: i18nText("BI-Basic_Front"), },
value: 0, width: o.dateType === DynamicDateCard.TYPE.WORK_DAY ? 60 : 20,
}, {
text: i18nText("BI-Basic_Behind"),
value: 1,
}],
ref: _ref => {
this.offsetCombo = _ref;
}, },
container: null, {
value: o.offset, type: TextValueCombo.xtype,
listeners: [{ height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
eventName: TextValueCombo.EVENT_CHANGE, items: [
action: () => { {
this.fireEvent(DynamicDateParamItem.EVENT_CHANGE); text: i18nText("BI-Basic_Front"),
value: 0,
},
{
text: i18nText("BI-Basic_Behind"),
value: 1,
}
],
ref: _ref => {
this.offsetCombo = _ref;
}, },
}], container: null,
}], value: o.offset,
listeners: [
{
eventName: TextValueCombo.EVENT_CHANGE,
action: () => {
this.fireEvent(DynamicDateParamItem.EVENT_CHANGE);
},
}
],
}
],
}; };
} }
@ -111,7 +124,7 @@ export class DynamicDateParamItem extends Widget {
text = i18nText("BI-Basic_Work_Day"); text = i18nText("BI-Basic_Work_Day");
break; break;
} }
return text; return text;
} }

288
src/widget/dynamicdate/dynamicdate.popup.js

@ -1,16 +1,33 @@
import { shortcut, Widget, createWidget, i18nText, toPix, createItems, isNull, isEmptyObject, isEmptyString, getDate, checkDateVoid, print } from "@/core"; import {
import { DynamicDateCombo } from "./dynamicdate.combo"; VerticalLayout,
GridLayout,
shortcut,
Widget,
createWidget,
i18nText,
toPix,
createItems,
isNull,
isEmptyObject,
isEmptyString,
getDate,
checkDateVoid,
print
} from "@/core";
import { TextButton, Tab } from "@/base"; import { TextButton, Tab } from "@/base";
import { LinearSegment } from "@/case";
import { DynamicDateCard } from "./dynamicdate.card";
import { DateCalendarPopup } from "../date/calendar"; import { DateCalendarPopup } from "../date/calendar";
import { DynamicDateCombo } from "./dynamicdate.combo";
import { DynamicDateHelper } from "./dynamicdate.caculate"; import { DynamicDateHelper } from "./dynamicdate.caculate";
@shortcut() @shortcut()
export class DynamicDatePopup extends Widget { export class DynamicDatePopup extends Widget {
static xtype = "bi.dynamic_date_popup" static xtype = "bi.dynamic_date_popup";
constants = { constants = {
tabHeight: 40, tabHeight: 40,
} };
props = { props = {
baseCls: "bi-dynamic-date-popup", baseCls: "bi-dynamic-date-popup",
@ -18,11 +35,11 @@ export class DynamicDatePopup extends Widget {
supportDynamic: true, supportDynamic: true,
}; };
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE" static BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE";
static BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE" static BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE";
static BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE" static BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE";
static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW" static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW";
_init() { _init() {
super._init(...arguments); super._init(...arguments);
@ -32,72 +49,86 @@ export class DynamicDatePopup extends Widget {
}; };
createWidget({ createWidget({
element: this, element: this,
type: "bi.vertical", type: VerticalLayout.xtype,
items: [{ items: [
el: this._getTabJson(), {
}, { el: this._getTabJson(),
el: { },
type: "bi.grid", {
items: [ el: {
[{ type: GridLayout.xtype,
type: "bi.text_button", items: [
cls: "bi-high-light bi-split-top", [
shadow: true, {
text: i18nText("BI-Basic_Clear"), type: TextButton.xtype,
textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), cls: "bi-high-light bi-split-top",
listeners: [{ shadow: true,
eventName: TextButton.EVENT_CHANGE, text: i18nText("BI-Basic_Clear"),
action: () => { textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1),
this.fireEvent(DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE); listeners: [
}, {
}], eventName: TextButton.EVENT_CHANGE,
}, { action: () => {
type: "bi.text_button", this.fireEvent(DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE);
cls: "bi-split-left bi-split-right bi-high-light bi-split-top", },
shadow: true, }
textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), ],
text: i18nText("BI-Multi_Date_Today"),
disabled: this._checkTodayValid(),
ref: _ref => {
this.todayButton = _ref;
},
listeners: [{
eventName: TextButton.EVENT_CHANGE,
action: () => {
this.fireEvent(DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE);
}, },
}], {
}, { type: TextButton.xtype,
type: "bi.text_button", cls: "bi-split-left bi-split-right bi-high-light bi-split-top",
cls: "bi-high-light bi-split-top", shadow: true,
textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1),
shadow: true, text: i18nText("BI-Multi_Date_Today"),
text: i18nText("BI-Basic_OK"), disabled: this._checkTodayValid(),
listeners: [{ ref: _ref => {
eventName: TextButton.EVENT_CHANGE, this.todayButton = _ref;
action: () => { },
const type = this.dateTab.getSelect(); listeners: [
if (type === DynamicDateCombo.Dynamic) { {
this.dynamicPane.checkValidation(true) && this.fireEvent(DynamicDatePopup.BUTTON_OK_EVENT_CHANGE); eventName: TextButton.EVENT_CHANGE,
} else { action: () => {
this.fireEvent(DynamicDatePopup.BUTTON_OK_EVENT_CHANGE); this.fireEvent(DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE);
} },
}
],
}, },
}], {
}] type: TextButton.xtype,
], cls: "bi-high-light bi-split-top",
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1),
}, shadow: true,
}], text: i18nText("BI-Basic_OK"),
listeners: [
{
eventName: TextButton.EVENT_CHANGE,
action: () => {
const type = this.dateTab.getSelect();
if (type === DynamicDateCombo.Dynamic) {
this.dynamicPane.checkValidation(true) &&
this.fireEvent(DynamicDatePopup.BUTTON_OK_EVENT_CHANGE);
} else {
this.fireEvent(DynamicDatePopup.BUTTON_OK_EVENT_CHANGE);
}
},
}
],
}
]
],
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
},
}
],
}); });
this.setValue(opts.value); this.setValue(opts.value);
} }
_getTabJson() { _getTabJson() {
const o = this.options; const o = this.options;
return { return {
type: "bi.tab", type: Tab.xtype,
logic: { logic: {
dynamic: true, dynamic: true,
}, },
@ -105,32 +136,40 @@ export class DynamicDatePopup extends Widget {
this.dateTab = _ref; this.dateTab = _ref;
}, },
tab: { tab: {
type: "bi.linear_segment", type: LinearSegment.xtype,
invisible: !o.supportDynamic, invisible: !o.supportDynamic,
cls: "bi-split-bottom", cls: "bi-split-bottom",
height: this.constants.tabHeight, height: this.constants.tabHeight,
items: createItems([{ items: createItems(
text: i18nText("BI-Multi_Date_YMD"), [
value: DynamicDateCombo.Static, {
}, { text: i18nText("BI-Multi_Date_YMD"),
text: i18nText("BI-Basic_Dynamic_Title"), value: DynamicDateCombo.Static,
value: DynamicDateCombo.Dynamic, },
}], { {
textAlign: "center", text: i18nText("BI-Basic_Dynamic_Title"),
}), value: DynamicDateCombo.Dynamic,
}
],
{
textAlign: "center",
}
),
}, },
cardCreator: v => { cardCreator: v => {
switch (v) { switch (v) {
case DynamicDateCombo.Dynamic: case DynamicDateCombo.Dynamic:
return { return {
type: "bi.dynamic_date_card", type: DynamicDateCard.xtype,
cls: "dynamic-date-pane", cls: "dynamic-date-pane",
listeners: [{ listeners: [
eventName: "EVENT_CHANGE", {
action: () => { eventName: "EVENT_CHANGE",
this._setInnerValue(this.year, v); action: () => {
}, this._setInnerValue(this.year, v);
}], },
}
],
min: this.options.min, min: this.options.min,
max: this.options.max, max: this.options.max,
ref: _ref => { ref: _ref => {
@ -140,56 +179,61 @@ export class DynamicDatePopup extends Widget {
case DynamicDateCombo.Static: case DynamicDateCombo.Static:
default: default:
return { return {
type: "bi.date_calendar_popup", type: DateCalendarPopup.xtype,
behaviors: o.behaviors, behaviors: o.behaviors,
min: this.options.min, min: this.options.min,
max: this.options.max, max: this.options.max,
listeners: [{ listeners: [
eventName: DateCalendarPopup.EVENT_CHANGE, {
action: () => { eventName: DateCalendarPopup.EVENT_CHANGE,
this.fireEvent(DynamicDatePopup.EVENT_CHANGE); action: () => {
}, this.fireEvent(DynamicDatePopup.EVENT_CHANGE);
}, { },
eventName: DateCalendarPopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW,
action: () => {
this.fireEvent(DynamicDatePopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW);
}, },
}], {
eventName: DateCalendarPopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW,
action: () => {
this.fireEvent(DynamicDatePopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW);
},
}
],
ref: _ref => { ref: _ref => {
this.ymd = _ref; this.ymd = _ref;
}, },
}; };
} }
}, },
listeners: [{ listeners: [
eventName: Tab.EVENT_CHANGE, {
action: () => { eventName: Tab.EVENT_CHANGE,
const v = this.dateTab.getSelect(); action: () => {
let date; const v = this.dateTab.getSelect();
switch (v) { let date;
case DynamicDateCombo.Static: switch (v) {
date = DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); case DynamicDateCombo.Static:
this.ymd.setValue({ date = DynamicDateHelper.getCalculation(this.dynamicPane.getValue());
year: date.getFullYear(), this.ymd.setValue({
month: date.getMonth() + 1, year: date.getFullYear(),
day: date.getDate(), month: date.getMonth() + 1,
}); day: date.getDate(),
this._setInnerValue();
break;
case DynamicDateCombo.Dynamic:
default:
if (this.storeValue && this.storeValue.type === DynamicDateCombo.Dynamic) {
this.dynamicPane.setValue(this.storeValue.value);
} else {
this.dynamicPane.setValue({
year: 0,
}); });
this._setInnerValue();
break;
case DynamicDateCombo.Dynamic:
default:
if (this.storeValue && this.storeValue.type === DynamicDateCombo.Dynamic) {
this.dynamicPane.setValue(this.storeValue.value);
} else {
this.dynamicPane.setValue({
year: 0,
});
}
this._setInnerValue();
break;
} }
this._setInnerValue(); },
break; }
} ],
},
}],
}; };
} }
@ -212,7 +256,7 @@ export class DynamicDatePopup extends Widget {
_checkTodayValid() { _checkTodayValid() {
const o = this.options; const o = this.options;
const today = getDate(); const today = getDate();
return !!checkDateVoid(today.getFullYear(), today.getMonth() + 1, today.getDate(), o.min, o.max)[0]; return !!checkDateVoid(today.getFullYear(), today.getMonth() + 1, today.getDate(), o.min, o.max)[0];
} }

156
src/widget/dynamicdate/dynamicdate.trigger.js

@ -1,13 +1,32 @@
import { shortcut, i18nText, createWidget, isKey, checkDateLegal, parseDateTime, bind, isNotNull, isNotEmptyString, isEqual, isEmptyObject, getDate, isEmptyString, isNull, each, checkDateVoid, print } from "@/core";
import { Trigger } from "@/base";
import { SignEditor } from "@/case"; import { SignEditor } from "@/case";
import {
HTapeLayout,
AbsoluteLayout,
shortcut,
i18nText,
createWidget,
isKey,
checkDateLegal,
parseDateTime,
bind,
isNotNull,
isNotEmptyString,
isEqual,
isEmptyObject,
getDate,
isEmptyString,
isNull,
each,
checkDateVoid,
print
} from "@/core";
import { IconButton, Text, Trigger } from "@/base";
import { DynamicDateCombo } from "./dynamicdate.combo"; import { DynamicDateCombo } from "./dynamicdate.combo";
import { DynamicDateHelper } from "./dynamicdate.caculate"; import { DynamicDateHelper } from "./dynamicdate.caculate";
@shortcut() @shortcut()
export class DynamicDateTrigger extends Trigger { export class DynamicDateTrigger extends Trigger {
static xtype = "bi.dynamic_date_trigger" static xtype = "bi.dynamic_date_trigger";
_const = { _const = {
hgap: 4, hgap: 4,
@ -19,16 +38,16 @@ export class DynamicDateTrigger extends Trigger {
iconWidth: 24, iconWidth: 24,
}; };
static EVENT_BLUR = "EVENT_BLUR" static EVENT_BLUR = "EVENT_BLUR";
static EVENT_FOCUS = "EVENT_FOCUS" static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_START = "EVENT_START" static EVENT_START = "EVENT_START";
static EVENT_STOP = "EVENT_STOP" static EVENT_STOP = "EVENT_STOP";
static EVENT_CONFIRM = "EVENT_CONFIRM" static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_VALID = "EVENT_VALID" static EVENT_VALID = "EVENT_VALID";
static EVENT_ERROR = "EVENT_ERROR" static EVENT_ERROR = "EVENT_ERROR";
static EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK" static EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK";
static EVENT_KEY_DOWN = "EVENT_KEY_DOWN" static EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
props() { props() {
return { return {
@ -49,21 +68,25 @@ export class DynamicDateTrigger extends Trigger {
c = this._const; c = this._const;
this.storeTriggerValue = ""; this.storeTriggerValue = "";
this.editor = createWidget({ this.editor = createWidget({
type: "bi.sign_editor", type: SignEditor.xtype,
simple: o.simple, simple: o.simple,
height: o.height, height: o.height,
validationChecker: v => { validationChecker: v => {
const formatStr = this._getStandardDateStr(v); const formatStr = this._getStandardDateStr(v);
const date = formatStr.match(/\d+/g); const date = formatStr.match(/\d+/g);
!isKey(o.format) && this._autoAppend(v, date); !isKey(o.format) && this._autoAppend(v, date);
return this._dateCheck(formatStr) && checkDateLegal(formatStr) && this._checkVoid({ return (
year: date[0] | 0, this._dateCheck(formatStr) &&
month: date[1] | 0, checkDateLegal(formatStr) &&
day: date[2] | 0, this._checkVoid({
}); year: date[0] | 0,
month: date[1] | 0,
day: date[2] | 0,
})
);
}, },
quitChecker () { quitChecker() {
return false; return false;
}, },
hgap: c.hgap, hgap: c.hgap,
@ -74,11 +97,14 @@ export class DynamicDateTrigger extends Trigger {
let str = ""; let str = "";
if (!isKey(o.format)) { if (!isKey(o.format)) {
if (!this._dateCheck(v)) { if (!this._dateCheck(v)) {
str = this.editor.isEditing() ? i18nText("BI-Date_Trigger_Error_Text") : i18nText("BI-Year_Trigger_Invalid_Text"); str = this.editor.isEditing()
? i18nText("BI-Date_Trigger_Error_Text")
: i18nText("BI-Year_Trigger_Invalid_Text");
} else { } else {
const start = parseDateTime(o.min, "%Y-%X-%d"); const start = parseDateTime(o.min, "%Y-%X-%d");
const end = parseDateTime(o.max, "%Y-%X-%d"); const end = parseDateTime(o.max, "%Y-%X-%d");
str = i18nText("BI-Basic_Date_Range_Error", str = i18nText(
"BI-Basic_Date_Range_Error",
start.getFullYear(), start.getFullYear(),
start.getMonth() + 1, start.getMonth() + 1,
start.getDate(), start.getDate(),
@ -144,34 +170,40 @@ export class DynamicDateTrigger extends Trigger {
this.fireEvent(DynamicDateTrigger.EVENT_CHANGE); this.fireEvent(DynamicDateTrigger.EVENT_CHANGE);
}); });
createWidget({ createWidget({
type: "bi.htape", type: HTapeLayout.xtype,
element: this, element: this,
columnSize: ["", this._const.iconWidth], columnSize: ["", this._const.iconWidth],
items: [{ items: [
el: this.editor, {
}, { el: this.editor,
el: {
type: "bi.icon_button",
cls: "bi-trigger-icon-button date-font",
width: this._const.iconWidth,
},
width: this._const.iconWidth,
}],
});
!o.allowEdit && createWidget({
type: "bi.absolute",
element: this,
items: [{
el: {
type: "bi.text",
title: bind(this._getTitle, this),
}, },
left: 0, {
right: o.iconWidth, el: {
top: 0, type: IconButton.xtype,
bottom: 0, cls: "bi-trigger-icon-button date-font",
}], width: this._const.iconWidth,
},
width: this._const.iconWidth,
}
],
}); });
!o.allowEdit &&
createWidget({
type: AbsoluteLayout.xtype,
element: this,
items: [
{
el: {
type: Text.xtype,
title: bind(this._getTitle, this),
},
left: 0,
right: o.iconWidth,
top: 0,
bottom: 0,
}
],
});
this.setValue(o.value); this.setValue(o.value);
} }
@ -189,15 +221,15 @@ export class DynamicDateTrigger extends Trigger {
date = getDate(); date = getDate();
date = DynamicDateHelper.getCalculation(value); date = DynamicDateHelper.getCalculation(value);
dateStr = print(date, this._getFormatString()); dateStr = print(date, this._getFormatString());
return isEmptyString(text) ? dateStr : (`${text}:${dateStr}`); return isEmptyString(text) ? dateStr : `${text}:${dateStr}`;
case DynamicDateCombo.Static: case DynamicDateCombo.Static:
default: default:
if (isNull(value) || isNull(value.day)) { if (isNull(value) || isNull(value.day)) {
return ""; return "";
} }
return print(getDate(value.year, (value.month - 1), value.day), this._getFormatString()); return print(getDate(value.year, value.month - 1, value.day), this._getFormatString());
} }
} }
@ -248,10 +280,12 @@ export class DynamicDateTrigger extends Trigger {
} }
_dateCheck(date) { _dateCheck(date) {
return print(parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === date || return (
print(parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === date ||
print(parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date || print(parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date ||
print(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; print(parseDateTime(date, "%Y-%X-%e"), "%Y-%X-%e") === date
);
} }
_checkVoid(obj) { _checkVoid(obj) {
@ -280,16 +314,20 @@ export class DynamicDateTrigger extends Trigger {
_yearCheck(v) { _yearCheck(v) {
const date = print(parseDateTime(v, this._getFormatString()), this._const.compareFormat); const date = print(parseDateTime(v, this._getFormatString()), this._const.compareFormat);
return print(parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max; return print(parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
} }
_monthCheck(v) { _monthCheck(v) {
const date = parseDateTime(v, this._getFormatString()); const date = parseDateTime(v, this._getFormatString());
const dateStr = print(date, this._const.compareFormat); const dateStr = print(date, this._const.compareFormat);
return (date.getMonth() >= 0 && (print(parseDateTime(v, "%Y-%X"), "%Y-%X") === v || return (
print(parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; date.getMonth() >= 0 &&
(print(parseDateTime(v, "%Y-%X"), "%Y-%X") === v || print(parseDateTime(v, "%Y-%x"), "%Y-%x") === v) &&
dateStr >= this.options.min &&
dateStr <= this.options.max
);
} }
_setInnerValue(date) { _setInnerValue(date) {
@ -322,7 +360,7 @@ export class DynamicDateTrigger extends Trigger {
this.editor.setState(""); this.editor.setState("");
this.editor.setValue(""); this.editor.setValue("");
} else { } else {
const dateStr = print(getDate(value.year, (value.month - 1), value.day), this._getFormatString()); const dateStr = print(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);
} }

480
src/widget/dynamicdatetime/dynamicdatetime.combo.js

@ -1,15 +1,27 @@
import { shortcut, getDate, toPix, isEqual, isNotEmptyString, isEmptyString, isNotNull, isNotEmptyObject, checkDateVoid } from "@/core"; import {
import { Single, Combo } from "@/base"; AbsoluteLayout,
HorizontalFillLayout,
shortcut,
getDate,
toPix,
isEqual,
isNotEmptyString,
isEmptyString,
isNotNull,
isNotEmptyObject,
checkDateVoid
} from "@/core";
import { Combo, IconButton, Single } from "@/base";
import { DynamicDateTimeTrigger } from "./dynamicdatetime.trigger"; import { DynamicDateTimeTrigger } from "./dynamicdatetime.trigger";
import { DynamicDateTimePopup } from "./dynamicdatetime.popup"; import { DynamicDateTimePopup } from "./dynamicdatetime.popup";
import { DynamicDateCombo } from "../dynamicdate"; import { DynamicDateCombo } from "../dynamicdate";
@shortcut() @shortcut()
export class DynamicDateTimeCombo extends Single { export class DynamicDateTimeCombo extends Single {
static xtype = "bi.dynamic_date_time_combo" static xtype = "bi.dynamic_date_time_combo";
static Static = 1 static Static = 1;
static Dynamic = 2 static Dynamic = 2;
constants = { constants = {
popupHeight: 259, popupHeight: 259,
@ -17,7 +29,7 @@ export class DynamicDateTimeCombo extends Single {
comboAdjustHeight: 1, comboAdjustHeight: 1,
border: 1, border: 1,
iconWidth: 24, iconWidth: 24,
} };
props = { props = {
baseCls: "bi-dynamic-date--time-combo", baseCls: "bi-dynamic-date--time-combo",
@ -34,16 +46,15 @@ export class DynamicDateTimeCombo extends Single {
isNeedAdjustWidth: false, isNeedAdjustWidth: false,
}; };
static EVENT_KEY_DOWN = "EVENT_KEY_DOWN" static EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
static EVENT_CONFIRM = "EVENT_CONFIRM" static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_FOCUS = "EVENT_FOCUS" static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR" static EVENT_BLUR = "EVENT_BLUR";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_VALID = "EVENT_VALID" static EVENT_VALID = "EVENT_VALID";
static EVENT_ERROR = "EVENT_ERROR" static EVENT_ERROR = "EVENT_ERROR";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW" static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW" static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW";
_init() { _init() {
super._init(...arguments); super._init(...arguments);
@ -57,208 +68,231 @@ export class DynamicDateTimeCombo extends Single {
const border = opts.simple ? 1 : 2; const border = opts.simple ? 1 : 2;
return { return {
type: "bi.absolute", type: AbsoluteLayout.xtype,
items: [{ items: [
el: { {
type: "bi.combo",
cls: `${opts.simple ? "bi-border-bottom" : "bi-border bi-border-radius"} bi-focus-shadow`,
destroyWhenHide: true,
container: opts.container,
ref: _ref => {
this.combo = _ref;
},
toggle: false,
isNeedAdjustHeight: opts.isNeedAdjustHeight,
isNeedAdjustWidth: opts.isNeedAdjustWidth,
el: { el: {
type: "bi.horizontal_fill", type: Combo.xtype,
columnSize: [this.constants.iconWidth, "fill"], cls: `${opts.simple ? "bi-border-bottom" : "bi-border bi-border-radius"} bi-focus-shadow`,
height: toPix(opts.height, border), destroyWhenHide: true,
items: [{ container: opts.container,
el: { ref: (_ref) => {
type: "bi.icon_button", this.combo = _ref;
cls: "bi-trigger-icon-button date-change-h-font", },
width: this.constants.iconWidth, toggle: false,
height: toPix(opts.height, border), isNeedAdjustHeight: opts.isNeedAdjustHeight,
ref: _ref => { isNeedAdjustWidth: opts.isNeedAdjustWidth,
this.changeIcon = _ref; el: {
}, type: HorizontalFillLayout.xtype,
}, columnSize: [this.constants.iconWidth, "fill"],
}, {
type: "bi.dynamic_date_time_trigger",
simple: opts.simple,
min: opts.minDate,
max: opts.maxDate,
allowEdit: opts.allowEdit,
watermark: opts.watermark,
format: opts.format,
iconWidth: this.constants.iconWidth,
height: toPix(opts.height, border), height: toPix(opts.height, border),
value: opts.value, items: [
ref: _ref => { {
this.trigger = _ref; el: {
}, type: IconButton.xtype,
listeners: [{ cls: "bi-trigger-icon-button date-change-h-font",
eventName: DynamicDateTimeTrigger.EVENT_KEY_DOWN, width: this.constants.iconWidth,
action: (...args) => { height: toPix(opts.height, border),
if (this.combo.isViewVisible()) { ref: (_ref) => {
this.combo.hideView(); this.changeIcon = _ref;
}
this.fireEvent(DynamicDateTimeCombo.EVENT_KEY_DOWN, ...args);
},
}, {
eventName: DynamicDateTimeTrigger.EVENT_STOP,
action: () => {
if (!this.combo.isViewVisible()) {
this.combo.showView();
}
},
}, {
eventName: DynamicDateTimeTrigger.EVENT_TRIGGER_CLICK,
action: () => {
this.combo.toggle();
},
}, {
eventName: DynamicDateTimeTrigger.EVENT_FOCUS,
action: () => {
this.storeTriggerValue = this.trigger.getKey();
if (!this.combo.isViewVisible()) {
this.combo.showView();
}
this.fireEvent(DynamicDateTimeCombo.EVENT_FOCUS);
},
}, {
eventName: DynamicDateTimeTrigger.EVENT_BLUR,
action: () => {
this.fireEvent(DynamicDateTimeCombo.EVENT_BLUR);
},
}, {
eventName: DynamicDateTimeTrigger.EVENT_ERROR,
action: () => {
this.storeValue = {
type: DynamicDateTimeCombo.Static,
value: {
year: date.getFullYear(),
month: date.getMonth() + 1,
}, },
}; },
this.combo.element.addClass("error");
this.fireEvent(DynamicDateTimeCombo.EVENT_ERROR);
},
}, {
eventName: DynamicDateTimeTrigger.EVENT_VALID,
action: () => {
this.storeValue = this.trigger.getValue();
this.combo.element.removeClass("error");
this.fireEvent(DynamicDateTimeCombo.EVENT_VALID);
},
}, {
eventName: DynamicDateTimeTrigger.EVENT_CHANGE,
action: () => {
this.fireEvent(DynamicDateTimeCombo.EVENT_CHANGE);
}, },
}, { {
eventName: DynamicDateTimeTrigger.EVENT_CONFIRM, type: DynamicDateTimeTrigger.xtype,
action: () => { simple: opts.simple,
const dateStore = this.storeTriggerValue; min: opts.minDate,
const dateObj = this.trigger.getKey(); max: opts.maxDate,
if (this.combo.isViewVisible() || isEqual(dateObj, dateStore)) { allowEdit: opts.allowEdit,
return; watermark: opts.watermark,
} format: opts.format,
if (isNotEmptyString(dateObj) && !isEqual(dateObj, dateStore)) { iconWidth: this.constants.iconWidth,
this.storeValue = this.trigger.getValue(); height: toPix(opts.height, border),
this.setValue(this.trigger.getValue()); value: opts.value,
} else if (isEmptyString(dateObj)) { ref: (_ref) => {
this.storeValue = null; this.trigger = _ref;
this.trigger.setValue(); },
} listeners: [
this._checkDynamicValue(this.storeValue); {
this.fireEvent(DynamicDateTimeCombo.EVENT_CONFIRM); eventName: DynamicDateTimeTrigger.EVENT_KEY_DOWN,
}, action: (...args) => {
}], if (this.combo.isViewVisible()) {
}], this.combo.hideView();
}, }
adjustLength: this.constants.comboAdjustHeight, this.fireEvent(DynamicDateTimeCombo.EVENT_KEY_DOWN, ...args);
popup: { },
el: {
type: "bi.dynamic_date_time_popup",
width: opts.isNeedAdjustWidth ? opts.width : undefined,
supportDynamic: opts.supportDynamic,
behaviors: opts.behaviors,
min: opts.minDate,
max: opts.maxDate,
ref: _ref => {
this.popup = _ref;
},
listeners: [{
eventName: DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE,
action: () => {
this.setValue();
this.combo.hideView();
this.fireEvent(DynamicDateTimeCombo.EVENT_CONFIRM);
},
}, {
eventName: DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE,
action: () => {
const date = getDate();
this.setValue({
type: DynamicDateTimeCombo.Static,
value: {
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
hour: 0,
minute: 0,
second: 0,
}, },
}); {
this.combo.hideView(); eventName: DynamicDateTimeTrigger.EVENT_STOP,
this.fireEvent(DynamicDateTimeCombo.EVENT_CONFIRM); action: () => {
}, if (!this.combo.isViewVisible()) {
}, { this.combo.showView();
eventName: DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE, }
action: () => { },
const value = this.popup.getValue(); },
if (this._checkValue(value)) { {
this.setValue(value); eventName: DynamicDateTimeTrigger.EVENT_TRIGGER_CLICK,
} action: () => {
this.combo.hideView(); this.combo.toggle();
this.fireEvent(DynamicDateTimeCombo.EVENT_CONFIRM); },
},
{
eventName: DynamicDateTimeTrigger.EVENT_FOCUS,
action: () => {
this.storeTriggerValue = this.trigger.getKey();
if (!this.combo.isViewVisible()) {
this.combo.showView();
}
this.fireEvent(DynamicDateTimeCombo.EVENT_FOCUS);
},
},
{
eventName: DynamicDateTimeTrigger.EVENT_BLUR,
action: () => {
this.fireEvent(DynamicDateTimeCombo.EVENT_BLUR);
},
},
{
eventName: DynamicDateTimeTrigger.EVENT_ERROR,
action: () => {
this.storeValue = {
type: DynamicDateTimeCombo.Static,
value: {
year: date.getFullYear(),
month: date.getMonth() + 1,
},
};
this.combo.element.addClass("error");
this.fireEvent(DynamicDateTimeCombo.EVENT_ERROR);
},
},
{
eventName: DynamicDateTimeTrigger.EVENT_VALID,
action: () => {
this.storeValue = this.trigger.getValue();
this.combo.element.removeClass("error");
this.fireEvent(DynamicDateTimeCombo.EVENT_VALID);
},
},
{
eventName: DynamicDateTimeTrigger.EVENT_CHANGE,
action: () => {
this.fireEvent(DynamicDateTimeCombo.EVENT_CHANGE);
},
},
{
eventName: DynamicDateTimeTrigger.EVENT_CONFIRM,
action: () => {
const dateStore = this.storeTriggerValue;
const dateObj = this.trigger.getKey();
if (this.combo.isViewVisible() || isEqual(dateObj, dateStore)) {
return;
}
if (isNotEmptyString(dateObj) && !isEqual(dateObj, dateStore)) {
this.storeValue = this.trigger.getValue();
this.setValue(this.trigger.getValue());
} else if (isEmptyString(dateObj)) {
this.storeValue = null;
this.trigger.setValue();
}
this._checkDynamicValue(this.storeValue);
this.fireEvent(DynamicDateTimeCombo.EVENT_CONFIRM);
},
},
],
}, },
}, { ],
eventName: DynamicDateTimePopup.EVENT_CHANGE, },
action: () => { adjustLength: this.constants.comboAdjustHeight,
this.setValue(this.popup.getValue()); popup: {
this.combo.hideView(); el: {
this.fireEvent(DynamicDateTimeCombo.EVENT_CONFIRM); type: DynamicDateTimePopup.xtype,
width: opts.isNeedAdjustWidth ? opts.width : undefined,
supportDynamic: opts.supportDynamic,
behaviors: opts.behaviors,
min: opts.minDate,
max: opts.maxDate,
ref: (_ref) => {
this.popup = _ref;
}, },
}, { listeners: [
eventName: DynamicDateTimePopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW, {
eventName: DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE,
action: () => {
this.setValue();
this.combo.hideView();
this.fireEvent(DynamicDateTimeCombo.EVENT_CONFIRM);
},
},
{
eventName: DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE,
action: () => {
const date = getDate();
this.setValue({
type: DynamicDateTimeCombo.Static,
value: {
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
hour: 0,
minute: 0,
second: 0,
},
});
this.combo.hideView();
this.fireEvent(DynamicDateTimeCombo.EVENT_CONFIRM);
},
},
{
eventName: DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE,
action: () => {
const value = this.popup.getValue();
if (this._checkValue(value)) {
this.setValue(value);
}
this.combo.hideView();
this.fireEvent(DynamicDateTimeCombo.EVENT_CONFIRM);
},
},
{
eventName: DynamicDateTimePopup.EVENT_CHANGE,
action: () => {
this.setValue(this.popup.getValue());
this.combo.hideView();
this.fireEvent(DynamicDateTimeCombo.EVENT_CONFIRM);
},
},
{
eventName: DynamicDateTimePopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW,
action: () => {
this.fireEvent(DynamicDateTimeCombo.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW);
},
},
],
},
},
listeners: [
{
eventName: Combo.EVENT_BEFORE_POPUPVIEW,
action: () => { action: () => {
this.fireEvent(DynamicDateTimeCombo.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW); this.popup.setMinDate(opts.minDate);
this.popup.setMaxDate(opts.maxDate);
this.popup.setValue(this.storeValue);
this.fireEvent(DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW);
}, },
}], },
}, ],
// // DEC-4250 和复选下拉一样,点击不收起
// hideChecker: function (e) {
// return self.triggerBtn.element.find(e.target).length === 0;
// }
}, },
listeners: [{ top: 0,
eventName: Combo.EVENT_BEFORE_POPUPVIEW, left: 0,
action: () => { right: 0,
this.popup.setMinDate(opts.minDate); bottom: 0,
this.popup.setMaxDate(opts.maxDate);
this.popup.setValue(this.storeValue);
this.fireEvent(DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW);
},
}],
// // DEC-4250 和复选下拉一样,点击不收起
// hideChecker: function (e) {
// return self.triggerBtn.element.find(e.target).length === 0;
// }
}, },
top: 0, ],
left: 0,
right: 0,
bottom: 0,
}],
}; };
} }
@ -272,16 +306,16 @@ export class DynamicDateTimeCombo extends Single {
type = v.type; type = v.type;
} }
switch (type) { switch (type) {
case DynamicDateTimeCombo.Dynamic: case DynamicDateTimeCombo.Dynamic:
this.changeIcon.setVisible(true); this.changeIcon.setVisible(true);
// this.comboWrapper.attr("items")[0].width = o.height - (this.options.simple ? 1 : 2); // this.comboWrapper.attr("items")[0].width = o.height - (this.options.simple ? 1 : 2);
// this.comboWrapper.resize(); // this.comboWrapper.resize();
break; break;
default: default:
// this.comboWrapper.attr("items")[0].width = 0; // this.comboWrapper.attr("items")[0].width = 0;
// this.comboWrapper.resize(); // this.comboWrapper.resize();
this.changeIcon.setVisible(false); this.changeIcon.setVisible(false);
break; break;
} }
} }
@ -289,12 +323,12 @@ export class DynamicDateTimeCombo extends Single {
const o = this.options; const o = this.options;
const value = v.value || {}; const value = v.value || {};
switch (v.type) { switch (v.type) {
case DynamicDateCombo.Dynamic: case DynamicDateCombo.Dynamic:
return isNotEmptyObject(v.value); return isNotEmptyObject(v.value);
case DynamicDateCombo.Static: case DynamicDateCombo.Static:
return !checkDateVoid(value.year, value.month, value.day, o.minDate, o.maxDate)[0]; return !checkDateVoid(value.year, value.month, value.day, o.minDate, o.maxDate)[0];
default: default:
return true; return true;
} }
} }

320
src/widget/dynamicdatetime/dynamicdatetime.popup.js

@ -1,17 +1,35 @@
import { shortcut, Widget, createWidget, toPix, i18nText, createItems, print, isNull, isEmptyObject, isEmptyString, getDate, checkDateVoid, extend } from "@/core"; import {
import { DynamicDateCombo, DynamicDateHelper } from "../dynamicdate"; VerticalLayout,
GridLayout,
shortcut,
Widget,
createWidget,
toPix,
i18nText,
createItems,
print,
isNull,
isEmptyObject,
isEmptyString,
getDate,
checkDateVoid,
extend
} from "@/core";
import { TextButton, Tab } from "@/base"; import { TextButton, Tab } from "@/base";
import { LinearSegment } from "@/case";
import { DynamicDateCard, DynamicDateCombo, DynamicDateHelper } from "../dynamicdate";
import { DateCalendarPopup } from "../date/calendar"; import { DateCalendarPopup } from "../date/calendar";
import { DynamicDateTimeSelect } from "./dynamicdatetime.timeselect";
import { DynamicDateTimeCombo } from "./dynamicdatetime.combo"; import { DynamicDateTimeCombo } from "./dynamicdatetime.combo";
@shortcut() @shortcut()
export class DynamicDateTimePopup extends Widget { export class DynamicDateTimePopup extends Widget {
static xtype = "bi.dynamic_date_time_popup" static xtype = "bi.dynamic_date_time_popup";
constants = { constants = {
tabHeight: 40, tabHeight: 40,
buttonHeight: 24, buttonHeight: 24,
} };
props = { props = {
baseCls: "bi-dynamic-date-time-popup", baseCls: "bi-dynamic-date-time-popup",
@ -19,11 +37,11 @@ export class DynamicDateTimePopup extends Widget {
supportDynamic: true, supportDynamic: true,
}; };
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE" static BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE";
static BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE" static BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE";
static BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE" static BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE";
static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW" static EVENT_BEFORE_YEAR_MONTH_POPUPVIEW = "EVENT_BEFORE_YEAR_MONTH_POPUPVIEW";
_init() { _init() {
super._init(...arguments); super._init(...arguments);
@ -33,72 +51,86 @@ export class DynamicDateTimePopup extends Widget {
}; };
createWidget({ createWidget({
element: this, element: this,
type: "bi.vertical", type: VerticalLayout.xtype,
items: [{ items: [
el: this._getTabJson(), {
}, { el: this._getTabJson(),
el: { },
type: "bi.grid", {
items: [ el: {
[{ type: GridLayout.xtype,
type: "bi.text_button", items: [
cls: "bi-high-light bi-split-top", [
textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), {
shadow: true, type: TextButton.xtype,
text: i18nText("BI-Basic_Clear"), cls: "bi-high-light bi-split-top",
listeners: [{ textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1),
eventName: TextButton.EVENT_CHANGE, shadow: true,
action: () => { text: i18nText("BI-Basic_Clear"),
this.fireEvent(DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE); listeners: [
{
eventName: TextButton.EVENT_CHANGE,
action: () => {
this.fireEvent(DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE);
},
}
],
}, },
}], {
}, { type: TextButton.xtype,
type: "bi.text_button", cls: "bi-split-left bi-split-right bi-high-light bi-split-top",
cls: "bi-split-left bi-split-right bi-high-light bi-split-top", textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1),
textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), shadow: true,
shadow: true, text: i18nText("BI-Multi_Date_Today"),
text: i18nText("BI-Multi_Date_Today"), disabled: this._checkTodayValid(),
disabled: this._checkTodayValid(), ref: _ref => {
ref: _ref => { this.todayButton = _ref;
this.todayButton = _ref; },
}, listeners: [
listeners: [{ {
eventName: TextButton.EVENT_CHANGE, eventName: TextButton.EVENT_CHANGE,
action: () => { action: () => {
this.fireEvent(DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE); this.fireEvent(DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE);
},
}
],
}, },
}], {
}, { type: TextButton.xtype,
type: "bi.text_button", cls: "bi-high-light bi-split-top",
cls: "bi-high-light bi-split-top", textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1),
textHeight: toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), shadow: true,
shadow: true, text: i18nText("BI-Basic_OK"),
text: i18nText("BI-Basic_OK"), listeners: [
listeners: [{ {
eventName: TextButton.EVENT_CHANGE, eventName: TextButton.EVENT_CHANGE,
action: () => { action: () => {
const type = this.dateTab.getSelect(); const type = this.dateTab.getSelect();
if (type === DynamicDateCombo.Dynamic) { if (type === DynamicDateCombo.Dynamic) {
this.dynamicPane.checkValidation(true) && this.fireEvent(DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE); this.dynamicPane.checkValidation(true) &&
} else { this.fireEvent(DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE);
this.fireEvent(DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE); } else {
} this.fireEvent(DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE);
}, }
}], },
}] }
], ],
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, }
}, ]
}], ],
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
},
}
],
}); });
this.setValue(opts.value); this.setValue(opts.value);
} }
_getTabJson() { _getTabJson() {
const o = this.options; const o = this.options;
return { return {
type: "bi.tab", type: Tab.xtype,
logic: { logic: {
dynamic: true, dynamic: true,
}, },
@ -106,32 +138,40 @@ export class DynamicDateTimePopup extends Widget {
this.dateTab = _ref; this.dateTab = _ref;
}, },
tab: { tab: {
type: "bi.linear_segment", type: LinearSegment.xtype,
invisible: !o.supportDynamic, invisible: !o.supportDynamic,
cls: "bi-split-bottom", cls: "bi-split-bottom",
height: this.constants.tabHeight, height: this.constants.tabHeight,
items: createItems([{ items: createItems(
text: i18nText("BI-Multi_Date_YMD"), [
value: DynamicDateCombo.Static, {
}, { text: i18nText("BI-Multi_Date_YMD"),
text: i18nText("BI-Basic_Dynamic_Title"), value: DynamicDateCombo.Static,
value: DynamicDateCombo.Dynamic, },
}], { {
textAlign: "center", text: i18nText("BI-Basic_Dynamic_Title"),
}), value: DynamicDateCombo.Dynamic,
}
],
{
textAlign: "center",
}
),
}, },
cardCreator: v => { cardCreator: v => {
switch (v) { switch (v) {
case DynamicDateCombo.Dynamic: case DynamicDateCombo.Dynamic:
return { return {
type: "bi.dynamic_date_card", type: DynamicDateCard.xtype,
cls: "dynamic-date-pane", cls: "dynamic-date-pane",
listeners: [{ listeners: [
eventName: "EVENT_CHANGE", {
action: () => { eventName: "EVENT_CHANGE",
this._setInnerValue(this.year, v); action: () => {
}, this._setInnerValue(this.year, v);
}], },
}
],
ref: _ref => { ref: _ref => {
this.dynamicPane = _ref; this.dynamicPane = _ref;
}, },
@ -141,63 +181,70 @@ export class DynamicDateTimePopup extends Widget {
case DynamicDateCombo.Static: case DynamicDateCombo.Static:
default: default:
return { return {
type: "bi.vertical", type: VerticalLayout.xtype,
items: [{ items: [
type: "bi.date_calendar_popup", {
behaviors: o.behaviors, type: DateCalendarPopup.xtype,
min: this.options.min, behaviors: o.behaviors,
max: this.options.max, min: this.options.min,
ref: _ref => { max: this.options.max,
this.ymd = _ref;
},
listeners: [{
eventName: DateCalendarPopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW,
action: () => {
this.fireEvent(DynamicDateTimePopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW);
},
}],
}, {
el: {
type: "bi.dynamic_date_time_select",
cls: "bi-split-top",
ref: _ref => { ref: _ref => {
this.timeSelect = _ref; this.ymd = _ref;
}, },
height: 40, listeners: [
{
eventName: DateCalendarPopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW,
action: () => {
this.fireEvent(DynamicDateTimePopup.EVENT_BEFORE_YEAR_MONTH_POPUPVIEW);
},
}
],
}, },
}], {
el: {
type: DynamicDateTimeSelect.xtype,
cls: "bi-split-top",
ref: _ref => {
this.timeSelect = _ref;
},
height: 40,
},
}
],
}; };
} }
}, },
listeners: [{ listeners: [
eventName: Tab.EVENT_CHANGE, {
action: () => { eventName: Tab.EVENT_CHANGE,
const v = this.dateTab.getSelect(); action: () => {
const date = DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); const v = this.dateTab.getSelect();
switch (v) { const date = DynamicDateHelper.getCalculation(this.dynamicPane.getValue());
case DynamicDateCombo.Static: switch (v) {
this.ymd.setValue({ case DynamicDateCombo.Static:
year: date.getFullYear(), this.ymd.setValue({
month: date.getMonth() + 1, year: date.getFullYear(),
day: date.getDate(), month: date.getMonth() + 1,
}); day: date.getDate(),
this.timeSelect.setValue();
this._setInnerValue();
break;
case DynamicDateCombo.Dynamic:
default:
if (this.storeValue && this.storeValue.type === DynamicDateCombo.Dynamic) {
this.dynamicPane.setValue(this.storeValue.value);
} else {
this.dynamicPane.setValue({
year: 0,
}); });
this.timeSelect.setValue();
this._setInnerValue();
break;
case DynamicDateCombo.Dynamic:
default:
if (this.storeValue && this.storeValue.type === DynamicDateCombo.Dynamic) {
this.dynamicPane.setValue(this.storeValue.value);
} else {
this.dynamicPane.setValue({
year: 0,
});
}
this._setInnerValue();
break;
} }
this._setInnerValue(); },
break; }
} ],
},
}],
}; };
} }
@ -220,7 +267,7 @@ export class DynamicDateTimePopup extends Widget {
_checkTodayValid() { _checkTodayValid() {
const o = this.options; const o = this.options;
const today = getDate(); const today = getDate();
return !!checkDateVoid(today.getFullYear(), today.getMonth() + 1, today.getDate(), o.min, o.max)[0]; return !!checkDateVoid(today.getFullYear(), today.getMonth() + 1, today.getDate(), o.min, o.max)[0];
} }
@ -276,10 +323,13 @@ export class DynamicDateTimePopup extends Widget {
getValue() { getValue() {
const type = this.dateTab.getSelect(); const type = this.dateTab.getSelect();
return { return {
type, type,
value: type === DynamicDateTimeCombo.Static ? extend(this.ymd.getValue(), this.timeSelect.getValue()) : this.dynamicPane.getValue(), value:
type === DynamicDateTimeCombo.Static
? extend(this.ymd.getValue(), this.timeSelect.getValue())
: this.dynamicPane.getValue(),
}; };
} }
} }

249
src/widget/dynamicdatetime/dynamicdatetime.timeselect.js

@ -1,15 +1,28 @@
import { shortcut, Widget, isNaturalNumber, parseInt, isNumeric, i18nText, isNull, isEmptyString } from "@/core"; import {
CenterAdaptLayout,
VerticalAdaptLayout,
shortcut,
Widget,
isNaturalNumber,
parseInt,
isNumeric,
i18nText,
isNull,
isEmptyString
} from "@/core";
import { NumberEditor } from "../numbereditor/number.editor";
import { Label } from "@/base";
import { SignEditor } from "@/case"; import { SignEditor } from "@/case";
@shortcut() @shortcut()
export class DynamicDateTimeSelect extends Widget { export class DynamicDateTimeSelect extends Widget {
static xtype = "bi.dynamic_date_time_select" static xtype = "bi.dynamic_date_time_select";
static HOUR = 1 static HOUR = 1;
static MINUTE = 2 static MINUTE = 2;
static SECOND = 3 static SECOND = 3;
static EVENT_CONFIRM = "EVENT_CONFIRM" static EVENT_CONFIRM = "EVENT_CONFIRM";
props = { props = {
baseCls: "bi-date-time-select", baseCls: "bi-date-time-select",
@ -17,111 +30,133 @@ export class DynamicDateTimeSelect extends Widget {
render() { render() {
return { return {
type: "bi.center_adapt", type: CenterAdaptLayout.xtype,
items: [{ items: [
type: "bi.vertical_adapt", {
items: [{ type: VerticalAdaptLayout.xtype,
el: { items: [
type: "bi.number_editor", {
ref: _ref => { el: {
this.hour = _ref; type: NumberEditor.xtype,
}, ref: _ref => {
validationChecker (v) { this.hour = _ref;
return isNaturalNumber(v) && parseInt(v) < 24; },
validationChecker(v) {
return isNaturalNumber(v) && parseInt(v) < 24;
},
errorText(v) {
if (isNumeric(v)) {
return i18nText("BI-Basic_Input_From_To_Number", "\"00-23\"");
}
return i18nText("BI-Numerical_Interval_Input_Data");
},
listeners: [
{
eventName: SignEditor.EVENT_CONFIRM,
action: () => {
const value = this.hour.getValue();
this._checkHour(value);
this.hour.setValue(this._formatValueToDoubleDigit(value));
this.fireEvent(DynamicDateTimeSelect.EVENT_CONFIRM);
},
},
{
eventName: SignEditor.EVENT_CHANGE,
action: () => {
const value = this._autoSwitch(
this.hour.getValue(),
DynamicDateTimeSelect.HOUR
);
this.hour.setValue(value);
},
}
],
width: 60,
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
},
}, },
errorText (v) { {
if (isNumeric(v)) { type: Label.xtype,
return i18nText("BI-Basic_Input_From_To_Number", "\"00-23\""); text: ":",
} width: 20,
return i18nText("BI-Numerical_Interval_Input_Data");
}, },
listeners: [{ {
eventName: SignEditor.EVENT_CONFIRM, type: NumberEditor.xtype,
action: () => { ref: _ref => {
const value = this.hour.getValue(); this.minute = _ref;
this._checkHour(value);
this.hour.setValue(this._formatValueToDoubleDigit(value));
this.fireEvent(DynamicDateTimeSelect.EVENT_CONFIRM);
}, },
}, { validationChecker(v) {
eventName: SignEditor.EVENT_CHANGE, return isNaturalNumber(v) && parseInt(v) < 60;
action: () => {
const value = this._autoSwitch(this.hour.getValue(), DynamicDateTimeSelect.HOUR);
this.hour.setValue(value);
}, },
}], errorText(v) {
width: 60, if (isNumeric(v)) {
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, return i18nText("BI-Basic_Input_From_To_Number", "\"00-59\"");
}, }
}, {
type: "bi.label", return i18nText("BI-Numerical_Interval_Input_Data");
text: ":", },
width: 20, listeners: [
}, { {
type: "bi.number_editor", eventName: SignEditor.EVENT_CONFIRM,
ref: _ref => { action: () => {
this.minute = _ref; const value = this.minute.getValue();
}, this._checkMinute(value);
validationChecker (v) { this.minute.setValue(
return isNaturalNumber(v) && parseInt(v) < 60; this._formatValueToDoubleDigit(value),
}, DynamicDateTimeSelect.MINUTE
errorText (v) { );
if (isNumeric(v)) { this.fireEvent(DynamicDateTimeSelect.EVENT_CONFIRM);
return i18nText("BI-Basic_Input_From_To_Number", "\"00-59\""); },
} },
{
return i18nText("BI-Numerical_Interval_Input_Data"); eventName: SignEditor.EVENT_CHANGE,
}, action: () => {
listeners: [{ const value = this._autoSwitch(this.getValue(), DynamicDateTimeSelect.MINUTE);
eventName: SignEditor.EVENT_CONFIRM, this.minute.setValue(value);
action: () => { },
const value = this.minute.getValue(); }
this._checkMinute(value); ],
this.minute.setValue(this._formatValueToDoubleDigit(value), DynamicDateTimeSelect.MINUTE); width: 60,
this.fireEvent(DynamicDateTimeSelect.EVENT_CONFIRM); height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
}, },
}, { {
eventName: SignEditor.EVENT_CHANGE, type: Label.xtype,
action: () => { text: ":",
const value = this._autoSwitch(this.getValue(), DynamicDateTimeSelect.MINUTE); width: 20,
this.minute.setValue(value);
}, },
}], {
width: 60, type: NumberEditor.xtype,
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, ref: _ref => {
}, { this.second = _ref;
type: "bi.label", },
text: ":", validationChecker(v) {
width: 20, return isNaturalNumber(v) && parseInt(v) < 60;
}, { },
type: "bi.number_editor", errorText(v) {
ref: _ref => { if (isNumeric(v)) {
this.second = _ref; return i18nText("BI-Basic_Input_From_To_Number", "\"00-59\"");
}, }
validationChecker (v) {
return isNaturalNumber(v) && parseInt(v) < 60; return i18nText("BI-Numerical_Interval_Input_Data");
}, },
errorText (v) { listeners: [
if (isNumeric(v)) { {
return i18nText("BI-Basic_Input_From_To_Number", "\"00-59\""); eventName: SignEditor.EVENT_CONFIRM,
action: () => {
const value = this.second.getValue();
this._checkSecond(value);
this.second.setValue(this._formatValueToDoubleDigit(value));
this.fireEvent(DynamicDateTimeSelect.EVENT_CONFIRM);
},
}
],
width: 60,
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
} }
],
return i18nText("BI-Numerical_Interval_Input_Data"); }
}, ],
listeners: [{
eventName: SignEditor.EVENT_CONFIRM,
action: () => {
const value = this.second.getValue();
this._checkSecond(value);
this.second.setValue(this._formatValueToDoubleDigit(value));
this.fireEvent(DynamicDateTimeSelect.EVENT_CONFIRM);
},
}],
width: 60,
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
}],
}],
}; };
} }
@ -176,7 +211,7 @@ export class DynamicDateTimeSelect extends Widget {
break; break;
} }
} }
return value; return value;
} }
@ -188,7 +223,7 @@ export class DynamicDateTimeSelect extends Widget {
if (value < 10) { if (value < 10) {
value = `0${value}`; value = `0${value}`;
} }
return value; return value;
} }
@ -197,7 +232,7 @@ export class DynamicDateTimeSelect extends Widget {
v.hour = this._formatValueToDoubleDigit(v.hour) || "00"; v.hour = this._formatValueToDoubleDigit(v.hour) || "00";
v.minute = this._formatValueToDoubleDigit(v.minute) || "00"; v.minute = this._formatValueToDoubleDigit(v.minute) || "00";
v.second = this._formatValueToDoubleDigit(v.second) || "00"; v.second = this._formatValueToDoubleDigit(v.second) || "00";
return v; return v;
} }

211
src/widget/dynamicdatetime/dynamicdatetime.trigger.js

@ -1,11 +1,34 @@
import { shortcut, i18nText, createWidget, isKey, checkDateLegal, parseDateTime, bind, isNotNull, isNotEmptyString, isEqual, isEmptyObject, isEmptyString, isNull, getDate, each, isNumeric, checkDateVoid, parseInt, size, print } from "@/core";
import { Trigger } from "@/base";
import { SignEditor } from "@/case"; import { SignEditor } from "@/case";
import {
HTapeLayout,
AbsoluteLayout,
shortcut,
i18nText,
createWidget,
isKey,
checkDateLegal,
parseDateTime,
bind,
isNotNull,
isNotEmptyString,
isEqual,
isEmptyObject,
isEmptyString,
isNull,
getDate,
each,
isNumeric,
checkDateVoid,
parseInt,
size,
print
} from "@/core";
import { IconButton, Text, Trigger } from "@/base";
import { DynamicDateCombo, DynamicDateCard, DynamicDateHelper } from "../dynamicdate"; import { DynamicDateCombo, DynamicDateCard, DynamicDateHelper } from "../dynamicdate";
@shortcut() @shortcut()
export class DynamicDateTimeTrigger extends Trigger { export class DynamicDateTimeTrigger extends Trigger {
static xtype = "bi.dynamic_date_time_trigger" static xtype = "bi.dynamic_date_time_trigger";
_const = { _const = {
hgap: 4, hgap: 4,
@ -17,16 +40,16 @@ export class DynamicDateTimeTrigger extends Trigger {
iconWidth: 24, iconWidth: 24,
}; };
static EVENT_BLUR = "EVENT_BLUR" static EVENT_BLUR = "EVENT_BLUR";
static EVENT_FOCUS = "EVENT_FOCUS" static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_START = "EVENT_START" static EVENT_START = "EVENT_START";
static EVENT_STOP = "EVENT_STOP" static EVENT_STOP = "EVENT_STOP";
static EVENT_CONFIRM = "EVENT_CONFIRM" static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_VALID = "EVENT_VALID" static EVENT_VALID = "EVENT_VALID";
static EVENT_ERROR = "EVENT_ERROR" static EVENT_ERROR = "EVENT_ERROR";
static EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK" static EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK";
static EVENT_KEY_DOWN = "EVENT_KEY_DOWN" static EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
props() { props() {
return { return {
@ -47,21 +70,25 @@ export class DynamicDateTimeTrigger extends Trigger {
c = this._const; c = this._const;
this.storeTriggerValue = ""; this.storeTriggerValue = "";
this.editor = createWidget({ this.editor = createWidget({
type: "bi.sign_editor", type: SignEditor.xtype,
simple: o.simple, simple: o.simple,
height: o.height, height: o.height,
validationChecker: v => { validationChecker: v => {
const formatStr = this._getStandardDateStr(v); const formatStr = this._getStandardDateStr(v);
const date = formatStr.match(/\d+/g); const date = formatStr.match(/\d+/g);
!isKey(o.format) && this._autoAppend(v, date); !isKey(o.format) && this._autoAppend(v, date);
return this._dateCheck(formatStr) && checkDateLegal(formatStr) && this._checkVoid({ return (
year: date[0] | 0, this._dateCheck(formatStr) &&
month: date[1] | 0, checkDateLegal(formatStr) &&
day: date[2] | 0, this._checkVoid({
}); year: date[0] | 0,
month: date[1] | 0,
day: date[2] | 0,
})
);
}, },
quitChecker () { quitChecker() {
return false; return false;
}, },
hgap: c.hgap, hgap: c.hgap,
@ -72,11 +99,14 @@ export class DynamicDateTimeTrigger extends Trigger {
let str = ""; let str = "";
if (!isKey(o.format)) { if (!isKey(o.format)) {
if (!this._dateCheck(v)) { if (!this._dateCheck(v)) {
str = this.editor.isEditing() ? i18nText("BI-Date_Trigger_Error_Text") : i18nText("BI-Year_Trigger_Invalid_Text"); str = this.editor.isEditing()
? i18nText("BI-Date_Trigger_Error_Text")
: i18nText("BI-Year_Trigger_Invalid_Text");
} else { } else {
const start = parseDateTime(o.min, "%Y-%X-%d"); const start = parseDateTime(o.min, "%Y-%X-%d");
const end = parseDateTime(o.max, "%Y-%X-%d"); const end = parseDateTime(o.max, "%Y-%X-%d");
str = i18nText("BI-Basic_Date_Range_Error", str = i18nText(
"BI-Basic_Date_Range_Error",
start.getFullYear(), start.getFullYear(),
start.getMonth() + 1, start.getMonth() + 1,
start.getDate(), start.getDate(),
@ -140,34 +170,40 @@ export class DynamicDateTimeTrigger extends Trigger {
this.fireEvent(DynamicDateTimeTrigger.EVENT_CHANGE); this.fireEvent(DynamicDateTimeTrigger.EVENT_CHANGE);
}); });
createWidget({ createWidget({
type: "bi.htape", type: HTapeLayout.xtype,
element: this, element: this,
columnSize: ["", this._const.iconWidth], columnSize: ["", this._const.iconWidth],
items: [{ items: [
el: this.editor, {
}, { el: this.editor,
el: {
type: "bi.icon_button",
cls: "bi-trigger-icon-button date-font",
}, },
width: o.iconWidth, {
}], el: {
type: IconButton.xtype,
cls: "bi-trigger-icon-button date-font",
},
width: o.iconWidth,
}
],
}); });
!o.allowEdit && createWidget({ !o.allowEdit &&
type: "bi.absolute", createWidget({
element: this, type: AbsoluteLayout.xtype,
items: [{ element: this,
el: { items: [
type: "bi.text", {
title: bind(this._getTitle, this), el: {
}, type: Text.xtype,
left: 0, title: bind(this._getTitle, this),
right: o.iconWidth, },
top: 0, left: 0,
bottom: 0, right: o.iconWidth,
}], top: 0,
}); bottom: 0,
}
],
});
this.setValue(o.value); this.setValue(o.value);
} }
@ -185,15 +221,24 @@ export class DynamicDateTimeTrigger extends Trigger {
switch (type) { switch (type) {
case DynamicDateCombo.Dynamic: case DynamicDateCombo.Dynamic:
return isEmptyString(text) ? dateStr : (`${text}:${dateStr}`); return isEmptyString(text) ? dateStr : `${text}:${dateStr}`;
case DynamicDateCombo.Static: case DynamicDateCombo.Static:
default: default:
if (isNull(value) || isNull(value.day)) { if (isNull(value) || isNull(value.day)) {
return ""; return "";
} }
return print(getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, return print(
value.second || 0), this._getFormatString()); getDate(
value.year,
value.month - 1,
value.day,
value.hour || 0,
value.minute || 0,
value.second || 0
),
this._getFormatString()
);
} }
} }
@ -251,7 +296,7 @@ export class DynamicDateTimeTrigger extends Trigger {
if (isNotEmptyString(suffixString)) { if (isNotEmptyString(suffixString)) {
dateString += ` ${suffixString}`; dateString += ` ${suffixString}`;
} }
return dateString; return dateString;
} }
@ -260,15 +305,16 @@ export class DynamicDateTimeTrigger extends Trigger {
} }
_dateCheck(date) { _dateCheck(date) {
return print(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 ||
print(parseDateTime(date, "%Y-%X-%d %H:%M:%S"), "%Y-%X-%d %H:%M:%S") === date || print(parseDateTime(date, "%Y-%X-%d %H:%M:%S"), "%Y-%X-%d %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 ||
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 ||
print(parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === date || print(parseDateTime(date, "%Y-%x-%d"), "%Y-%x-%d") === date ||
print(parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date || print(parseDateTime(date, "%Y-%X-%d"), "%Y-%X-%d") === date ||
print(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; print(parseDateTime(date, "%Y-%X-%e"), "%Y-%X-%e") === date
);
} }
_checkVoid(obj) { _checkVoid(obj) {
@ -297,16 +343,20 @@ export class DynamicDateTimeTrigger extends Trigger {
_yearCheck(v) { _yearCheck(v) {
const date = print(parseDateTime(v, "%Y-%X-%d"), "%Y-%X-%d"); const date = print(parseDateTime(v, "%Y-%X-%d"), "%Y-%X-%d");
return print(parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max; return print(parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
} }
_monthCheck(v) { _monthCheck(v) {
const date = parseDateTime(v, "%Y-%X-%d"); const date = parseDateTime(v, "%Y-%X-%d");
const dateStr = print(date, "%Y-%X-%d"); const dateStr = print(date, "%Y-%X-%d");
return (date.getMonth() > 0 && (print(parseDateTime(v, "%Y-%X"), "%Y-%X") === v || return (
print(parseDateTime(v, "%Y-%x"), "%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; date.getMonth() > 0 &&
(print(parseDateTime(v, "%Y-%X"), "%Y-%X") === v || print(parseDateTime(v, "%Y-%x"), "%Y-%x") === v) &&
dateStr >= this.options.min &&
dateStr <= this.options.max
);
} }
_setInnerValue(date) { _setInnerValue(date) {
@ -320,38 +370,56 @@ export class DynamicDateTimeTrigger extends Trigger {
let endText = ""; let endText = "";
if (isNotNull(obj.year)) { if (isNotNull(obj.year)) {
if (parseInt(obj.year) !== 0) { if (parseInt(obj.year) !== 0) {
value += Math.abs(obj.year) + i18nText("BI-Basic_Year") + (obj.year < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.year) +
i18nText("BI-Basic_Year") +
(obj.year < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
endText = getPositionText(i18nText("BI-Basic_Year"), obj.position); endText = getPositionText(i18nText("BI-Basic_Year"), obj.position);
} }
if (isNotNull(obj.quarter)) { if (isNotNull(obj.quarter)) {
if (parseInt(obj.quarter) !== 0) { if (parseInt(obj.quarter) !== 0) {
value += Math.abs(obj.quarter) + i18nText("BI-Basic_Single_Quarter") + (obj.quarter < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.quarter) +
i18nText("BI-Basic_Single_Quarter") +
(obj.quarter < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
endText = getPositionText(i18nText("BI-Basic_Single_Quarter"), obj.position); endText = getPositionText(i18nText("BI-Basic_Single_Quarter"), obj.position);
} }
if (isNotNull(obj.month)) { if (isNotNull(obj.month)) {
if (parseInt(obj.month) !== 0) { if (parseInt(obj.month) !== 0) {
value += Math.abs(obj.month) + i18nText("BI-Basic_Month") + (obj.month < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.month) +
i18nText("BI-Basic_Month") +
(obj.month < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
endText = getPositionText(i18nText("BI-Basic_Month"), obj.position); endText = getPositionText(i18nText("BI-Basic_Month"), obj.position);
} }
if (isNotNull(obj.week)) { if (isNotNull(obj.week)) {
if (parseInt(obj.week) !== 0) { if (parseInt(obj.week) !== 0) {
value += Math.abs(obj.week) + i18nText("BI-Basic_Week") + (obj.week < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.week) +
i18nText("BI-Basic_Week") +
(obj.week < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
endText = getPositionText(i18nText("BI-Basic_Week"), obj.position); endText = getPositionText(i18nText("BI-Basic_Week"), obj.position);
} }
if (isNotNull(obj.day)) { if (isNotNull(obj.day)) {
if (parseInt(obj.day) !== 0) { if (parseInt(obj.day) !== 0) {
value += Math.abs(obj.day) + i18nText("BI-Basic_Day") + (obj.day < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.day) +
i18nText("BI-Basic_Day") +
(obj.day < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
endText = size(obj) === 1 ? getPositionText(i18nText("BI-Basic_Month"), obj.position) : ""; endText = size(obj) === 1 ? getPositionText(i18nText("BI-Basic_Month"), obj.position) : "";
} }
if (isNotNull(obj.workDay) && parseInt(obj.workDay) !== 0) { if (isNotNull(obj.workDay) && parseInt(obj.workDay) !== 0) {
value += Math.abs(obj.workDay) + i18nText("BI-Basic_Work_Day") + (obj.workDay < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind")); value +=
Math.abs(obj.workDay) +
i18nText("BI-Basic_Work_Day") +
(obj.workDay < 0 ? i18nText("BI-Basic_Front") : i18nText("BI-Basic_Behind"));
} }
return value + endText; return value + endText;
function getPositionText(baseText, position) { function getPositionText(baseText, position) {
@ -400,8 +468,17 @@ export class DynamicDateTimeTrigger extends Trigger {
this.editor.setState(""); this.editor.setState("");
this.editor.setValue(""); this.editor.setValue("");
} else { } else {
const dateStr = print(getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, const dateStr = print(
value.second || 0), this._getFormatString()); getDate(
value.year,
value.month - 1,
value.day,
value.hour || 0,
value.minute || 0,
value.second || 0
),
this._getFormatString()
);
this.editor.setState(dateStr); this.editor.setState(dateStr);
this.editor.setValue(dateStr); this.editor.setValue(dateStr);
} }

93
src/widget/editor/editor.search.js

@ -1,35 +1,50 @@
import { shortcut, Widget, extend, i18nText, emptyFn, createWidget, toPix, isKey, Controller, Events, HTapeLayout, isEndWithBlank } from "@/core"; import {
shortcut,
Widget,
extend,
i18nText,
emptyFn,
createWidget,
toPix,
isKey,
Controller,
Events,
HTapeLayout,
isEndWithBlank
} from "@/core";
import { IconButton, Editor, IconLabel } from "@/base"; import { IconButton, Editor, IconLabel } from "@/base";
@shortcut() @shortcut()
export class SearchEditor extends Widget { export class SearchEditor extends Widget {
static xtype = "bi.search_editor" static xtype = "bi.search_editor";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_FOCUS = "EVENT_FOCUS" static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR" static EVENT_BLUR = "EVENT_BLUR";
static EVENT_CLICK = "EVENT_CLICK" static EVENT_CLICK = "EVENT_CLICK";
static EVENT_KEY_DOWN = "EVENT_KEY_DOWN" static EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
static EVENT_SPACE = "EVENT_SPACE" static EVENT_SPACE = "EVENT_SPACE";
static EVENT_BACKSPACE = "EVENT_BACKSPACE" static EVENT_BACKSPACE = "EVENT_BACKSPACE";
static EVENT_CLEAR = "EVENT_CLEAR" static EVENT_CLEAR = "EVENT_CLEAR";
static EVENT_START = "EVENT_START" static EVENT_START = "EVENT_START";
static EVENT_PAUSE = "EVENT_PAUSE" static EVENT_PAUSE = "EVENT_PAUSE";
static EVENT_STOP = "EVENT_STOP" static EVENT_STOP = "EVENT_STOP";
static EVENT_CONFIRM = "EVENT_CONFIRM" static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_CHANGE_CONFIRM = "EVENT_CHANGE_CONFIRM" static EVENT_CHANGE_CONFIRM = "EVENT_CHANGE_CONFIRM";
static EVENT_VALID = "EVENT_VALID" static EVENT_VALID = "EVENT_VALID";
static EVENT_ERROR = "EVENT_ERROR" static EVENT_ERROR = "EVENT_ERROR";
static EVENT_ENTER = "EVENT_ENTER" static EVENT_ENTER = "EVENT_ENTER";
static EVENT_RESTRICT = "EVENT_RESTRICT" static EVENT_RESTRICT = "EVENT_RESTRICT";
static EVENT_REMOVE = "EVENT_REMOVE" static EVENT_REMOVE = "EVENT_REMOVE";
static EVENT_EMPTY = "EVENT_EMPTY" static EVENT_EMPTY = "EVENT_EMPTY";
_defaultConfig(config) { _defaultConfig(config) {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, { return extend(conf, {
baseCls: `bi-search-editor bi-focus-shadow ${config.simple ? "bi-border-bottom" : "bi-border bi-border-radius"}`, baseCls: `bi-search-editor bi-focus-shadow ${
config.simple ? "bi-border-bottom" : "bi-border bi-border-radius"
}`,
height: 24, height: 24,
errorText: "", errorText: "",
watermark: i18nText("BI-Basic_Search"), watermark: i18nText("BI-Basic_Search"),
@ -72,20 +87,21 @@ export class SearchEditor extends Widget {
element: this, element: this,
height: toPix(o.height, o.simple ? 1 : 2), height: toPix(o.height, o.simple ? 1 : 2),
type: HTapeLayout.xtype, type: HTapeLayout.xtype,
items: [{ items: [
el: { {
type: IconLabel.xtype, el: {
cls: "search-font", type: IconLabel.xtype,
cls: "search-font",
},
width: 24,
},
{
el: this.editor,
}, },
width: 24, {
}, el: this.clear,
{ width: 24,
el: this.editor, }
},
{
el: this.clear,
width: 24,
}
], ],
}); });
this.editor.on(Controller.EVENT_CHANGE, (...args) => { this.editor.on(Controller.EVENT_CHANGE, (...args) => {
@ -115,7 +131,6 @@ export class SearchEditor extends Widget {
this.fireEvent(SearchEditor.EVENT_BACKSPACE); this.fireEvent(SearchEditor.EVENT_BACKSPACE);
}); });
this.editor.on(Editor.EVENT_VALID, () => { this.editor.on(Editor.EVENT_VALID, () => {
this.fireEvent(SearchEditor.EVENT_VALID); this.fireEvent(SearchEditor.EVENT_VALID);
}); });
@ -185,7 +200,7 @@ export class SearchEditor extends Widget {
if (isEndWithBlank(val)) { if (isEndWithBlank(val)) {
return keywords.concat([" "]); return keywords.concat([" "]);
} }
return keywords; return keywords;
} }

4
src/widget/editor/editor.search.small.js

@ -3,11 +3,11 @@ import { SearchEditor } from "./editor.search";
@shortcut() @shortcut()
export class SmallSearchEditor extends SearchEditor { export class SmallSearchEditor extends SearchEditor {
static xtype = "bi.small_search_editor" static xtype = "bi.small_search_editor";
_defaultConfig() { _defaultConfig() {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, { return extend(conf, {
baseCls: `${conf.baseCls || ""} bi-small-search-editor`, baseCls: `${conf.baseCls || ""} bi-small-search-editor`,
height: 20, height: 20,

41
src/widget/editor/editor.text.js

@ -3,30 +3,30 @@ import { Editor } from "@/base";
@shortcut() @shortcut()
export class TextEditor extends Widget { export class TextEditor extends Widget {
static xtype = "bi.text_editor" static xtype = "bi.text_editor";
static EVENT_CHANGE = "EVENT_CHANGE" static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_FOCUS = "EVENT_FOCUS" static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR" static EVENT_BLUR = "EVENT_BLUR";
static EVENT_CLICK = "EVENT_CLICK" static EVENT_CLICK = "EVENT_CLICK";
static EVENT_KEY_DOWN = "EVENT_KEY_DOWN" static EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
static EVENT_SPACE = "EVENT_SPACE" static EVENT_SPACE = "EVENT_SPACE";
static EVENT_BACKSPACE = "EVENT_BACKSPACE" static EVENT_BACKSPACE = "EVENT_BACKSPACE";
static EVENT_START = "EVENT_START" static EVENT_START = "EVENT_START";
static EVENT_PAUSE = "EVENT_PAUSE" static EVENT_PAUSE = "EVENT_PAUSE";
static EVENT_STOP = "EVENT_STOP" static EVENT_STOP = "EVENT_STOP";
static EVENT_CONFIRM = "EVENT_CONFIRM" static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_CHANGE_CONFIRM = "EVENT_CHANGE_CONFIRM" static EVENT_CHANGE_CONFIRM = "EVENT_CHANGE_CONFIRM";
static EVENT_VALID = "EVENT_VALID" static EVENT_VALID = "EVENT_VALID";
static EVENT_ERROR = "EVENT_ERROR" static EVENT_ERROR = "EVENT_ERROR";
static EVENT_ENTER = "EVENT_ENTER" static EVENT_ENTER = "EVENT_ENTER";
static EVENT_RESTRICT = "EVENT_RESTRICT" static EVENT_RESTRICT = "EVENT_RESTRICT";
static EVENT_REMOVE = "EVENT_REMOVE" static EVENT_REMOVE = "EVENT_REMOVE";
static EVENT_EMPTY = "EVENT_EMPTY" static EVENT_EMPTY = "EVENT_EMPTY";
_defaultConfig(config) { _defaultConfig(config) {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, { return extend(conf, {
extraCls: `bi-text-editor bi-focus-shadow ${config.simple ? "bi-border-bottom" : "bi-border"}`, extraCls: `bi-text-editor bi-focus-shadow ${config.simple ? "bi-border-bottom" : "bi-border"}`,
hgap: 4, hgap: 4,
@ -97,7 +97,6 @@ export class TextEditor extends Widget {
this.fireEvent(TextEditor.EVENT_BACKSPACE); this.fireEvent(TextEditor.EVENT_BACKSPACE);
}); });
this.editor.on(Editor.EVENT_VALID, () => { this.editor.on(Editor.EVENT_VALID, () => {
this.element.removeClass("error"); this.element.removeClass("error");
this.fireEvent(TextEditor.EVENT_VALID); this.fireEvent(TextEditor.EVENT_VALID);

4
src/widget/editor/editor.text.small.js

@ -3,11 +3,11 @@ import { TextEditor } from "./editor.text";
@shortcut() @shortcut()
export class SmallTextEditor extends TextEditor { export class SmallTextEditor extends TextEditor {
static xtype = "bi.small_text_editor" static xtype = "bi.small_text_editor";
_defaultConfig() { _defaultConfig() {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, { return extend(conf, {
baseCls: `${conf.baseCls || ""} bi-small-text-editor`, baseCls: `${conf.baseCls || ""} bi-small-text-editor`,
height: 20, height: 20,

4
src/widget/intervalslider/index.js

@ -1,2 +1,2 @@
export { AccurateCalculationModel } from "./model.accuratecalculation"; export { AccurateCalculationModel } from "./model.accuratecalculation";
export { IntervalSlider } from "./intervalslider"; export { IntervalSlider } from "./intervalslider";

151
src/widget/intervalslider/intervalslider.js

@ -1,4 +1,6 @@
import { import {
VerticalFillLayout,
HorizontalLayout,
shortcut, shortcut,
createWidget, createWidget,
toPix, toPix,
@ -32,7 +34,7 @@ export class IntervalSlider extends Single {
SLIDER_WIDTH: 30, SLIDER_WIDTH: 30,
SLIDER_HEIGHT: 30, SLIDER_HEIGHT: 30,
TRACK_HEIGHT: 24, TRACK_HEIGHT: 24,
} };
props = { props = {
baseCls: "bi-interval-slider bi-slider-track", baseCls: "bi-interval-slider bi-slider-track",
digit: false, digit: false,
@ -84,9 +86,7 @@ export class IntervalSlider extends Single {
}); });
this.labelOne.element.hover( this.labelOne.element.hover(
() => { () => {
this.labelOne.element this.labelOne.element.removeClass("bi-border").addClass("bi-border");
.removeClass("bi-border")
.addClass("bi-border");
}, },
() => { () => {
this.labelOne.element.removeClass("bi-border"); this.labelOne.element.removeClass("bi-border");
@ -100,12 +100,7 @@ export class IntervalSlider extends Single {
const significantPercent = parseFloat(percent.toFixed(1)); // 分成1000份 const significantPercent = parseFloat(percent.toFixed(1)); // 分成1000份
this._setSliderOnePosition(significantPercent); this._setSliderOnePosition(significantPercent);
this._setBlueTrack(); this._setBlueTrack();
this._checkLabelPosition( this._checkLabelPosition(oldValueOne, this.valueTwo, this.valueOne, this.valueTwo);
oldValueOne,
this.valueTwo,
this.valueOne,
this.valueTwo
);
this.fireEvent(IntervalSlider.EVENT_CHANGE); this.fireEvent(IntervalSlider.EVENT_CHANGE);
}); });
@ -120,9 +115,7 @@ export class IntervalSlider extends Single {
}); });
this.labelTwo.element.hover( this.labelTwo.element.hover(
() => { () => {
this.labelTwo.element this.labelTwo.element.removeClass("bi-border").addClass("bi-border");
.removeClass("bi-border")
.addClass("bi-border");
}, },
() => { () => {
this.labelTwo.element.removeClass("bi-border"); this.labelTwo.element.removeClass("bi-border");
@ -136,12 +129,7 @@ export class IntervalSlider extends Single {
const significantPercent = parseFloat(percent.toFixed(1)); const significantPercent = parseFloat(percent.toFixed(1));
this._setSliderTwoPosition(significantPercent); this._setSliderTwoPosition(significantPercent);
this._setBlueTrack(); this._setBlueTrack();
this._checkLabelPosition( this._checkLabelPosition(this.valueOne, oldValueTwo, this.valueOne, this.valueTwo);
this.valueOne,
oldValueTwo,
this.valueOne,
this.valueTwo
);
this.fireEvent(IntervalSlider.EVENT_CHANGE); this.fireEvent(IntervalSlider.EVENT_CHANGE);
}); });
@ -156,7 +144,7 @@ export class IntervalSlider extends Single {
this._setVisible(false); this._setVisible(false);
return { return {
type: "bi.vertical_fill", type: VerticalFillLayout.xtype,
rowSize: [30, 30], rowSize: [30, 30],
items: [ items: [
this._createLabelWrapper(), this._createLabelWrapper(),
@ -165,7 +153,7 @@ export class IntervalSlider extends Single {
items: [ items: [
{ {
el: { el: {
type: "bi.horizontal", type: HorizontalLayout.xtype,
horizontalAlign: "stretch", horizontalAlign: "stretch",
verticalAlign: "middle", verticalAlign: "middle",
columnSize: ["fill"], columnSize: ["fill"],
@ -198,22 +186,12 @@ export class IntervalSlider extends Single {
this._setSliderOnePosition(significantPercent); this._setSliderOnePosition(significantPercent);
this.labelOne.setValue(v); this.labelOne.setValue(v);
this.valueOne = v; this.valueOne = v;
this._checkLabelPosition( this._checkLabelPosition(oldValueOne, oldValueTwo, v, this.valueTwo);
oldValueOne,
oldValueTwo,
v,
this.valueTwo
);
} else { } else {
this._setSliderTwoPosition(significantPercent); this._setSliderTwoPosition(significantPercent);
this.labelTwo.setValue(v); this.labelTwo.setValue(v);
this.valueTwo = v; this.valueTwo = v;
this._checkLabelPosition( this._checkLabelPosition(oldValueOne, oldValueTwo, this.valueOne, v);
oldValueOne,
oldValueTwo,
this.valueOne,
v
);
} }
this._setBlueTrack(); this._setBlueTrack();
} }
@ -221,9 +199,7 @@ export class IntervalSlider extends Single {
_rePosBySizeAfterStop(size, isLeft) { _rePosBySizeAfterStop(size, isLeft) {
const percent = (size * 100) / this._getGrayTrackLength(); const percent = (size * 100) / this._getGrayTrackLength();
const significantPercent = parseFloat(percent.toFixed(1)); const significantPercent = parseFloat(percent.toFixed(1));
isLeft isLeft ? this._setSliderOnePosition(significantPercent) : this._setSliderTwoPosition(significantPercent);
? this._setSliderOnePosition(significantPercent)
: this._setSliderTwoPosition(significantPercent);
} }
_draggable(widget, isLeft) { _draggable(widget, isLeft) {
@ -232,7 +208,7 @@ export class IntervalSlider extends Single {
offset = 0, offset = 0,
defaultSize = 0; defaultSize = 0;
const mouseMoveTracker = new MouseMoveTracker( const mouseMoveTracker = new MouseMoveTracker(
(deltaX => { deltaX => {
if (mouseMoveTracker.isDragging()) { if (mouseMoveTracker.isDragging()) {
startDrag = true; startDrag = true;
offset += deltaX; offset += deltaX;
@ -240,8 +216,8 @@ export class IntervalSlider extends Single {
widget.element.addClass("dragging"); widget.element.addClass("dragging");
this._rePosBySizeAfterMove(size, isLeft); this._rePosBySizeAfterMove(size, isLeft);
} }
}), },
(() => { () => {
if (startDrag === true) { if (startDrag === true) {
size = optimizeSize(size); size = optimizeSize(size);
this._rePosBySizeAfterStop(size, isLeft); this._rePosBySizeAfterStop(size, isLeft);
@ -253,7 +229,7 @@ export class IntervalSlider extends Single {
widget.element.removeClass("dragging"); widget.element.removeClass("dragging");
mouseMoveTracker.releaseMouseMoves(); mouseMoveTracker.releaseMouseMoves();
this.fireEvent(IntervalSlider.EVENT_CHANGE); this.fireEvent(IntervalSlider.EVENT_CHANGE);
}), },
window window
); );
widget.element.on("mousedown", function (event) { widget.element.on("mousedown", function (event) {
@ -270,7 +246,7 @@ export class IntervalSlider extends Single {
_createLabelWrapper() { _createLabelWrapper() {
const c = this._constant; const c = this._constant;
return { return {
el: { el: {
type: VerticalLayout.xtype, type: VerticalLayout.xtype,
@ -308,7 +284,7 @@ export class IntervalSlider extends Single {
_createSliderWrapper() { _createSliderWrapper() {
return { return {
el: { el: {
type: "bi.horizontal", type: HorizontalLayout.xtype,
horizontalAlign: "stretch", horizontalAlign: "stretch",
verticalAlign: "middle", verticalAlign: "middle",
items: [ items: [
@ -340,7 +316,7 @@ export class IntervalSlider extends Single {
_createTrackWrapper() { _createTrackWrapper() {
return createWidget({ return createWidget({
type: "bi.horizontal", type: HorizontalLayout.xtype,
cls: "track-wrapper", cls: "track-wrapper",
horizontalAlign: "stretch", horizontalAlign: "stretch",
verticalAlign: "middle", verticalAlign: "middle",
@ -375,7 +351,7 @@ export class IntervalSlider extends Single {
const o = this.options; const o = this.options;
let valid = false; let valid = false;
// 像90.这样的既不属于整数又不属于小数,是不合法的值 // 像90.这样的既不属于整数又不属于小数,是不合法的值
let dotText = (`${v}`).split(".")[1]; let dotText = `${v}`.split(".")[1];
// eslint-disable-next-line no-empty // eslint-disable-next-line no-empty
if (isEmptyString(dotText)) { if (isEmptyString(dotText)) {
} else { } else {
@ -390,7 +366,7 @@ export class IntervalSlider extends Single {
} }
} }
} }
return valid; return valid;
} }
@ -421,9 +397,7 @@ export class IntervalSlider extends Single {
(oldValueOne <= oldValueTwo && valueOne > valueTwo) || (oldValueOne <= oldValueTwo && valueOne > valueTwo) ||
(oldValueOne >= oldValueTwo && valueOne < valueTwo) (oldValueOne >= oldValueTwo && valueOne < valueTwo)
) { ) {
const isSliderOneLeft = const isSliderOneLeft = parseFloat(this.labelOne.getValue()) < parseFloat(this.labelTwo.getValue());
parseFloat(this.labelOne.getValue()) <
parseFloat(this.labelTwo.getValue());
this._resetLabelPosition(!isSliderOneLeft); this._resetLabelPosition(!isSliderOneLeft);
} }
} }
@ -475,11 +449,7 @@ export class IntervalSlider extends Single {
} }
_setErrorText() { _setErrorText() {
const errorText = i18nText( const errorText = i18nText("BI-Basic_Please_Enter_Number_Between", this.min, this.max);
"BI-Basic_Please_Enter_Number_Between",
this.min,
this.max
);
this.labelOne.setErrorText(errorText); this.labelOne.setErrorText(errorText);
this.labelTwo.setErrorText(errorText); this.labelTwo.setErrorText(errorText);
} }
@ -500,27 +470,13 @@ export class IntervalSlider extends Single {
const mul = this.calculation.accurateMultiplication(sub, percent); const mul = this.calculation.accurateMultiplication(sub, percent);
const div = this.calculation.accurateDivisionTenExponent(mul, 2); const div = this.calculation.accurateDivisionTenExponent(mul, 2);
if (this.precision < 0) { if (this.precision < 0) {
const value = parseFloat( const value = parseFloat(this.calculation.accurateAddition(div, this.min));
this.calculation.accurateAddition(div, this.min) const reduceValue = Math.round(this.calculation.accurateDivisionTenExponent(value, -this.precision));
);
const reduceValue = Math.round( return this.calculation.accurateMultiplication(reduceValue, Math.pow(10, -this.precision));
this.calculation.accurateDivisionTenExponent(
value,
-this.precision
)
);
return this.calculation.accurateMultiplication(
reduceValue,
Math.pow(10, -this.precision)
);
} }
return parseFloat( return parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision));
this.calculation
.accurateAddition(div, this.min)
.toFixed(this.precision)
);
} }
_getPercentByValue(v) { _getPercentByValue(v) {
@ -541,11 +497,11 @@ export class IntervalSlider extends Single {
arr = pre.split("e"); arr = pre.split("e");
const decimalPartLength = size(arr[0].split(".")[1]); const decimalPartLength = size(arr[0].split(".")[1]);
const sciencePartLength = parseInt(arr[1].substring(1)); const sciencePartLength = parseInt(arr[1].substring(1));
return decimalPartLength - sciencePartLength; return decimalPartLength - sciencePartLength;
} }
arr = pre.split("."); arr = pre.split(".");
return arr.length > 1 ? arr[1].length : 0; return arr.length > 1 ? arr[1].length : 0;
} }
@ -556,20 +512,16 @@ export class IntervalSlider extends Single {
if (value >= this.max) { if (value >= this.max) {
return this.max; return this.max;
} }
return value; return value;
} }
_setEnable(b) { _setEnable(b) {
super._setEnable.apply(this, [b]); super._setEnable.apply(this, [b]);
if (b) { if (b) {
this.blueTrack.element this.blueTrack.element.removeClass("disabled-blue-track").addClass("blue-track");
.removeClass("disabled-blue-track")
.addClass("blue-track");
} else { } else {
this.blueTrack.element this.blueTrack.element.removeClass("blue-track").addClass("disabled-blue-track");
.removeClass("blue-track")
.addClass("disabled-blue-track");
} }
} }
@ -577,7 +529,7 @@ export class IntervalSlider extends Single {
if (this.valueOne <= this.valueTwo) { if (this.valueOne <= this.valueTwo) {
return { min: this.valueOne, max: this.valueTwo }; return { min: this.valueOne, max: this.valueTwo };
} }
return { min: this.valueTwo, max: this.valueOne }; return { min: this.valueTwo, max: this.valueOne };
} }
@ -602,22 +554,14 @@ export class IntervalSlider extends Single {
const o = this.options; const o = this.options;
let valueOne = parseFloat(v.min); let valueOne = parseFloat(v.min);
let valueTwo = parseFloat(v.max); let valueTwo = parseFloat(v.max);
valueOne = valueOne = o.digit === false ? valueOne : parseFloat(valueOne.toFixed(o.digit));
o.digit === false valueTwo = o.digit === false ? valueTwo : parseFloat(valueTwo.toFixed(o.digit));
? valueOne
: parseFloat(valueOne.toFixed(o.digit));
valueTwo =
o.digit === false
? valueTwo
: parseFloat(valueTwo.toFixed(o.digit));
if (!isNaN(valueOne) && !isNaN(valueTwo)) { if (!isNaN(valueOne) && !isNaN(valueTwo)) {
if (this._checkValidation(valueOne)) { if (this._checkValidation(valueOne)) {
this.valueOne = this.valueOne = this.valueOne <= this.valueTwo ? valueOne : valueTwo;
this.valueOne <= this.valueTwo ? valueOne : valueTwo;
} }
if (this._checkValidation(valueTwo)) { if (this._checkValidation(valueTwo)) {
this.valueTwo = this.valueTwo = this.valueOne <= this.valueTwo ? valueTwo : valueOne;
this.valueOne <= this.valueTwo ? valueTwo : valueOne;
} }
if (valueOne < this.min) { if (valueOne < this.min) {
this.valueOne = this.min; this.valueOne = this.min;
@ -648,20 +592,9 @@ export class IntervalSlider extends Single {
(isNumeric(this.valueOne) || isNotEmptyString(this.valueOne)) && (isNumeric(this.valueOne) || isNotEmptyString(this.valueOne)) &&
(isNumeric(this.valueTwo) || isNotEmptyString(this.valueTwo)) (isNumeric(this.valueTwo) || isNotEmptyString(this.valueTwo))
) { ) {
this.labelOne.setValue( this.labelOne.setValue(o.digit === false ? this.valueOne : parseFloat(this.valueOne).toFixed(o.digit));
o.digit === false this.labelTwo.setValue(o.digit === false ? this.valueTwo : parseFloat(this.valueTwo).toFixed(o.digit));
? this.valueOne this._setAllPosition(this._getPercentByValue(this.valueOne), this._getPercentByValue(this.valueTwo));
: parseFloat(this.valueOne).toFixed(o.digit)
);
this.labelTwo.setValue(
o.digit === false
? this.valueTwo
: parseFloat(this.valueTwo).toFixed(o.digit)
);
this._setAllPosition(
this._getPercentByValue(this.valueOne),
this._getPercentByValue(this.valueTwo)
);
} else { } else {
this.labelOne.setValue(this.min); this.labelOne.setValue(this.min);
this.labelTwo.setValue(this.max); this.labelTwo.setValue(this.max);

86
src/widget/intervalslider/model.accuratecalculation.js

@ -16,7 +16,7 @@ export class AccurateCalculationModel extends Widget {
for (let i = 0; i < n; i++) { for (let i = 0; i < n; i++) {
magnitude += "0"; magnitude += "0";
} }
return parseInt(magnitude); return parseInt(magnitude);
} }
@ -24,8 +24,7 @@ export class AccurateCalculationModel extends Widget {
if (stringNumber1.numDecimalLength === stringNumber2.numDecimalLength) { if (stringNumber1.numDecimalLength === stringNumber2.numDecimalLength) {
return; return;
} }
let magnitudeDiff = let magnitudeDiff = stringNumber1.numDecimalLength - stringNumber2.numDecimalLength;
stringNumber1.numDecimalLength - stringNumber2.numDecimalLength;
let needAddZero; let needAddZero;
if (magnitudeDiff > 0) { if (magnitudeDiff > 0) {
needAddZero = stringNumber2; needAddZero = stringNumber2;
@ -54,7 +53,7 @@ export class AccurateCalculationModel extends Widget {
numDecimal = numStrArray[1]; numDecimal = numStrArray[1];
numDecimalLength = numStrArray[1].length; numDecimalLength = numStrArray[1].length;
} }
return { return {
numInteger, numInteger,
numDecimal, numDecimal,
@ -67,27 +66,16 @@ export class AccurateCalculationModel extends Widget {
const stringNumber1 = this._stringNumberFactory(num1); const stringNumber1 = this._stringNumberFactory(num1);
const stringNumber2 = this._stringNumberFactory(num2); const stringNumber2 = this._stringNumberFactory(num2);
// 整数部分计算 // 整数部分计算
let integerResult = let integerResult = parseInt(stringNumber1.numInteger) - parseInt(stringNumber2.numInteger);
parseInt(stringNumber1.numInteger) -
parseInt(stringNumber2.numInteger);
// 小数部分 // 小数部分
this._formatDecimal(stringNumber1, stringNumber2); this._formatDecimal(stringNumber1, stringNumber2);
const decimalMaxLength = getDecimalMaxLength( const decimalMaxLength = getDecimalMaxLength(stringNumber1, stringNumber2);
stringNumber1,
stringNumber2
);
let decimalResultTemp; let decimalResultTemp;
let decimalResult; let decimalResult;
if ( if (parseInt(stringNumber1.numDecimal) >= parseInt(stringNumber2.numDecimal)) {
parseInt(stringNumber1.numDecimal) >= decimalResultTemp = (parseInt(stringNumber1.numDecimal) - parseInt(stringNumber2.numDecimal)).toString();
parseInt(stringNumber2.numDecimal)
) {
decimalResultTemp = (
parseInt(stringNumber1.numDecimal) -
parseInt(stringNumber2.numDecimal)
).toString();
decimalResult = addZero(decimalResultTemp, decimalMaxLength); decimalResult = addZero(decimalResultTemp, decimalMaxLength);
} else { } else {
// 否则借位 // 否则借位
@ -101,14 +89,14 @@ export class AccurateCalculationModel extends Widget {
decimalResult = addZero(decimalResultTemp, decimalMaxLength); decimalResult = addZero(decimalResultTemp, decimalMaxLength);
} }
const result = `${integerResult}.${decimalResult}`; const result = `${integerResult}.${decimalResult}`;
return parseFloat(result); return parseFloat(result);
function getDecimalMaxLength(num1, num2) { function getDecimalMaxLength(num1, num2) {
if (num1.numDecimal.length >= num2.numDecimal.length) { if (num1.numDecimal.length >= num2.numDecimal.length) {
return num1.numDecimal.length; return num1.numDecimal.length;
} }
return num2.numDecimal.length; return num2.numDecimal.length;
} }
@ -117,7 +105,7 @@ export class AccurateCalculationModel extends Widget {
for (let i = 0; i < diff; i++) { for (let i = 0; i < diff; i++) {
resultTemp = `0${resultTemp}`; resultTemp = `0${resultTemp}`;
} }
return resultTemp; return resultTemp;
} }
} }
@ -127,30 +115,22 @@ export class AccurateCalculationModel extends Widget {
const stringNumber1 = this._stringNumberFactory(num1); const stringNumber1 = this._stringNumberFactory(num1);
const stringNumber2 = this._stringNumberFactory(num2); const stringNumber2 = this._stringNumberFactory(num2);
// 整数部分计算 // 整数部分计算
let integerResult = let integerResult = parseInt(stringNumber1.numInteger) + parseInt(stringNumber2.numInteger);
parseInt(stringNumber1.numInteger) +
parseInt(stringNumber2.numInteger);
// 小数部分 // 小数部分
this._formatDecimal(stringNumber1, stringNumber2); this._formatDecimal(stringNumber1, stringNumber2);
let decimalResult = ( let decimalResult = (parseInt(stringNumber1.numDecimal) + parseInt(stringNumber2.numDecimal)).toString();
parseInt(stringNumber1.numDecimal) +
parseInt(stringNumber2.numDecimal)
).toString();
if (decimalResult !== "0") { if (decimalResult !== "0") {
if (decimalResult.length <= stringNumber1.numDecimal.length) { if (decimalResult.length <= stringNumber1.numDecimal.length) {
decimalResult = addZero( decimalResult = addZero(decimalResult, stringNumber1.numDecimal.length);
decimalResult,
stringNumber1.numDecimal.length
);
} else { } else {
integerResult++; // 进一 integerResult++; // 进一
decimalResult = decimalResult.slice(1); decimalResult = decimalResult.slice(1);
} }
} }
const result = `${integerResult}.${decimalResult}`; const result = `${integerResult}.${decimalResult}`;
return parseFloat(result); return parseFloat(result);
function addZero(resultTemp, length) { function addZero(resultTemp, length) {
@ -158,7 +138,7 @@ export class AccurateCalculationModel extends Widget {
for (let i = 0; i < diff; i++) { for (let i = 0; i < diff; i++) {
resultTemp = `0${resultTemp}`; resultTemp = `0${resultTemp}`;
} }
return resultTemp; return resultTemp;
} }
} }
@ -168,33 +148,25 @@ export class AccurateCalculationModel extends Widget {
const stringNumber1 = this._stringNumberFactory(num1); const stringNumber1 = this._stringNumberFactory(num1);
const stringNumber2 = this._stringNumberFactory(num2); const stringNumber2 = this._stringNumberFactory(num2);
// 整数部分计算 // 整数部分计算
const integerResult = const integerResult = parseInt(stringNumber1.numInteger) * parseInt(stringNumber2.numInteger);
parseInt(stringNumber1.numInteger) *
parseInt(stringNumber2.numInteger);
// num1的小数和num2的整数 // num1的小数和num2的整数
const dec1Int2 = this._accurateDivisionTenExponent( const dec1Int2 = this._accurateDivisionTenExponent(
parseInt(stringNumber1.numDecimal) * parseInt(stringNumber1.numDecimal) * parseInt(stringNumber2.numInteger),
parseInt(stringNumber2.numInteger),
stringNumber1.numDecimalLength stringNumber1.numDecimalLength
); );
// num1的整数和num2的小数 // num1的整数和num2的小数
const int1dec2 = this._accurateDivisionTenExponent( const int1dec2 = this._accurateDivisionTenExponent(
parseInt(stringNumber1.numInteger) * parseInt(stringNumber1.numInteger) * parseInt(stringNumber2.numDecimal),
parseInt(stringNumber2.numDecimal),
stringNumber2.numDecimalLength stringNumber2.numDecimalLength
); );
// 小数*小数 // 小数*小数
const dec1dec2 = this._accurateDivisionTenExponent( const dec1dec2 = this._accurateDivisionTenExponent(
parseInt(stringNumber1.numDecimal) * parseInt(stringNumber1.numDecimal) * parseInt(stringNumber2.numDecimal),
parseInt(stringNumber2.numDecimal),
stringNumber1.numDecimalLength + stringNumber2.numDecimalLength stringNumber1.numDecimalLength + stringNumber2.numDecimalLength
); );
return this._accurateAddition( return this._accurateAddition(
this._accurateAddition( this._accurateAddition(this._accurateAddition(integerResult, dec1Int2), int1dec2),
this._accurateAddition(integerResult, dec1Int2),
int1dec2
),
dec1dec2 dec1dec2
); );
} }
@ -204,18 +176,14 @@ export class AccurateCalculationModel extends Widget {
const stringNumber = this._stringNumberFactory(num); const stringNumber = this._stringNumberFactory(num);
let integerResult, partDecimalResult; let integerResult, partDecimalResult;
if (stringNumber.numInteger.length > n) { if (stringNumber.numInteger.length > n) {
integerResult = stringNumber.numInteger.slice( integerResult = stringNumber.numInteger.slice(0, stringNumber.numInteger.length - n);
0,
stringNumber.numInteger.length - n
);
partDecimalResult = stringNumber.numInteger.slice(-n); partDecimalResult = stringNumber.numInteger.slice(-n);
} else { } else {
integerResult = "0"; integerResult = "0";
partDecimalResult = addZero(stringNumber.numInteger, n); partDecimalResult = addZero(stringNumber.numInteger, n);
} }
const result = const result = `${integerResult}.${partDecimalResult}${stringNumber.numDecimal}`;
`${integerResult}.${partDecimalResult}${stringNumber.numDecimal}`;
return parseFloat(result); return parseFloat(result);
function addZero(resultTemp, length) { function addZero(resultTemp, length) {
@ -223,7 +191,7 @@ export class AccurateCalculationModel extends Widget {
for (let i = 0; i < diff; i++) { for (let i = 0; i < diff; i++) {
resultTemp = `0${resultTemp}`; resultTemp = `0${resultTemp}`;
} }
return resultTemp; return resultTemp;
} }
} }
@ -233,7 +201,7 @@ export class AccurateCalculationModel extends Widget {
if (num1 >= num2) { if (num1 >= num2) {
return this._accurateSubtraction(num1, num2); return this._accurateSubtraction(num1, num2);
} }
return -this._accurateSubtraction(num2, num1); return -this._accurateSubtraction(num2, num1);
} }
if (num1 >= 0 && num2 < 0) { if (num1 >= 0 && num2 < 0) {
@ -246,7 +214,7 @@ export class AccurateCalculationModel extends Widget {
if (num1 >= num2) { if (num1 >= num2) {
return this._accurateSubtraction(-num2, -num1); return this._accurateSubtraction(-num2, -num1);
} }
return this._accurateSubtraction(-num1, -num2); return this._accurateSubtraction(-num1, -num2);
} }
} }
@ -285,7 +253,7 @@ export class AccurateCalculationModel extends Widget {
if (num1 >= 0) { if (num1 >= 0) {
return this._accurateDivisionTenExponent(num1, n); return this._accurateDivisionTenExponent(num1, n);
} }
return -this._accurateDivisionTenExponent(-num1, n); return -this._accurateDivisionTenExponent(-num1, n);
} }
} }

6
src/widget/multilayerdownlist/combo.downlist.js

@ -1,5 +1,5 @@
import { shortcut, Widget, extend, createWidget } from "@/core";
import { MultiLayerDownListPopup } from "./popup.downlist"; import { MultiLayerDownListPopup } from "./popup.downlist";
import { shortcut, Widget, extend, createWidget } from "@/core";
import { Combo } from "@/base"; import { Combo } from "@/base";
import { IconTrigger } from "@/case"; import { IconTrigger } from "@/case";
@ -29,13 +29,13 @@ export class MultiLayerDownListCombo extends Widget {
super._init(...arguments); super._init(...arguments);
const o = this.options; const o = this.options;
this.popupview = createWidget({ this.popupview = createWidget({
type: "bi.multi_layer_down_list_popup", type: MultiLayerDownListPopup.xtype,
items: o.items, items: o.items,
chooseType: o.chooseType, chooseType: o.chooseType,
value: o.value, value: o.value,
}); });
this.popupview.on(MultiLayerDownListPopup.EVENT_CHANGE, value => { this.popupview.on(MultiLayerDownListPopup.EVENT_CHANGE, (value) => {
this.fireEvent(MultiLayerDownListCombo.EVENT_CHANGE, value); this.fireEvent(MultiLayerDownListCombo.EVENT_CHANGE, value);
this.downlistcombo.hideView(); this.downlistcombo.hideView();
}); });

38
src/widget/multilayerdownlist/popup.downlist.js

@ -40,7 +40,7 @@ export class MultiLayerDownListPopup extends Pane {
_defaultConfig() { _defaultConfig() {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, { return extend(conf, {
baseCls: "bi-down-list-popup", baseCls: "bi-down-list-popup",
items: [], items: [],
@ -82,7 +82,7 @@ export class MultiLayerDownListPopup extends Pane {
if (isNotNull(self.childValueMap[value])) { if (isNotNull(self.childValueMap[value])) {
changedValue = self.childValueMap[value]; changedValue = self.childValueMap[value];
const fatherValue = self.fatherValueMap[value]; const fatherValue = self.fatherValueMap[value];
const fatherArrayValue = (`${fatherValue}`).split(BlankSplitChar); const fatherArrayValue = `${fatherValue}`.split(BlankSplitChar);
self.fireEvent( self.fireEvent(
MultiLayerDownListPopup.EVENT_SON_VALUE_CHANGE, MultiLayerDownListPopup.EVENT_SON_VALUE_CHANGE,
changedValue, changedValue,
@ -193,7 +193,7 @@ export class MultiLayerDownListPopup extends Pane {
result.push(spliter_container); result.push(spliter_container);
} }
}); });
return result; return result;
} }
@ -252,7 +252,7 @@ export class MultiLayerDownListPopup extends Pane {
if (isArray(fatherValue)) { if (isArray(fatherValue)) {
fValue = fatherValue.join(BlankSplitChar); fValue = fatherValue.join(BlankSplitChar);
} }
return fValue + BlankSplitChar + childValue; return fValue + BlankSplitChar + childValue;
} }
@ -268,7 +268,7 @@ export class MultiLayerDownListPopup extends Pane {
} }
valueArray.push(value); valueArray.push(value);
}); });
return valueArray; return valueArray;
} }
@ -289,19 +289,21 @@ export class MultiLayerDownListPopup extends Pane {
} }
}); });
}); });
return value; return value;
function joinValue(sources, targets) { function joinValue(sources, targets) {
let value = ""; let value = "";
some(sources, (idx, s) => some(targets, (id, t) => { some(sources, (idx, s) =>
if (s === t) { some(targets, (id, t) => {
value = s; if (s === t) {
value = s;
return true;
} return true;
})); }
})
);
return value; return value;
} }
@ -314,7 +316,7 @@ export class MultiLayerDownListPopup extends Pane {
} else { } else {
children.push(item.value); children.push(item.value);
} }
return children; return children;
} }
} }
@ -346,7 +348,7 @@ export class MultiLayerDownListPopup extends Pane {
each(this.popup.getAllButtons(), (i, item) => { each(this.popup.getAllButtons(), (i, item) => {
i % 2 === 0 && v.push(item.getValue()); i % 2 === 0 && v.push(item.getValue());
}); });
return v; return v;
} }
@ -359,14 +361,14 @@ export class MultiLayerDownListPopup extends Pane {
if (isNotNull(self.childValueMap[value])) { if (isNotNull(self.childValueMap[value])) {
const fartherValue = self.fatherValueMap[value]; const fartherValue = self.fatherValueMap[value];
valueItem.childValue = self.childValueMap[value]; valueItem.childValue = self.childValueMap[value];
const fatherArrayValue = (`${fartherValue}`).split(BlankSplitChar); const fatherArrayValue = `${fartherValue}`.split(BlankSplitChar);
valueItem.value = fatherArrayValue.length > 1 ? fatherArrayValue : fartherValue; valueItem.value = fatherArrayValue.length > 1 ? fatherArrayValue : fartherValue;
} else { } else {
valueItem.value = value; valueItem.value = value;
} }
result.push(valueItem); result.push(valueItem);
}); });
return result; return result;
} }
} }

78
src/widget/multilayerselecttree/multilayerselecttree.combo.js

@ -1,14 +1,4 @@
import { import { shortcut, Widget, extend, emptyFn, isKey, toPix, AbsoluteLayout, nextTick, isArray } from "@/core";
shortcut,
Widget,
extend,
emptyFn,
isKey,
toPix,
AbsoluteLayout,
nextTick,
isArray
} from "@/core";
import { SingleTreeTrigger } from "../singletree/singletree.trigger"; import { SingleTreeTrigger } from "../singletree/singletree.trigger";
import { MultiLayerSelectTreePopup } from "./multilayerselecttree.popup"; import { MultiLayerSelectTreePopup } from "./multilayerselecttree.popup";
import { Combo } from "@/base"; import { Combo } from "@/base";
@ -121,8 +111,7 @@ export class MultiLayerSelectTreeCombo extends Widget {
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
items: o.items, items: o.items,
ref(_ref) { ref(_ref) {
self.trigger && self.trigger && self.trigger.getSearcher().setAdapter(_ref);
self.trigger.getSearcher().setAdapter(_ref);
}, },
listeners: [ listeners: [
{ {
@ -130,13 +119,8 @@ export class MultiLayerSelectTreeCombo extends Widget {
action() { action() {
self.setValue(this.getValue()); self.setValue(this.getValue());
self.combo.hideView(); self.combo.hideView();
self.fireEvent( self.fireEvent(MultiLayerSelectTreeCombo.EVENT_CHANGE);
MultiLayerSelectTreeCombo.EVENT_CHANGE self.fireEvent(MultiLayerSelectTreeCombo.EVENT_CLICK_ITEM, self.combo.getValue());
);
self.fireEvent(
MultiLayerSelectTreeCombo.EVENT_CLICK_ITEM,
self.combo.getValue()
);
}, },
} }
], ],
@ -157,9 +141,7 @@ export class MultiLayerSelectTreeCombo extends Widget {
{ {
eventName: Combo.EVENT_BEFORE_POPUPVIEW, eventName: Combo.EVENT_BEFORE_POPUPVIEW,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeCombo.EVENT_BEFORE_POPUPVIEW);
MultiLayerSelectTreeCombo.EVENT_BEFORE_POPUPVIEW
);
}, },
} }
], ],
@ -198,45 +180,32 @@ export class MultiLayerSelectTreeCombo extends Widget {
action() { action() {
self.setValue(this.getValue()); self.setValue(this.getValue());
self.combo.hideView(); self.combo.hideView();
self.fireEvent( self.fireEvent(MultiLayerSelectTreeCombo.EVENT_CHANGE);
MultiLayerSelectTreeCombo.EVENT_CHANGE self.fireEvent(MultiLayerSelectTreeCombo.EVENT_CLICK_ITEM, self.combo.getValue());
);
self.fireEvent(
MultiLayerSelectTreeCombo.EVENT_CLICK_ITEM,
self.combo.getValue()
);
}, },
}, },
{ {
eventName: MultiLayerSelectTreeTrigger.EVENT_FOCUS, eventName: MultiLayerSelectTreeTrigger.EVENT_FOCUS,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeCombo.EVENT_FOCUS);
MultiLayerSelectTreeCombo.EVENT_FOCUS
);
}, },
}, },
{ {
eventName: MultiLayerSelectTreeTrigger.EVENT_BLUR, eventName: MultiLayerSelectTreeTrigger.EVENT_BLUR,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeCombo.EVENT_BLUR);
MultiLayerSelectTreeCombo.EVENT_BLUR
);
}, },
}, },
{ {
eventName: MultiLayerSelectTreeTrigger.EVENT_SEARCHING, eventName: MultiLayerSelectTreeTrigger.EVENT_SEARCHING,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeCombo.EVENT_SEARCHING);
MultiLayerSelectTreeCombo.EVENT_SEARCHING
);
}, },
}, },
{ {
eventName: MultiLayerSelectTreeTrigger.EVENT_STOP, eventName: MultiLayerSelectTreeTrigger.EVENT_STOP,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeCombo.EVENT_STOP);
MultiLayerSelectTreeCombo.EVENT_STOP
);
}, },
}, },
{ {
@ -245,9 +214,7 @@ export class MultiLayerSelectTreeCombo extends Widget {
const value = self.trigger.getSearcher().getKeyword(); const value = self.trigger.getSearcher().getKeyword();
self.combo.setValue([value]); self.combo.setValue([value]);
self.combo.hideView(); self.combo.hideView();
self.fireEvent( self.fireEvent(MultiLayerSelectTreeCombo.EVENT_CHANGE);
MultiLayerSelectTreeCombo.EVENT_CHANGE
);
}, },
} }
], ],
@ -259,9 +226,8 @@ export class MultiLayerSelectTreeCombo extends Widget {
// 通过container参数将popup放置于popover之外解决此问题, 其他下拉控件由于元素少或者有分页,所以 // 通过container参数将popup放置于popover之外解决此问题, 其他下拉控件由于元素少或者有分页,所以
// 卡顿不明显, 先在此做尝试, 并在FineUI特殊处理待解决文档中标记跟踪 // 卡顿不明显, 先在此做尝试, 并在FineUI特殊处理待解决文档中标记跟踪
return o.container && return o.container &&
self.trigger.getSearcher().isSearching() && self.trigger.getSearcher().isSearching() &&
self.trigger.getSearcher().getView().element.find(e.target) self.trigger.getSearcher().getView().element.find(e.target).length > 0
.length > 0
? false ? false
: self.triggerBtn?.element.find(e.target).length === 0; : self.triggerBtn?.element.find(e.target).length === 0;
}, },
@ -275,9 +241,7 @@ export class MultiLayerSelectTreeCombo extends Widget {
{ {
eventName: Combo.EVENT_BEFORE_POPUPVIEW, eventName: Combo.EVENT_BEFORE_POPUPVIEW,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeCombo.EVENT_BEFORE_POPUPVIEW);
MultiLayerSelectTreeCombo.EVENT_BEFORE_POPUPVIEW
);
}, },
} }
], ],
@ -321,9 +285,7 @@ export class MultiLayerSelectTreeCombo extends Widget {
} }
getSearcher() { getSearcher() {
return this.trigger return this.trigger ? this.trigger.getSearcher() : this.textTrigger.getTextor();
? this.trigger.getSearcher()
: this.textTrigger.getTextor();
} }
clear() { clear() {
@ -339,9 +301,7 @@ export class MultiLayerSelectTreeCombo extends Widget {
} }
setTipType(v) { setTipType(v) {
this.trigger this.trigger ? this.trigger.setTipType(v) : this.textTrigger.setTipType(v);
? this.trigger.setTipType(v)
: this.textTrigger.setTipType(v);
} }
populate(items) { populate(items) {
@ -361,8 +321,6 @@ export class MultiLayerSelectTreeCombo extends Widget {
} }
setWaterMark(v) { setWaterMark(v) {
this.trigger this.trigger ? this.trigger.setWaterMark(v) : this.textTrigger.setWaterMark(v);
? this.trigger.setWaterMark(v)
: this.textTrigger.setWaterMark(v);
} }
} }

14
src/widget/multilayerselecttree/multilayerselecttree.insert.search.pane.js

@ -59,9 +59,7 @@ export class MultiLayerSelectTreeInsertSearchPane extends Widget {
{ {
eventName: MultiLayerSelectLevelTree.EVENT_CHANGE, eventName: MultiLayerSelectLevelTree.EVENT_CHANGE,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeInsertSearchPane.EVENT_CHANGE);
MultiLayerSelectTreeInsertSearchPane.EVENT_CHANGE
);
}, },
} }
], ],
@ -84,10 +82,7 @@ export class MultiLayerSelectTreeInsertSearchPane extends Widget {
self.addNotMatchTip = _ref; self.addNotMatchTip = _ref;
}, },
handler() { handler() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeInsertSearchPane.EVENT_ADD_ITEM, o.keywordGetter());
MultiLayerSelectTreeInsertSearchPane.EVENT_ADD_ITEM,
o.keywordGetter()
);
}, },
}, },
this.tree this.tree
@ -98,10 +93,7 @@ export class MultiLayerSelectTreeInsertSearchPane extends Widget {
setKeyword(keyword) { setKeyword(keyword) {
const showTip = isEmptyArray(this.tree.getAllLeaves()); const showTip = isEmptyArray(this.tree.getAllLeaves());
this.addNotMatchTip.setVisible(showTip); this.addNotMatchTip.setVisible(showTip);
showTip && showTip && this.addNotMatchTip.setText(i18nText("BI-Basic_Click_To_Add_Text", keyword));
this.addNotMatchTip.setText(
i18nText("BI-Basic_Click_To_Add_Text", keyword)
);
} }
getValue() { getValue() {

42
src/widget/multilayerselecttree/multilayerselecttree.leveltree.js

@ -66,11 +66,7 @@ export class MultiLayerSelectLevelTree extends Pane {
} }
node.keyword = node.keyword || keyword; node.keyword = node.keyword || keyword;
extend.pNode = pNode; extend.pNode = pNode;
if ( if (node.isParent === true || node.parent === true || isNotEmptyArray(node.children)) {
node.isParent === true ||
node.parent === true ||
isNotEmptyArray(node.children)
) {
extend.type = BasicTreeNode.xtype; extend.type = BasicTreeNode.xtype;
extend.selectable = true; extend.selectable = true;
defaults(node, extend); defaults(node, extend);
@ -112,10 +108,10 @@ export class MultiLayerSelectLevelTree extends Pane {
items: this._formatItems(Tree.transformToTreeFormat(nodes), 0), items: this._formatItems(Tree.transformToTreeFormat(nodes), 0),
itemsCreator(op, callback) { itemsCreator(op, callback) {
op.times === 1 && op.times === 1 &&
!op.node && !op.node &&
nextTick(() => { nextTick(() => {
self.loading(); self.loading();
}); });
o.itemsCreator(op, ob => { o.itemsCreator(op, ob => {
hasNext = ob.hasNext; hasNext = ob.hasNext;
op.times === 1 && !op.node && self._populate(ob.items); op.times === 1 && !op.node && self._populate(ob.items);
@ -128,10 +124,10 @@ export class MultiLayerSelectLevelTree extends Pane {
); );
self.setValue(self.storeValue); self.setValue(self.storeValue);
op.times === 1 && op.times === 1 &&
!op.node && !op.node &&
nextTick(() => { nextTick(() => {
self.loaded(); self.loaded();
}); });
}); });
}, },
value: o.value, value: o.value,
@ -141,10 +137,7 @@ export class MultiLayerSelectLevelTree extends Pane {
isDefaultInit: o.itemsCreator !== emptyFn, isDefaultInit: o.itemsCreator !== emptyFn,
el: { el: {
type: ButtonTree.xtype, type: ButtonTree.xtype,
chooseType: chooseType: o.chooseType === Selection.None ? Selection.None : Selection.Default, // 不使用buttontree内部getValue逻辑
o.chooseType === Selection.None
? Selection.None
: Selection.Default, // 不使用buttontree内部getValue逻辑
behaviors: o.behaviors, behaviors: o.behaviors,
layouts: [ layouts: [
{ {
@ -161,10 +154,7 @@ export class MultiLayerSelectLevelTree extends Pane {
self.fireEvent(Controller.EVENT_CHANGE, arguments); self.fireEvent(Controller.EVENT_CHANGE, arguments);
if (type === Events.CLICK) { if (type === Events.CLICK) {
self.setValue(value); self.setValue(value);
self.fireEvent( self.fireEvent(MultiLayerSelectLevelTree.EVENT_CHANGE, arguments);
MultiLayerSelectLevelTree.EVENT_CHANGE,
arguments
);
} }
}); });
@ -184,9 +174,7 @@ export class MultiLayerSelectLevelTree extends Pane {
this._populate(nodes); this._populate(nodes);
isNull(nodes) isNull(nodes)
? this.tree.populate() ? this.tree.populate()
: this.tree.populate( : this.tree.populate(this._formatItems(Tree.transformToTreeFormat(nodes), 0));
this._formatItems(Tree.transformToTreeFormat(nodes), 0)
);
} }
setValue(v) { setValue(v) {
@ -199,11 +187,7 @@ export class MultiLayerSelectLevelTree extends Pane {
} }
getValue() { getValue() {
return isArray(this.storeValue) return isArray(this.storeValue) ? this.storeValue : isNull(this.storeValue) ? [] : [this.storeValue];
? this.storeValue
: isNull(this.storeValue)
? []
: [this.storeValue];
} }
getAllLeaves() { getAllLeaves() {

12
src/widget/multilayerselecttree/multilayerselecttree.popup.js

@ -1,14 +1,4 @@
import { import { shortcut, Widget, extend, i18nText, emptyFn, createWidget, Controller, VerticalLayout, isArray } from "@/core";
shortcut,
Widget,
extend,
i18nText,
emptyFn,
createWidget,
Controller,
VerticalLayout,
isArray
} from "@/core";
import { MultiLayerSelectLevelTree } from "./multilayerselecttree.leveltree"; import { MultiLayerSelectLevelTree } from "./multilayerselecttree.leveltree";
@shortcut() @shortcut()

41
src/widget/multilayerselecttree/multilayerselecttree.trigger.js

@ -75,9 +75,7 @@ export class MultiLayerSelectTreeTrigger extends Trigger {
self.editor = this; self.editor = this;
}, },
defaultText: o.defaultText, defaultText: o.defaultText,
text: isKey(o.value) text: isKey(o.value) ? this._digest(o.value) : o.text,
? this._digest(o.value)
: o.text,
value: o.value, value: o.value,
height: o.height, height: o.height,
tipText: "", tipText: "",
@ -86,25 +84,19 @@ export class MultiLayerSelectTreeTrigger extends Trigger {
{ {
eventName: StateEditor.EVENT_FOCUS, eventName: StateEditor.EVENT_FOCUS,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeTrigger.EVENT_FOCUS);
MultiLayerSelectTreeTrigger.EVENT_FOCUS
);
}, },
}, },
{ {
eventName: StateEditor.EVENT_BLUR, eventName: StateEditor.EVENT_BLUR,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeTrigger.EVENT_BLUR);
MultiLayerSelectTreeTrigger.EVENT_BLUR
);
}, },
}, },
{ {
eventName: StateEditor.EVENT_CHANGE, eventName: StateEditor.EVENT_CHANGE,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeTrigger.EVENT_SEARCHING);
MultiLayerSelectTreeTrigger.EVENT_SEARCHING
);
}, },
} }
], ],
@ -126,15 +118,10 @@ export class MultiLayerSelectTreeTrigger extends Trigger {
cls: "bi-card", cls: "bi-card",
listeners: [ listeners: [
{ {
eventName: eventName: MultiLayerSelectTreeInsertSearchPane.EVENT_ADD_ITEM,
MultiLayerSelectTreeInsertSearchPane.EVENT_ADD_ITEM,
action() { action() {
self.options.text = self self.options.text = self.getSearcher().getKeyword();
.getSearcher() self.fireEvent(MultiLayerSelectTreeTrigger.EVENT_ADD_ITEM);
.getKeyword();
self.fireEvent(
MultiLayerSelectTreeTrigger.EVENT_ADD_ITEM
);
}, },
} }
], ],
@ -146,8 +133,7 @@ export class MultiLayerSelectTreeTrigger extends Trigger {
const keyword = obj.keyword; const keyword = obj.keyword;
if (o.itemsCreator === BI.emptyFn) { if (o.itemsCreator === BI.emptyFn) {
callback(self._getSearchItems(keyword)); callback(self._getSearchItems(keyword));
o.allowInsertValue && o.allowInsertValue && self.popup.setKeyword(keyword);
self.popup.setKeyword(keyword);
} else { } else {
callback(); callback();
} }
@ -156,9 +142,7 @@ export class MultiLayerSelectTreeTrigger extends Trigger {
{ {
eventName: Searcher.EVENT_CHANGE, eventName: Searcher.EVENT_CHANGE,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSelectTreeTrigger.EVENT_CHANGE);
MultiLayerSelectTreeTrigger.EVENT_CHANGE
);
}, },
} }
], ],
@ -184,12 +168,7 @@ export class MultiLayerSelectTreeTrigger extends Trigger {
const items = []; const items = [];
this.tree.traverse(node => { this.tree.traverse(node => {
const find = Func.getSearchResult( const find = Func.getSearchResult(
self.tree.isRoot(node) self.tree.isRoot(node) ? [] : concat([node.text], o.allowSearchValue ? [node.value] : []),
? []
: concat(
[node.text],
o.allowSearchValue ? [node.value] : []
),
keyword keyword
); );
if (find.find.length > 0 || find.match.length > 0) { if (find.find.length > 0 || find.match.length > 0) {

68
src/widget/multilayersingletree/multilayersingletree.combo.js

@ -1,14 +1,4 @@
import { import { shortcut, Widget, extend, emptyFn, isKey, toPix, AbsoluteLayout, nextTick, isArray } from "@/core";
shortcut,
Widget,
extend,
emptyFn,
isKey,
toPix,
AbsoluteLayout,
nextTick,
isArray
} from "@/core";
import { SingleTreeTrigger } from "../singletree/singletree.trigger"; import { SingleTreeTrigger } from "../singletree/singletree.trigger";
import { MultiLayerSingleTreePopup } from "./multilayersingletree.popup"; import { MultiLayerSingleTreePopup } from "./multilayersingletree.popup";
import { Combo } from "@/base"; import { Combo } from "@/base";
@ -47,9 +37,7 @@ export class MultiLayerSingleTreeCombo extends Widget {
o = this.options; o = this.options;
const cls = const cls =
(o.simple (o.simple ? "bi-border-bottom bi-focus-shadow " : "bi-border bi-border-radius bi-focus-shadow ") +
? "bi-border-bottom bi-focus-shadow "
: "bi-border bi-border-radius bi-focus-shadow ") +
(isKey(o.status) ? `status-${o.status}` : ""); (isKey(o.status) ? `status-${o.status}` : "");
const baseConfig = this._getBaseConfig(); const baseConfig = this._getBaseConfig();
@ -121,8 +109,7 @@ export class MultiLayerSingleTreeCombo extends Widget {
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
items: o.items, items: o.items,
ref(_ref) { ref(_ref) {
self.trigger && self.trigger && self.trigger.getSearcher().setAdapter(_ref);
self.trigger.getSearcher().setAdapter(_ref);
}, },
listeners: [ listeners: [
{ {
@ -130,9 +117,7 @@ export class MultiLayerSingleTreeCombo extends Widget {
action() { action() {
self.setValue(this.getValue()); self.setValue(this.getValue());
self.combo.hideView(); self.combo.hideView();
self.fireEvent( self.fireEvent(MultiLayerSingleTreeCombo.EVENT_CHANGE);
MultiLayerSingleTreeCombo.EVENT_CHANGE
);
}, },
} }
], ],
@ -153,9 +138,7 @@ export class MultiLayerSingleTreeCombo extends Widget {
{ {
eventName: Combo.EVENT_BEFORE_POPUPVIEW, eventName: Combo.EVENT_BEFORE_POPUPVIEW,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeCombo.EVENT_BEFORE_POPUPVIEW);
MultiLayerSingleTreeCombo.EVENT_BEFORE_POPUPVIEW
);
}, },
} }
], ],
@ -193,41 +176,31 @@ export class MultiLayerSingleTreeCombo extends Widget {
action() { action() {
self.setValue(this.getValue()); self.setValue(this.getValue());
self.combo.hideView(); self.combo.hideView();
self.fireEvent( self.fireEvent(MultiLayerSingleTreeCombo.EVENT_CHANGE);
MultiLayerSingleTreeCombo.EVENT_CHANGE
);
}, },
}, },
{ {
eventName: MultiLayerSingleTreeTrigger.EVENT_FOCUS, eventName: MultiLayerSingleTreeTrigger.EVENT_FOCUS,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeCombo.EVENT_FOCUS);
MultiLayerSingleTreeCombo.EVENT_FOCUS
);
}, },
}, },
{ {
eventName: MultiLayerSingleTreeTrigger.EVENT_BLUR, eventName: MultiLayerSingleTreeTrigger.EVENT_BLUR,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeCombo.EVENT_BLUR);
MultiLayerSingleTreeCombo.EVENT_BLUR
);
}, },
}, },
{ {
eventName: MultiLayerSingleTreeTrigger.EVENT_SEARCHING, eventName: MultiLayerSingleTreeTrigger.EVENT_SEARCHING,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeCombo.EVENT_SEARCHING);
MultiLayerSingleTreeCombo.EVENT_SEARCHING
);
}, },
}, },
{ {
eventName: MultiLayerSingleTreeTrigger.EVENT_STOP, eventName: MultiLayerSingleTreeTrigger.EVENT_STOP,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeCombo.EVENT_STOP);
MultiLayerSingleTreeCombo.EVENT_STOP
);
}, },
}, },
{ {
@ -236,9 +209,7 @@ export class MultiLayerSingleTreeCombo extends Widget {
const value = self.trigger.getSearcher().getKeyword(); const value = self.trigger.getSearcher().getKeyword();
self.combo.setValue([value]); self.combo.setValue([value]);
self.combo.hideView(); self.combo.hideView();
self.fireEvent( self.fireEvent(MultiLayerSingleTreeCombo.EVENT_CHANGE);
MultiLayerSingleTreeCombo.EVENT_CHANGE
);
}, },
} }
], ],
@ -250,9 +221,8 @@ export class MultiLayerSingleTreeCombo extends Widget {
// 通过container参数将popup放置于popover之外解决此问题, 其他下拉控件由于元素少或者有分页,所以 // 通过container参数将popup放置于popover之外解决此问题, 其他下拉控件由于元素少或者有分页,所以
// 卡顿不明显, 先在此做尝试, 并在FineUI特殊处理待解决文档中标记跟踪 // 卡顿不明显, 先在此做尝试, 并在FineUI特殊处理待解决文档中标记跟踪
return o.container && return o.container &&
self.trigger.getSearcher().isSearching() && self.trigger.getSearcher().isSearching() &&
self.trigger.getSearcher().getView().element.find(e.target) self.trigger.getSearcher().getView().element.find(e.target).length > 0
.length > 0
? false ? false
: self.triggerBtn?.element.find(e.target).length === 0; : self.triggerBtn?.element.find(e.target).length === 0;
}, },
@ -266,9 +236,7 @@ export class MultiLayerSingleTreeCombo extends Widget {
{ {
eventName: Combo.EVENT_BEFORE_POPUPVIEW, eventName: Combo.EVENT_BEFORE_POPUPVIEW,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeCombo.EVENT_BEFORE_POPUPVIEW);
MultiLayerSingleTreeCombo.EVENT_BEFORE_POPUPVIEW
);
}, },
} }
], ],
@ -303,9 +271,7 @@ export class MultiLayerSingleTreeCombo extends Widget {
} }
getSearcher() { getSearcher() {
return this.trigger return this.trigger ? this.trigger.getSearcher() : this.textTrigger.getTextor();
? this.trigger.getSearcher()
: this.textTrigger.getTextor();
} }
setValue(v) { setValue(v) {
@ -326,9 +292,7 @@ export class MultiLayerSingleTreeCombo extends Widget {
} }
setTipType(v) { setTipType(v) {
this.trigger this.trigger ? this.trigger.setTipType(v) : this.textTrigger.setTipType(v);
? this.trigger.setTipType(v)
: this.textTrigger.setTipType(v);
} }
populate(items) { populate(items) {

14
src/widget/multilayersingletree/multilayersingletree.insert.search.pane.js

@ -59,9 +59,7 @@ export class MultiLayerSingleTreeInsertSearchPane extends Widget {
{ {
eventName: MultiLayerSingleLevelTree.EVENT_CHANGE, eventName: MultiLayerSingleLevelTree.EVENT_CHANGE,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeInsertSearchPane.EVENT_CHANGE);
MultiLayerSingleTreeInsertSearchPane.EVENT_CHANGE
);
}, },
} }
], ],
@ -84,10 +82,7 @@ export class MultiLayerSingleTreeInsertSearchPane extends Widget {
self.addNotMatchTip = _ref; self.addNotMatchTip = _ref;
}, },
handler() { handler() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM, o.keywordGetter());
MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM,
o.keywordGetter()
);
}, },
}, },
this.tree this.tree
@ -98,10 +93,7 @@ export class MultiLayerSingleTreeInsertSearchPane extends Widget {
setKeyword(keyword) { setKeyword(keyword) {
const showTip = isEmptyArray(this.tree.getAllLeaves()); const showTip = isEmptyArray(this.tree.getAllLeaves());
this.addNotMatchTip.setVisible(showTip); this.addNotMatchTip.setVisible(showTip);
showTip && showTip && this.addNotMatchTip.setText(i18nText("BI-Basic_Click_To_Add_Text", keyword));
this.addNotMatchTip.setText(
i18nText("BI-Basic_Click_To_Add_Text", keyword)
);
} }
getValue() { getValue() {

37
src/widget/multilayersingletree/multilayersingletree.leveltree.js

@ -66,11 +66,7 @@ export class MultiLayerSingleLevelTree extends Pane {
} }
node.keyword = node.keyword || keyword; node.keyword = node.keyword || keyword;
extend.pNode = pNode; extend.pNode = pNode;
if ( if (node.isParent === true || node.parent === true || isNotEmptyArray(node.children)) {
node.isParent === true ||
node.parent === true ||
isNotEmptyArray(node.children)
) {
extend.type = BasicTreeNode.xtype; extend.type = BasicTreeNode.xtype;
extend.selectable = false; extend.selectable = false;
defaults(node, extend); defaults(node, extend);
@ -112,10 +108,10 @@ export class MultiLayerSingleLevelTree extends Pane {
value: o.value, value: o.value,
itemsCreator(op, callback) { itemsCreator(op, callback) {
op.times === 1 && op.times === 1 &&
!op.node && !op.node &&
nextTick(() => { nextTick(() => {
self.loading(); self.loading();
}); });
o.itemsCreator(op, ob => { o.itemsCreator(op, ob => {
hasNext = ob.hasNext; hasNext = ob.hasNext;
op.times === 1 && !op.node && self._populate(ob.items); op.times === 1 && !op.node && self._populate(ob.items);
@ -128,10 +124,10 @@ export class MultiLayerSingleLevelTree extends Pane {
); );
self.setValue(self.storeValue); self.setValue(self.storeValue);
op.times === 1 && op.times === 1 &&
!op.node && !op.node &&
nextTick(() => { nextTick(() => {
self.loaded(); self.loaded();
}); });
}); });
}, },
@ -140,10 +136,7 @@ export class MultiLayerSingleLevelTree extends Pane {
isDefaultInit: o.itemsCreator !== emptyFn, isDefaultInit: o.itemsCreator !== emptyFn,
el: { el: {
type: ButtonTree.xtype, type: ButtonTree.xtype,
chooseType: chooseType: o.chooseType === Selection.None ? Selection.None : Selection.Default, // 不使用buttontree内部getValue逻辑
o.chooseType === Selection.None
? Selection.None
: Selection.Default, // 不使用buttontree内部getValue逻辑
behaviors: o.behaviors, behaviors: o.behaviors,
layouts: [ layouts: [
{ {
@ -180,9 +173,7 @@ export class MultiLayerSingleLevelTree extends Pane {
this._populate(nodes); this._populate(nodes);
isNull(nodes) isNull(nodes)
? this.tree.populate() ? this.tree.populate()
: this.tree.populate( : this.tree.populate(this._formatItems(Tree.transformToTreeFormat(nodes), 0));
this._formatItems(Tree.transformToTreeFormat(nodes), 0)
);
} }
setValue(v) { setValue(v) {
@ -195,11 +186,7 @@ export class MultiLayerSingleLevelTree extends Pane {
} }
getValue() { getValue() {
return isArray(this.storeValue) return isArray(this.storeValue) ? this.storeValue : isNull(this.storeValue) ? [] : [this.storeValue];
? this.storeValue
: isNull(this.storeValue)
? []
: [this.storeValue];
} }
getAllLeaves() { getAllLeaves() {

12
src/widget/multilayersingletree/multilayersingletree.popup.js

@ -1,14 +1,4 @@
import { import { shortcut, Widget, extend, i18nText, emptyFn, createWidget, Controller, VerticalLayout, isArray } from "@/core";
shortcut,
Widget,
extend,
i18nText,
emptyFn,
createWidget,
Controller,
VerticalLayout,
isArray
} from "@/core";
import { MultiLayerSingleLevelTree } from "./multilayersingletree.leveltree"; import { MultiLayerSingleLevelTree } from "./multilayersingletree.leveltree";
@shortcut() @shortcut()

41
src/widget/multilayersingletree/multilayersingletree.trigger.js

@ -75,9 +75,7 @@ export class MultiLayerSingleTreeTrigger extends Trigger {
self.editor = this; self.editor = this;
}, },
defaultText: o.defaultText, defaultText: o.defaultText,
text: isKey(o.value) text: isKey(o.value) ? this._digest(o.value) : o.text,
? this._digest(o.value)
: o.text,
value: o.value, value: o.value,
height: o.height, height: o.height,
tipText: "", tipText: "",
@ -86,25 +84,19 @@ export class MultiLayerSingleTreeTrigger extends Trigger {
{ {
eventName: StateEditor.EVENT_FOCUS, eventName: StateEditor.EVENT_FOCUS,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_FOCUS);
MultiLayerSingleTreeTrigger.EVENT_FOCUS
);
}, },
}, },
{ {
eventName: StateEditor.EVENT_BLUR, eventName: StateEditor.EVENT_BLUR,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_BLUR);
MultiLayerSingleTreeTrigger.EVENT_BLUR
);
}, },
}, },
{ {
eventName: StateEditor.EVENT_CHANGE, eventName: StateEditor.EVENT_CHANGE,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_SEARCHING);
MultiLayerSingleTreeTrigger.EVENT_SEARCHING
);
}, },
} }
], ],
@ -126,15 +118,10 @@ export class MultiLayerSingleTreeTrigger extends Trigger {
cls: "bi-card", cls: "bi-card",
listeners: [ listeners: [
{ {
eventName: eventName: MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM,
MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM,
action() { action() {
self.options.text = self self.options.text = self.getSearcher().getKeyword();
.getSearcher() self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_ADD_ITEM);
.getKeyword();
self.fireEvent(
MultiLayerSingleTreeTrigger.EVENT_ADD_ITEM
);
}, },
} }
], ],
@ -146,8 +133,7 @@ export class MultiLayerSingleTreeTrigger extends Trigger {
const keyword = obj.keyword; const keyword = obj.keyword;
if (o.itemsCreator === BI.emptyFn) { if (o.itemsCreator === BI.emptyFn) {
callback(self._getSearchItems(keyword)); callback(self._getSearchItems(keyword));
o.allowInsertValue && o.allowInsertValue && self.popup.setKeyword(keyword);
self.popup.setKeyword(keyword);
} else { } else {
callback(); callback();
} }
@ -156,9 +142,7 @@ export class MultiLayerSingleTreeTrigger extends Trigger {
{ {
eventName: Searcher.EVENT_CHANGE, eventName: Searcher.EVENT_CHANGE,
action() { action() {
self.fireEvent( self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_CHANGE);
MultiLayerSingleTreeTrigger.EVENT_CHANGE
);
}, },
} }
], ],
@ -184,12 +168,7 @@ export class MultiLayerSingleTreeTrigger extends Trigger {
const items = []; const items = [];
this.tree.traverse(node => { this.tree.traverse(node => {
const find = Func.getSearchResult( const find = Func.getSearchResult(
self.tree.isRoot(node) self.tree.isRoot(node) ? [] : concat([node.text], o.allowSearchValue ? [node.value] : []),
? []
: concat(
[node.text],
o.allowSearchValue ? [node.value] : []
),
keyword keyword
); );
if (find.find.length > 0 || find.match.length > 0) { if (find.find.length > 0 || find.match.length > 0) {

3
src/widget/multiselect/check/multiselect.check.pane.js

@ -6,7 +6,8 @@ import {
createWidget, createWidget,
map, map,
i18nText, i18nText,
VerticalAdaptLayout, VTapeLayout VerticalAdaptLayout,
VTapeLayout
} from "@/core"; } from "@/core";
import { TextButton, Label } from "@/base"; import { TextButton, Label } from "@/base";
import { DisplaySelectedList } from "./multiselect.display"; import { DisplaySelectedList } from "./multiselect.display";

22
src/widget/multiselect/check/multiselect.display.js

@ -1,11 +1,4 @@
import { import { shortcut, extend, emptyFn, createWidget, VerticalLayout, createItems } from "@/core";
shortcut,
extend,
emptyFn,
createWidget,
VerticalLayout,
createItems
} from "@/core";
import { Pane, ButtonGroup, Loader, IconTextItem } from "@/base"; import { Pane, ButtonGroup, Loader, IconTextItem } from "@/base";
import { ListPane } from "@/case"; import { ListPane } from "@/case";
@ -51,7 +44,7 @@ export class DisplaySelectedList extends Pane {
} }
], ],
}, },
itemsCreator (options, callback) { itemsCreator(options, callback) {
if (options.times === 1) { if (options.times === 1) {
cacheItems = []; cacheItems = [];
} }
@ -61,7 +54,7 @@ export class DisplaySelectedList extends Pane {
cacheItems = cacheItems.slice(100); cacheItems = cacheItems.slice(100);
self.hasNext = cacheItems.length > 0; self.hasNext = cacheItems.length > 0;
callback(self._createItems(renderedItems)); callback(self._createItems(renderedItems));
return; return;
} }
@ -70,15 +63,12 @@ export class DisplaySelectedList extends Pane {
const firstItemsCount = 100 + (ob.items.length % 100); const firstItemsCount = 100 + (ob.items.length % 100);
if (ob.items.length > 100) { if (ob.items.length > 100) {
cacheItems = ob.items.slice(firstItemsCount); cacheItems = ob.items.slice(firstItemsCount);
self.hasNext = self.hasNext = firstItemsCount !== ob.items.length;
firstItemsCount !== ob.items.length;
} }
callback( callback(self._createItems(ob.items.slice(0, firstItemsCount)));
self._createItems(ob.items.slice(0, firstItemsCount))
);
}); });
}, },
hasNext () { hasNext() {
return self.hasNext; return self.hasNext;
}, },
}); });

50
src/widget/multiselect/loader.js

@ -1,3 +1,4 @@
import { LoadingBar, ButtonGroup, Loader } from "@/base";
import { import {
shortcut, shortcut,
Widget, Widget,
@ -17,7 +18,6 @@ import {
isArray, isArray,
each each
} from "@/core"; } from "@/core";
import { ButtonGroup, Loader } from "@/base";
@shortcut() @shortcut()
export class MultiSelectInnerLoader extends Widget { export class MultiSelectInnerLoader extends Widget {
@ -103,21 +103,18 @@ export class MultiSelectInnerLoader extends Widget {
], ],
value: o.value, value: o.value,
}); });
this.button_group.on( this.button_group.on(Controller.EVENT_CHANGE, function (type, value, obj) {
Controller.EVENT_CHANGE, if (type === Events.CLICK) {
function (type, value, obj) { const node = self.cachGroup.getNodeByValue(value);
if (type === Events.CLICK) { if (node) {
const node = self.cachGroup.getNodeByValue(value); node.setSelected(obj.isSelected());
if (node) {
node.setSelected(obj.isSelected());
}
}
self.fireEvent(Controller.EVENT_CHANGE, arguments);
if (type === Events.CLICK) {
self.fireEvent(Loader.EVENT_CHANGE, obj);
} }
} }
); self.fireEvent(Controller.EVENT_CHANGE, arguments);
if (type === Events.CLICK) {
self.fireEvent(Loader.EVENT_CHANGE, obj);
}
});
const renderEngine = Widget._renderEngine; const renderEngine = Widget._renderEngine;
Widget.registerRenderEngine(BI.Element.renderEngine); Widget.registerRenderEngine(BI.Element.renderEngine);
@ -140,7 +137,7 @@ export class MultiSelectInnerLoader extends Widget {
this.next = createWidget( this.next = createWidget(
extend( extend(
{ {
type: "bi.loading_bar", type: LoadingBar.xtype,
}, },
o.next o.next
) )
@ -159,12 +156,12 @@ export class MultiSelectInnerLoader extends Widget {
}); });
o.isDefaultInit && o.isDefaultInit &&
isEmpty(o.items) && isEmpty(o.items) &&
nextTick( nextTick(
bind(function () { bind(function () {
o.isDefaultInit && isEmpty(o.items) && this._populate(); o.isDefaultInit && isEmpty(o.items) && this._populate();
}, this) }, this)
); );
} }
hasNext() { hasNext() {
@ -218,10 +215,7 @@ export class MultiSelectInnerLoader extends Widget {
return false; return false;
} }
this.options.items = (items || []).slice( this.options.items = (items || []).slice(0, 100 + ((items || []).length % 100));
0,
100 + ((items || []).length % 100)
);
this.times = 1; this.times = 1;
this.count = 0; this.count = 0;
this.count += items.length; this.count += items.length;
@ -247,11 +241,7 @@ export class MultiSelectInnerLoader extends Widget {
Widget.registerRenderEngine(BI.Element.renderEngine); Widget.registerRenderEngine(BI.Element.renderEngine);
this.cachGroup.populate.call(this.cachGroup, items, keyword); this.cachGroup.populate.call(this.cachGroup, items, keyword);
Widget.registerRenderEngine(renderEngine); Widget.registerRenderEngine(renderEngine);
this.button_group.populate.call( this.button_group.populate.call(this.button_group, items.slice(0, firstItemsCount), keyword);
this.button_group,
items.slice(0, firstItemsCount),
keyword
);
} }
} }

124
src/widget/multiselect/multiselect.combo.js

@ -1,3 +1,4 @@
import { MultiSelectPopupView } from "./multiselect.popup.view";
import { import {
shortcut, shortcut,
extend, extend,
@ -23,12 +24,11 @@ import {
values, values,
filter, filter,
contains, contains,
isNull isNull,
} from "@/core"; } from "@/core";
import { Single, Combo } from "@/base"; import { Single, Combo } from "@/base";
import { TriggerIconButton } from "@/case"; import { TriggerIconButton } from "@/case";
import { MultiSelectTrigger } from "./multiselect.trigger"; import { MultiSelectTrigger } from "./multiselect.trigger";
import { MultiSelectPopupView } from "./multiselect.popup.view";
import { MultiSelectCheckSelectedSwitcher } from "./trigger/switcher.checkselected"; import { MultiSelectCheckSelectedSwitcher } from "./trigger/switcher.checkselected";
@shortcut() @shortcut()
@ -125,28 +125,25 @@ export class MultiSelectCombo extends Single {
self._setStartValue(""); self._setStartValue("");
self.fireEvent(MultiSelectCombo.EVENT_STOP); self.fireEvent(MultiSelectCombo.EVENT_STOP);
}); });
this.trigger.on( this.trigger.on(MultiSelectTrigger.EVENT_SEARCHING, (keywords) => {
MultiSelectTrigger.EVENT_SEARCHING, const lastKeyword = last(keywords);
keywords => { keywords = initial(keywords || []);
const lastKeyword = last(keywords); if (keywords.length > 0) {
keywords = initial(keywords || []); self._joinKeywords(keywords, () => {
if (keywords.length > 0) { if (BI.endWith(lastKeyword, BI.BlankSplitChar)) {
self._joinKeywords(keywords, () => { self.combo.setValue(self.storeValue);
if (BI.endWith(lastKeyword, BI.BlankSplitChar)) { assertShowValue();
self.combo.setValue(self.storeValue); self.combo.populate();
assertShowValue(); self._setStartValue("");
self.combo.populate(); } else {
self._setStartValue(""); self.combo.setValue(self.storeValue);
} else { assertShowValue();
self.combo.setValue(self.storeValue); }
assertShowValue(); self._dataChange = true;
} });
self._dataChange = true;
});
}
self.fireEvent(MultiSelectCombo.EVENT_SEARCHING);
} }
); self.fireEvent(MultiSelectCombo.EVENT_SEARCHING);
});
this.trigger.on(MultiSelectTrigger.EVENT_CHANGE, function (value, obj) { this.trigger.on(MultiSelectTrigger.EVENT_CHANGE, function (value, obj) {
if (obj instanceof BI.MultiSelectBar) { if (obj instanceof BI.MultiSelectBar) {
@ -162,14 +159,11 @@ export class MultiSelectCombo extends Single {
} }
self._dataChange = true; self._dataChange = true;
}); });
this.trigger.on( this.trigger.on(MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, () => {
MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, // counter的值随点击项的改变而改变, 点击counter的时候不需要setValue(counter会请求刷新计数)
() => { // 只需要更新查看面板的selectedValue用以请求已选数据
// counter的值随点击项的改变而改变, 点击counter的时候不需要setValue(counter会请求刷新计数) self.numberCounter.updateSelectedValue(self.storeValue);
// 只需要更新查看面板的selectedValue用以请求已选数据 });
self.numberCounter.updateSelectedValue(self.storeValue);
}
);
this.trigger.on(MultiSelectTrigger.EVENT_COUNTER_CLICK, () => { this.trigger.on(MultiSelectTrigger.EVENT_COUNTER_CLICK, () => {
if (!self.combo.isViewVisible()) { if (!self.combo.isViewVisible()) {
self.combo.showView(); self.combo.showView();
@ -184,7 +178,7 @@ export class MultiSelectCombo extends Single {
el: this.trigger, el: this.trigger,
adjustLength: 1, adjustLength: 1,
popup: { popup: {
type: "bi.multi_select_popup_view", type: MultiSelectPopupView.xtype,
ref() { ref() {
self.popup = this; self.popup = this;
self.trigger.setAdapter(this); self.trigger.setAdapter(this);
@ -215,7 +209,7 @@ export class MultiSelectCombo extends Single {
self.setValue(); self.setValue();
self._defaultState(); self._defaultState();
}, },
} },
], ],
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
itemHeight: o.itemHeight, itemHeight: o.itemHeight,
@ -256,8 +250,7 @@ export class MultiSelectCombo extends Single {
if (self.requesting === true) { if (self.requesting === true) {
self.wants2Quit = true; self.wants2Quit = true;
} else { } else {
self._dataChange && self._dataChange && self.fireEvent(MultiSelectCombo.EVENT_CONFIRM);
self.fireEvent(MultiSelectCombo.EVENT_CONFIRM);
} }
}); });
@ -284,41 +277,30 @@ export class MultiSelectCombo extends Single {
itemsCreator: bind(this._itemsCreator4Trigger, this), itemsCreator: bind(this._itemsCreator4Trigger, this),
value: this.storeValue, value: this.storeValue,
}); });
this.numberCounter.on( this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, () => {
MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, if (!self.combo.isViewVisible()) {
() => { self.combo.showView();
if (!self.combo.isViewVisible()) {
self.combo.showView();
}
}
);
this.numberCounter.on(
MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW,
function () {
this.updateSelectedValue(self.storeValue);
} }
); });
this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW, function () {
this.updateSelectedValue(self.storeValue);
});
this.numberCounter.on(Events.VIEW, b => { this.numberCounter.on(Events.VIEW, (b) => {
nextTick(() => { nextTick(() => {
// 自动调整宽度 // 自动调整宽度
self.trigger.refreshPlaceHolderWidth( self.trigger.refreshPlaceHolderWidth(b === true ? self.numberCounter.element.outerWidth() + 8 : 0);
b === true ? self.numberCounter.element.outerWidth() + 8 : 0
);
}); });
}); });
this.numberCounter.on( this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW, () => {
MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW, nextTick(() => {
() => { // 收起时自动调整宽度
nextTick(() => { self.trigger.refreshPlaceHolderWidth(0);
// 收起时自动调整宽度 });
self.trigger.refreshPlaceHolderWidth(0); });
});
}
);
this.trigger.element.click(e => { this.trigger.element.click((e) => {
if (self.trigger.element.find(e.target).length > 0) { if (self.trigger.element.find(e.target).length > 0) {
self.numberCounter.hideView(); self.numberCounter.hideView();
} }
@ -349,7 +331,7 @@ export class MultiSelectCombo extends Single {
right: o.height, right: o.height,
top: 0, top: 0,
height: o.height, height: o.height,
} },
], ],
}); });
} }
@ -396,7 +378,7 @@ export class MultiSelectCombo extends Single {
type: MultiSelectCombo.REQ_GET_ALL_DATA, type: MultiSelectCombo.REQ_GET_ALL_DATA,
keywords, keywords,
}, },
ob => { (ob) => {
const values = map(ob.items, "value"); const values = map(ob.items, "value");
digest(values); digest(values);
} }
@ -436,8 +418,7 @@ export class MultiSelectCombo extends Single {
const v = obj.value; const v = obj.value;
if (isNotNull(tempMap[v])) { if (isNotNull(tempMap[v])) {
change = true; change = true;
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(tempMap[v]);
self.storeValue.assist.push(tempMap[v]);
delete tempMap[v]; delete tempMap[v];
} }
}); });
@ -452,15 +433,14 @@ export class MultiSelectCombo extends Single {
keywords: [this.trigger.getKey()], keywords: [this.trigger.getKey()],
selectedValues: filter(this.storeValue.value, (_i, v) => !contains(res.value, v)), selectedValues: filter(this.storeValue.value, (_i, v) => !contains(res.value, v)),
}, },
ob => { (ob) => {
const items = map(ob.items, "value"); const items = map(ob.items, "value");
const selectedMap = self._makeMap(self.storeValue.value); const selectedMap = self._makeMap(self.storeValue.value);
const notSelectedMap = self._makeMap(res.value); const notSelectedMap = self._makeMap(res.value);
const newItems = []; const newItems = [];
each(items, (i, item) => { each(items, (i, item) => {
if (isNotNull(selectedMap[items[i]])) { if (isNotNull(selectedMap[items[i]])) {
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(selectedMap[items[i]]);
self.storeValue.assist.push(selectedMap[items[i]]);
delete selectedMap[items[i]]; delete selectedMap[items[i]];
} }
if (isNull(notSelectedMap[items[i]])) { if (isNull(notSelectedMap[items[i]])) {
@ -481,8 +461,7 @@ export class MultiSelectCombo extends Single {
function adjust() { function adjust() {
if (self.wants2Quit === true) { if (self.wants2Quit === true) {
self._dataChange && self._dataChange && self.fireEvent(MultiSelectCombo.EVENT_CONFIRM);
self.fireEvent(MultiSelectCombo.EVENT_CONFIRM);
self.wants2Quit = false; self.wants2Quit = false;
} }
self.requesting = false; self.requesting = false;
@ -506,8 +485,7 @@ export class MultiSelectCombo extends Single {
each(res.assist, (i, v) => { each(res.assist, (i, v) => {
if (isNotNull(map[v])) { if (isNotNull(map[v])) {
change = true; change = true;
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(map[v]);
self.storeValue.assist.push(map[v]);
delete map[v]; delete map[v];
} }
}); });

112
src/widget/multiselect/multiselect.combo.nobar.js

@ -23,7 +23,9 @@ import {
values, values,
filter, filter,
contains, contains,
isNull, pushDistinct, Selection isNull,
pushDistinct,
Selection
} from "@/core"; } from "@/core";
import { Single, Combo } from "@/base"; import { Single, Combo } from "@/base";
import { MultiSelectBar, TriggerIconButton } from "@/case"; import { MultiSelectBar, TriggerIconButton } from "@/case";
@ -126,27 +128,24 @@ export class MultiSelectNoBarCombo extends Single {
self.fireEvent(MultiSelectNoBarCombo.EVENT_STOP); self.fireEvent(MultiSelectNoBarCombo.EVENT_STOP);
}); });
this.trigger.on( this.trigger.on(MultiSelectTrigger.EVENT_SEARCHING, keywords => {
MultiSelectTrigger.EVENT_SEARCHING, const lastKeyword = last(keywords);
keywords => { keywords = initial(keywords || []);
const lastKeyword = last(keywords); if (keywords.length > 0) {
keywords = initial(keywords || []); self._joinKeywords(keywords, () => {
if (keywords.length > 0) { if (BI.endWith(lastKeyword, BI.BlankSplitChar)) {
self._joinKeywords(keywords, () => { self.combo.setValue(self.storeValue);
if (BI.endWith(lastKeyword, BI.BlankSplitChar)) { assertShowValue();
self.combo.setValue(self.storeValue); self.combo.populate();
assertShowValue(); self._setStartValue("");
self.combo.populate(); } else {
self._setStartValue(""); self.combo.setValue(self.storeValue);
} else { assertShowValue();
self.combo.setValue(self.storeValue); }
assertShowValue(); self._dataChange = true;
} });
self._dataChange = true;
});
}
} }
); });
this.trigger.on(MultiSelectTrigger.EVENT_CHANGE, function (value, obj) { this.trigger.on(MultiSelectTrigger.EVENT_CHANGE, function (value, obj) {
if (obj instanceof MultiSelectBar) { if (obj instanceof MultiSelectBar) {
@ -161,14 +160,11 @@ export class MultiSelectNoBarCombo extends Single {
self._dataChange = true; self._dataChange = true;
self.fireEvent(MultiSelectNoBarCombo.EVENT_CLICK_ITEM); self.fireEvent(MultiSelectNoBarCombo.EVENT_CLICK_ITEM);
}); });
this.trigger.on( this.trigger.on(MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, () => {
MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, // counter的值随点击项的改变而改变, 点击counter的时候不需要setValue(counter会请求刷新计数)
() => { // 只需要更新查看面板的selectedValue用以请求已选数据
// counter的值随点击项的改变而改变, 点击counter的时候不需要setValue(counter会请求刷新计数) self.numberCounter.updateSelectedValue(self.storeValue);
// 只需要更新查看面板的selectedValue用以请求已选数据 });
self.numberCounter.updateSelectedValue(self.storeValue);
}
);
this.trigger.on(MultiSelectTrigger.EVENT_COUNTER_CLICK, () => { this.trigger.on(MultiSelectTrigger.EVENT_COUNTER_CLICK, () => {
if (!self.combo.isViewVisible()) { if (!self.combo.isViewVisible()) {
self.combo.showView(); self.combo.showView();
@ -198,9 +194,7 @@ export class MultiSelectNoBarCombo extends Single {
self._adjust(() => { self._adjust(() => {
assertShowValue(); assertShowValue();
}); });
self.fireEvent( self.fireEvent(MultiSelectNoBarCombo.EVENT_CLICK_ITEM);
MultiSelectNoBarCombo.EVENT_CLICK_ITEM
);
}, },
}, },
{ {
@ -260,8 +254,7 @@ export class MultiSelectNoBarCombo extends Single {
if (self.requesting === true) { if (self.requesting === true) {
self.wants2Quit = true; self.wants2Quit = true;
} else { } else {
self._dataChange && self._dataChange && self.fireEvent(MultiSelectNoBarCombo.EVENT_CONFIRM);
self.fireEvent(MultiSelectNoBarCombo.EVENT_CONFIRM);
} }
}); });
@ -291,39 +284,28 @@ export class MultiSelectNoBarCombo extends Single {
value: o.value, value: o.value,
}, },
}); });
this.numberCounter.on( this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, () => {
MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, if (!self.combo.isViewVisible()) {
() => { self.combo.showView();
if (!self.combo.isViewVisible()) {
self.combo.showView();
}
}
);
this.numberCounter.on(
MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW,
function () {
this.updateSelectedValue(self.storeValue);
} }
); });
this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW, function () {
this.updateSelectedValue(self.storeValue);
});
this.numberCounter.on(Events.VIEW, b => { this.numberCounter.on(Events.VIEW, b => {
nextTick(() => { nextTick(() => {
// 自动调整宽度 // 自动调整宽度
self.trigger.refreshPlaceHolderWidth( self.trigger.refreshPlaceHolderWidth(b === true ? self.numberCounter.element.outerWidth() + 8 : 0);
b === true ? self.numberCounter.element.outerWidth() + 8 : 0
);
}); });
}); });
this.numberCounter.on( this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW, () => {
MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW, nextTick(() => {
() => { // 收起时自动调整宽度
nextTick(() => { self.trigger.refreshPlaceHolderWidth(0);
// 收起时自动调整宽度 });
self.trigger.refreshPlaceHolderWidth(0); });
});
}
);
this.trigger.element.click(e => { this.trigger.element.click(e => {
if (self.trigger.element.find(e.target).length > 0) { if (self.trigger.element.find(e.target).length > 0) {
@ -466,8 +448,7 @@ export class MultiSelectNoBarCombo extends Single {
const v = obj.value; const v = obj.value;
if (isNotNull(tempMap[v])) { if (isNotNull(tempMap[v])) {
change = true; change = true;
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(tempMap[v]);
self.storeValue.assist.push(tempMap[v]);
delete tempMap[v]; delete tempMap[v];
} }
}); });
@ -489,8 +470,7 @@ export class MultiSelectNoBarCombo extends Single {
const newItems = []; const newItems = [];
each(items, (i, item) => { each(items, (i, item) => {
if (isNotNull(selectedMap[items[i]])) { if (isNotNull(selectedMap[items[i]])) {
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(selectedMap[items[i]]);
self.storeValue.assist.push(selectedMap[items[i]]);
delete selectedMap[items[i]]; delete selectedMap[items[i]];
} }
if (isNull(notSelectedMap[items[i]])) { if (isNull(notSelectedMap[items[i]])) {
@ -511,8 +491,7 @@ export class MultiSelectNoBarCombo extends Single {
function adjust() { function adjust() {
if (self.wants2Quit === true) { if (self.wants2Quit === true) {
self._dataChange && self._dataChange && self.fireEvent(MultiSelectNoBarCombo.EVENT_CONFIRM);
self.fireEvent(MultiSelectNoBarCombo.EVENT_CONFIRM);
self.wants2Quit = false; self.wants2Quit = false;
} }
self.requesting = false; self.requesting = false;
@ -536,8 +515,7 @@ export class MultiSelectNoBarCombo extends Single {
each(res.assist, (i, v) => { each(res.assist, (i, v) => {
if (isNotNull(map[v])) { if (isNotNull(map[v])) {
change = true; change = true;
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(map[v]);
self.storeValue.assist.push(map[v]);
delete map[v]; delete map[v];
} }
}); });

173
src/widget/multiselect/multiselect.insert.combo.js

@ -1,3 +1,5 @@
import { MultiSelectInsertTrigger } from "./multiselect.insert.trigger";
import { MultiSelectPopupView } from "./multiselect.popup.view";
import { import {
shortcut, shortcut,
extend, extend,
@ -24,11 +26,12 @@ import {
values, values,
filter, filter,
contains, contains,
isNull, endWith, pushDistinct, Selection isNull,
endWith,
pushDistinct,
Selection
} from "@/core"; } from "@/core";
import { Single, Combo, Msg } from "@/base"; import { Single, Combo, Msg } from "@/base";
import { MultiSelectInsertTrigger } from "./multiselect.insert.trigger";
import { MultiSelectPopupView } from "./multiselect.popup.view";
import { MultiSelectBar, TriggerIconButton } from "@/case"; import { MultiSelectBar, TriggerIconButton } from "@/case";
import { MultiSelectCheckSelectedSwitcher } from "./trigger/switcher.checkselected"; import { MultiSelectCheckSelectedSwitcher } from "./trigger/switcher.checkselected";
@ -88,7 +91,7 @@ export class MultiSelectInsertCombo extends Single {
this.requesting = false; this.requesting = false;
this.trigger = createWidget({ this.trigger = createWidget({
type: "bi.multi_select_insert_trigger", type: MultiSelectInsertTrigger.xtype,
allowEdit: o.allowEdit, allowEdit: o.allowEdit,
height: toPix(o.height, o.simple ? 1 : 2), height: toPix(o.height, o.simple ? 1 : 2),
text: o.text, text: o.text,
@ -127,72 +130,54 @@ export class MultiSelectInsertCombo extends Single {
}); });
this.trigger.on(MultiSelectInsertTrigger.EVENT_PAUSE, function () { this.trigger.on(MultiSelectInsertTrigger.EVENT_PAUSE, function () {
self._addItem(assertShowValue, true); self._addItem(assertShowValue, true);
self.fireEvent( self.fireEvent(MultiSelectInsertCombo.EVENT_ADD_ITEM, this.getSearcher().getKeyword());
MultiSelectInsertCombo.EVENT_ADD_ITEM,
this.getSearcher().getKeyword()
);
}); });
this.trigger.on( this.trigger.on(MultiSelectInsertTrigger.EVENT_SEARCHING, function (keywords) {
MultiSelectInsertTrigger.EVENT_SEARCHING, const lastKeyword = last(keywords);
function (keywords) { keywords = initial(keywords || []);
const lastKeyword = last(keywords); if (keywords.length > 0) {
keywords = initial(keywords || []); self._joinKeywords(keywords, () => {
if (keywords.length > 0) { if (endWith(lastKeyword, BI.BlankSplitChar)) {
self._joinKeywords(keywords, () => { self.combo.setValue(self.storeValue);
if (endWith(lastKeyword, BI.BlankSplitChar)) {
self.combo.setValue(self.storeValue);
assertShowValue();
self.combo.populate();
self._setStartValue("");
} else {
self.combo.setValue(self.storeValue);
assertShowValue();
}
self._dataChange = true;
});
this.getSearcher().getKeywordsLength() > 2000 &&
Msg.alert(
i18nText("BI-Basic_Prompt"),
i18nText("BI-Basic_Too_Much_Value_Get_Two_Thousand")
);
}
self.fireEvent(MultiSelectInsertCombo.EVENT_SEARCHING);
}
);
this.trigger.on(
MultiSelectInsertTrigger.EVENT_CHANGE,
function (value, obj) {
if (obj instanceof MultiSelectBar) {
self._joinAll(this.getValue(), () => {
assertShowValue(); assertShowValue();
self.fireEvent(MultiSelectInsertCombo.EVENT_CLICK_ITEM); self.combo.populate();
}); self._setStartValue("");
} else { } else {
self._join(this.getValue(), () => { self.combo.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.fireEvent(MultiSelectInsertCombo.EVENT_CLICK_ITEM); }
}); self._dataChange = true;
} });
self._dataChange = true; this.getSearcher().getKeywordsLength() > 2000 &&
Msg.alert(i18nText("BI-Basic_Prompt"), i18nText("BI-Basic_Too_Much_Value_Get_Two_Thousand"));
} }
); self.fireEvent(MultiSelectInsertCombo.EVENT_SEARCHING);
this.trigger.on( });
MultiSelectInsertTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW,
() => { this.trigger.on(MultiSelectInsertTrigger.EVENT_CHANGE, function (value, obj) {
// counter的值随点击项的改变而改变, 点击counter的时候不需要setValue(counter会请求刷新计数) if (obj instanceof MultiSelectBar) {
// 只需要更新查看面板的selectedValue用以请求已选数据 self._joinAll(this.getValue(), () => {
self.numberCounter.updateSelectedValue(self.storeValue); assertShowValue();
self.fireEvent(MultiSelectInsertCombo.EVENT_CLICK_ITEM);
});
} else {
self._join(this.getValue(), () => {
assertShowValue();
self.fireEvent(MultiSelectInsertCombo.EVENT_CLICK_ITEM);
});
} }
); self._dataChange = true;
this.trigger.on( });
MultiSelectInsertTrigger.EVENT_COUNTER_CLICK, this.trigger.on(MultiSelectInsertTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, () => {
() => { // counter的值随点击项的改变而改变, 点击counter的时候不需要setValue(counter会请求刷新计数)
if (!self.combo.isViewVisible()) { // 只需要更新查看面板的selectedValue用以请求已选数据
self.combo.showView(); self.numberCounter.updateSelectedValue(self.storeValue);
} });
this.trigger.on(MultiSelectInsertTrigger.EVENT_COUNTER_CLICK, () => {
if (!self.combo.isViewVisible()) {
self.combo.showView();
} }
); });
this.combo = createWidget({ this.combo = createWidget({
type: Combo.xtype, type: Combo.xtype,
@ -202,7 +187,7 @@ export class MultiSelectInsertCombo extends Single {
adjustLength: 1, adjustLength: 1,
container: o.container, container: o.container,
popup: { popup: {
type: "bi.multi_select_popup_view", type: MultiSelectPopupView.xtype,
ref() { ref() {
self.popup = this; self.popup = this;
self.trigger.setAdapter(this); self.trigger.setAdapter(this);
@ -217,9 +202,7 @@ export class MultiSelectInsertCombo extends Single {
self._adjust(() => { self._adjust(() => {
assertShowValue(); assertShowValue();
}); });
self.fireEvent( self.fireEvent(MultiSelectInsertCombo.EVENT_CLICK_ITEM);
MultiSelectInsertCombo.EVENT_CLICK_ITEM
);
}, },
}, },
{ {
@ -276,8 +259,7 @@ export class MultiSelectInsertCombo extends Single {
if (self.requesting === true) { if (self.requesting === true) {
self.wants2Quit = true; self.wants2Quit = true;
} else { } else {
self._dataChange && self._dataChange && self.fireEvent(MultiSelectInsertCombo.EVENT_CONFIRM);
self.fireEvent(MultiSelectInsertCombo.EVENT_CONFIRM);
} }
}); });
@ -304,39 +286,28 @@ export class MultiSelectInsertCombo extends Single {
itemsCreator: bind(this._itemsCreator4Trigger, this), itemsCreator: bind(this._itemsCreator4Trigger, this),
value: o.value, value: o.value,
}); });
this.numberCounter.on( this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, () => {
MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, if (!self.combo.isViewVisible()) {
() => { self.combo.showView();
if (!self.combo.isViewVisible()) {
self.combo.showView();
}
}
);
this.numberCounter.on(
MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW,
function () {
this.updateSelectedValue(self.storeValue);
} }
); });
this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW, function () {
this.updateSelectedValue(self.storeValue);
});
this.numberCounter.on(Events.VIEW, b => { this.numberCounter.on(Events.VIEW, b => {
nextTick(() => { nextTick(() => {
// 自动调整宽度 // 自动调整宽度
self.trigger.refreshPlaceHolderWidth( self.trigger.refreshPlaceHolderWidth(b === true ? self.numberCounter.element.outerWidth() + 8 : 0);
b === true ? self.numberCounter.element.outerWidth() + 8 : 0
);
}); });
}); });
this.numberCounter.on( this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW, () => {
MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW, nextTick(() => {
() => { // 收起时自动调整宽度
nextTick(() => { self.trigger.refreshPlaceHolderWidth(0);
// 收起时自动调整宽度 });
self.trigger.refreshPlaceHolderWidth(0); });
});
}
);
this.trigger.element.click(e => { this.trigger.element.click(e => {
if (self.trigger.element.find(e.target).length > 0) { if (self.trigger.element.find(e.target).length > 0) {
@ -467,8 +438,7 @@ export class MultiSelectInsertCombo extends Single {
const v = obj.value; const v = obj.value;
if (isNotNull(tempMap[v])) { if (isNotNull(tempMap[v])) {
change = true; change = true;
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(tempMap[v]);
self.storeValue.assist.push(tempMap[v]);
delete tempMap[v]; delete tempMap[v];
} }
}); });
@ -490,8 +460,7 @@ export class MultiSelectInsertCombo extends Single {
const newItems = []; const newItems = [];
each(items, (i, item) => { each(items, (i, item) => {
if (isNotNull(selectedMap[items[i]])) { if (isNotNull(selectedMap[items[i]])) {
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(selectedMap[items[i]]);
self.storeValue.assist.push(selectedMap[items[i]]);
delete selectedMap[items[i]]; delete selectedMap[items[i]];
} }
if (isNull(notSelectedMap[items[i]])) { if (isNull(notSelectedMap[items[i]])) {
@ -512,8 +481,7 @@ export class MultiSelectInsertCombo extends Single {
function adjust() { function adjust() {
if (self.wants2Quit === true) { if (self.wants2Quit === true) {
self._dataChange && self._dataChange && self.fireEvent(MultiSelectInsertCombo.EVENT_CONFIRM);
self.fireEvent(MultiSelectInsertCombo.EVENT_CONFIRM);
self.wants2Quit = false; self.wants2Quit = false;
} }
self.requesting = false; self.requesting = false;
@ -538,8 +506,7 @@ export class MultiSelectInsertCombo extends Single {
each(res.assist, (i, v) => { each(res.assist, (i, v) => {
if (isNotNull(map[v])) { if (isNotNull(map[v])) {
change = true; change = true;
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(map[v]);
self.storeValue.assist.push(map[v]);
delete map[v]; delete map[v];
} }
}); });

155
src/widget/multiselect/multiselect.insert.combo.nobar.js

@ -24,7 +24,10 @@ import {
values, values,
filter, filter,
contains, contains,
isNull, endWith, pushDistinct, Selection isNull,
endWith,
pushDistinct,
Selection
} from "@/core"; } from "@/core";
import { Single, Combo, Msg } from "@/base"; import { Single, Combo, Msg } from "@/base";
import { MultiSelectInsertTrigger } from "./multiselect.insert.trigger"; import { MultiSelectInsertTrigger } from "./multiselect.insert.trigger";
@ -116,69 +119,51 @@ export class MultiSelectInsertNoBarCombo extends Single {
}); });
this.trigger.on(MultiSelectInsertTrigger.EVENT_PAUSE, function () { this.trigger.on(MultiSelectInsertTrigger.EVENT_PAUSE, function () {
self._addItem(assertShowValue, true); self._addItem(assertShowValue, true);
self.fireEvent( self.fireEvent(MultiSelectInsertNoBarCombo.EVENT_ADD_ITEM, this.getSearcher().getKeyword());
MultiSelectInsertNoBarCombo.EVENT_ADD_ITEM,
this.getSearcher().getKeyword()
);
}); });
this.trigger.on( this.trigger.on(MultiSelectInsertTrigger.EVENT_SEARCHING, function (keywords) {
MultiSelectInsertTrigger.EVENT_SEARCHING, const lastKeyword = last(keywords);
function (keywords) { keywords = initial(keywords || []);
const lastKeyword = last(keywords); if (keywords.length > 0) {
keywords = initial(keywords || []); self._joinKeywords(keywords, () => {
if (keywords.length > 0) { if (endWith(lastKeyword, BI.BlankSplitChar)) {
self._joinKeywords(keywords, () => { self.combo.setValue(self.storeValue);
if (endWith(lastKeyword, BI.BlankSplitChar)) {
self.combo.setValue(self.storeValue);
assertShowValue();
self.combo.populate();
self._setStartValue("");
} else {
self.combo.setValue(self.storeValue);
assertShowValue();
}
self._dataChange = true;
});
this.getSearcher().getKeywordsLength() > 2000 &&
Msg.alert(
i18nText("BI-Basic_Prompt"),
i18nText("BI-Basic_Too_Much_Value_Get_Two_Thousand")
);
}
}
);
this.trigger.on(
MultiSelectInsertTrigger.EVENT_CHANGE,
function (value, obj) {
if (obj instanceof MultiSelectBar) {
self._joinAll(this.getValue(), () => {
assertShowValue(); assertShowValue();
}); self.combo.populate();
} else { self._setStartValue("");
self._join(this.getValue(), () => { } else {
self.combo.setValue(self.storeValue);
assertShowValue(); assertShowValue();
}); }
} self._dataChange = true;
self._dataChange = true; });
this.getSearcher().getKeywordsLength() > 2000 &&
Msg.alert(i18nText("BI-Basic_Prompt"), i18nText("BI-Basic_Too_Much_Value_Get_Two_Thousand"));
} }
); });
this.trigger.on(
MultiSelectInsertTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, this.trigger.on(MultiSelectInsertTrigger.EVENT_CHANGE, function (value, obj) {
() => { if (obj instanceof MultiSelectBar) {
// counter的值随点击项的改变而改变, 点击counter的时候不需要setValue(counter会请求刷新计数) self._joinAll(this.getValue(), () => {
// 只需要更新查看面板的selectedValue用以请求已选数据 assertShowValue();
self.numberCounter.updateSelectedValue(self.storeValue); });
} else {
self._join(this.getValue(), () => {
assertShowValue();
});
} }
); self._dataChange = true;
this.trigger.on( });
MultiSelectInsertTrigger.EVENT_COUNTER_CLICK, this.trigger.on(MultiSelectInsertTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, () => {
() => { // counter的值随点击项的改变而改变, 点击counter的时候不需要setValue(counter会请求刷新计数)
if (!self.combo.isViewVisible()) { // 只需要更新查看面板的selectedValue用以请求已选数据
self.combo.showView(); self.numberCounter.updateSelectedValue(self.storeValue);
} });
this.trigger.on(MultiSelectInsertTrigger.EVENT_COUNTER_CLICK, () => {
if (!self.combo.isViewVisible()) {
self.combo.showView();
} }
); });
this.combo = createWidget({ this.combo = createWidget({
type: Combo.xtype, type: Combo.xtype,
@ -261,8 +246,7 @@ export class MultiSelectInsertNoBarCombo extends Single {
if (self.requesting === true) { if (self.requesting === true) {
self.wants2Quit = true; self.wants2Quit = true;
} else { } else {
self._dataChange && self._dataChange && self.fireEvent(MultiSelectInsertNoBarCombo.EVENT_CONFIRM);
self.fireEvent(MultiSelectInsertNoBarCombo.EVENT_CONFIRM);
} }
}); });
@ -292,39 +276,28 @@ export class MultiSelectInsertNoBarCombo extends Single {
value: o.value, value: o.value,
}, },
}); });
this.numberCounter.on( this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, () => {
MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, if (!self.combo.isViewVisible()) {
() => { self.combo.showView();
if (!self.combo.isViewVisible()) {
self.combo.showView();
}
}
);
this.numberCounter.on(
MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW,
function () {
this.updateSelectedValue(self.storeValue);
} }
); });
this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW, function () {
this.updateSelectedValue(self.storeValue);
});
this.numberCounter.on(Events.VIEW, b => { this.numberCounter.on(Events.VIEW, b => {
nextTick(() => { nextTick(() => {
// 自动调整宽度 // 自动调整宽度
self.trigger.refreshPlaceHolderWidth( self.trigger.refreshPlaceHolderWidth(b === true ? self.numberCounter.element.outerWidth() + 8 : 0);
b === true ? self.numberCounter.element.outerWidth() + 8 : 0
);
}); });
}); });
this.numberCounter.on( this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW, () => {
MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW, nextTick(() => {
() => { // 收起时自动调整宽度
nextTick(() => { self.trigger.refreshPlaceHolderWidth(0);
// 收起时自动调整宽度 });
self.trigger.refreshPlaceHolderWidth(0); });
});
}
);
this.trigger.element.click(e => { this.trigger.element.click(e => {
if (self.trigger.element.find(e.target).length > 0) { if (self.trigger.element.find(e.target).length > 0) {
@ -455,8 +428,7 @@ export class MultiSelectInsertNoBarCombo extends Single {
const v = obj.value; const v = obj.value;
if (isNotNull(tempMap[v])) { if (isNotNull(tempMap[v])) {
change = true; change = true;
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(tempMap[v]);
self.storeValue.assist.push(tempMap[v]);
delete tempMap[v]; delete tempMap[v];
} }
}); });
@ -478,8 +450,7 @@ export class MultiSelectInsertNoBarCombo extends Single {
const newItems = []; const newItems = [];
each(items, (i, item) => { each(items, (i, item) => {
if (isNotNull(selectedMap[items[i]])) { if (isNotNull(selectedMap[items[i]])) {
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(selectedMap[items[i]]);
self.storeValue.assist.push(selectedMap[items[i]]);
delete selectedMap[items[i]]; delete selectedMap[items[i]];
} }
if (isNull(notSelectedMap[items[i]])) { if (isNull(notSelectedMap[items[i]])) {
@ -500,8 +471,7 @@ export class MultiSelectInsertNoBarCombo extends Single {
function adjust() { function adjust() {
if (self.wants2Quit === true) { if (self.wants2Quit === true) {
self._dataChange && self._dataChange && self.fireEvent(MultiSelectInsertNoBarCombo.EVENT_CONFIRM);
self.fireEvent(MultiSelectInsertNoBarCombo.EVENT_CONFIRM);
self.wants2Quit = false; self.wants2Quit = false;
} }
self.requesting = false; self.requesting = false;
@ -525,8 +495,7 @@ export class MultiSelectInsertNoBarCombo extends Single {
each(res.assist, (i, v) => { each(res.assist, (i, v) => {
if (isNotNull(map[v])) { if (isNotNull(map[v])) {
change = true; change = true;
self.storeValue.assist && self.storeValue.assist && self.storeValue.assist.push(map[v]);
self.storeValue.assist.push(map[v]);
delete map[v]; delete map[v];
} }
}); });

56
src/widget/multiselect/multiselect.insert.trigger.js

@ -1,12 +1,4 @@
import { import { shortcut, extend, emptyFn, createWidget, Layout, HTapeLayout, AbsoluteLayout } from "@/core";
shortcut,
extend,
emptyFn,
createWidget,
Layout,
HTapeLayout,
AbsoluteLayout
} from "@/core";
import { Trigger, Text } from "@/base"; import { Trigger, Text } from "@/base";
import { MultiSelectInsertSearcher } from "./trigger/searcher.multiselect.insert"; import { MultiSelectInsertSearcher } from "./trigger/searcher.multiselect.insert";
@ -69,15 +61,9 @@ export class MultiSelectInsertTrigger extends Trigger {
this.searcher.on(MultiSelectInsertSearcher.EVENT_PAUSE, () => { this.searcher.on(MultiSelectInsertSearcher.EVENT_PAUSE, () => {
self.fireEvent(MultiSelectInsertTrigger.EVENT_PAUSE); self.fireEvent(MultiSelectInsertTrigger.EVENT_PAUSE);
}); });
this.searcher.on( this.searcher.on(MultiSelectInsertSearcher.EVENT_SEARCHING, function () {
MultiSelectInsertSearcher.EVENT_SEARCHING, self.fireEvent(MultiSelectInsertTrigger.EVENT_SEARCHING, arguments);
function () { });
self.fireEvent(
MultiSelectInsertTrigger.EVENT_SEARCHING,
arguments
);
}
);
this.searcher.on(MultiSelectInsertSearcher.EVENT_STOP, () => { this.searcher.on(MultiSelectInsertSearcher.EVENT_STOP, () => {
self.fireEvent(MultiSelectInsertTrigger.EVENT_STOP); self.fireEvent(MultiSelectInsertTrigger.EVENT_STOP);
}); });
@ -115,24 +101,24 @@ export class MultiSelectInsertTrigger extends Trigger {
}); });
!o.allowEdit && !o.allowEdit &&
createWidget({ createWidget({
type: AbsoluteLayout.xtype, type: AbsoluteLayout.xtype,
element: this, element: this,
items: [ items: [
{ {
el: { el: {
type: Text.xtype, type: Text.xtype,
title() { title() {
return self.searcher.getState(); return self.searcher.getState();
},
}, },
}, left: 0,
left: 0, right: 24,
right: 24, top: 0,
top: 0, bottom: 0,
bottom: 0, }
} ],
], });
});
} }
refreshPlaceHolderWidth(width) { refreshPlaceHolderWidth(width) {

60
src/widget/multiselect/multiselect.loader.js

@ -11,7 +11,10 @@ import {
Controller, Controller,
delay, delay,
isNotNull, isNotNull,
Selection, Direction, LogicFactory, pushDistinct Selection,
Direction,
LogicFactory,
pushDistinct
} from "@/core"; } from "@/core";
import { SelectList, MultiSelectBar, MultiSelectItem } from "@/case"; import { SelectList, MultiSelectBar, MultiSelectItem } from "@/case";
import { MultiSelectInnerLoader } from "./loader"; import { MultiSelectInnerLoader } from "./loader";
@ -56,9 +59,7 @@ export class MultiSelectLoader extends Widget {
toolbar: { toolbar: {
type: MultiSelectBar.xtype, type: MultiSelectBar.xtype,
cls: "bi-list-item-active", cls: "bi-list-item-active",
height: height: this.options.itemHeight || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
this.options.itemHeight ||
BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
iconWrapperWidth: 36, iconWrapperWidth: 36,
}, },
el: extend( el: extend(
@ -74,13 +75,12 @@ export class MultiSelectLoader extends Widget {
itemsCreator(op, callback) { itemsCreator(op, callback) {
const startValue = self._startValue; const startValue = self._startValue;
self.storeValue && self.storeValue &&
(op = extend(op || {}, { (op = extend(op || {}, {
selectedValues: selectedValues:
isKey(startValue) && isKey(startValue) && self.storeValue.type === Selection.Multi
self.storeValue.type === Selection.Multi ? self.storeValue.value.concat(startValue)
? self.storeValue.value.concat(startValue) : self.storeValue.value,
: self.storeValue.value, }));
}));
opts.itemsCreator(op, ob => { opts.itemsCreator(op, ob => {
hasNext = ob.hasNext; hasNext = ob.hasNext;
let firstItems = []; let firstItems = [];
@ -92,16 +92,11 @@ export class MultiSelectLoader extends Widget {
text: txt, text: txt,
value: v, value: v,
title: txt, title: txt,
selected: selected: self.storeValue.type === Selection.Multi,
self.storeValue.type === Selection.Multi,
}; };
}); });
if ( if (isKey(self._startValue) && !contains(self.storeValue.value, self._startValue)) {
isKey(self._startValue) && const txt = opts.valueFormatter(startValue) || startValue;
!contains(self.storeValue.value, self._startValue)
) {
const txt =
opts.valueFormatter(startValue) || startValue;
json.unshift({ json.unshift({
text: txt, text: txt,
value: startValue, value: startValue,
@ -111,18 +106,12 @@ export class MultiSelectLoader extends Widget {
} }
firstItems = self._createItems(json); firstItems = self._createItems(json);
} }
callback( callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || "");
firstItems.concat(self._createItems(ob.items)),
ob.keyword || ""
);
if (op.times === 1 && self.storeValue) { if (op.times === 1 && self.storeValue) {
isKey(startValue) && isKey(startValue) &&
(self.storeValue.type === Selection.All (self.storeValue.type === Selection.All
? remove(self.storeValue.value, startValue) ? remove(self.storeValue.value, startValue)
: pushDistinct( : pushDistinct(self.storeValue.value, startValue));
self.storeValue.value,
startValue
));
self.setValue(self.storeValue); self.setValue(self.storeValue);
} }
op.times === 1 && self._scrollToTop(); op.times === 1 && self._scrollToTop();
@ -140,9 +129,7 @@ export class MultiSelectLoader extends Widget {
element: this, element: this,
}, },
LogicFactory.createLogic( LogicFactory.createLogic(
LogicFactory.createLogicTypeByDirection( LogicFactory.createLogicTypeByDirection(Direction.Top),
Direction.Top
),
extend( extend(
{ {
scrolly: true, scrolly: true,
@ -150,10 +137,7 @@ export class MultiSelectLoader extends Widget {
}, },
opts.logic, opts.logic,
{ {
items: LogicFactory.createLogicItemsByDirection( items: LogicFactory.createLogicItemsByDirection(Direction.Top, this.button_group),
Direction.Top,
this.button_group
),
} }
) )
) )
@ -176,9 +160,7 @@ export class MultiSelectLoader extends Widget {
type: MultiSelectItem.xtype, type: MultiSelectItem.xtype,
logic: this.options.logic, logic: this.options.logic,
cls: "bi-list-item-active", cls: "bi-list-item-active",
height: height: this.options.itemHeight || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
this.options.itemHeight ||
BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
selected: allSelected, selected: allSelected,
iconWrapperWidth: 36, iconWrapperWidth: 36,
...item, ...item,

76
src/widget/multiselect/multiselect.loader.nobar.js

@ -81,44 +81,28 @@ export class MultiSelectNoBarLoader extends Widget {
itemsCreator(op, callback) { itemsCreator(op, callback) {
const startValue = self._startValue; const startValue = self._startValue;
self.storeValue && self.storeValue &&
(op = extend(op || {}, { (op = extend(op || {}, {
selectedValues: selectedValues:
isKey(startValue) && isKey(startValue) && self.storeValue.type === Selection.Multi
self.storeValue.type === Selection.Multi ? self.storeValue.value.concat(startValue)
? self.storeValue.value.concat( : self.storeValue.value,
startValue }));
)
: self.storeValue.value,
}));
opts.itemsCreator(op, ob => { opts.itemsCreator(op, ob => {
hasNext = ob.hasNext; hasNext = ob.hasNext;
let firstItems = []; let firstItems = [];
if (op.times === 1 && self.storeValue) { if (op.times === 1 && self.storeValue) {
const json = map( const json = map(self.storeValue.value, (i, v) => {
self.storeValue.value, const txt = opts.valueFormatter(v) || v;
(i, v) => {
const txt = opts.valueFormatter(v) || v; return {
text: txt,
return { value: v,
text: txt, title: txt,
value: v, selected: self.storeValue.type === Selection.Multi,
title: txt, };
selected: });
self.storeValue.type === if (isKey(self._startValue) && !contains(self.storeValue.value, self._startValue)) {
Selection.Multi, const txt = opts.valueFormatter(startValue) || startValue;
};
}
);
if (
isKey(self._startValue) &&
!contains(
self.storeValue.value,
self._startValue
)
) {
const txt =
opts.valueFormatter(startValue) ||
startValue;
json.unshift({ json.unshift({
text: txt, text: txt,
value: startValue, value: startValue,
@ -128,21 +112,12 @@ export class MultiSelectNoBarLoader extends Widget {
} }
firstItems = self._createItems(json); firstItems = self._createItems(json);
} }
callback( callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || "");
firstItems.concat(self._createItems(ob.items)),
ob.keyword || ""
);
if (op.times === 1 && self.storeValue) { if (op.times === 1 && self.storeValue) {
isKey(startValue) && isKey(startValue) &&
(self.storeValue.type === Selection.All (self.storeValue.type === Selection.All
? remove( ? remove(self.storeValue.value, startValue)
self.storeValue.value, : pushDistinct(self.storeValue.value, startValue));
startValue
)
: pushDistinct(
self.storeValue.value,
startValue
));
self.setValue(self.storeValue); self.setValue(self.storeValue);
} }
op.times === 1 && self._scrollToTop(); op.times === 1 && self._scrollToTop();
@ -178,9 +153,7 @@ export class MultiSelectNoBarLoader extends Widget {
type: MultiSelectItem.xtype, type: MultiSelectItem.xtype,
cls: "bi-list-item-active", cls: "bi-list-item-active",
logic: this.options.logic, logic: this.options.logic,
height: height: this.options.itemHeight || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
this.options.itemHeight ||
BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
iconWrapperWidth: 36, iconWrapperWidth: 36,
...item, ...item,
...this.options.itemFormatter(item), ...this.options.itemFormatter(item),
@ -237,6 +210,5 @@ export class MultiSelectNoBarLoader extends Widget {
this.button_group.element.css({ "max-height": toPix(h) }); this.button_group.element.css({ "max-height": toPix(h) });
} }
resetWidth() { resetWidth() {}
}
} }

36
src/widget/multiselect/multiselect.popup.view.js

@ -1,11 +1,4 @@
import { import { shortcut, Widget, extend, emptyFn, createWidget, i18nText } from "@/core";
shortcut,
Widget,
extend,
emptyFn,
createWidget,
i18nText
} from "@/core";
import { MultiPopupView } from "@/case"; import { MultiPopupView } from "@/case";
import { MultiSelectLoader } from "./multiselect.loader"; import { MultiSelectLoader } from "./multiselect.loader";
@ -60,23 +53,18 @@ export class MultiSelectPopupView extends Widget {
this.popupView.on(MultiPopupView.EVENT_CHANGE, () => { this.popupView.on(MultiPopupView.EVENT_CHANGE, () => {
self.fireEvent(MultiSelectPopupView.EVENT_CHANGE); self.fireEvent(MultiSelectPopupView.EVENT_CHANGE);
}); });
this.popupView.on( this.popupView.on(MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, index => {
MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, switch (index) {
index => { case 0:
switch (index) { self.fireEvent(MultiSelectPopupView.EVENT_CLICK_CLEAR);
case 0: break;
self.fireEvent(MultiSelectPopupView.EVENT_CLICK_CLEAR); case 1:
break; self.fireEvent(MultiSelectPopupView.EVENT_CLICK_CONFIRM);
case 1: break;
self.fireEvent( default:
MultiSelectPopupView.EVENT_CLICK_CONFIRM break;
);
break;
default:
break;
}
} }
); });
} }
isAllSelected() { isAllSelected() {

34
src/widget/multiselect/multiselect.popup.view.nobar.js

@ -1,11 +1,4 @@
import { import { shortcut, Widget, extend, emptyFn, createWidget, i18nText } from "@/core";
shortcut,
Widget,
extend,
emptyFn,
createWidget,
i18nText
} from "@/core";
import { MultiPopupView } from "@/case"; import { MultiPopupView } from "@/case";
import { MultiSelectNoBarLoader } from "./multiselect.loader.nobar"; import { MultiSelectNoBarLoader } from "./multiselect.loader.nobar";
@ -60,23 +53,16 @@ export class MultiSelectNoBarPopupView extends Widget {
this.popupView.on(MultiPopupView.EVENT_CHANGE, () => { this.popupView.on(MultiPopupView.EVENT_CHANGE, () => {
self.fireEvent(MultiSelectNoBarPopupView.EVENT_CHANGE); self.fireEvent(MultiSelectNoBarPopupView.EVENT_CHANGE);
}); });
this.popupView.on( this.popupView.on(MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, index => {
MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, switch (index) {
index => { case 0:
switch (index) { self.fireEvent(MultiSelectNoBarPopupView.EVENT_CLICK_CLEAR);
case 0: break;
self.fireEvent( case 1:
MultiSelectNoBarPopupView.EVENT_CLICK_CLEAR self.fireEvent(MultiSelectNoBarPopupView.EVENT_CLICK_CONFIRM);
); break;
break;
case 1:
self.fireEvent(
MultiSelectNoBarPopupView.EVENT_CLICK_CONFIRM
);
break;
}
} }
); });
} }
setStartValue(v) { setStartValue(v) {

57
src/widget/multiselect/multiselect.trigger.js

@ -1,13 +1,4 @@
import { import { shortcut, extend, emptyFn, createWidget, isFunction, Layout, HTapeLayout, AbsoluteLayout } from "@/core";
shortcut,
extend,
emptyFn,
createWidget,
isFunction,
Layout,
HTapeLayout,
AbsoluteLayout
} from "@/core";
import { Trigger, Text } from "@/base"; import { Trigger, Text } from "@/base";
import { MultiSelectSearcher } from "./trigger/searcher.multiselect"; import { MultiSelectSearcher } from "./trigger/searcher.multiselect";
@ -103,30 +94,30 @@ export class MultiSelectTrigger extends Trigger {
}); });
!o.allowEdit && !o.allowEdit &&
createWidget({ createWidget({
type: AbsoluteLayout.xtype, type: AbsoluteLayout.xtype,
element: this, element: this,
items: [ items: [
{ {
el: { el: {
type: Text.xtype, type: Text.xtype,
title() { title() {
/** 修正REPORT-73699引入,需要考虑到传递过来的值是方法的情况 */ /** 修正REPORT-73699引入,需要考虑到传递过来的值是方法的情况 */
const state = self.searcher.getState(); const state = self.searcher.getState();
if (isFunction(state)) { if (isFunction(state)) {
return state(); return state();
} }
return state; return state;
},
}, },
}, left: 0,
left: 0, right: 24,
right: 24, top: 0,
top: 0, bottom: 0,
bottom: 0, }
} ],
], });
});
} }
refreshPlaceHolderWidth(width) { refreshPlaceHolderWidth(width) {

14
src/widget/multiselect/search/multiselect.search.insert.pane.js

@ -1,12 +1,4 @@
import { import { shortcut, Widget, extend, emptyFn, createWidget, i18nText, Controller, VerticalFillLayout } from "@/core";
shortcut,
Widget,
extend,
emptyFn,
createWidget,
i18nText,
Controller, VerticalFillLayout
} from "@/core";
import { Label } from "@/base"; import { Label } from "@/base";
import { MultiSelectSearchLoader } from "./multiselect.search.loader"; import { MultiSelectSearchLoader } from "./multiselect.search.loader";
@ -78,9 +70,7 @@ export class MultiSelectSearchInsertPane extends Widget {
} }
setKeyword(keyword) { setKeyword(keyword) {
this.addNotMatchTip.setText( this.addNotMatchTip.setText(i18nText("BI-Basic_Press_Enter_To_Add_Text", keyword));
i18nText("BI-Basic_Press_Enter_To_Add_Text", keyword)
);
} }
isAllSelected() { isAllSelected() {

16
src/widget/multiselect/search/multiselect.search.loader.js

@ -77,9 +77,9 @@ export class MultiSelectSearchLoader extends Widget {
}, },
itemsCreator(op, callback) { itemsCreator(op, callback) {
self.storeValue && self.storeValue &&
(op = extend(op || {}, { (op = extend(op || {}, {
selectedValues: self.storeValue.value, selectedValues: self.storeValue.value,
})); }));
opts.itemsCreator(op, ob => { opts.itemsCreator(op, ob => {
const keyword = (ob.keyword = opts.keywordGetter()); const keyword = (ob.keyword = opts.keywordGetter());
hasNext = ob.hasNext; hasNext = ob.hasNext;
@ -91,11 +91,7 @@ export class MultiSelectSearchLoader extends Widget {
const context = { const context = {
tipText: ob.tipText, tipText: ob.tipText,
}; };
callback( callback(firstItems.concat(self._createItems(ob.items)), keyword, context);
firstItems.concat(self._createItems(ob.items)),
keyword,
context
);
if (op.times === 1 && self.storeValue) { if (op.times === 1 && self.storeValue) {
self.setValue(self.storeValue); self.setValue(self.storeValue);
} }
@ -123,9 +119,7 @@ export class MultiSelectSearchLoader extends Widget {
logic: { logic: {
dynamic: false, dynamic: false,
}, },
height: height: this.options.itemHeight || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
this.options.itemHeight ||
BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
selected: allSelected, selected: allSelected,
cls: "bi-list-item-active", cls: "bi-list-item-active",
iconWrapperWidth: 36, iconWrapperWidth: 36,

13
src/widget/multiselect/search/multiselect.search.pane.js

@ -1,12 +1,4 @@
import { import { shortcut, Widget, extend, emptyFn, createWidget, Controller, AbsoluteLayout } from "@/core";
shortcut,
Widget,
extend,
emptyFn,
createWidget,
Controller,
AbsoluteLayout
} from "@/core";
import { MultiSelectSearchLoader } from "./multiselect.search.loader"; import { MultiSelectSearchLoader } from "./multiselect.search.loader";
@shortcut() @shortcut()
@ -71,8 +63,7 @@ export class MultiSelectSearchPane extends Widget {
return this.loader.isAllSelected(); return this.loader.isAllSelected();
} }
hasMatched() { hasMatched() {}
}
setValue(v) { setValue(v) {
this.loader.setValue(v); this.loader.setValue(v);

8
src/widget/multiselect/trigger/button.checkselected.js

@ -44,10 +44,7 @@ export class MultiSelectCheckSelectedButton extends Single {
}); });
this.numberCounter.on(TextButton.EVENT_CHANGE, function () { this.numberCounter.on(TextButton.EVENT_CHANGE, function () {
self.fireEvent( self.fireEvent(MultiSelectCheckSelectedButton.EVENT_CHANGE, arguments);
MultiSelectCheckSelectedButton.EVENT_CHANGE,
arguments
);
}); });
this.numberCounter.element.hover( this.numberCounter.element.hover(
@ -119,6 +116,5 @@ export class MultiSelectCheckSelectedButton extends Single {
this._populate(this._assertValue(this.options.value)); this._populate(this._assertValue(this.options.value));
} }
getValue() { getValue() {}
}
} }

11
src/widget/multiselect/trigger/editor.multiselect.js

@ -1,13 +1,4 @@
import { import { shortcut, Widget, extend, i18nText, createWidget, Controller, isEmptyString, isEmptyArray } from "@/core";
shortcut,
Widget,
extend,
i18nText,
createWidget,
Controller,
isEmptyString,
isEmptyArray
} from "@/core";
import { StateEditor } from "@/case"; import { StateEditor } from "@/case";
import { SelectPatchEditor } from "./editor/editor.patch"; import { SelectPatchEditor } from "./editor/editor.patch";

24
src/widget/multiselect/trigger/editor/editor.patch.js

@ -8,7 +8,8 @@ import {
contains, contains,
isKey, isKey,
Events, Events,
trim, replaceAll trim,
replaceAll
} from "@/core"; } from "@/core";
import { Editor, TextAreaEditor } from "@/base"; import { Editor, TextAreaEditor } from "@/base";
import { StateEditor } from "@/case"; import { StateEditor } from "@/case";
@ -79,20 +80,14 @@ export class SelectPatchEditor extends Widget {
{ {
eventName: Editor.EVENT_FOCUS, eventName: Editor.EVENT_FOCUS,
action() { action() {
self.fireEvent( self.fireEvent(SelectPatchEditor.EVENT_FOCUS, arguments);
SelectPatchEditor.EVENT_FOCUS,
arguments
);
}, },
}, },
{ {
eventName: Editor.EVENT_BLUR, eventName: Editor.EVENT_BLUR,
action() { action() {
self._start = false; self._start = false;
self.fireEvent( self.fireEvent(SelectPatchEditor.EVENT_BLUR, arguments);
SelectPatchEditor.EVENT_BLUR,
arguments
);
}, },
} }
], ],
@ -119,18 +114,11 @@ export class SelectPatchEditor extends Widget {
if ( if (
!this._start || !this._start ||
!isKey(this._lastValue) || !isKey(this._lastValue) ||
(this._pause === true && (this._pause === true && this._trimValue(this._lastValue) !== this._trimValue(value))
this._trimValue(this._lastValue) !==
this._trimValue(value))
) { ) {
this._start = true; this._start = true;
this._pause = false; this._pause = false;
this.fireEvent( this.fireEvent(Controller.EVENT_CHANGE, Events.STARTEDIT, this.getValue(), this);
Controller.EVENT_CHANGE,
Events.STARTEDIT,
this.getValue(),
this
);
} }
} }
if (this._trimValue(this._lastValue) !== this._trimValue(value)) { if (this._trimValue(this._lastValue) !== this._trimValue(value)) {

37
src/widget/multiselect/trigger/searcher.multiselect.insert.js

@ -1,15 +1,4 @@
import { import { shortcut, Widget, extend, emptyFn, i18nText, createWidget, isNotNull, isEmptyArray, size, each } from "@/core";
shortcut,
Widget,
extend,
emptyFn,
i18nText,
createWidget,
isNotNull,
isEmptyArray,
size,
each
} from "@/core";
import { MultiSelectEditor } from "./editor.multiselect"; import { MultiSelectEditor } from "./editor.multiselect";
import { Searcher } from "@/base"; import { Searcher } from "@/base";
import { MultiSelectSearchInsertPane } from "../search/multiselect.search.insert.pane"; import { MultiSelectSearchInsertPane } from "../search/multiselect.search.insert.pane";
@ -121,9 +110,7 @@ export class MultiSelectInsertSearcher extends Widget {
const keywords = this.getKeywords(); const keywords = this.getKeywords();
self.fireEvent( self.fireEvent(
MultiSelectInsertSearcher.EVENT_SEARCHING, MultiSelectInsertSearcher.EVENT_SEARCHING,
keywords.length > 2000 keywords.length > 2000 ? keywords.slice(0, 2000).concat([BI.BlankSplitChar]) : keywords.slice(0, 2000)
? keywords.slice(0, 2000).concat([BI.BlankSplitChar])
: keywords.slice(0, 2000)
); );
}); });
if (isNotNull(o.value)) { if (isNotNull(o.value)) {
@ -146,9 +133,7 @@ export class MultiSelectInsertSearcher extends Widget {
getKeywordsLength() { getKeywordsLength() {
const keywords = this.editor.getKeywords(); const keywords = this.editor.getKeywords();
return keywords[keywords.length - 1] === BI.BlankSplitChar return keywords[keywords.length - 1] === BI.BlankSplitChar ? keywords.length - 1 : keywords.length;
? keywords.length - 1
: keywords.length;
} }
getKeyword() { getKeyword() {
@ -184,13 +169,9 @@ export class MultiSelectInsertSearcher extends Widget {
state = ""; state = "";
each(ob.assist, (i, v) => { each(ob.assist, (i, v) => {
if (i === 0) { if (i === 0) {
state += state += `${v === null ? "" : o.valueFormatter(`${v}`) || v}`;
`${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
} else { } else {
state += state += `,${v === null ? "" : o.valueFormatter(`${v}`) || v}`;
`,${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
} }
}); });
this.editor.setState(state); this.editor.setState(state);
@ -204,13 +185,9 @@ export class MultiSelectInsertSearcher extends Widget {
state = ""; state = "";
each(ob.value, (i, v) => { each(ob.value, (i, v) => {
if (i === 0) { if (i === 0) {
state += state += `${v === null ? "" : o.valueFormatter(`${v}`) || v}`;
`${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
} else { } else {
state += state += `,${v === null ? "" : o.valueFormatter(`${v}`) || v}`;
`,${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
} }
}); });
this.editor.setState(state); this.editor.setState(state);

28
src/widget/multiselect/trigger/searcher.multiselect.js

@ -1,14 +1,4 @@
import { import { shortcut, Widget, extend, emptyFn, i18nText, createWidget, isNotNull, size, each } from "@/core";
shortcut,
Widget,
extend,
emptyFn,
i18nText,
createWidget,
isNotNull,
size,
each
} from "@/core";
import { MultiSelectEditor } from "./editor.multiselect"; import { MultiSelectEditor } from "./editor.multiselect";
import { Searcher } from "@/base"; import { Searcher } from "@/base";
import { MultiSelectSearchPane } from "../search/multiselect.search.pane"; import { MultiSelectSearchPane } from "../search/multiselect.search.pane";
@ -175,13 +165,9 @@ export class MultiSelectSearcher extends Widget {
state = ""; state = "";
each(ob.assist, (i, v) => { each(ob.assist, (i, v) => {
if (i === 0) { if (i === 0) {
state += state += `${v === null ? "" : o.valueFormatter(`${v}`) || v}`;
`${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
} else { } else {
state += state += `,${v === null ? "" : o.valueFormatter(`${v}`) || v}`;
`,${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
} }
}); });
this.editor.setState(state); this.editor.setState(state);
@ -195,13 +181,9 @@ export class MultiSelectSearcher extends Widget {
state = ""; state = "";
each(ob.value, (i, v) => { each(ob.value, (i, v) => {
if (i === 0) { if (i === 0) {
state += state += `${v === null ? "" : o.valueFormatter(`${v}`) || v}`;
`${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
} else { } else {
state += state += `,${v === null ? "" : o.valueFormatter(`${v}`) || v}`;
`,${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
} }
}); });
this.editor.setState(state); this.editor.setState(state);

25
src/widget/multiselect/trigger/switcher.checkselected.js

@ -1,12 +1,4 @@
import { import { shortcut, Widget, extend, emptyFn, createWidget, Events, nextTick } from "@/core";
shortcut,
Widget,
extend,
emptyFn,
createWidget,
Events,
nextTick
} from "@/core";
import { Switcher } from "@/base"; import { Switcher } from "@/base";
import { MultiSelectCheckSelectedButton } from "./button.checkselected"; import { MultiSelectCheckSelectedButton } from "./button.checkselected";
import { MultiSelectCheckPane } from "../check/multiselect.check.pane"; import { MultiSelectCheckPane } from "../check/multiselect.check.pane";
@ -68,19 +60,13 @@ export class MultiSelectCheckSelectedSwitcher extends Widget {
masker: o.masker, masker: o.masker,
}); });
this.switcher.on(Switcher.EVENT_TRIGGER_CHANGE, () => { this.switcher.on(Switcher.EVENT_TRIGGER_CHANGE, () => {
self.fireEvent( self.fireEvent(MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE);
MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE
);
}); });
this.switcher.on(Switcher.EVENT_BEFORE_POPUPVIEW, () => { this.switcher.on(Switcher.EVENT_BEFORE_POPUPVIEW, () => {
self.fireEvent( self.fireEvent(MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW);
MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW
);
}); });
this.switcher.on(Switcher.EVENT_AFTER_HIDEVIEW, () => { this.switcher.on(Switcher.EVENT_AFTER_HIDEVIEW, () => {
self.fireEvent( self.fireEvent(MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW);
MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW
);
}); });
this.switcher.on(Switcher.EVENT_AFTER_POPUPVIEW, function () { this.switcher.on(Switcher.EVENT_AFTER_POPUPVIEW, function () {
const me = this; const me = this;
@ -115,8 +101,7 @@ export class MultiSelectCheckSelectedSwitcher extends Widget {
this.button.setValue(v); this.button.setValue(v);
} }
getValue() { getValue() {}
}
populate(items) { populate(items) {
this.switcher.populate.apply(this.switcher, arguments); this.switcher.populate.apply(this.switcher, arguments);

53
src/widget/multiselectlist/multiselectlist.insert.js

@ -25,7 +25,8 @@ import {
values, values,
filter, filter,
contains, contains,
isNull, VerticalFillLayout isNull,
VerticalFillLayout
} from "@/core"; } from "@/core";
import { Single, Searcher } from "@/base"; import { Single, Searcher } from "@/base";
import { MultiSelectBar } from "@/case"; import { MultiSelectBar } from "@/case";
@ -34,7 +35,6 @@ import { MultiSelectLoader } from "../multiselect/multiselect.loader";
import { MultiSelectSearchInsertPane } from "../multiselect/search/multiselect.search.insert.pane"; import { MultiSelectSearchInsertPane } from "../multiselect/search/multiselect.search.insert.pane";
import { SearchEditor } from "@/widget/editor/editor.search"; import { SearchEditor } from "@/widget/editor/editor.search";
@shortcut() @shortcut()
export class MultiSelectInsertList extends Single { export class MultiSelectInsertList extends Single {
static xtype = "bi.multi_select_insert_list"; static xtype = "bi.multi_select_insert_list";
@ -62,9 +62,9 @@ export class MultiSelectInsertList extends Single {
function assertShowValue() { function assertShowValue() {
isKey(self._startValue) && isKey(self._startValue) &&
(self.storeValue.type === Selection.All (self.storeValue.type === Selection.All
? remove(self.storeValue.value, self._startValue) ? remove(self.storeValue.value, self._startValue)
: pushDistinct(self.storeValue.value, self._startValue)); : pushDistinct(self.storeValue.value, self._startValue));
// self.trigger.setValue(self.storeValue); // self.trigger.setValue(self.storeValue);
} }
@ -152,14 +152,10 @@ export class MultiSelectInsertList extends Single {
eventName: Searcher.EVENT_PAUSE, eventName: Searcher.EVENT_PAUSE,
action() { action() {
let keywords = self._getKeywords(); let keywords = self._getKeywords();
if ( if (keywords[keywords.length - 1] === BI.BlankSplitChar) {
keywords[keywords.length - 1] === BI.BlankSplitChar
) {
keywords = keywords.slice(0, keywords.length - 1); keywords = keywords.slice(0, keywords.length - 1);
} }
const keyword = isEmptyArray(keywords) const keyword = isEmptyArray(keywords) ? "" : keywords[keywords.length - 1];
? ""
: keywords[keywords.length - 1];
self._join( self._join(
{ {
type: Selection.Multi, type: Selection.Multi,
@ -167,10 +163,7 @@ export class MultiSelectInsertList extends Single {
}, },
() => { () => {
if (self.storeValue.type === Selection.Multi) { if (self.storeValue.type === Selection.Multi) {
pushDistinct( pushDistinct(self.storeValue.value, keyword);
self.storeValue.value,
keyword
);
} }
self._showAdapter(); self._showAdapter();
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
@ -178,9 +171,7 @@ export class MultiSelectInsertList extends Single {
assertShowValue(); assertShowValue();
self.adapter.populate(); self.adapter.populate();
self._setStartValue(""); self._setStartValue("");
self.fireEvent( self.fireEvent(MultiSelectInsertList.EVENT_CHANGE);
MultiSelectInsertList.EVENT_CHANGE
);
} }
); );
self._showAdapter(); self._showAdapter();
@ -203,17 +194,13 @@ export class MultiSelectInsertList extends Single {
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue(); assertShowValue();
} }
self.fireEvent( self.fireEvent(MultiSelectInsertList.EVENT_CHANGE);
MultiSelectInsertList.EVENT_CHANGE
);
}); });
self._getKeywordsLength() > 2000 && self._getKeywordsLength() > 2000 &&
BI.Msg.alert( BI.Msg.alert(
i18nText("BI-Basic_Prompt"), i18nText("BI-Basic_Prompt"),
i18nText( i18nText("BI-Basic_Too_Much_Value_Get_Two_Thousand")
"BI-Basic_Too_Much_Value_Get_Two_Thousand" );
)
);
} }
}, },
}, },
@ -223,16 +210,12 @@ export class MultiSelectInsertList extends Single {
if (obj instanceof MultiSelectBar) { if (obj instanceof MultiSelectBar) {
self._joinAll(this.getValue(), () => { self._joinAll(this.getValue(), () => {
assertShowValue(); assertShowValue();
self.fireEvent( self.fireEvent(MultiSelectInsertList.EVENT_CHANGE);
MultiSelectInsertList.EVENT_CHANGE
);
}); });
} else { } else {
self._join(this.getValue(), () => { self._join(this.getValue(), () => {
assertShowValue(); assertShowValue();
self.fireEvent( self.fireEvent(MultiSelectInsertList.EVENT_CHANGE);
MultiSelectInsertList.EVENT_CHANGE
);
}); });
} }
}, },
@ -279,9 +262,7 @@ export class MultiSelectInsertList extends Single {
keywords = keywords.concat([BI.BlankSplitChar]); keywords = keywords.concat([BI.BlankSplitChar]);
} }
return keywords.length > 2000 return keywords.length > 2000 ? keywords.slice(0, 2000).concat([BI.BlankSplitChar]) : keywords.slice(0, 2000);
? keywords.slice(0, 2000).concat([BI.BlankSplitChar])
: keywords.slice(0, 2000);
} }
_getKeywordsLength() { _getKeywordsLength() {

53
src/widget/multiselectlist/multiselectlist.insert.nobar.js

@ -25,7 +25,8 @@ import {
values, values,
filter, filter,
contains, contains,
isNull, VTapeLayout isNull,
VTapeLayout
} from "@/core"; } from "@/core";
import { Single, Searcher, Msg } from "@/base"; import { Single, Searcher, Msg } from "@/base";
import { MultiSelectBar } from "@/case"; import { MultiSelectBar } from "@/case";
@ -34,7 +35,6 @@ import { MultiSelectNoBarLoader } from "../multiselect/multiselect.loader.nobar"
import { MultiSelectSearchInsertPane } from "../multiselect/search/multiselect.search.insert.pane"; import { MultiSelectSearchInsertPane } from "../multiselect/search/multiselect.search.insert.pane";
import { SearchEditor } from "../editor/editor.search"; import { SearchEditor } from "../editor/editor.search";
@shortcut() @shortcut()
export class MultiSelectInsertNoBarList extends Single { export class MultiSelectInsertNoBarList extends Single {
static xtype = "bi.multi_select_insert_no_bar_list"; static xtype = "bi.multi_select_insert_no_bar_list";
@ -64,9 +64,9 @@ export class MultiSelectInsertNoBarList extends Single {
function assertShowValue() { function assertShowValue() {
isKey(self._startValue) && isKey(self._startValue) &&
(self.storeValue.type === Selection.All (self.storeValue.type === Selection.All
? remove(self.storeValue.value, self._startValue) ? remove(self.storeValue.value, self._startValue)
: pushDistinct(self.storeValue.value, self._startValue)); : pushDistinct(self.storeValue.value, self._startValue));
// self.trigger.setValue(self.storeValue); // self.trigger.setValue(self.storeValue);
} }
@ -155,14 +155,10 @@ export class MultiSelectInsertNoBarList extends Single {
eventName: Searcher.EVENT_PAUSE, eventName: Searcher.EVENT_PAUSE,
action() { action() {
let keywords = self._getKeywords(); let keywords = self._getKeywords();
if ( if (keywords[keywords.length - 1] === BI.BlankSplitChar) {
keywords[keywords.length - 1] === BI.BlankSplitChar
) {
keywords = keywords.slice(0, keywords.length - 1); keywords = keywords.slice(0, keywords.length - 1);
} }
const keyword = isEmptyArray(keywords) const keyword = isEmptyArray(keywords) ? "" : keywords[keywords.length - 1];
? ""
: keywords[keywords.length - 1];
self._join( self._join(
{ {
type: Selection.Multi, type: Selection.Multi,
@ -170,10 +166,7 @@ export class MultiSelectInsertNoBarList extends Single {
}, },
() => { () => {
if (self.storeValue.type === Selection.Multi) { if (self.storeValue.type === Selection.Multi) {
pushDistinct( pushDistinct(self.storeValue.value, keyword);
self.storeValue.value,
keyword
);
} }
self._showAdapter(); self._showAdapter();
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
@ -181,9 +174,7 @@ export class MultiSelectInsertNoBarList extends Single {
assertShowValue(); assertShowValue();
self.adapter.populate(); self.adapter.populate();
self._setStartValue(""); self._setStartValue("");
self.fireEvent( self.fireEvent(MultiSelectInsertNoBarList.EVENT_CHANGE);
MultiSelectInsertNoBarList.EVENT_CHANGE
);
} }
); );
}, },
@ -205,17 +196,13 @@ export class MultiSelectInsertNoBarList extends Single {
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue(); assertShowValue();
} }
self.fireEvent( self.fireEvent(MultiSelectInsertNoBarList.EVENT_CHANGE);
MultiSelectInsertNoBarList.EVENT_CHANGE
);
}); });
self._getKeywordsLength() > 2000 && self._getKeywordsLength() > 2000 &&
Msg.alert( Msg.alert(
i18nText("BI-Basic_Prompt"), i18nText("BI-Basic_Prompt"),
i18nText( i18nText("BI-Basic_Too_Much_Value_Get_Two_Thousand")
"BI-Basic_Too_Much_Value_Get_Two_Thousand" );
)
);
} }
}, },
}, },
@ -225,16 +212,12 @@ export class MultiSelectInsertNoBarList extends Single {
if (obj instanceof MultiSelectBar) { if (obj instanceof MultiSelectBar) {
self._joinAll(this.getValue(), () => { self._joinAll(this.getValue(), () => {
assertShowValue(); assertShowValue();
self.fireEvent( self.fireEvent(MultiSelectInsertNoBarList.EVENT_CHANGE);
MultiSelectInsertNoBarList.EVENT_CHANGE
);
}); });
} else { } else {
self._join(this.getValue(), () => { self._join(this.getValue(), () => {
assertShowValue(); assertShowValue();
self.fireEvent( self.fireEvent(MultiSelectInsertNoBarList.EVENT_CHANGE);
MultiSelectInsertNoBarList.EVENT_CHANGE
);
}); });
} }
}, },
@ -285,9 +268,7 @@ export class MultiSelectInsertNoBarList extends Single {
keywords = keywords.concat([BI.BlankSplitChar]); keywords = keywords.concat([BI.BlankSplitChar]);
} }
return keywords.length > 2000 return keywords.length > 2000 ? keywords.slice(0, 2000).concat([BI.BlankSplitChar]) : keywords.slice(0, 2000);
? keywords.slice(0, 2000).concat([BI.BlankSplitChar])
: keywords.slice(0, 2000);
} }
_getKeywordsLength() { _getKeywordsLength() {

24
src/widget/multiselectlist/multiselectlist.js

@ -24,7 +24,8 @@ import {
values, values,
filter, filter,
contains, contains,
isNull, VTapeLayout isNull,
VTapeLayout
} from "@/core"; } from "@/core";
import { Searcher } from "@/base"; import { Searcher } from "@/base";
import { MultiSelectBar } from "@/case"; import { MultiSelectBar } from "@/case";
@ -33,7 +34,6 @@ import { MultiSelectSearchPane } from "../multiselect/search/multiselect.search.
import { SelectPatchEditor } from "../multiselect/trigger/editor/editor.patch"; import { SelectPatchEditor } from "../multiselect/trigger/editor/editor.patch";
import { SearchEditor } from "../editor/editor.search"; import { SearchEditor } from "../editor/editor.search";
@shortcut() @shortcut()
export class MultiSelectList extends Widget { export class MultiSelectList extends Widget {
static xtype = "bi.multi_select_list"; static xtype = "bi.multi_select_list";
@ -61,9 +61,9 @@ export class MultiSelectList extends Widget {
function assertShowValue() { function assertShowValue() {
isKey(self._startValue) && isKey(self._startValue) &&
(self.storeValue.type === Selection.All (self.storeValue.type === Selection.All
? remove(self.storeValue.value, self._startValue) ? remove(self.storeValue.value, self._startValue)
: pushDistinct(self.storeValue.value, self._startValue)); : pushDistinct(self.storeValue.value, self._startValue));
// self.trigger.setValue(self.storeValue); // self.trigger.setValue(self.storeValue);
} }
@ -365,18 +365,12 @@ export class MultiSelectList extends Widget {
} }
function adjust() { function adjust() {
if ( if (self.storeValue.type === Selection.All && self.storeValue.value.length >= self._count) {
self.storeValue.type === Selection.All &&
self.storeValue.value.length >= self._count
) {
self.storeValue = { self.storeValue = {
type: Selection.Multi, type: Selection.Multi,
value: [], value: [],
}; };
} else if ( } else if (self.storeValue.type === Selection.Multi && self.storeValue.value.length >= self._count) {
self.storeValue.type === Selection.Multi &&
self.storeValue.value.length >= self._count
) {
self.storeValue = { self.storeValue = {
type: Selection.All, type: Selection.All,
value: [], value: [],
@ -421,9 +415,7 @@ export class MultiSelectList extends Widget {
return this.adapter.isAllSelected(); return this.adapter.isAllSelected();
} }
resize() { resize() {}
}
setValue(v) { setValue(v) {
this.storeValue = v || {}; this.storeValue = v || {};

17
src/widget/multiselecttree/multiselecttree.js

@ -1,11 +1,5 @@
import { import { MultiTreeSearchPane } from "../multitree/trigger/multi.tree.search.pane";
shortcut, import { VerticalFillLayout, shortcut, extend, emptyFn, createWidget, nextTick, AbsoluteLayout } from "@/core";
extend,
emptyFn,
createWidget,
nextTick,
AbsoluteLayout
} from "@/core";
import { Single, Searcher } from "@/base"; import { Single, Searcher } from "@/base";
import { MultiSelectTreePopup } from "./multiselecttree.popup"; import { MultiSelectTreePopup } from "./multiselecttree.popup";
@ -47,7 +41,7 @@ export class MultiSelectTree extends Single {
// 搜索中的时候用的是parttree,同adapter中的synctree不一样 // 搜索中的时候用的是parttree,同adapter中的synctree不一样
this.searcherPane = createWidget({ this.searcherPane = createWidget({
type: "bi.multi_tree_search_pane", type: MultiTreeSearchPane.xtype,
cls: "bi-border-left bi-border-right bi-border-bottom", cls: "bi-border-left bi-border-right bi-border-bottom",
keywordGetter() { keywordGetter() {
return self.searcher.getKeyword(); return self.searcher.getKeyword();
@ -121,7 +115,7 @@ export class MultiSelectTree extends Single {
}); });
createWidget({ createWidget({
type: "bi.vertical_fill", type: VerticalFillLayout.xtype,
element: this, element: this,
items: [ items: [
{ {
@ -159,8 +153,7 @@ export class MultiSelectTree extends Single {
this.adapter.setVisible(false); this.adapter.setVisible(false);
} }
resize() { resize() {}
}
setSelectedValue(v) { setSelectedValue(v) {
this.storeValue.value = v || {}; this.storeValue.value = v || {};

3
src/widget/multiselecttree/multiselecttree.popup.js

@ -10,8 +10,7 @@ export class MultiSelectTreePopup extends Widget {
_defaultConfig() { _defaultConfig() {
return extend(super._defaultConfig(...arguments), { return extend(super._defaultConfig(...arguments), {
baseCls: baseCls: "bi-multi-select-tree-popup bi-border-left bi-border-right bi-border-bottom",
"bi-multi-select-tree-popup bi-border-left bi-border-right bi-border-bottom",
itemsCreator: emptyFn, itemsCreator: emptyFn,
}); });
} }

Loading…
Cancel
Save