From d2f320307cf4d09a5e67e02cf4cd47e336373ef7 Mon Sep 17 00:00:00 2001 From: impact Date: Mon, 16 Jan 2023 17:27:20 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-14107=20refactor:=20widget/searchmultite?= =?UTF-8?q?xtvaluecombo=E3=80=81textvaluedownlistcombo=20ES6=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/combination/searcher.js | 15 +- src/base/single/bar/bar.loading.js | 2 +- src/case/editor/editor.state.js | 3 +- src/case/editor/editor.state.simple.js | 3 +- src/widget/index.js | 6 +- .../multitree/trigger/searcher.multi.tree.js | 4 +- .../multitextvalue.combo.search.js | 143 ++++++++++-------- .../multitextvalue.combo.trigger.search.js | 39 ++--- .../multitextvalue.loader.search.js | 52 ++++--- .../multitextvalue.popup.view.search.js | 30 ++-- .../trigger/searcher.multitextvalue.js | 8 +- .../combo.textvaluedownlist.js | 129 +++++++++------- src/widget/textvaluedownlistcombo/index.js | 2 + .../trigger.textvaluedownlist.js | 67 ++++---- 14 files changed, 263 insertions(+), 240 deletions(-) create mode 100644 src/widget/textvaluedownlistcombo/index.js diff --git a/src/base/combination/searcher.js b/src/base/combination/searcher.js index aaa0a1694..eaf583485 100644 --- a/src/base/combination/searcher.js +++ b/src/base/combination/searcher.js @@ -13,7 +13,8 @@ import { deepWithout, nextTick, isEmptyString, - isNull + isNull, + BlankSplitChar } from "@/core"; import { ButtonGroup } from "./group.button"; import { Maskers } from "@/base/0.base"; @@ -109,7 +110,7 @@ export class Searcher extends Widget { search(); break; case BI.Events.PAUSE: - if (endWith(this.getValue(), BI.BlankSplitChar)) { + if (endWith(this.editor.getValue(), BlankSplitChar)) { this._pauseSearch(); } break; @@ -229,14 +230,14 @@ export class Searcher extends Widget { keyword, selectedValues: adapter && adapter.getValue(), }, - (searchResult, matchResult, ...arg) => { + (...args) => { if (!this._stop && keyword === this.editor.getValue()) { - const args = [searchResult, matchResult, ...arg]; - if (args.length > 0) { - args.push(keyword); + const _args = args; + if (_args.length > 0) { + _args.push(keyword); } 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()); this.popupView.loaded && this.popupView.loaded(); this.fireEvent(Searcher.EVENT_SEARCHING); diff --git a/src/base/single/bar/bar.loading.js b/src/base/single/bar/bar.loading.js index 3bfa473b1..03a90fcb4 100644 --- a/src/base/single/bar/bar.loading.js +++ b/src/base/single/bar/bar.loading.js @@ -26,7 +26,7 @@ export class LoadingBar extends Single { handler: this.options.handler, }); 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({ diff --git a/src/case/editor/editor.state.js b/src/case/editor/editor.state.js index 09625729c..bdb731adc 100644 --- a/src/case/editor/editor.state.js +++ b/src/case/editor/editor.state.js @@ -15,7 +15,8 @@ import { isKey, isFunction, isNumber, - isEmpty + isEmpty, + Selection } from "@/core"; /** diff --git a/src/case/editor/editor.state.simple.js b/src/case/editor/editor.state.simple.js index 8175c5083..367b3a34e 100644 --- a/src/case/editor/editor.state.simple.js +++ b/src/case/editor/editor.state.simple.js @@ -15,7 +15,8 @@ import { isFunction, isArray, isNumber, - isEmpty + isEmpty, + Selection } from "@/core"; /** diff --git a/src/widget/index.js b/src/widget/index.js index 091420ad1..af799dc06 100644 --- a/src/widget/index.js +++ b/src/widget/index.js @@ -29,8 +29,9 @@ import { YearInterval } from "./yearinterval/yearinterval"; import * as singleselect from "./singleselect"; import * as multilayerdownlist from "./multilayerdownlist"; import * as multilayersingletree from "./multilayersingletree"; - +import * as textvaluedownlistcombo from "./textvaluedownlistcombo"; import * as searchmultitextvaluecombo from "./searchmultitextvaluecombo"; + Object.assign(BI, { Collapse, ...calendar, @@ -63,6 +64,7 @@ Object.assign(BI, { ...singleselect, ...multilayerdownlist, ...multilayersingletree, + ...textvaluedownlistcombo, ...searchmultitextvaluecombo, }); @@ -87,6 +89,8 @@ export * from "./searchmultitextvaluecombo"; export * from "./singleselect"; export * from "./multilayerdownlist"; export * from "./yearquarter"; +export * from "./textvaluedownlistcombo"; +export * from "./searchmultitextvaluecombo"; export { Collapse, diff --git a/src/widget/multitree/trigger/searcher.multi.tree.js b/src/widget/multitree/trigger/searcher.multi.tree.js index cfc2a5201..13cda220a 100644 --- a/src/widget/multitree/trigger/searcher.multi.tree.js +++ b/src/widget/multitree/trigger/searcher.multi.tree.js @@ -203,7 +203,7 @@ export class MultiTreeSearcher extends Widget { function getChildrenNode(ob) { let text = ""; - const size = size(ob); + const _size = size(ob); let index = 0; const names = Func.getSortedResult(keys(ob)); @@ -215,7 +215,7 @@ export class MultiTreeSearcher extends Widget { ? "" : o.valueFormatter(`${name}`) || name) + (childNodes === "" ? "" : `:${childNodes}`) + - (index === size ? "" : ","); + (index === _size ? "" : ","); if (childNodes === "") { count++; } diff --git a/src/widget/searchmultitextvaluecombo/multitextvalue.combo.search.js b/src/widget/searchmultitextvaluecombo/multitextvalue.combo.search.js index 4b8b3dc91..3effa3c62 100644 --- a/src/widget/searchmultitextvaluecombo/multitextvalue.combo.search.js +++ b/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 { MultiSelectTrigger, MultiSelectPopupView, MultiSelectCombo, SearchMultiSelectTrigger, SearchMultiSelectPopupView } from "@/widget"; import { MultiSelectBar, TriggerIconButton } from "@/case"; @@ -63,12 +92,13 @@ export class SearchMultiTextValueCombo extends Single { allValueGetter: () => this.allValue, valueFormatter: o.valueFormatter, itemsCreator: (op, callback) => { - this._itemsCreator(op, res => { + this._itemsCreator(op, (res, ...args) => { if (op.times === 1 && isNotNull(op.keywords)) { // 预防trigger内部把当前的storeValue改掉 this.trigger.setValue(deepClone(this.getValue())); } - callback.apply(this, ...arguments); + + callback.apply(this, [res, ...args]); }); }, value: this.storeValue, @@ -77,32 +107,29 @@ export class SearchMultiTextValueCombo extends Single { this.trigger.on(MultiSelectTrigger.EVENT_START, () => { this._setStartValue(""); - this.getSearcher().setValue(this.storeValue); + this.trigger.getSearcher().setValue(this.storeValue); }); this.trigger.on(MultiSelectTrigger.EVENT_STOP, () => { this._setStartValue(""); }); - this.trigger.on( - MultiSelectTrigger.EVENT_SEARCHING, - keywords => { - const lastKeyWord = last(keywords); - keywords = initial(keywords || []); - if (keywords.length > 0) { - this._joinKeywords(keywords, () => { - if (endWith(lastKeyWord, BI.BlankSplitChar)) { - this.combo.setValue(this.storeValue); - assertShowValue(); - this.combo.populate(); - this._setStartValue(""); - } else { - this.combo.setValue(this.storeValue); - assertShowValue(); - } - this._dataChange = true; - }); - } + this.trigger.on(MultiSelectTrigger.EVENT_SEARCHING, keywords => { + const _last = last(keywords); + keywords = initial(keywords || []); + if (keywords.length > 0) { + this._joinKeywords(keywords, () => { + if (endWith(_last, BlankSplitChar)) { + this.combo.setValue(this.storeValue); + assertShowValue(); + this.combo.populate(); + this._setStartValue(""); + } else { + this.combo.setValue(this.storeValue); + assertShowValue(); + } + this._dataChange = true; + }); } - ); + }); this.trigger.on(MultiSelectTrigger.EVENT_CHANGE, (value, obj) => { if (obj instanceof MultiSelectBar) { @@ -116,12 +143,9 @@ export class SearchMultiTextValueCombo extends Single { } this._dataChange = true; }); - this.trigger.on( - MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, - () => { - this.getCounter().setValue(this.storeValue); - } - ); + this.trigger.on(MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, () => { + this.trigger.getCounter().setValue(this.storeValue); + }); this.trigger.on(MultiSelectTrigger.EVENT_COUNTER_CLICK, () => { if (!this.combo.isViewVisible()) { this.combo.showView(); @@ -144,9 +168,9 @@ export class SearchMultiTextValueCombo extends Single { listeners: [ { eventName: MultiSelectPopupView.EVENT_CHANGE, - action :() => { + action: () => { this._dataChange = true; - this.storeValue = this.getValue(); + this.storeValue = this.popup.getValue(); this._adjust(() => { assertShowValue(); }); @@ -154,7 +178,7 @@ export class SearchMultiTextValueCombo extends Single { }, { eventName: MultiSelectPopupView.EVENT_CLICK_CONFIRM, - action :() => { + action: () => { this._defaultState(); }, }, @@ -183,7 +207,7 @@ export class SearchMultiTextValueCombo extends Single { }); this.combo.on(Combo.EVENT_BEFORE_POPUPVIEW, () => { - if (!this.isViewVisible()) { + if (!this.combo.isViewVisible()) { this._dataChange = false; // 标记数据是否发生变化 } this.setValue(this.storeValue); @@ -203,11 +227,11 @@ export class SearchMultiTextValueCombo extends Single { * 在存在标红的情况,如果popover没有发生改变就确认需要同步trigger的值,否则对外value值和trigger样式不统一 */ assertShowValue(); - this._dataChange && - this.fireEvent(SearchMultiTextValueCombo.EVENT_CONFIRM); + this._dataChange && this.fireEvent(SearchMultiTextValueCombo.EVENT_CONFIRM); } }); + triggerBtn.on(TriggerIconButton.EVENT_CHANGE, () => { this.trigger.getCounter().hideView(); if (this.combo.isViewVisible()) { @@ -256,8 +280,6 @@ export class SearchMultiTextValueCombo extends Single { } _joinKeywords(keywords, callback) { - this._assertValue(this.storeValue); - this.requesting = true; const digest = items => { const selectedMap = this._makeMap(items); each(keywords, (i, val) => { @@ -269,6 +291,9 @@ export class SearchMultiTextValueCombo extends Single { }); this._adjust(callback); }; + + this._assertValue(this.storeValue); + this.requesting = true; this._itemsCreator( { type: SearchMultiTextValueCombo.REQ_GET_ALL_DATA, @@ -290,19 +315,18 @@ export class SearchMultiTextValueCombo extends Single { keywords: [this.trigger.getKey()], }, ob => { - const map = this._makeMap(this.storeValue.value); const items = map(ob.items, "value"); if (this.storeValue.type === res.type) { let change = false; + const _map = this._makeMap(this.storeValue.value); each(items, (i, v) => { - if (isNotNull(map[v])) { + if (isNotNull(_map[v])) { change = true; - this.storeValue.assist && - this.storeValue.assist.push(map[v]); - delete map[v]; + this.storeValue.assist && this.storeValue.assist.push(_map[v]); + delete _map[v]; } }); - change && (this.storeValue.value = values(map)); + change && (this.storeValue.value = values(_map)); this._adjust(callback); return; @@ -312,8 +336,7 @@ export class SearchMultiTextValueCombo extends Single { const newItems = []; each(items, (i, item) => { if (isNotNull(selectedMap[items[i]])) { - this.storeValue.assist && - this.storeValue.assist.push(selectedMap[items[i]]); + this.storeValue.assist && this.storeValue.assist.push(selectedMap[items[i]]); delete selectedMap[items[i]]; } if (isNull(notSelectedMap[items[i]])) { @@ -329,18 +352,12 @@ export class SearchMultiTextValueCombo extends Single { _adjust(callback) { const adjust = () => { - if ( - this.storeValue.type === Selection.All && - this.storeValue.value.length >= this._count - ) { + if (this.storeValue.type === Selection.All && this.storeValue.value.length >= this._count) { this.storeValue = { type: Selection.Multi, value: [], }; - } else if ( - this.storeValue.type === Selection.Multi && - this.storeValue.value.length >= this._count - ) { + } else if (this.storeValue.type === Selection.Multi && this.storeValue.value.length >= this._count) { this.storeValue = { type: Selection.All, value: [], @@ -349,8 +366,7 @@ export class SearchMultiTextValueCombo extends Single { this._updateAllValue(); this._checkError(); if (this.wants2Quit === true) { - this._dataChange && - this.fireEvent(SearchMultiTextValueCombo.EVENT_CONFIRM); + this._dataChange && this.fireEvent(SearchMultiTextValueCombo.EVENT_CONFIRM); this.wants2Quit = false; } this.requesting = false; @@ -388,8 +404,7 @@ export class SearchMultiTextValueCombo extends Single { each(res.assist, (i, v) => { if (isNotNull(map[v])) { change = true; - this.storeValue.assist && - this.storeValue.assist.push(map[v]); + this.storeValue.assist && this.storeValue.assist.push(map[v]); delete map[v]; } }); @@ -432,17 +447,17 @@ export class SearchMultiTextValueCombo extends Single { }); if (options.selectedValues) { // 过滤 - const filter = makeObject(options.selectedValues, true); - items = filter(items, (i, ob) => !filter[ob.value]); + const _filter = makeObject(options.selectedValues, true); + 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({ items, }); return; } - if (options.type === MultiSelectCombo.REQ_GET_DATA_LENGTH) { + if (options.type == MultiSelectCombo.REQ_GET_DATA_LENGTH) { callback({ count: items.length }); return; @@ -503,7 +518,3 @@ export class SearchMultiTextValueCombo extends Single { this._populate(); } } -extend(SearchMultiTextValueCombo, { - REQ_GET_DATA_LENGTH: 1, - REQ_GET_ALL_DATA: -1, -}); diff --git a/src/widget/searchmultitextvaluecombo/multitextvalue.combo.trigger.search.js b/src/widget/searchmultitextvaluecombo/multitextvalue.combo.trigger.search.js index ba9dae06a..019c6237e 100644 --- a/src/widget/searchmultitextvaluecombo/multitextvalue.combo.trigger.search.js +++ b/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 { MultiSelectCheckSelectedSwitcher, MultiSelectSearcher, SearchMultiSelectSearcher } from "@/widget"; @@ -18,9 +18,7 @@ export class SearchMultiSelectTrigger extends Trigger { static EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; _defaultConfig() { - const conf = super._defaultConfig(...arguments); - - return extend(conf, { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-multi-select-trigger", itemsCreator: emptyFn, valueFormatter: emptyFn, @@ -57,14 +55,14 @@ export class SearchMultiSelectTrigger extends Trigger { this.searcher.on(MultiSelectSearcher.EVENT_PAUSE, () => { this.fireEvent(SearchMultiSelectTrigger.EVENT_PAUSE); }); - this.searcher.on(MultiSelectSearcher.EVENT_SEARCHING, () => { - this.fireEvent(SearchMultiSelectTrigger.EVENT_SEARCHING, ...arguments); + this.searcher.on(MultiSelectSearcher.EVENT_SEARCHING, (...args) => { + this.fireEvent(SearchMultiSelectTrigger.EVENT_SEARCHING, ...args); }); this.searcher.on(MultiSelectSearcher.EVENT_STOP, () => { this.fireEvent(SearchMultiSelectTrigger.EVENT_STOP); }); - this.searcher.on(MultiSelectSearcher.EVENT_CHANGE, () => { - this.fireEvent(SearchMultiSelectTrigger.EVENT_CHANGE, ...arguments); + this.searcher.on(MultiSelectSearcher.EVENT_CHANGE, (...args) => { + this.fireEvent(SearchMultiSelectTrigger.EVENT_CHANGE, ...args); }); this.numberCounter = createWidget(o.switcher, { type: MultiSelectCheckSelectedSwitcher.xtype, @@ -74,20 +72,12 @@ export class SearchMultiSelectTrigger extends Trigger { masker: o.masker, value: o.value, }); - this.numberCounter.on( - MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, - () => { - 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_TRIGGER_CHANGE, () => { + this.fireEvent(SearchMultiSelectTrigger.EVENT_COUNTER_CLICK); + }); + this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW, () => { + this.fireEvent(SearchMultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW); + }); const wrapNumberCounter = createWidget({ type: RightVerticalAdaptLayout.xtype, @@ -121,10 +111,7 @@ export class SearchMultiSelectTrigger extends Trigger { this.numberCounter.on(Events.VIEW, b => { nextTick(() => { // 自动调整宽度 - wrapper.attr("items")[1].width = - b === true - ? this.numberCounter.element.outerWidth() + 8 - : 0; + wrapper.attr("items")[1].width = b === true ? this.numberCounter.element.outerWidth() + 8 : 0; wrapper.resize(); }); }); diff --git a/src/widget/searchmultitextvaluecombo/multitextvalue.loader.search.js b/src/widget/searchmultitextvaluecombo/multitextvalue.loader.search.js index d03a6865f..27dab4eff 100644 --- a/src/widget/searchmultitextvaluecombo/multitextvalue.loader.search.js +++ b/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 { SelectList, MultiSelectBar, MultiSelectItem } from "@/case"; @@ -73,8 +90,7 @@ export class SearchMultiSelectLoader extends Widget { this.storeValue && (op = extend(op || {}, { selectedValues: - isKey(startValue) && - this.storeValue.type === Selection.Multi + isKey(startValue) && this.storeValue.type === Selection.Multi ? this.storeValue.value.concat(startValue) : this.storeValue.value, })); @@ -89,16 +105,11 @@ export class SearchMultiSelectLoader extends Widget { text: txt, value: v, title: txt, - selected: - this.storeValue.type === Selection.Multi, + selected: this.storeValue.type === Selection.Multi, }; }); - if ( - isKey(this._startValue) && - !contains(this.storeValue.value, this._startValue) - ) { - const txt = - opts.valueFormatter(startValue) || startValue; + if (isKey(this._startValue) && !contains(this.storeValue.value, this._startValue)) { + const txt = opts.valueFormatter(startValue) || startValue; json.unshift({ text: txt, value: startValue, @@ -108,18 +119,13 @@ export class SearchMultiSelectLoader extends Widget { } firstItems = this._createItems(json); } - callback( - firstItems.concat(this._createItems(ob.items)), - ob.keyword || "" - ); + + callback(firstItems.concat(this._createItems(ob.items)), ob.keyword || ""); if (op.times === 1 && this.storeValue) { isKey(startValue) && (this.storeValue.type === Selection.All ? remove(this.storeValue.value, startValue) - : pushDistinct( - this.storeValue.value, - startValue - )); + : pushDistinct(this.storeValue.value, startValue)); this.setValue(this.storeValue); } op.times === 1 && this._scrollToTop(); @@ -128,11 +134,11 @@ export class SearchMultiSelectLoader extends Widget { hasNext: () => hasNext, value: this.storeValue, }); - this.button_group.on(Controller.EVENT_CHANGE, () => { - this.fireEvent(Controller.EVENT_CHANGE, arguments); + this.button_group.on(Controller.EVENT_CHANGE, (...args) => { + this.fireEvent(Controller.EVENT_CHANGE, ...args); }); - this.button_group.on(SelectList.EVENT_CHANGE, () => { - this.fireEvent(SearchMultiSelectLoader.EVENT_CHANGE, ...arguments); + this.button_group.on(SelectList.EVENT_CHANGE, (...args) => { + this.fireEvent(SearchMultiSelectLoader.EVENT_CHANGE, ...args); }); } diff --git a/src/widget/searchmultitextvaluecombo/multitextvalue.popup.view.search.js b/src/widget/searchmultitextvaluecombo/multitextvalue.popup.view.search.js index d2db9c7dd..bed51d655 100644 --- a/src/widget/searchmultitextvaluecombo/multitextvalue.popup.view.search.js +++ b/src/widget/searchmultitextvaluecombo/multitextvalue.popup.view.search.js @@ -49,25 +49,19 @@ export class SearchMultiSelectPopupView extends Widget { this.popupView.on(MultiPopupView.EVENT_CHANGE, () => { this.fireEvent(SearchMultiSelectPopupView.EVENT_CHANGE); }); - this.popupView.on( - MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, - index => { - switch (index) { - case 0: - this.fireEvent( - SearchMultiSelectPopupView.EVENT_CLICK_CLEAR - ); - break; - case 1: - this.fireEvent( - SearchMultiSelectPopupView.EVENT_CLICK_CONFIRM - ); - break; - default: - break; - } + + this.popupView.on(MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, index => { + switch (index) { + case 0: + this.fireEvent(SearchMultiSelectPopupView.EVENT_CLICK_CLEAR); + break; + case 1: + this.fireEvent(SearchMultiSelectPopupView.EVENT_CLICK_CONFIRM); + break; + default: + break; } - ); + }); } isAllSelected() { diff --git a/src/widget/searchmultitextvaluecombo/trigger/searcher.multitextvalue.js b/src/widget/searchmultitextvaluecombo/trigger/searcher.multitextvalue.js index a59d7582d..6f08741d4 100644 --- a/src/widget/searchmultitextvaluecombo/trigger/searcher.multitextvalue.js +++ b/src/widget/searchmultitextvaluecombo/trigger/searcher.multitextvalue.js @@ -74,11 +74,11 @@ export class SearchMultiSelectSearcher extends Widget { this.searcher.on(Searcher.EVENT_STOP, () => { this.fireEvent(SearchMultiSelectSearcher.EVENT_STOP); }); - this.searcher.on(Searcher.EVENT_CHANGE, () => { - this.fireEvent(SearchMultiSelectSearcher.EVENT_CHANGE, ...arguments); + this.searcher.on(Searcher.EVENT_CHANGE, (...args) => { + this.fireEvent(SearchMultiSelectSearcher.EVENT_CHANGE, ...args); }); this.searcher.on(Searcher.EVENT_SEARCHING, () => { - const keywords = this.getKeywords(); + const keywords = this.searcher.getKeywords(); this.fireEvent(SearchMultiSelectSearcher.EVENT_SEARCHING, keywords); }); if (isNotNull(o.value)) { @@ -174,6 +174,6 @@ export class SearchMultiSelectSearcher extends Widget { } populate(items) { - this.searcher.populate(...arguments); + this.searcher.populate.apply(this.searcher, arguments); } } diff --git a/src/widget/textvaluedownlistcombo/combo.textvaluedownlist.js b/src/widget/textvaluedownlistcombo/combo.textvaluedownlist.js index 956e18552..c2f3bb76d 100644 --- a/src/widget/textvaluedownlistcombo/combo.textvaluedownlist.js +++ b/src/widget/textvaluedownlistcombo/combo.textvaluedownlist.js @@ -1,99 +1,116 @@ -/** - * @class BI.TextValueDownListCombo - * @extend BI.Widget - */ -BI.TextValueDownListCombo = BI.inherit(BI.Widget, { - _defaultConfig: function (config) { - return BI.extend(BI.TextValueDownListCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-text-value-down-list-combo bi-border-radius " + (config.simple ? "bi-border-bottom" : "bi-border"), +import { + shortcut, + Widget, + extend, + isNotNull, + createWidget, + Selection, + 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, }); - }, + } - _init: function () { - var self = this, o = this.options; - BI.TextValueDownListCombo.superclass._init.apply(this, arguments); + _init() { + const o = this.options; + super._init(...arguments); this._createValueMap(); - var value; - if(BI.isNotNull(o.value)) { + let value; + if (isNotNull(o.value)) { value = this._digest(o.value); } - this.combo = BI.createWidget({ - type: "bi.down_list_combo", + this.combo = createWidget({ + type: DownListCombo.xtype, element: this, - chooseType: BI.Selection.Single, + chooseType: Selection.Single, adjustLength: 2, - width: BI.toPix(o.width, 2), - height: BI.toPix(o.height, 2), + width: toPix(o.width, 2), + height: toPix(o.height, 2), el: { type: "bi.down_list_select_text_trigger", - ref: function (_ref) { - self.trigger = _ref; + ref: _ref => { + this.trigger = _ref; }, cls: "text-value-down-list-trigger", - height: BI.toPix(o.height, 2), + height: toPix(o.height, 2), items: o.items, text: o.text, - value: value + value, }, - value: BI.isNull(value) ? [] : [value], - items: BI.deepClone(o.items) + value: isNull(value) ? [] : [value], + items: deepClone(o.items), }); - this.combo.on(BI.DownListCombo.EVENT_CHANGE, function () { - var currentVal = self.combo.getValue()[0].value; - if (currentVal !== self.value) { - self.setValue(currentVal); - self.fireEvent(BI.TextValueDownListCombo.EVENT_CHANGE); + this.combo.on(DownListCombo.EVENT_CHANGE, () => { + const currentVal = this.combo.getValue()[0].value; + if (currentVal !== this.value) { + this.setValue(currentVal); + this.fireEvent(TextValueDownListCombo.EVENT_CHANGE); } }); - this.combo.on(BI.DownListCombo.EVENT_SON_VALUE_CHANGE, function () { - var currentVal = self.combo.getValue()[0].childValue; - if (currentVal !== self.value) { - self.setValue(currentVal); - self.fireEvent(BI.TextValueDownListCombo.EVENT_CHANGE); + this.combo.on(DownListCombo.EVENT_SON_VALUE_CHANGE, () => { + const currentVal = this.combo.getValue()[0].childValue; + if (currentVal !== this.value) { + this.setValue(currentVal); + this.fireEvent(TextValueDownListCombo.EVENT_CHANGE); } }); - }, + } - _createValueMap: function () { - var self = this; + _createValueMap() { this.valueMap = {}; - BI.each(BI.flatten(this.options.items), function (idx, item) { - if (BI.has(item, "el")) { - BI.each(item.children, function (id, it) { - self.valueMap[it.value] = {value: item.el.value, childValue: it.value}; + each(flatten(this.options.items), (idx, item) => { + if (has(item, "el")) { + each(item.children, (id, it) => { + this.valueMap[it.value] = { value: item.el.value, childValue: it.value }; }); } else { - self.valueMap[item.value] = {value: item.value}; + this.valueMap[item.value] = { value: item.value }; } }); - }, + } - _digest: function (v) { + _digest(v) { this.value = v; + return this.valueMap[v]; - }, + } - setValue: function (v) { + setValue(v) { v = this._digest(v); this.combo.setValue([v]); this.trigger?.setValue(v); - }, + } - getValue: function () { - var v = this.combo.getValue()[0]; + getValue() { + const v = this.combo.getValue()[0]; + return [v.childValue || v.value]; - }, + } - populate: function (items) { - this.options.items = BI.flatten(items); + populate(items) { + this.options.items = flatten(items); this.combo.populate(items); this._createValueMap(); } -}); -BI.TextValueDownListCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.text_value_down_list_combo", BI.TextValueDownListCombo); +} diff --git a/src/widget/textvaluedownlistcombo/index.js b/src/widget/textvaluedownlistcombo/index.js new file mode 100644 index 000000000..930fb6d00 --- /dev/null +++ b/src/widget/textvaluedownlistcombo/index.js @@ -0,0 +1,2 @@ +export { TextValueDownListCombo } from "./combo.textvaluedownlist"; +export { DownListSelectTextTrigger } from "./trigger.textvaluedownlist"; diff --git a/src/widget/textvaluedownlistcombo/trigger.textvaluedownlist.js b/src/widget/textvaluedownlistcombo/trigger.textvaluedownlist.js index b335ce5c1..b22dadd9d 100644 --- a/src/widget/textvaluedownlistcombo/trigger.textvaluedownlist.js +++ b/src/widget/textvaluedownlistcombo/trigger.textvaluedownlist.js @@ -1,55 +1,54 @@ -/** - * 选择字段trigger, downlist专用 - * 显示形式为 父亲值(儿子值) - * - * @class BI.DownListSelectTextTrigger - * @extends BI.Trigger - */ -BI.DownListSelectTextTrigger = BI.inherit(BI.Trigger, { +import { shortcut, extend, createWidget, isNull, flatten, deepClone, each, has, concat } from "@/core"; +import { Trigger } from "@/base"; +import { SelectTextTrigger } from "@/case"; - _defaultConfig: function () { - return BI.extend(BI.DownListSelectTextTrigger.superclass._defaultConfig.apply(this, arguments), { +@shortcut() +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", height: 24, - text: "" + text: "", }); - }, + } - _init: function () { - BI.DownListSelectTextTrigger.superclass._init.apply(this, arguments); - var o = this.options; - this.trigger = BI.createWidget({ - type: "bi.select_text_trigger", + _init() { + super._init(...arguments); + const o = this.options; + this.trigger = createWidget({ + type: SelectTextTrigger.xtype, element: this, height: o.height, items: this._formatItemArray(o.items), 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 () { - var sourceArray = BI.flatten(BI.deepClone(this.options.items)); - var targetArray = []; - BI.each(sourceArray, function (idx, item) { - if(BI.has(item, "el")) { - BI.each(item.children, function (id, it) { - it.text = item.el.text + "(" + it.text + ")"; + _formatItemArray() { + const sourceArray = flatten(deepClone(this.options.items)); + let targetArray = []; + each(sourceArray, (idx, item) => { + if (has(item, "el")) { + each(item.children, (id, it) => { + it.text = `${item.el.text}(${it.text})`; }); - targetArray = BI.concat(targetArray, item.children); - }else{ + targetArray = concat(targetArray, item.children); + } else { targetArray.push(item); } }); + return targetArray; - }, + } - setValue: function (vals) { + setValue(vals) { this.trigger.setValue(vals.childValue || vals.value); - }, + } - populate: function (items) { + populate(items) { this.trigger.populate(this._formatItemArray(items)); } -}); -BI.shortcut("bi.down_list_select_text_trigger", BI.DownListSelectTextTrigger); \ No newline at end of file +}