Browse Source

KERNEL-14107 refactor: widget/searchmultitextvaluecombo、textvaluedownlistcombo ES6化

es6
impact 1 year ago
parent
commit
d2f320307c
  1. 15
      src/base/combination/searcher.js
  2. 2
      src/base/single/bar/bar.loading.js
  3. 3
      src/case/editor/editor.state.js
  4. 3
      src/case/editor/editor.state.simple.js
  5. 6
      src/widget/index.js
  6. 4
      src/widget/multitree/trigger/searcher.multi.tree.js
  7. 143
      src/widget/searchmultitextvaluecombo/multitextvalue.combo.search.js
  8. 39
      src/widget/searchmultitextvaluecombo/multitextvalue.combo.trigger.search.js
  9. 52
      src/widget/searchmultitextvaluecombo/multitextvalue.loader.search.js
  10. 30
      src/widget/searchmultitextvaluecombo/multitextvalue.popup.view.search.js
  11. 8
      src/widget/searchmultitextvaluecombo/trigger/searcher.multitextvalue.js
  12. 129
      src/widget/textvaluedownlistcombo/combo.textvaluedownlist.js
  13. 2
      src/widget/textvaluedownlistcombo/index.js
  14. 67
      src/widget/textvaluedownlistcombo/trigger.textvaluedownlist.js

15
src/base/combination/searcher.js

