fineui是帆软报表和BI产品线所使用的前端框架。
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.

235 lines
6.8 KiB

import {
shortcut,
Widget,
extend,
emptyFn,
i18nText,
createWidget,
isNotNull,
size,
each
} from "@/core";
import { MultiSelectEditor } from "editor.multiselect";
import { Searcher } from "@/base";
@shortcut()
export class MultiSelectSearcher extends Widget {
static xtype = "bi.multi_select_searcher";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
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_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
7 years ago
baseCls: "bi-multi-select-searcher",
itemsCreator: emptyFn,
el: {},
popup: {},
valueFormatter: emptyFn,
adapter: null,
7 years ago
masker: {},
defaultText: i18nText("BI-Basic_Please_Select"),
itemHeight: 24,
});
}
_init() {
super._init(...arguments);
const self = this,
o = this.options;
this.editor = createWidget(o.el, {
type: MultiSelectEditor.xtype,
7 years ago
height: o.height,
text: o.text,
defaultText: o.defaultText,
watermark: o.watermark,
listeners: [
{
eventName: MultiSelectEditor.EVENT_FOCUS,
action () {
self.fireEvent(MultiSelectSearcher.EVENT_FOCUS);
},
},
{
eventName: MultiSelectEditor.EVENT_BLUR,
action () {
self.fireEvent(MultiSelectSearcher.EVENT_BLUR);
},
}
],
});
this.searcher = createWidget({
type: Searcher.xtype,
element: this,
height: o.height,
isAutoSearch: false,
isAutoSync: false,
onSearch (op, callback) {
callback();
},
el: this.editor,
popup: extend(
{
type: "bi.multi_select_search_pane",
valueFormatter: o.valueFormatter,
itemFormatter: o.itemFormatter,
keywordGetter () {
return self.editor.getValue();
},
itemsCreator (op, callback) {
const keyword = self.editor.getValue();
op.keywords = [keyword];
o.itemsCreator(op, () => {
const keyword = self.editor.getValue();
op.keywords = [keyword];
o.itemsCreator(op, function () {
if (keyword === self.editor.getValue()) {
callback.apply(null, arguments);
}
});
});
},
itemHeight: o.itemHeight,
value: o.value,
},
o.popup
),
adapter: o.adapter,
masker: o.masker,
});
this.searcher.on(Searcher.EVENT_START, () => {
self.fireEvent(MultiSelectSearcher.EVENT_START);
});
this.searcher.on(Searcher.EVENT_PAUSE, function () {
if (this.hasMatched()) {
}
self.fireEvent(MultiSelectSearcher.EVENT_PAUSE);
});
this.searcher.on(Searcher.EVENT_STOP, () => {
self.fireEvent(MultiSelectSearcher.EVENT_STOP);
});
this.searcher.on(Searcher.EVENT_CHANGE, function () {
self.fireEvent(MultiSelectSearcher.EVENT_CHANGE, arguments);
});
this.searcher.on(Searcher.EVENT_SEARCHING, function () {
const keywords = this.getKeywords();
self.fireEvent(MultiSelectSearcher.EVENT_SEARCHING, keywords);
});
if (isNotNull(o.value)) {
this.setState(o.value);
}
}
focus() {
this.editor.focus();
}
blur() {
this.editor.blur();
}
adjustView() {
this.searcher.adjustView();
}
isSearching() {
return this.searcher.isSearching();
}
stopSearch() {
this.searcher.stopSearch();
}
getKeyword() {
return this.editor.getValue();
}
hasMatched() {
return this.searcher.hasMatched();
}
hasChecked() {
return this.searcher.getView() && this.searcher.getView().hasChecked();
}
setAdapter(adapter) {
8 years ago
this.searcher.setAdapter(adapter);
}
8 years ago
setState(ob) {
const o = this.options;
ob || (ob = {});
ob.value || (ob.value = []);
if (ob.type === BI.Selection.All) {
8 years ago
if (ob.value.length === 0) {
this.editor.setState(BI.Selection.All);
} else if (size(ob.assist) <= 20) {
8 years ago
var state = "";
each(ob.assist, (i, v) => {
8 years ago
if (i === 0) {
state +=
`${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
8 years ago
} else {
state +=
`,${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
8 years ago
}
});
this.editor.setState(state);
8 years ago
} else {
8 years ago
this.editor.setState(BI.Selection.Multi);
8 years ago
}
} else {
8 years ago
if (ob.value.length === 0) {
this.editor.setState(BI.Selection.None);
} else if (size(ob.value) <= 20) {
8 years ago
var state = "";
each(ob.value, (i, v) => {
8 years ago
if (i === 0) {
state +=
`${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
8 years ago
} else {
state +=
`,${
v === null ? "" : o.valueFormatter(`${v}`) || v}`;
8 years ago
}
});
this.editor.setState(state);
} else {
8 years ago
this.editor.setState(BI.Selection.Multi);
}
}
}
getState() {
return this.editor.getState();
}
setValue(ob) {
this.setState(ob);
this.searcher.setValue(ob);
}
getKey() {
return this.editor.getValue();
}
getValue() {
return this.searcher.getValue();
}
populate(items) {
this.searcher.populate.apply(this.searcher, arguments);
}
}