Browse Source

KERNEL-14109 refactor:componet/treevaluechooser文件es6化

es6
Joker.Wang-王顺 2 years ago
parent
commit
8aac9606ec
  1. 3
      src/case/ztree/tree.display.js
  2. 3
      src/case/ztree/treeview.js
  3. 3
      src/component/index.js
  4. 881
      src/component/treevaluechooser/abstract.treevaluechooser.js
  5. 289
      src/component/treevaluechooser/abstract.treevaluechooser.list.js
  6. 175
      src/component/treevaluechooser/combo.listtreevaluechooser.js
  7. 177
      src/component/treevaluechooser/combo.treevaluechooser.insert.js
  8. 194
      src/component/treevaluechooser/combo.treevaluechooser.js
  9. 6
      src/component/treevaluechooser/index.js
  10. 76
      src/component/treevaluechooser/pane.treevaluechooser.js
  11. 12
      src/widget/multitree/multi.tree.combo.js

3
src/case/ztree/tree.display.js

@ -1,4 +1,4 @@
import { extend } from "@/core"; import { extend, shortcut } from "@/core";
import { TreeView } from "./treeview"; import { TreeView } from "./treeview";
/** /**
@ -8,6 +8,7 @@ import { TreeView } from "./treeview";
* @extends BI.TreeView * @extends BI.TreeView
*/ */
@shortcut()
export class DisplayTree extends TreeView { export class DisplayTree extends TreeView {
static xtype = "bi.display_tree"; static xtype = "bi.display_tree";
static EVENT_CHANGE = "EVENT_CHANGE"; static EVENT_CHANGE = "EVENT_CHANGE";

3
src/case/ztree/treeview.js

@ -20,7 +20,8 @@ import {
shortcut, shortcut,
VerticalLayout, VerticalLayout,
Layout, Layout,
DefaultLayout DefaultLayout,
some
} from "@/core"; } from "@/core";
import { Msg, Pane, LoadingBar, Text } from "@/base"; import { Msg, Pane, LoadingBar, Text } from "@/base";

3
src/component/index.js

@ -1,18 +1,21 @@
export * as allvaluechooser from "./allvaluechooser"; export * as allvaluechooser from "./allvaluechooser";
export * as form from "./form"; export * as form from "./form";
export * as valueChooser from "./valuechooser"; export * as valueChooser from "./valuechooser";
export * as treeValueChooser from "./treevaluechooser";
export { AllValueMultiTextValueCombo } from "./allvaluemultitextvaluecombo/allvalue.multitextvalue.combo"; export { AllValueMultiTextValueCombo } from "./allvaluemultitextvaluecombo/allvalue.multitextvalue.combo";
// Object.assign(BI, { // Object.assign(BI, {
// ...allvaluechooser, // ...allvaluechooser,
// ...form, // ...form,
// ...valueChooser, // ...valueChooser,
// ......treeValueChooser,
// AllValueMultiTextValueCombo, // AllValueMultiTextValueCombo,
// }); // });
// export * from "./allvaluechooser"; // export * from "./allvaluechooser";
// export * from "./form"; // export * from "./form";
// export * from "./valuechooser"; // export * from "./valuechooser";
// export * from "./treevaluechooser";
// export { // export {
// AllValueMultiTextValueCombo // AllValueMultiTextValueCombo
// }; // };

881
src/component/treevaluechooser/abstract.treevaluechooser.js

File diff suppressed because it is too large Load Diff

289
src/component/treevaluechooser/abstract.treevaluechooser.list.js

@ -1,36 +1,60 @@
BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, { import {
isEmpty,
values,
each,
isNull,
UUID,
has,
nextTick,
last,
concat,
filter,
Func,
clone,
any,
isEqual,
every,
flatten,
map,
difference
} from "@/core";
import { AbstractTreeValueChooser } from "./abstract.treevaluechooser";
_reqDisplayTreeNode: function (op, callback) { export class AbstractListTreeValueChooser extends AbstractTreeValueChooser {
var self = this; _reqDisplayTreeNode(op, callback) {
var result = {}; const result = {};
var selectedValues = op.selectedValues; const selectedValues = op.selectedValues;
if (selectedValues == null || BI.isEmpty(selectedValues)) { if (selectedValues == null || isEmpty(selectedValues)) {
callback({}); callback({});
return; return;
} }
doCheck([], this.tree.getRoot(), selectedValues); doCheck([], this.tree.getRoot(), selectedValues);
callback({ callback({
items: BI.values(result) items: values(result),
}); });
function doCheck(parentValues, node, selected) { function doCheck(parentValues, node, selected) {
BI.each(selected, function (idx, path) { each(selected, (idx, path) => {
BI.each(path, function (id, value) { each(path, (id, value) => {
var nodeValue = value; const nodeValue = value;
var node = self._getTreeNode(path.slice(0, id), nodeValue); const node = this._getTreeNode(path.slice(0, id), nodeValue);
// 找不到就是新增值 // 找不到就是新增值
if (BI.isNull(node)) { if (isNull(node)) {
createOneJson({ createOneJson(
id: BI.UUID(), {
text: nodeValue, id: UUID(),
value: nodeValue, text: nodeValue,
isLeaf: true value: nodeValue,
}, BI.UUID()); isLeaf: true,
},
UUID()
);
} else { } else {
if(!BI.has(result, node.id)) { if (!has(result, node.id)) {
createOneJson(node, node.parent && node.parent.id); createOneJson(node, node.parent && node.parent.id);
} }
result[node.id].isLeaf !== true && (result[node.id].isLeaf = id === path.length - 1); result[node.id].isLeaf !== true && (result[node.id].isLeaf = id === path.length - 1);
@ -42,35 +66,34 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, {
function createOneJson(node, pId) { function createOneJson(node, pId) {
result[node.id] = { result[node.id] = {
id: node.id, id: node.id,
pId: pId, pId,
text: node.text, text: node.text,
value: node.value, value: node.value,
open: true, open: true,
isLeaf: node.isLeaf isLeaf: node.isLeaf,
}; };
} }
}, }
_reqInitTreeNode: function (op, callback) { _reqInitTreeNode(op, callback) {
var self = this; let result = [];
var result = []; const keyword = op.keyword || "";
var keyword = op.keyword || ""; const selectedValues = op.selectedValues;
var selectedValues = op.selectedValues; const lastSearchValue = op.lastSearchValue || ""; // 一次请求100个,但是搜索是拿全部的,lastSearchValue是上一次遍历到的节点索引
var lastSearchValue = op.lastSearchValue || ""; // 一次请求100个,但是搜索是拿全部的,lastSearchValue是上一次遍历到的节点索引 const output = search();
var output = search(); nextTick(() => {
BI.nextTick(function () {
callback({ callback({
hasNext: output.length > self._const.perPage, hasNext: output.length > this._const.perPage,
items: result, items: result,
lastSearchValue: BI.last(output) lastSearchValue: last(output),
}); });
}); });
function search() { const search = () => {
var children = self._getChildren([]); const children = this._getChildren([]);
var start = children.length; let start = children.length;
if (lastSearchValue !== "") { if (lastSearchValue !== "") {
for (var j = 0, len = start; j < len; j++) { for (let j = 0, len = start; j < len; j++) {
if (children[j].value === lastSearchValue) { if (children[j].value === lastSearchValue) {
start = j + 1; start = j + 1;
break; break;
@ -79,46 +102,72 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, {
} else { } else {
start = 0; start = 0;
} }
var output = []; const output = [];
for (var i = start, len = children.length; i < len; i++) { let find;
if (output.length < self._const.perPage) { for (let i = start, len = children.length; i < len; i++) {
var find = nodeSearch(1, [], children[i].value, result); if (output.length < this._const.perPage) {
} else if (output.length === self._const.perPage) { find = nodeSearch(1, [], children[i].value, result);
var find = nodeSearch(1, [], children[i].value, []); } else if (output.length === this._const.perPage) {
find = nodeSearch(1, [], children[i].value, []);
} }
if (find[0] === true) { if (find[0] === true) {
output.push(children[i].value); output.push(children[i].value);
} }
if (output.length > self._const.perPage) { if (output.length > this._const.perPage) {
break; break;
} }
} }
// 深层嵌套的比较麻烦,这边先实现的是在根节点添加 // 深层嵌套的比较麻烦,这边先实现的是在根节点添加
if (op.times === 1) { if (op.times === 1) {
var nodes = self._getAddedValueNode([], selectedValues); const nodes = this._getAddedValueNode([], selectedValues);
result = BI.concat(BI.filter(nodes, function (idx, node) { result = concat(
var find = BI.Func.getSearchResult([node.text || node.value], keyword); filter(nodes, (idx, node) => {
return find.find.length > 0 || find.match.length > 0; const find = Func.getSearchResult([node.text || node.value], keyword);
}), result);
return find.find.length > 0 || find.match.length > 0;
}),
result
);
} }
return output; return output;
} };
function nodeSearch(deep, parentValues, current, result) { const createOneJson = (parentValues, value, isOpen, checked, flag, result) => {
if (self._isMatch(parentValues, current, keyword)) { const node = this._getTreeNode(parentValues, value);
var checked = isSelected(parentValues, current); result.push({
id: node.id,
pId: node.pId,
text: node.text,
value: node.value,
title: node.title,
isParent: node.getChildrenLength() > 0,
open: isOpen,
checked,
halfCheck: false,
flag,
disabled: node.disabled,
});
};
const nodeSearch = (deep, parentValues, current, result) => {
let checked;
if (this._isMatch(parentValues, current, keyword)) {
checked = isSelected(parentValues, current);
createOneJson(parentValues, current, false, checked, true, result); createOneJson(parentValues, current, false, checked, true, result);
return [true, checked]; return [true, checked];
} }
var newParents = BI.clone(parentValues); const newParents = clone(parentValues);
newParents.push(current); newParents.push(current);
var children = self._getChildren(newParents); const children = this._getChildren(newParents);
var can = false, checked = false; let can = false;
checked = false;
BI.each(children, function (i, child) { each(children, (i, child) => {
var state = nodeSearch(deep + 1, newParents, child.value, result); const state = nodeSearch(deep + 1, newParents, child.value, result);
if (state[1] === true) { if (state[1] === true) {
checked = true; checked = true;
} }
@ -130,48 +179,36 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, {
checked = isSelected(parentValues, current); checked = isSelected(parentValues, current);
createOneJson(parentValues, current, true, checked, false, result); createOneJson(parentValues, current, true, checked, false, result);
} }
return [can, checked];
}
function createOneJson(parentValues, value, isOpen, checked, flag, result) { return [can, checked];
var node = self._getTreeNode(parentValues, value); };
result.push({
id: node.id,
pId: node.pId,
text: node.text,
value: node.value,
title: node.title,
isParent: node.getChildrenLength() > 0,
open: isOpen,
checked: checked,
halfCheck: false,
flag: flag,
disabled: node.disabled
});
}
// eslint-disable-next-line no-unused-vars
function isHalf(parentValues, value) { function isHalf(parentValues, value) {
var find = findSelectedObj(parentValues); const find = findSelectedObj(parentValues);
if (find == null) { if (find == null) {
return null; return null;
} }
return BI.any(find, function (v, ob) {
return any(find, (v, ob) => {
if (v === value) { if (v === value) {
if (ob != null && !BI.isEmpty(ob)) { if (ob != null && !isEmpty(ob)) {
return true; return true;
} }
} }
}); });
} }
// eslint-disable-next-line no-unused-vars
function isAllSelected(parentValues, value) { function isAllSelected(parentValues, value) {
var find = findSelectedObj(parentValues); const find = findSelectedObj(parentValues);
if (find == null) { if (find == null) {
return null; return null;
} }
return BI.any(find, function (v, ob) {
return any(find, (v, ob) => {
if (v === value) { if (v === value) {
if (ob != null && BI.isEmpty(ob)) { if (ob != null && isEmpty(ob)) {
return true; return true;
} }
} }
@ -179,37 +216,37 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, {
} }
function isSelected(parentValues, value) { function isSelected(parentValues, value) {
return BI.any(selectedValues, function (idx, array) { return any(selectedValues, (idx, array) => isEqual(parentValues, array.slice(0, parentValues.length)) && last(array) === value);
return BI.isEqual(parentValues, array.slice(0, parentValues.length)) && BI.last(array) === value;
});
} }
function findSelectedObj(parentValues) { function findSelectedObj(parentValues) {
var find = selectedValues; let find = selectedValues;
if (find == null) { if (find == null) {
return null; return null;
} }
BI.every(parentValues, function (i, v) { every(parentValues, (i, v) => {
find = find[v]; find = find[v];
if (find == null) { if (find == null) {
return false; return false;
} }
return true; return true;
}); });
return find; return find;
} }
}, }
_reqTreeNode: function (op, callback) { _reqTreeNode(op, callback) {
var self = this, o = this.options; const o = this.options;
var result = []; let result = [];
var times = op.times; const times = op.times;
var parentValues = op.parentValues || []; const parentValues = op.parentValues || [];
var selectedValues = op.selectedValues || []; const selectedValues = op.selectedValues || [];
var valueMap = dealWithSelectedValue(parentValues, selectedValues); const valueMap = dealWithSelectedValue(parentValues, selectedValues);
var nodes = this._getChildren(parentValues); const nodes = this._getChildren(parentValues);
for (var i = (times - 1) * this._const.perPage; nodes[i] && i < times * this._const.perPage; i++) { for (let i = (times - 1) * this._const.perPage; nodes[i] && i < times * this._const.perPage; i++) {
var checked = BI.has(valueMap, nodes[i].value); const checked = has(valueMap, nodes[i].value);
result.push({ result.push({
id: nodes[i].id, id: nodes[i].id,
pId: nodes[i].pId, pId: nodes[i].pId,
@ -217,22 +254,22 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, {
text: nodes[i].text, text: nodes[i].text,
times: 1, times: 1,
isParent: nodes[i].getChildrenLength() > 0, isParent: nodes[i].getChildrenLength() > 0,
checked: checked, checked,
halfCheck: false, halfCheck: false,
open: o.open, open: o.open,
disabled: nodes[i].disabled disabled: nodes[i].disabled,
}); });
} }
// 如果指定节点全部打开 // 如果指定节点全部打开
if (o.open) { if (o.open) {
var allNodes = []; let allNodes = [];
// 获取所有节点 // 获取所有节点
BI.each(nodes, function (idx, node) { each(nodes, (idx, node) => {
allNodes = BI.concat(allNodes, self._getAllChildren(parentValues.concat([node.value]))); allNodes = concat(allNodes, this._getAllChildren(parentValues.concat([node.value])));
}); });
BI.each(allNodes, function (idx, node) { each(allNodes, (idx, node) => {
var valueMap = dealWithSelectedValue(node.parentValues, selectedValues); const valueMap = dealWithSelectedValue(node.parentValues, selectedValues);
var checked = BI.has(valueMap, node.value); const checked = has(valueMap, node.value);
result.push({ result.push({
id: node.id, id: node.id,
pId: node.pId, pId: node.pId,
@ -240,51 +277,53 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, {
text: node.text, text: node.text,
times: 1, times: 1,
isParent: node.getChildrenLength() > 0, isParent: node.getChildrenLength() > 0,
checked: checked, checked,
halfCheck: false, halfCheck: false,
open: o.open, open: o.open,
disabled: node.disabled disabled: node.disabled,
}); });
}); });
} }
// 深层嵌套的比较麻烦,这边先实现的是在根节点添加 // 深层嵌套的比较麻烦,这边先实现的是在根节点添加
if (parentValues.length === 0 && times === 1) { if (parentValues.length === 0 && times === 1) {
result = BI.concat(self._getAddedValueNode(parentValues, selectedValues), result); result = concat(this._getAddedValueNode(parentValues, selectedValues), result);
} }
BI.nextTick(function () { nextTick(() => {
callback({ callback({
items: result, items: result,
hasNext: nodes.length > times * self._const.perPage hasNext: nodes.length > times * this._const.perPage,
}); });
}); });
function dealWithSelectedValue(parentValues, selectedValues) { function dealWithSelectedValue(parentValues, selectedValues) {
var valueMap = {}; const valueMap = {};
BI.each(selectedValues, function (idx, v) { each(selectedValues, (idx, v) => {
if (BI.isEqual(parentValues, v.slice(0, parentValues.length))) { if (isEqual(parentValues, v.slice(0, parentValues.length))) {
valueMap[BI.last(v)] = [2, 0]; valueMap[last(v)] = [2, 0];
} }
}); });
return valueMap; return valueMap;
} }
}, }
_getAddedValueNode: function (parentValues, selectedValues) { _getAddedValueNode(parentValues, selectedValues) {
var nodes = this._getChildren(parentValues); const nodes = this._getChildren(parentValues);
var values = BI.flatten(BI.filter(selectedValues, function (idx, array) { const values = flatten(
return array.length === 1; filter(selectedValues, (idx, array) => array.length === 1)
})); );
return BI.map(BI.difference(values, BI.map(nodes, "value")), function (idx, v) {
return map(difference(values, map(nodes, "value")), (idx, v) => {
return { return {
id: BI.UUID(), id: UUID(),
pId: nodes.length > 0 ? nodes[0].pId : BI.UUID(), pId: nodes.length > 0 ? nodes[0].pId : UUID(),
value: v, value: v,
text: v, text: v,
times: 1, times: 1,
isParent: false, isParent: false,
checked: true, checked: true,
halfCheck: false halfCheck: false,
}; };
}); });
} }
}); }

175
src/component/treevaluechooser/combo.listtreevaluechooser.js

@ -1,31 +1,39 @@
/** import { shortcut, extend, emptyFn, isNotNull, createWidget, bind } from "@/core";
* 简单的复选下拉树控件, 适用于数据量少的情况, 可以自增值 import { AbstractListTreeValueChooser } from "./abstract.treevaluechooser.list";
* import { MultiTreeListCombo, MultiTreeCombo } from "@/widget";
* Created by GUY on 2015/10/29. import { TreeValueChooserInsertCombo } from "./combo.treevaluechooser.insert";
* @class BI.ListTreeValueChooserInsertCombo
* @extends BI.Widget
*/
BI.ListTreeValueChooserInsertCombo = BI.inherit(BI.AbstractListTreeValueChooser, {
_defaultConfig: function () { @shortcut()
return BI.extend(BI.ListTreeValueChooserInsertCombo.superclass._defaultConfig.apply(this, arguments), { export class ListTreeValueChooserInsertCombo extends AbstractListTreeValueChooser {
static xtype = "bi.list_tree_value_chooser_insert_combo";
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR";
static EVENT_STOP = "EVENT_STOP";
static EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM";
static EVENT_SEARCHING = "EVENT_SEARCHING";
static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-list-tree-value-chooser-insert-combo", baseCls: "bi-list-tree-value-chooser-insert-combo",
width: 200, width: 200,
height: 24, height: 24,
items: null, items: null,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
isNeedAdjustWidth: true, isNeedAdjustWidth: true,
}); });
}, }
_init: function () { _init() {
BI.ListTreeValueChooserInsertCombo.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
if (BI.isNotNull(o.items)) { if (isNotNull(o.items)) {
this._initData(o.items); this._initData(o.items);
} }
this.combo = BI.createWidget({ this.combo = createWidget({
type: "bi.multi_tree_list_combo", type: MultiTreeListCombo.xtype,
simple: o.simple, simple: o.simple,
isNeedAdjustWidth: o.isNeedAdjustWidth, isNeedAdjustWidth: o.isNeedAdjustWidth,
element: this, element: this,
@ -35,94 +43,93 @@ BI.ListTreeValueChooserInsertCombo = BI.inherit(BI.AbstractListTreeValueChooser,
watermark: o.watermark, watermark: o.watermark,
allowInsertValue: o.allowInsertValue, allowInsertValue: o.allowInsertValue,
allowEdit: o.allowEdit, allowEdit: o.allowEdit,
itemsCreator: BI.bind(this._itemsCreator, this), itemsCreator: bind(this._itemsCreator, this),
valueFormatter: BI.bind(this._valueFormatter, this), valueFormatter: bind(this._valueFormatter, this),
width: o.width, width: o.width,
height: o.height, height: o.height,
listeners: [{ listeners: [
eventName: BI.MultiTreeListCombo.EVENT_FOCUS, {
action: function () { eventName: MultiTreeListCombo.EVENT_FOCUS,
self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_FOCUS); action: () => {
} this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_FOCUS);
}, { },
eventName: BI.MultiTreeListCombo.EVENT_BLUR, },
action: function () { {
self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_BLUR); eventName: MultiTreeListCombo.EVENT_BLUR,
} action: () => {
}, { this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_BLUR);
eventName: BI.MultiTreeListCombo.EVENT_STOP, },
action: function () { },
self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_STOP); {
eventName: MultiTreeListCombo.EVENT_STOP,
action: () => {
this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_STOP);
},
},
{
eventName: MultiTreeListCombo.EVENT_CLICK_ITEM,
action: v => {
this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_CLICK_ITEM, v);
},
},
{
eventName: MultiTreeListCombo.EVENT_SEARCHING,
action: () => {
this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_SEARCHING);
},
},
{
eventName: MultiTreeListCombo.EVENT_CONFIRM,
action: () => {
this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_CONFIRM);
},
},
{
eventName: MultiTreeCombo.EVENT_BEFORE_POPUPVIEW,
action: () => {
this.fireEvent(TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW);
},
} }
}, { ],
eventName: BI.MultiTreeListCombo.EVENT_CLICK_ITEM,
action: function (v) {
self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_CLICK_ITEM, v);
}
}, {
eventName: BI.MultiTreeListCombo.EVENT_SEARCHING,
action: function () {
self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_SEARCHING);
}
}, {
eventName: BI.MultiTreeListCombo.EVENT_CONFIRM,
action: function () {
self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_CONFIRM);
}
}, {
eventName: BI.MultiTreeCombo.EVENT_BEFORE_POPUPVIEW,
action: function () {
self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW);
}
}]
}); });
}, }
showView: function () { showView() {
this.combo.showView(); this.combo.showView();
}, }
hideView: function () { hideView() {
this.combo.hideView(); this.combo.hideView();
}, }
getSearcher: function () { getSearcher() {
return this.combo.getSearcher(); return this.combo.getSearcher();
}, }
setValue: function (v) { setValue(v) {
this.combo.setValue(v); this.combo.setValue(v);
}, }
getValue: function () { getValue() {
return this.combo.getValue(); return this.combo.getValue();
}, }
populate: function (items) { populate(items) {
if (BI.isNotNull(items)) { if (isNotNull(items)) {
this._initData(items); this._initData(items);
} }
this.combo.populate(); this.combo.populate();
}, }
focus: function () { focus() {
this.combo.focus(); this.combo.focus();
}, }
blur: function () { blur() {
this.combo.blur(); this.combo.blur();
}, }
setWaterMark: function (v) { setWaterMark(v) {
this.combo.setWaterMark(v); this.combo.setWaterMark(v);
} }
}); }
BI.ListTreeValueChooserInsertCombo.EVENT_FOCUS = "EVENT_FOCUS";
BI.ListTreeValueChooserInsertCombo.EVENT_BLUR = "EVENT_BLUR";
BI.ListTreeValueChooserInsertCombo.EVENT_STOP = "EVENT_STOP";
BI.ListTreeValueChooserInsertCombo.EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM";
BI.ListTreeValueChooserInsertCombo.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.ListTreeValueChooserInsertCombo.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.ListTreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
BI.shortcut("bi.list_tree_value_chooser_insert_combo", BI.ListTreeValueChooserInsertCombo);

177
src/component/treevaluechooser/combo.treevaluechooser.insert.js

@ -1,31 +1,39 @@
/** import { shortcut, extend, emptyFn, isNotNull, createWidget, bind } from "@/core";
* 简单的复选下拉树控件, 适用于数据量少的情况, 可以自增值 import { AbstractTreeValueChooser } from "./abstract.treevaluechooser";
* import { MultiTreeInsertCombo, MultiTreeCombo } from "@/widget";
* Created by GUY on 2015/10/29. import { TreeValueChooserCombo } from "./combo.treevaluechooser";
* @class BI.TreeValueChooserInsertCombo
* @extends BI.Widget
*/
BI.TreeValueChooserInsertCombo = BI.inherit(BI.AbstractTreeValueChooser, {
_defaultConfig: function () { @shortcut()
return BI.extend(BI.TreeValueChooserInsertCombo.superclass._defaultConfig.apply(this, arguments), { export class TreeValueChooserInsertCombo extends AbstractTreeValueChooser {
static xtype = "bi.tree_value_chooser_insert_combo";
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR";
static EVENT_STOP = "EVENT_STOP";
static EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM";
static EVENT_SEARCHING = "EVENT_SEARCHING";
static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-tree-value-chooser-insert-combo", baseCls: "bi-tree-value-chooser-insert-combo",
width: 200, width: 200,
height: 24, height: 24,
items: null, items: null,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
isNeedAdjustWidth: true isNeedAdjustWidth: true,
}); });
}, }
_init: function () { _init() {
BI.TreeValueChooserInsertCombo.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
if (BI.isNotNull(o.items)) { if (isNotNull(o.items)) {
this._initData(o.items); this._initData(o.items);
} }
this.combo = BI.createWidget({ this.combo = createWidget({
type: "bi.multi_tree_insert_combo", type: MultiTreeInsertCombo.xtype,
simple: o.simple, simple: o.simple,
isNeedAdjustWidth: o.isNeedAdjustWidth, isNeedAdjustWidth: o.isNeedAdjustWidth,
allowEdit: o.allowEdit, allowEdit: o.allowEdit,
@ -34,94 +42,93 @@ BI.TreeValueChooserInsertCombo = BI.inherit(BI.AbstractTreeValueChooser, {
value: o.value, value: o.value,
watermark: o.watermark, watermark: o.watermark,
element: this, element: this,
itemsCreator: BI.bind(this._itemsCreator, this), itemsCreator: bind(this._itemsCreator, this),
valueFormatter: BI.bind(this._valueFormatter, this), valueFormatter: bind(this._valueFormatter, this),
width: o.width, width: o.width,
height: o.height, height: o.height,
listeners: [{ listeners: [
eventName: BI.MultiTreeInsertCombo.EVENT_FOCUS, {
action: function () { eventName: MultiTreeInsertCombo.EVENT_FOCUS,
self.fireEvent(BI.TreeValueChooserCombo.EVENT_FOCUS); action: () => {
} this.fireEvent(TreeValueChooserCombo.EVENT_FOCUS);
}, { },
eventName: BI.MultiTreeInsertCombo.EVENT_BLUR, },
action: function () { {
self.fireEvent(BI.TreeValueChooserCombo.EVENT_BLUR); eventName: MultiTreeInsertCombo.EVENT_BLUR,
} action: () => {
}, { this.fireEvent(TreeValueChooserCombo.EVENT_BLUR);
eventName: BI.MultiTreeInsertCombo.EVENT_STOP, },
action: function () { },
self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_STOP); {
eventName: MultiTreeInsertCombo.EVENT_STOP,
action: () => {
this.fireEvent(TreeValueChooserInsertCombo.EVENT_STOP);
},
},
{
eventName: MultiTreeInsertCombo.EVENT_CLICK_ITEM,
action: v => {
this.fireEvent(TreeValueChooserInsertCombo.EVENT_CLICK_ITEM, v);
},
},
{
eventName: MultiTreeInsertCombo.EVENT_SEARCHING,
action: () => {
this.fireEvent(TreeValueChooserInsertCombo.EVENT_SEARCHING);
},
},
{
eventName: MultiTreeInsertCombo.EVENT_CONFIRM,
action: () => {
this.fireEvent(TreeValueChooserInsertCombo.EVENT_CONFIRM);
},
},
{
eventName: MultiTreeCombo.EVENT_BEFORE_POPUPVIEW,
action: () => {
this.fireEvent(TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW);
},
} }
}, { ],
eventName: BI.MultiTreeInsertCombo.EVENT_CLICK_ITEM,
action: function (v) {
self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_CLICK_ITEM, v);
}
}, {
eventName: BI.MultiTreeInsertCombo.EVENT_SEARCHING,
action: function () {
self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_SEARCHING);
}
}, {
eventName: BI.MultiTreeInsertCombo.EVENT_CONFIRM,
action: function () {
self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_CONFIRM);
}
}, {
eventName: BI.MultiTreeCombo.EVENT_BEFORE_POPUPVIEW,
action: function () {
self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW);
}
}]
}); });
}, }
showView: function () { showView() {
this.combo.showView(); this.combo.showView();
}, }
hideView: function () { hideView() {
this.combo.hideView(); this.combo.hideView();
}, }
getSearcher: function () { getSearcher() {
return this.combo.getSearcher(); return this.combo.getSearcher();
}, }
setValue: function (v) { setValue(v) {
this.combo.setValue(v); this.combo.setValue(v);
}, }
getValue: function () { getValue() {
return this.combo.getValue(); return this.combo.getValue();
}, }
populate: function (items) { populate(items) {
if (BI.isNotNull(items)) { if (isNotNull(items)) {
this._initData(items); this._initData(items);
} }
this.combo.populate(); this.combo.populate();
}, }
focus: function () { focus() {
this.combo.focus(); this.combo.focus();
}, }
blur: function () { blur() {
this.combo.blur(); this.combo.blur();
}, }
setWaterMark: function (v) { setWaterMark(v) {
this.combo.setWaterMark(v); this.combo.setWaterMark(v);
} }
}); }
BI.TreeValueChooserInsertCombo.EVENT_FOCUS = "EVENT_FOCUS";
BI.TreeValueChooserInsertCombo.EVENT_BLUR = "EVENT_BLUR";
BI.TreeValueChooserInsertCombo.EVENT_STOP = "EVENT_STOP";
BI.TreeValueChooserInsertCombo.EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM";
BI.TreeValueChooserInsertCombo.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.TreeValueChooserInsertCombo.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
BI.shortcut("bi.tree_value_chooser_insert_combo", BI.TreeValueChooserInsertCombo);

194
src/component/treevaluechooser/combo.treevaluechooser.js

@ -1,31 +1,40 @@
/** import { shortcut, extend, emptyFn, isNotNull, createWidget, bind } from "@/core";
* 简单的复选下拉树控件, 适用于数据量少的情况 import { AbstractTreeValueChooser } from "./abstract.treevaluechooser";
* import { MultiTreeCombo } from "@/widget";
* Created by GUY on 2015/10/29.
* @class BI.TreeValueChooserCombo
* @extends BI.Widget
*/
BI.TreeValueChooserCombo = BI.inherit(BI.AbstractTreeValueChooser, {
_defaultConfig: function () { @shortcut()
return BI.extend(BI.TreeValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { export class TreeValueChooserCombo extends AbstractTreeValueChooser {
// TODO:该组件有问题,未报错,但不显示pane,该问题看起来是其他组件es6化导致
static xtype = "bi.tree_value_chooser_combo";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR";
static EVENT_STOP = "EVENT_STOP";
static EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM";
static EVENT_SEARCHING = "EVENT_SEARCHING";
static EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-tree-value-chooser-combo", baseCls: "bi-tree-value-chooser-combo",
width: 200, width: 200,
height: 24, height: 24,
items: null, items: null,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
isNeedAdjustWidth: true isNeedAdjustWidth: true,
}); });
}, }
_init: function () { _init() {
BI.TreeValueChooserCombo.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
if (BI.isNotNull(o.items)) { if (isNotNull(o.items)) {
this._initData(o.items); this._initData(o.items);
} }
this.combo = BI.createWidget({ this.combo = createWidget({
type: "bi.multi_tree_combo", type: MultiTreeCombo.xtype,
simple: o.simple, simple: o.simple,
text: o.text, text: o.text,
defaultText: o.defaultText, defaultText: o.defaultText,
@ -33,105 +42,104 @@ BI.TreeValueChooserCombo = BI.inherit(BI.AbstractTreeValueChooser, {
value: this.assertSelectedValue(o.value, o.items), value: this.assertSelectedValue(o.value, o.items),
watermark: o.watermark, watermark: o.watermark,
element: this, element: this,
itemsCreator: BI.bind(this._itemsCreator, this), itemsCreator: bind(this._itemsCreator, this),
valueFormatter: BI.bind(this._valueFormatter, this), valueFormatter: bind(this._valueFormatter, this),
width: o.width, width: o.width,
height: o.height, height: o.height,
isNeedAdjustWidth: o.isNeedAdjustWidth, isNeedAdjustWidth: o.isNeedAdjustWidth,
listeners: [{ listeners: [
eventName: BI.MultiTreeCombo.EVENT_FOCUS, {
action: function () { eventName: MultiTreeCombo.EVENT_FOCUS,
self.fireEvent(BI.TreeValueChooserCombo.EVENT_FOCUS); action: () => {
} this.fireEvent(TreeValueChooserCombo.EVENT_FOCUS);
}, { },
eventName: BI.MultiTreeCombo.EVENT_BLUR, },
action: function () { {
self.fireEvent(BI.TreeValueChooserCombo.EVENT_BLUR); eventName: MultiTreeCombo.EVENT_BLUR,
} action: () => {
}, { this.fireEvent(TreeValueChooserCombo.EVENT_BLUR);
eventName: BI.MultiTreeCombo.EVENT_STOP, },
action: function () { },
self.fireEvent(BI.TreeValueChooserCombo.EVENT_STOP); {
} eventName: MultiTreeCombo.EVENT_STOP,
}, { action: () => {
eventName: BI.MultiTreeCombo.EVENT_CLICK_ITEM, this.fireEvent(TreeValueChooserCombo.EVENT_STOP);
action: function (v) { },
self.fireEvent(BI.TreeValueChooserCombo.EVENT_CLICK_ITEM, v); },
{
eventName: MultiTreeCombo.EVENT_CLICK_ITEM,
action: v => {
this.fireEvent(TreeValueChooserCombo.EVENT_CLICK_ITEM, v);
},
},
{
eventName: MultiTreeCombo.EVENT_SEARCHING,
action: () => {
this.fireEvent(TreeValueChooserCombo.EVENT_SEARCHING);
},
},
{
eventName: MultiTreeCombo.EVENT_CONFIRM,
action: () => {
this.fireEvent(TreeValueChooserCombo.EVENT_CONFIRM);
},
},
{
eventName: MultiTreeCombo.EVENT_BEFORE_POPUPVIEW,
action: () => {
this.fireEvent(TreeValueChooserCombo.EVENT_BEFORE_POPUPVIEW);
},
},
{
eventName: MultiTreeCombo.EVENT_AFTER_HIDEVIEW,
action: () => {
this.fireEvent(TreeValueChooserCombo.EVENT_AFTER_HIDEVIEW);
},
} }
}, { ],
eventName: BI.MultiTreeCombo.EVENT_SEARCHING,
action: function () {
self.fireEvent(BI.TreeValueChooserCombo.EVENT_SEARCHING);
}
}, {
eventName: BI.MultiTreeCombo.EVENT_CONFIRM,
action: function () {
self.fireEvent(BI.TreeValueChooserCombo.EVENT_CONFIRM);
}
}, {
eventName: BI.MultiTreeCombo.EVENT_BEFORE_POPUPVIEW,
action: function () {
self.fireEvent(BI.TreeValueChooserCombo.EVENT_BEFORE_POPUPVIEW);
}
}, {
eventName: BI.MultiTreeCombo.EVENT_AFTER_HIDEVIEW,
action: function () {
self.fireEvent(BI.TreeValueChooserCombo.EVENT_AFTER_HIDEVIEW);
}
}]
}); });
}, }
showView: function () { showView() {
this.combo.showView(); this.combo.showView();
}, }
hideView: function () { hideView() {
this.combo.hideView(); this.combo.hideView();
}, }
getSearcher: function () { getSearcher() {
return this.combo.getSearcher(); return this.combo.getSearcher();
}, }
setValue: function (v) { setValue(v) {
this.combo.setValue(v); this.combo.setValue(v);
}, }
getValue: function () { getValue() {
return this.combo.getValue(); return this.combo.getValue();
}, }
getAllValue: function () { getAllValue() {
return this.buildCompleteTree(this.combo.getValue()); return this.buildCompleteTree(this.combo.getValue());
}, }
populate: function (items) { populate(items) {
if (BI.isNotNull(items)) { if (isNotNull(items)) {
this._initData(items); this._initData(items);
} }
this.combo.populate(); this.combo.populate();
}, }
focus: function () { focus() {
this.combo.focus(); this.combo.focus();
}, }
blur: function () { blur() {
this.combo.blur(); this.combo.blur();
}, }
setWaterMark: function (v) { setWaterMark(v) {
this.combo.setWaterMark(v); this.combo.setWaterMark(v);
} }
}); }
BI.TreeValueChooserCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
BI.TreeValueChooserCombo.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.TreeValueChooserCombo.EVENT_FOCUS = "EVENT_FOCUS";
BI.TreeValueChooserCombo.EVENT_BLUR = "EVENT_BLUR";
BI.TreeValueChooserCombo.EVENT_STOP = "EVENT_STOP";
BI.TreeValueChooserCombo.EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM";
BI.TreeValueChooserCombo.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.TreeValueChooserCombo.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW";
BI.shortcut("bi.tree_value_chooser_combo", BI.TreeValueChooserCombo);

6
src/component/treevaluechooser/index.js

@ -0,0 +1,6 @@
export { AbstractTreeValueChooser } from "./abstract.treevaluechooser";
export { AbstractListTreeValueChooser } from "./abstract.treevaluechooser.list";
export { ListTreeValueChooserInsertCombo } from "./combo.listtreevaluechooser";
export { TreeValueChooserInsertCombo } from "./combo.treevaluechooser.insert";
export { TreeValueChooserCombo } from "./combo.treevaluechooser";
export { TreeValueChooserPane } from "./pane.treevaluechooser";

76
src/component/treevaluechooser/pane.treevaluechooser.js

@ -1,66 +1,66 @@
/** import { shortcut, extend, emptyFn, createWidget, bind, isNotNull } from "@/core";
* 简单的树面板, 适用于数据量少的情况 import { AbstractTreeValueChooser } from "./abstract.treevaluechooser";
* import { MultiSelectTree } from "@/widget/multiselecttree/multiselecttree";
* Created by GUY on 2015/10/29. import { MultiSelectTreePopup } from "@/widget/multiselecttree/multiselecttree.popup";
* @class BI.TreeValueChooserPane
* @extends BI.AbstractTreeValueChooser
*/
BI.TreeValueChooserPane = BI.inherit(BI.AbstractTreeValueChooser, {
_defaultConfig: function () { @shortcut()
return BI.extend(BI.TreeValueChooserPane.superclass._defaultConfig.apply(this, arguments), { export class TreeValueChooserPane extends AbstractTreeValueChooser {
static xtype = "bi.tree_value_chooser_pane";
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-tree-value-chooser-pane", baseCls: "bi-tree-value-chooser-pane",
items: null, items: null,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
showLine: true showLine: true,
}); });
}, }
_init: function () { _init() {
BI.TreeValueChooserPane.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
this.pane = BI.createWidget({ this.pane = createWidget({
type: o.hideSearch ? "bi.multi_select_tree_popup" : "bi.multi_select_tree", type: o.hideSearch ? MultiSelectTreePopup.xtype : MultiSelectTree.xtype,
element: this, element: this,
showLine: o.showLine, showLine: o.showLine,
itemsCreator: BI.bind(this._itemsCreator, this) itemsCreator: bind(this._itemsCreator, this),
}); });
this.pane.on(BI.MultiSelectTree.EVENT_CHANGE, function () { this.pane.on(MultiSelectTree.EVENT_CHANGE, () => {
self.fireEvent(BI.TreeValueChooserPane.EVENT_CHANGE); this.fireEvent(TreeValueChooserPane.EVENT_CHANGE);
}); });
if (BI.isNotNull(o.value)) { if (isNotNull(o.value)) {
var selectedValues = this.assertSelectedValue(o.value, o.items); const selectedValues = this.assertSelectedValue(o.value, o.items);
this.pane.setSelectedValue(selectedValues); this.pane.setSelectedValue(selectedValues);
} }
if (BI.isNotNull(o.items)) { if (isNotNull(o.items)) {
this._initData(o.items); this._initData(o.items);
this.pane.populate(); this.pane.populate();
} }
}, }
setSelectedValue: function (v) { setSelectedValue(v) {
this.pane.setSelectedValue(v); this.pane.setSelectedValue(v);
}, }
setValue: function (v) { setValue(v) {
this.pane.setValue(v); this.pane.setValue(v);
}, }
getValue: function () { getValue() {
return this.pane.getValue(); return this.pane.getValue();
}, }
getAllValue: function() { getAllValue() {
return this.buildCompleteTree(this.pane.getValue()); return this.buildCompleteTree(this.pane.getValue());
}, }
populate: function (items) { populate(items) {
if (BI.isNotNull(items)) { if (isNotNull(items)) {
this._initData(items); this._initData(items);
} }
this.pane.populate(); this.pane.populate();
} }
}); }
BI.TreeValueChooserPane.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.tree_value_chooser_pane", BI.TreeValueChooserPane);

12
src/widget/multitree/multi.tree.combo.js

@ -16,6 +16,8 @@ import { MultiTreePopup } from "./multi.tree.popup";
import { MultiSelectTrigger } from "../multiselect/multiselect.trigger"; import { MultiSelectTrigger } from "../multiselect/multiselect.trigger";
import { TriggerIconButton } from "@/case"; import { TriggerIconButton } from "@/case";
import { MultiSelectCheckSelectedSwitcher } from "../multiselect/trigger/switcher.checkselected"; import { MultiSelectCheckSelectedSwitcher } from "../multiselect/trigger/switcher.checkselected";
import { MultiTreeCheckSelectedButton } from "./trigger/multi.tree.button.checkselected";
import { MultiTreeCheckPane } from "./check/multi.tree.check.pane";
@shortcut() @shortcut()
export class MultiTreeCombo extends Single { export class MultiTreeCombo extends Single {
@ -42,6 +44,8 @@ export class MultiTreeCombo extends Single {
} }
_init() { _init() {
const self = this,
o = this.options;
const triggerBtn = createWidget({ const triggerBtn = createWidget({
type: TriggerIconButton.xtype, type: TriggerIconButton.xtype,
width: o.height, width: o.height,
@ -50,8 +54,6 @@ export class MultiTreeCombo extends Single {
}); });
let clear; let clear;
let change; let change;
const self = this,
o = this.options;
super._init(...arguments); super._init(...arguments);
let isInit = false; let isInit = false;
let want2showCounter = false; let want2showCounter = false;
@ -293,10 +295,12 @@ export class MultiTreeCombo extends Single {
this.numberCounter = createWidget({ this.numberCounter = createWidget({
type: "bi.multi_select_check_selected_switcher", type: "bi.multi_select_check_selected_switcher",
el: { el: {
type: "bi.multi_tree_check_selected_button", // type: "bi.multi_tree_check_selected_button",
type: MultiTreeCheckSelectedButton.xtype,
}, },
popup: { popup: {
type: "bi.multi_tree_check_pane", // type: "bi.multi_tree_check_pane",
type: MultiTreeCheckPane.xtype,
}, },
masker: { masker: {
offset: { offset: {

Loading…
Cancel
Save