@ -13,7 +13,8 @@ import {
deepWithout, deepWithout,
nextTick, nextTick,
isEmptyString, isEmptyString,
isNull isNull,
BlankSplitChar
} from "@/core"; } from "@/core";
import { ButtonGroup } from "./group.button"; import { ButtonGroup } from "./group.button";
import { Maskers } from "@/base/0.base"; import { Maskers } from "@/base/0.base";
@ -109,7 +110,7 @@ export class Searcher extends Widget {
search(); search();
break; break;
case BI.Events.PAUSE: case BI.Events.PAUSE:
if (endWith(this.getValue(), BI.BlankSplitChar)) { if (endWith(this.editor.getValue(), BlankSplitChar)) {
this._pauseSearch(); this._pauseSearch();
} }
break; break;
@ -229,14 +230,14 @@ export class Searcher extends Widget {
keyword, keyword,
selectedValues: adapter && adapter.getValue(), selectedValues: adapter && adapter.getValue(),
}, },
(searchResult, matchResult, ...arg) => { (...args) => {
if (!this._stop && keyword === this.editor.getValue()) { if (!this._stop && keyword === this.editor.getValue()) {
const args = [searchResult, matchResult, ...arg]; const _args = args;
if (args.length > 0) { if (_args.length > 0) {
args.push(keyword); _args.push(keyword);
} }
Maskers.show(this.getName()); Maskers.show(this.getName());
this.popupView.populate.apply(this.popupView, args); this.popupView.populate.apply(this.popupView, _args);
isAutoSync && adapter && adapter.getValue && this.popupView.setValue(adapter.getValue()); isAutoSync && adapter && adapter.getValue && this.popupView.setValue(adapter.getValue());
this.popupView.loaded && this.popupView.loaded(); this.popupView.loaded && this.popupView.loaded();
this.fireEvent(Searcher.EVENT_SEARCHING); this.fireEvent(Searcher.EVENT_SEARCHING);

2
src/base/single/bar/bar.loading.js

@ -26,7 +26,7 @@ export class LoadingBar extends Single {
handler: this.options.handler, handler: this.options.handler,
}); });
this.loaded.on(BI.Controller.EVENT_CHANGE, (...args) => { this.loaded.on(BI.Controller.EVENT_CHANGE, (...args) => {
this.fireEvent(BI.Controller.EVENT_CHANGE, args); this.fireEvent(BI.Controller.EVENT_CHANGE, ...args);
}); });
this.loading = BI.createWidget({ this.loading = BI.createWidget({

3
src/case/editor/editor.state.js

@ -15,7 +15,8 @@ import {
isKey, isKey,
isFunction, isFunction,
isNumber, isNumber,
isEmpty isEmpty,
Selection
} from "@/core"; } from "@/core";
/** /**

3
src/case/editor/editor.state.simple.js

@ -15,7 +15,8 @@ import {
isFunction, isFunction,
isArray, isArray,
isNumber, isNumber,
isEmpty isEmpty,
Selection
} from "@/core"; } from "@/core";
/** /**

6
src/widget/index.js

@ -29,8 +29,9 @@ import { YearInterval } from "./yearinterval/yearinterval";
import * as singleselect from "./singleselect"; import * as singleselect from "./singleselect";
import * as multilayerdownlist from "./multilayerdownlist"; import * as multilayerdownlist from "./multilayerdownlist";
import * as multilayersingletree from "./multilayersingletree"; import * as multilayersingletree from "./multilayersingletree";
import * as textvaluedownlistcombo from "./textvaluedownlistcombo";
import * as searchmultitextvaluecombo from "./searchmultitextvaluecombo"; import * as searchmultitextvaluecombo from "./searchmultitextvaluecombo";
Object.assign(BI, { Object.assign(BI, {
Collapse, Collapse,
...calendar, ...calendar,
@ -63,6 +64,7 @@ Object.assign(BI, {
...singleselect, ...singleselect,
...multilayerdownlist, ...multilayerdownlist,
...multilayersingletree, ...multilayersingletree,
...textvaluedownlistcombo,
...searchmultitextvaluecombo, ...searchmultitextvaluecombo,
}); });
@ -87,6 +89,8 @@ export * from "./searchmultitextvaluecombo";
export * from "./singleselect"; export * from "./singleselect";
export * from "./multilayerdownlist"; export * from "./multilayerdownlist";
export * from "./yearquarter"; export * from "./yearquarter";
export * from "./textvaluedownlistcombo";
export * from "./searchmultitextvaluecombo";
export { export {
Collapse, Collapse,

4
src/widget/multitree/trigger/searcher.multi.tree.js

@ -203,7 +203,7 @@ export class MultiTreeSearcher extends Widget {
function getChildrenNode(ob) { function getChildrenNode(ob) {
let text = ""; let text = "";
const size = size(ob); const _size = size(ob);
let index = 0; let index = 0;
const names = Func.getSortedResult(keys(ob)); const names = Func.getSortedResult(keys(ob));
@ -215,7 +215,7 @@ export class MultiTreeSearcher extends Widget {
? "" ? ""
: o.valueFormatter(`${name}`) || name) + : o.valueFormatter(`${name}`) || name) +
(childNodes === "" ? "" : `:${childNodes}`) + (childNodes === "" ? "" : `:${childNodes}`) +
(index === size ? "" : ","); (index === _size ? "" : ",");
if (childNodes === "") { if (childNodes === "") {
count++; count++;
} }

143
src/widget/searchmultitextvaluecombo/multitextvalue.combo.search.js

@ -1,4 +1,33 @@
import { shortcut, extend, isKey, Selection, remove, last, pushDistinct, deepClone, createWidget, toPix, isNotNull, initial, endWith, bind, nextTick, AbsoluteLayout, contains, map, makeObject, each, values, isNull, Func, isNotEmptyArray, isArray, find } from "@/core"; import {
shortcut,
extend,
isKey,
Selection,
remove,
pushDistinct,
deepClone,
createWidget,
toPix,
isNotNull,
last,
initial,
endWith,
bind,
nextTick,
AbsoluteLayout,
contains,
map,
makeObject,
each,
values,
isNull,
Func,
filter,
isNotEmptyArray,
isArray,
find,
BlankSplitChar
} from "@/core";
import { Single, Combo } from "@/base"; import { Single, Combo } from "@/base";
import { MultiSelectTrigger, MultiSelectPopupView, MultiSelectCombo, SearchMultiSelectTrigger, SearchMultiSelectPopupView } from "@/widget"; import { MultiSelectTrigger, MultiSelectPopupView, MultiSelectCombo, SearchMultiSelectTrigger, SearchMultiSelectPopupView } from "@/widget";
import { MultiSelectBar, TriggerIconButton } from "@/case"; import { MultiSelectBar, TriggerIconButton } from "@/case";
@ -63,12 +92,13 @@ export class SearchMultiTextValueCombo extends Single {
allValueGetter: () => this.allValue, allValueGetter: () => this.allValue,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
itemsCreator: (op, callback) => { itemsCreator: (op, callback) => {
this._itemsCreator(op, res => { this._itemsCreator(op, (res, ...args) => {
if (op.times === 1 && isNotNull(op.keywords)) { if (op.times === 1 && isNotNull(op.keywords)) {
// 预防trigger内部把当前的storeValue改掉 // 预防trigger内部把当前的storeValue改掉
this.trigger.setValue(deepClone(this.getValue())); this.trigger.setValue(deepClone(this.getValue()));
} }
callback.apply(this, ...arguments);
callback.apply(this, [res, ...args]);
}); });
}, },
value: this.storeValue, value: this.storeValue,
@ -77,32 +107,29 @@ export class SearchMultiTextValueCombo extends Single {
this.trigger.on(MultiSelectTrigger.EVENT_START, () => { this.trigger.on(MultiSelectTrigger.EVENT_START, () => {
this._setStartValue(""); this._setStartValue("");
this.getSearcher().setValue(this.storeValue); this.trigger.getSearcher().setValue(this.storeValue);
}); });
this.trigger.on(MultiSelectTrigger.EVENT_STOP, () => { this.trigger.on(MultiSelectTrigger.EVENT_STOP, () => {
this._setStartValue(""); this._setStartValue("");
}); });
this.trigger.on( this.trigger.on(MultiSelectTrigger.EVENT_SEARCHING, keywords => {
MultiSelectTrigger.EVENT_SEARCHING, const _last = last(keywords);
keywords => { keywords = initial(keywords || []);
const lastKeyWord = last(keywords); if (keywords.length > 0) {
keywords = initial(keywords || []); this._joinKeywords(keywords, () => {
if (keywords.length > 0) { if (endWith(_last, BlankSplitChar)) {
this._joinKeywords(keywords, () => { this.combo.setValue(this.storeValue);
if (endWith(lastKeyWord, BI.BlankSplitChar)) { assertShowValue();
this.combo.setValue(this.storeValue); this.combo.populate();
assertShowValue(); this._setStartValue("");
this.combo.populate(); } else {
this._setStartValue(""); this.combo.setValue(this.storeValue);
} else { assertShowValue();
this.combo.setValue(this.storeValue); }
assertShowValue(); this._dataChange = true;
} });
this._dataChange = true;
});
}
} }
); });
this.trigger.on(MultiSelectTrigger.EVENT_CHANGE, (value, obj) => { this.trigger.on(MultiSelectTrigger.EVENT_CHANGE, (value, obj) => {
if (obj instanceof MultiSelectBar) { if (obj instanceof MultiSelectBar) {
@ -116,12 +143,9 @@ export class SearchMultiTextValueCombo extends Single {
} }
this._dataChange = true; this._dataChange = true;
}); });
this.trigger.on( this.trigger.on(MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, () => {
MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, this.trigger.getCounter().setValue(this.storeValue);
() => { });
this.getCounter().setValue(this.storeValue);
}
);
this.trigger.on(MultiSelectTrigger.EVENT_COUNTER_CLICK, () => { this.trigger.on(MultiSelectTrigger.EVENT_COUNTER_CLICK, () => {
if (!this.combo.isViewVisible()) { if (!this.combo.isViewVisible()) {
this.combo.showView(); this.combo.showView();
@ -144,9 +168,9 @@ export class SearchMultiTextValueCombo extends Single {
listeners: [ listeners: [
{ {
eventName: MultiSelectPopupView.EVENT_CHANGE, eventName: MultiSelectPopupView.EVENT_CHANGE,
action :() => { action: () => {
this._dataChange = true; this._dataChange = true;
this.storeValue = this.getValue(); this.storeValue = this.popup.getValue();
this._adjust(() => { this._adjust(() => {
assertShowValue(); assertShowValue();
}); });
@ -154,7 +178,7 @@ export class SearchMultiTextValueCombo extends Single {
}, },
{ {
eventName: MultiSelectPopupView.EVENT_CLICK_CONFIRM, eventName: MultiSelectPopupView.EVENT_CLICK_CONFIRM,
action :() => { action: () => {
this._defaultState(); this._defaultState();
}, },
}, },
@ -183,7 +207,7 @@ export class SearchMultiTextValueCombo extends Single {
}); });
this.combo.on(Combo.EVENT_BEFORE_POPUPVIEW, () => { this.combo.on(Combo.EVENT_BEFORE_POPUPVIEW, () => {
if (!this.isViewVisible()) { if (!this.combo.isViewVisible()) {
this._dataChange = false; // 标记数据是否发生变化 this._dataChange = false; // 标记数据是否发生变化
} }
this.setValue(this.storeValue); this.setValue(this.storeValue);
@ -203,11 +227,11 @@ export class SearchMultiTextValueCombo extends Single {
* 在存在标红的情况如果popover没有发生改变就确认需要同步trigger的值否则对外value值和trigger样式不统一 * 在存在标红的情况如果popover没有发生改变就确认需要同步trigger的值否则对外value值和trigger样式不统一
*/ */
assertShowValue(); assertShowValue();
this._dataChange && this._dataChange && this.fireEvent(SearchMultiTextValueCombo.EVENT_CONFIRM);
this.fireEvent(SearchMultiTextValueCombo.EVENT_CONFIRM);
} }
}); });
triggerBtn.on(TriggerIconButton.EVENT_CHANGE, () => { triggerBtn.on(TriggerIconButton.EVENT_CHANGE, () => {
this.trigger.getCounter().hideView(); this.trigger.getCounter().hideView();
if (this.combo.isViewVisible()) { if (this.combo.isViewVisible()) {
@ -256,8 +280,6 @@ export class SearchMultiTextValueCombo extends Single {
} }
_joinKeywords(keywords, callback) { _joinKeywords(keywords, callback) {
this._assertValue(this.storeValue);
this.requesting = true;
const digest = items => { const digest = items => {
const selectedMap = this._makeMap(items); const selectedMap = this._makeMap(items);
each(keywords, (i, val) => { each(keywords, (i, val) => {
@ -269,6 +291,9 @@ export class SearchMultiTextValueCombo extends Single {
}); });
this._adjust(callback); this._adjust(callback);
}; };
this._assertValue(this.storeValue);
this.requesting = true;
this._itemsCreator( this._itemsCreator(
{ {
type: SearchMultiTextValueCombo.REQ_GET_ALL_DATA, type: SearchMultiTextValueCombo.REQ_GET_ALL_DATA,
@ -290,19 +315,18 @@ export class SearchMultiTextValueCombo extends Single {
keywords: [this.trigger.getKey()], keywords: [this.trigger.getKey()],
}, },
ob => { ob => {
const map = this._makeMap(this.storeValue.value);
const items = map(ob.items, "value"); const items = map(ob.items, "value");
if (this.storeValue.type === res.type) { if (this.storeValue.type === res.type) {
let change = false; let change = false;
const _map = this._makeMap(this.storeValue.value);
each(items, (i, v) => { each(items, (i, v) => {
if (isNotNull(map[v])) { if (isNotNull(_map[v])) {
change = true; change = true;
this.storeValue.assist && this.storeValue.assist && this.storeValue.assist.push(_map[v]);
this.storeValue.assist.push(map[v]); delete _map[v];
delete map[v];
} }
}); });
change && (this.storeValue.value = values(map)); change && (this.storeValue.value = values(_map));
this._adjust(callback); this._adjust(callback);
return; return;
@ -312,8 +336,7 @@ export class SearchMultiTextValueCombo extends Single {
const newItems = []; const newItems = [];
each(items, (i, item) => { each(items, (i, item) => {
if (isNotNull(selectedMap[items[i]])) { if (isNotNull(selectedMap[items[i]])) {
this.storeValue.assist && this.storeValue.assist && this.storeValue.assist.push(selectedMap[items[i]]);
this.storeValue.assist.push(selectedMap[items[i]]);
delete selectedMap[items[i]]; delete selectedMap[items[i]];
} }
if (isNull(notSelectedMap[items[i]])) { if (isNull(notSelectedMap[items[i]])) {
@ -329,18 +352,12 @@ export class SearchMultiTextValueCombo extends Single {
_adjust(callback) { _adjust(callback) {
const adjust = () => { const adjust = () => {
if ( if (this.storeValue.type === Selection.All && this.storeValue.value.length >= this._count) {
this.storeValue.type === Selection.All &&
this.storeValue.value.length >= this._count
) {
this.storeValue = { this.storeValue = {
type: Selection.Multi, type: Selection.Multi,
value: [], value: [],
}; };
} else if ( } else if (this.storeValue.type === Selection.Multi && this.storeValue.value.length >= this._count) {
this.storeValue.type === Selection.Multi &&
this.storeValue.value.length >= this._count
) {
this.storeValue = { this.storeValue = {
type: Selection.All, type: Selection.All,
value: [], value: [],
@ -349,8 +366,7 @@ export class SearchMultiTextValueCombo extends Single {
this._updateAllValue(); this._updateAllValue();
this._checkError(); this._checkError();
if (this.wants2Quit === true) { if (this.wants2Quit === true) {
this._dataChange && this._dataChange && this.fireEvent(SearchMultiTextValueCombo.EVENT_CONFIRM);
this.fireEvent(SearchMultiTextValueCombo.EVENT_CONFIRM);
this.wants2Quit = false; this.wants2Quit = false;
} }
this.requesting = false; this.requesting = false;
@ -388,8 +404,7 @@ export class SearchMultiTextValueCombo extends Single {
each(res.assist, (i, v) => { each(res.assist, (i, v) => {
if (isNotNull(map[v])) { if (isNotNull(map[v])) {
change = true; change = true;
this.storeValue.assist && this.storeValue.assist && this.storeValue.assist.push(map[v]);
this.storeValue.assist.push(map[v]);
delete map[v]; delete map[v];
} }
}); });
@ -432,17 +447,17 @@ export class SearchMultiTextValueCombo extends Single {
}); });
if (options.selectedValues) { if (options.selectedValues) {
// 过滤 // 过滤
const filter = makeObject(options.selectedValues, true); const _filter = makeObject(options.selectedValues, true);
items = filter(items, (i, ob) => !filter[ob.value]); items = filter(items, (i, ob) => !_filter[ob.value]);
} }
if (options.type === MultiSelectCombo.REQ_GET_ALL_DATA) { if (options.type == MultiSelectCombo.REQ_GET_ALL_DATA) {
callback({ callback({
items, items,
}); });
return; return;
} }
if (options.type === MultiSelectCombo.REQ_GET_DATA_LENGTH) { if (options.type == MultiSelectCombo.REQ_GET_DATA_LENGTH) {
callback({ count: items.length }); callback({ count: items.length });
return; return;
@ -503,7 +518,3 @@ export class SearchMultiTextValueCombo extends Single {
this._populate(); this._populate();
} }
} }
extend(SearchMultiTextValueCombo, {
REQ_GET_DATA_LENGTH: 1,
REQ_GET_ALL_DATA: -1,
});

39
src/widget/searchmultitextvaluecombo/multitextvalue.combo.trigger.search.js

@ -1,4 +1,4 @@
import { shortcut, extend, emptyFn, createWidget, Events, nextTick, HTapeLayout, RightVerticalAdaptLayout } from "@/core"; import { shortcut, extend, emptyFn, createWidget, Events, nextTick, HTapeLayout, RightVerticalAdaptLayout } from "@/core";
import { Trigger } from "@/base"; import { Trigger } from "@/base";
import { MultiSelectCheckSelectedSwitcher, MultiSelectSearcher, SearchMultiSelectSearcher } from "@/widget"; import { MultiSelectCheckSelectedSwitcher, MultiSelectSearcher, SearchMultiSelectSearcher } from "@/widget";
@ -18,9 +18,7 @@ export class SearchMultiSelectTrigger extends Trigger {
static EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; static EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW";
_defaultConfig() { _defaultConfig() {
const conf = super._defaultConfig(...arguments); return extend(super._defaultConfig(...arguments), {
return extend(conf, {
baseCls: "bi-multi-select-trigger", baseCls: "bi-multi-select-trigger",
itemsCreator: emptyFn, itemsCreator: emptyFn,
valueFormatter: emptyFn, valueFormatter: emptyFn,
@ -57,14 +55,14 @@ export class SearchMultiSelectTrigger extends Trigger {
this.searcher.on(MultiSelectSearcher.EVENT_PAUSE, () => { this.searcher.on(MultiSelectSearcher.EVENT_PAUSE, () => {
this.fireEvent(SearchMultiSelectTrigger.EVENT_PAUSE); this.fireEvent(SearchMultiSelectTrigger.EVENT_PAUSE);
}); });
this.searcher.on(MultiSelectSearcher.EVENT_SEARCHING, () => { this.searcher.on(MultiSelectSearcher.EVENT_SEARCHING, (...args) => {
this.fireEvent(SearchMultiSelectTrigger.EVENT_SEARCHING, ...arguments); this.fireEvent(SearchMultiSelectTrigger.EVENT_SEARCHING, ...args);
}); });
this.searcher.on(MultiSelectSearcher.EVENT_STOP, () => { this.searcher.on(MultiSelectSearcher.EVENT_STOP, () => {
this.fireEvent(SearchMultiSelectTrigger.EVENT_STOP); this.fireEvent(SearchMultiSelectTrigger.EVENT_STOP);
}); });
this.searcher.on(MultiSelectSearcher.EVENT_CHANGE, () => { this.searcher.on(MultiSelectSearcher.EVENT_CHANGE, (...args) => {
this.fireEvent(SearchMultiSelectTrigger.EVENT_CHANGE, ...arguments); this.fireEvent(SearchMultiSelectTrigger.EVENT_CHANGE, ...args);
}); });
this.numberCounter = createWidget(o.switcher, { this.numberCounter = createWidget(o.switcher, {
type: MultiSelectCheckSelectedSwitcher.xtype, type: MultiSelectCheckSelectedSwitcher.xtype,
@ -74,20 +72,12 @@ export class SearchMultiSelectTrigger extends Trigger {
masker: o.masker, masker: o.masker,
value: o.value, value: o.value,
}); });
this.numberCounter.on( this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, () => {
MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, this.fireEvent(SearchMultiSelectTrigger.EVENT_COUNTER_CLICK);
() => { });
this.fireEvent(SearchMultiSelectTrigger.EVENT_COUNTER_CLICK); this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW, () => {
} this.fireEvent(SearchMultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW);
); });
this.numberCounter.on(
MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW,
() => {
this.fireEvent(
SearchMultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW
);
}
);
const wrapNumberCounter = createWidget({ const wrapNumberCounter = createWidget({
type: RightVerticalAdaptLayout.xtype, type: RightVerticalAdaptLayout.xtype,
@ -121,10 +111,7 @@ export class SearchMultiSelectTrigger extends Trigger {
this.numberCounter.on(Events.VIEW, b => { this.numberCounter.on(Events.VIEW, b => {
nextTick(() => { nextTick(() => {
// 自动调整宽度 // 自动调整宽度
wrapper.attr("items")[1].width = wrapper.attr("items")[1].width = b === true ? this.numberCounter.element.outerWidth() + 8 : 0;
b === true
? this.numberCounter.element.outerWidth() + 8
: 0;
wrapper.resize(); wrapper.resize();
}); });
}); });

52
src/widget/searchmultitextvaluecombo/multitextvalue.loader.search.js

@ -1,4 +1,21 @@
import { shortcut, Widget, extend, emptyFn, createWidget, isKey, Selection, map, contains, remove, pushDistinct, Controller, VerticalLayout, createItems, delay, isNotNull } from "@/core"; import {
shortcut,
Widget,
extend,
emptyFn,
createWidget,
isKey,
Selection,
map,
contains,
remove,
pushDistinct,
Controller,
VerticalLayout,
createItems,
delay,
isNotNull
} from "@/core";
import { ButtonGroup, Loader } from "@/base"; import { ButtonGroup, Loader } from "@/base";
import { SelectList, MultiSelectBar, MultiSelectItem } from "@/case"; import { SelectList, MultiSelectBar, MultiSelectItem } from "@/case";
@ -73,8 +90,7 @@ export class SearchMultiSelectLoader extends Widget {
this.storeValue && this.storeValue &&
(op = extend(op || {}, { (op = extend(op || {}, {
selectedValues: selectedValues:
isKey(startValue) && isKey(startValue) && this.storeValue.type === Selection.Multi
this.storeValue.type === Selection.Multi
? this.storeValue.value.concat(startValue) ? this.storeValue.value.concat(startValue)
: this.storeValue.value, : this.storeValue.value,
})); }));
@ -89,16 +105,11 @@ export class SearchMultiSelectLoader extends Widget {
text: txt, text: txt,
value: v, value: v,
title: txt, title: txt,
selected: selected: this.storeValue.type === Selection.Multi,
this.storeValue.type === Selection.Multi,
}; };
}); });
if ( if (isKey(this._startValue) && !contains(this.storeValue.value, this._startValue)) {
isKey(this._startValue) && const txt = opts.valueFormatter(startValue) || startValue;
!contains(this.storeValue.value, this._startValue)
) {
const txt =
opts.valueFormatter(startValue) || startValue;
json.unshift({ json.unshift({
text: txt, text: txt,
value: startValue, value: startValue,
@ -108,18 +119,13 @@ export class SearchMultiSelectLoader extends Widget {
} }
firstItems = this._createItems(json); firstItems = this._createItems(json);
} }
callback(
firstItems.concat(this._createItems(ob.items)), callback(firstItems.concat(this._createItems(ob.items)), ob.keyword || "");
ob.keyword || ""
);
if (op.times === 1 && this.storeValue) { if (op.times === 1 && this.storeValue) {
isKey(startValue) && isKey(startValue) &&
(this.storeValue.type === Selection.All (this.storeValue.type === Selection.All
? remove(this.storeValue.value, startValue) ? remove(this.storeValue.value, startValue)
: pushDistinct( : pushDistinct(this.storeValue.value, startValue));
this.storeValue.value,
startValue
));
this.setValue(this.storeValue); this.setValue(this.storeValue);
} }
op.times === 1 && this._scrollToTop(); op.times === 1 && this._scrollToTop();
@ -128,11 +134,11 @@ export class SearchMultiSelectLoader extends Widget {
hasNext: () => hasNext, hasNext: () => hasNext,
value: this.storeValue, value: this.storeValue,
}); });
this.button_group.on(Controller.EVENT_CHANGE, () => { this.button_group.on(Controller.EVENT_CHANGE, (...args) => {
this.fireEvent(Controller.EVENT_CHANGE, arguments); this.fireEvent(Controller.EVENT_CHANGE, ...args);
}); });
this.button_group.on(SelectList.EVENT_CHANGE, () => { this.button_group.on(SelectList.EVENT_CHANGE, (...args) => {
this.fireEvent(SearchMultiSelectLoader.EVENT_CHANGE, ...arguments); this.fireEvent(SearchMultiSelectLoader.EVENT_CHANGE, ...args);
}); });
} }

30
src/widget/searchmultitextvaluecombo/multitextvalue.popup.view.search.js

@ -49,25 +49,19 @@ export class SearchMultiSelectPopupView extends Widget {
this.popupView.on(MultiPopupView.EVENT_CHANGE, () => { this.popupView.on(MultiPopupView.EVENT_CHANGE, () => {
this.fireEvent(SearchMultiSelectPopupView.EVENT_CHANGE); this.fireEvent(SearchMultiSelectPopupView.EVENT_CHANGE);
}); });
this.popupView.on(
MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, this.popupView.on(MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, index => {
index => { switch (index) {
switch (index) { case 0:
case 0: this.fireEvent(SearchMultiSelectPopupView.EVENT_CLICK_CLEAR);
this.fireEvent( break;
SearchMultiSelectPopupView.EVENT_CLICK_CLEAR case 1:
); this.fireEvent(SearchMultiSelectPopupView.EVENT_CLICK_CONFIRM);
break; break;
case 1: default:
this.fireEvent( break;
SearchMultiSelectPopupView.EVENT_CLICK_CONFIRM
);
break;
default:
break;
}
} }
); });
} }
isAllSelected() { isAllSelected() {

8
src/widget/searchmultitextvaluecombo/trigger/searcher.multitextvalue.js

@ -74,11 +74,11 @@ export class SearchMultiSelectSearcher extends Widget {
this.searcher.on(Searcher.EVENT_STOP, () => { this.searcher.on(Searcher.EVENT_STOP, () => {
this.fireEvent(SearchMultiSelectSearcher.EVENT_STOP); this.fireEvent(SearchMultiSelectSearcher.EVENT_STOP);
}); });
this.searcher.on(Searcher.EVENT_CHANGE, () => { this.searcher.on(Searcher.EVENT_CHANGE, (...args) => {
this.fireEvent(SearchMultiSelectSearcher.EVENT_CHANGE, ...arguments); this.fireEvent(SearchMultiSelectSearcher.EVENT_CHANGE, ...args);
}); });
this.searcher.on(Searcher.EVENT_SEARCHING, () => { this.searcher.on(Searcher.EVENT_SEARCHING, () => {
const keywords = this.getKeywords(); const keywords = this.searcher.getKeywords();
this.fireEvent(SearchMultiSelectSearcher.EVENT_SEARCHING, keywords); this.fireEvent(SearchMultiSelectSearcher.EVENT_SEARCHING, keywords);
}); });
if (isNotNull(o.value)) { if (isNotNull(o.value)) {
@ -174,6 +174,6 @@ export class SearchMultiSelectSearcher extends Widget {
} }
populate(items) { populate(items) {
this.searcher.populate(...arguments); this.searcher.populate.apply(this.searcher, arguments);
} }
} }

129
src/widget/textvaluedownlistcombo/combo.textvaluedownlist.js

@ -1,99 +1,116 @@
/** import {
* @class BI.TextValueDownListCombo shortcut,
* @extend BI.Widget Widget,
*/ extend,
BI.TextValueDownListCombo = BI.inherit(BI.Widget, { isNotNull,
_defaultConfig: function (config) { createWidget,
return BI.extend(BI.TextValueDownListCombo.superclass._defaultConfig.apply(this, arguments), { Selection,
baseCls: "bi-text-value-down-list-combo bi-border-radius " + (config.simple ? "bi-border-bottom" : "bi-border"), toPix,
isNull,
deepClone,
each,
flatten,
has
} from "@/core";
import { DownListCombo } from "../downlist";
@shortcut()
export class TextValueDownListCombo extends Widget {
static xtype = "bi.text_value_down_list_combo";
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig(config) {
return extend(super._defaultConfig(...arguments), {
baseCls:
`bi-text-value-down-list-combo bi-border-radius ${config.simple ? "bi-border-bottom" : "bi-border"}`,
height: 24, height: 24,
}); });
}, }
_init: function () { _init() {
var self = this, o = this.options; const o = this.options;
BI.TextValueDownListCombo.superclass._init.apply(this, arguments); super._init(...arguments);
this._createValueMap(); this._createValueMap();
var value; let value;
if(BI.isNotNull(o.value)) { if (isNotNull(o.value)) {
value = this._digest(o.value); value = this._digest(o.value);
} }
this.combo = BI.createWidget({ this.combo = createWidget({
type: "bi.down_list_combo", type: DownListCombo.xtype,
element: this, element: this,
chooseType: BI.Selection.Single, chooseType: Selection.Single,
adjustLength: 2, adjustLength: 2,
width: BI.toPix(o.width, 2), width: toPix(o.width, 2),
height: BI.toPix(o.height, 2), height: toPix(o.height, 2),
el: { el: {
type: "bi.down_list_select_text_trigger", type: "bi.down_list_select_text_trigger",
ref: function (_ref) { ref: _ref => {
self.trigger = _ref; this.trigger = _ref;
}, },
cls: "text-value-down-list-trigger", cls: "text-value-down-list-trigger",
height: BI.toPix(o.height, 2), height: toPix(o.height, 2),
items: o.items, items: o.items,
text: o.text, text: o.text,
value: value value,
}, },
value: BI.isNull(value) ? [] : [value], value: isNull(value) ? [] : [value],
items: BI.deepClone(o.items) items: deepClone(o.items),
}); });
this.combo.on(BI.DownListCombo.EVENT_CHANGE, function () { this.combo.on(DownListCombo.EVENT_CHANGE, () => {
var currentVal = self.combo.getValue()[0].value; const currentVal = this.combo.getValue()[0].value;
if (currentVal !== self.value) { if (currentVal !== this.value) {
self.setValue(currentVal); this.setValue(currentVal);
self.fireEvent(BI.TextValueDownListCombo.EVENT_CHANGE); this.fireEvent(TextValueDownListCombo.EVENT_CHANGE);
} }
}); });
this.combo.on(BI.DownListCombo.EVENT_SON_VALUE_CHANGE, function () { this.combo.on(DownListCombo.EVENT_SON_VALUE_CHANGE, () => {
var currentVal = self.combo.getValue()[0].childValue; const currentVal = this.combo.getValue()[0].childValue;
if (currentVal !== self.value) { if (currentVal !== this.value) {
self.setValue(currentVal); this.setValue(currentVal);
self.fireEvent(BI.TextValueDownListCombo.EVENT_CHANGE); this.fireEvent(TextValueDownListCombo.EVENT_CHANGE);
} }
}); });
}, }
_createValueMap: function () { _createValueMap() {
var self = this;
this.valueMap = {}; this.valueMap = {};
BI.each(BI.flatten(this.options.items), function (idx, item) { each(flatten(this.options.items), (idx, item) => {
if (BI.has(item, "el")) { if (has(item, "el")) {
BI.each(item.children, function (id, it) { each(item.children, (id, it) => {
self.valueMap[it.value] = {value: item.el.value, childValue: it.value}; this.valueMap[it.value] = { value: item.el.value, childValue: it.value };
}); });
} else { } else {
self.valueMap[item.value] = {value: item.value}; this.valueMap[item.value] = { value: item.value };
} }
}); });
}, }
_digest: function (v) { _digest(v) {
this.value = v; this.value = v;
return this.valueMap[v]; return this.valueMap[v];
}, }
setValue: function (v) { setValue(v) {
v = this._digest(v); v = this._digest(v);
this.combo.setValue([v]); this.combo.setValue([v]);
this.trigger?.setValue(v); this.trigger?.setValue(v);
}, }
getValue: function () { getValue() {
var v = this.combo.getValue()[0]; const v = this.combo.getValue()[0];
return [v.childValue || v.value]; return [v.childValue || v.value];
}, }
populate: function (items) { populate(items) {
this.options.items = BI.flatten(items); this.options.items = flatten(items);
this.combo.populate(items); this.combo.populate(items);
this._createValueMap(); this._createValueMap();
} }
}); }
BI.TextValueDownListCombo.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.text_value_down_list_combo", BI.TextValueDownListCombo);

2
src/widget/textvaluedownlistcombo/index.js

@ -0,0 +1,2 @@
export { TextValueDownListCombo } from "./combo.textvaluedownlist";
export { DownListSelectTextTrigger } from "./trigger.textvaluedownlist";

67
src/widget/textvaluedownlistcombo/trigger.textvaluedownlist.js

@ -1,55 +1,54 @@
/** import { shortcut, extend, createWidget, isNull, flatten, deepClone, each, has, concat } from "@/core";
* 选择字段trigger, downlist专用 import { Trigger } from "@/base";
* 显示形式为 父亲值(儿子值) import { SelectTextTrigger } from "@/case";
*
* @class BI.DownListSelectTextTrigger
* @extends BI.Trigger
*/
BI.DownListSelectTextTrigger = BI.inherit(BI.Trigger, {
_defaultConfig: function () { @shortcut()
return BI.extend(BI.DownListSelectTextTrigger.superclass._defaultConfig.apply(this, arguments), { export class DownListSelectTextTrigger extends Trigger {
static xtype = "bi.down_list_select_text_trigger";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-down-list-select-text-trigger", baseCls: "bi-down-list-select-text-trigger",
height: 24, height: 24,
text: "" text: "",
}); });
}, }
_init: function () { _init() {
BI.DownListSelectTextTrigger.superclass._init.apply(this, arguments); super._init(...arguments);
var o = this.options; const o = this.options;
this.trigger = BI.createWidget({ this.trigger = createWidget({
type: "bi.select_text_trigger", type: SelectTextTrigger.xtype,
element: this, element: this,
height: o.height, height: o.height,
items: this._formatItemArray(o.items), items: this._formatItemArray(o.items),
text: o.text, text: o.text,
value: BI.isNull(o.value) ? "" : o.value.childValue || o.value.value value: isNull(o.value) ? "" : o.value.childValue || o.value.value,
}); });
}, }
_formatItemArray: function () { _formatItemArray() {
var sourceArray = BI.flatten(BI.deepClone(this.options.items)); const sourceArray = flatten(deepClone(this.options.items));
var targetArray = []; let targetArray = [];
BI.each(sourceArray, function (idx, item) { each(sourceArray, (idx, item) => {
if(BI.has(item, "el")) { if (has(item, "el")) {
BI.each(item.children, function (id, it) { each(item.children, (id, it) => {
it.text = item.el.text + "(" + it.text + ")"; it.text = `${item.el.text}(${it.text})`;
}); });
targetArray = BI.concat(targetArray, item.children); targetArray = concat(targetArray, item.children);
}else{ } else {
targetArray.push(item); targetArray.push(item);
} }
}); });
return targetArray; return targetArray;
}, }
setValue: function (vals) { setValue(vals) {
this.trigger.setValue(vals.childValue || vals.value); this.trigger.setValue(vals.childValue || vals.value);
}, }
populate: function (items) { populate(items) {
this.trigger.populate(this._formatItemArray(items)); this.trigger.populate(this._formatItemArray(items));
} }
}); }
BI.shortcut("bi.down_list_select_text_trigger", BI.DownListSelectTextTrigger);

Loading…
Cancel
Save