forked from fanruan/fineui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
4.8 KiB
163 lines
4.8 KiB
import { shortcut, extend, emptyFn, createWidget, isFunction, Layout, HTapeLayout, AbsoluteLayout } from "@/core"; |
|
import { Trigger, Text } from "@/base"; |
|
import { MultiSelectSearcher } from "./trigger/searcher.multiselect"; |
|
|
|
@shortcut() |
|
export class MultiSelectTrigger extends Trigger { |
|
static xtype = "bi.multi_select_trigger"; |
|
|
|
constants = { height: 14, rgap: 4, lgap: 4 }; |
|
|
|
static EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; |
|
static EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK"; |
|
static EVENT_CHANGE = "EVENT_CHANGE"; |
|
static EVENT_START = "EVENT_START"; |
|
static EVENT_STOP = "EVENT_STOP"; |
|
static EVENT_PAUSE = "EVENT_PAUSE"; |
|
static EVENT_SEARCHING = "EVENT_SEARCHING"; |
|
static EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; |
|
static EVENT_BLUR = "EVENT_BLUR"; |
|
static EVENT_FOCUS = "EVENT_FOCUS"; |
|
|
|
_defaultConfig() { |
|
return extend(super._defaultConfig(...arguments), { |
|
baseCls: "bi-multi-select-trigger", |
|
itemsCreator: emptyFn, |
|
valueFormatter: emptyFn, |
|
searcher: {}, |
|
switcher: {}, |
|
|
|
adapter: null, |
|
masker: {}, |
|
allowEdit: true, |
|
itemHeight: 24, |
|
}); |
|
} |
|
|
|
_init() { |
|
super._init(...arguments); |
|
|
|
const self = this, |
|
o = this.options; |
|
|
|
this.searcher = createWidget(o.searcher, { |
|
type: MultiSelectSearcher.xtype, |
|
height: o.height, |
|
text: o.text, |
|
defaultText: o.defaultText, |
|
itemsCreator: o.itemsCreator, |
|
itemHeight: o.itemHeight, |
|
valueFormatter: o.valueFormatter, |
|
itemFormatter: o.itemFormatter, |
|
watermark: o.watermark, |
|
popup: {}, |
|
adapter: o.adapter, |
|
masker: o.masker, |
|
value: o.value, |
|
}); |
|
this.searcher.on(MultiSelectSearcher.EVENT_START, () => { |
|
self.fireEvent(MultiSelectTrigger.EVENT_START); |
|
}); |
|
this.searcher.on(MultiSelectSearcher.EVENT_PAUSE, () => { |
|
self.fireEvent(MultiSelectTrigger.EVENT_PAUSE); |
|
}); |
|
this.searcher.on(MultiSelectSearcher.EVENT_SEARCHING, function () { |
|
self.fireEvent(MultiSelectTrigger.EVENT_SEARCHING, arguments); |
|
}); |
|
this.searcher.on(MultiSelectSearcher.EVENT_STOP, () => { |
|
self.fireEvent(MultiSelectTrigger.EVENT_STOP); |
|
}); |
|
this.searcher.on(MultiSelectSearcher.EVENT_CHANGE, function () { |
|
self.fireEvent(MultiSelectTrigger.EVENT_CHANGE, arguments); |
|
}); |
|
this.searcher.on(MultiSelectSearcher.EVENT_BLUR, () => { |
|
self.fireEvent(MultiSelectTrigger.EVENT_BLUR); |
|
}); |
|
this.searcher.on(MultiSelectSearcher.EVENT_FOCUS, () => { |
|
self.fireEvent(MultiSelectTrigger.EVENT_FOCUS); |
|
}); |
|
|
|
this.wrapNumberCounter = createWidget({ |
|
type: Layout.xtype, |
|
}); |
|
|
|
this.wrapper = createWidget({ |
|
type: HTapeLayout.xtype, |
|
element: this, |
|
items: [ |
|
{ |
|
el: this.searcher, |
|
width: "fill", |
|
rgap: 24, |
|
} |
|
], |
|
}); |
|
|
|
!o.allowEdit && |
|
createWidget({ |
|
type: AbsoluteLayout.xtype, |
|
element: this, |
|
items: [ |
|
{ |
|
el: { |
|
type: Text.xtype, |
|
title() { |
|
/** 修正REPORT-73699引入,需要考虑到传递过来的值是方法的情况 */ |
|
const state = self.searcher.getState(); |
|
if (isFunction(state)) { |
|
return state(); |
|
} |
|
|
|
return state; |
|
}, |
|
}, |
|
left: 0, |
|
right: 24, |
|
top: 0, |
|
bottom: 0, |
|
} |
|
], |
|
}); |
|
} |
|
|
|
refreshPlaceHolderWidth(width) { |
|
this.wrapper.attr("items")[0].rgap = 24 + width; |
|
this.wrapper.resize(); |
|
} |
|
|
|
getSearcher() { |
|
return this.searcher; |
|
} |
|
|
|
stopEditing() { |
|
this.searcher.stopSearch(); |
|
} |
|
|
|
setAdapter(adapter) { |
|
this.searcher.setAdapter(adapter); |
|
} |
|
|
|
setValue(ob) { |
|
this.searcher.setValue(ob); |
|
} |
|
|
|
getKey() { |
|
return this.searcher.getKey(); |
|
} |
|
|
|
getValue() { |
|
return this.searcher.getValue(); |
|
} |
|
|
|
focus() { |
|
this.searcher.focus(); |
|
} |
|
|
|
blur() { |
|
this.searcher.blur(); |
|
} |
|
|
|
setWaterMark(v) { |
|
this.searcher.setWaterMark(v); |
|
} |
|
}
|
|
|