Browse Source

Merge branch 'es6' of ssh://code.fineres.com:7999/~treecat/fineui into es6

# Conflicts:
#	src/component/treevaluechooser/combo.treevaluechooser.insert.js
#	src/widget/multitree/multi.tree.combo.js
es6
Treecat 2 years ago
parent
commit
d4d2442812
  1. 3
      src/case/ztree/tree.display.js
  2. 3
      src/case/ztree/treeview.js
  3. 3
      src/component/index.js
  4. 887
      src/component/treevaluechooser/abstract.treevaluechooser.js
  5. 289
      src/component/treevaluechooser/abstract.treevaluechooser.list.js
  6. 175
      src/component/treevaluechooser/combo.listtreevaluechooser.js
  7. 31
      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. 87
      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";
/**
@ -8,6 +8,7 @@ import { TreeView } from "./treeview";
* @extends BI.TreeView
*/
@shortcut()
export class DisplayTree extends TreeView {
static xtype = "bi.display_tree";
static EVENT_CHANGE = "EVENT_CHANGE";

3
src/case/ztree/treeview.js

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

3
src/component/index.js

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

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

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

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

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

@ -28,8 +28,7 @@ export class TreeValueChooserInsertCombo extends AbstractTreeValueChooser {
_init() {
super._init(...arguments);
const self = this,
o = this.options;
const o = this.options;
if (isNotNull(o.items)) {
this._initData(o.items);
}
@ -50,44 +49,44 @@ export class TreeValueChooserInsertCombo extends AbstractTreeValueChooser {
listeners: [
{
eventName: MultiTreeInsertCombo.EVENT_FOCUS,
action () {
self.fireEvent(TreeValueChooserCombo.EVENT_FOCUS);
action: () => {
this.fireEvent(TreeValueChooserCombo.EVENT_FOCUS);
},
},
{
eventName: MultiTreeInsertCombo.EVENT_BLUR,
action () {
self.fireEvent(TreeValueChooserCombo.EVENT_BLUR);
action: () => {
this.fireEvent(TreeValueChooserCombo.EVENT_BLUR);
},
},
{
eventName: MultiTreeInsertCombo.EVENT_STOP,
action () {
self.fireEvent(TreeValueChooserInsertCombo.EVENT_STOP);
action: () => {
this.fireEvent(TreeValueChooserInsertCombo.EVENT_STOP);
},
},
{
eventName: MultiTreeInsertCombo.EVENT_CLICK_ITEM,
action (v) {
self.fireEvent(TreeValueChooserInsertCombo.EVENT_CLICK_ITEM, v);
action: v => {
this.fireEvent(TreeValueChooserInsertCombo.EVENT_CLICK_ITEM, v);
},
},
{
eventName: MultiTreeInsertCombo.EVENT_SEARCHING,
action () {
self.fireEvent(TreeValueChooserInsertCombo.EVENT_SEARCHING);
action: () => {
this.fireEvent(TreeValueChooserInsertCombo.EVENT_SEARCHING);
},
},
{
eventName: MultiTreeInsertCombo.EVENT_CONFIRM,
action () {
self.fireEvent(TreeValueChooserInsertCombo.EVENT_CONFIRM);
action: () => {
this.fireEvent(TreeValueChooserInsertCombo.EVENT_CONFIRM);
},
},
{
eventName: MultiTreeCombo.EVENT_BEFORE_POPUPVIEW,
action () {
self.fireEvent(TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW);
action: () => {
this.fireEvent(TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW);
},
}
],

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

@ -1,31 +1,40 @@
/**
* 简单的复选下拉树控件, 适用于数据量少的情况
*
* Created by GUY on 2015/10/29.
* @class BI.TreeValueChooserCombo
* @extends BI.Widget
*/
BI.TreeValueChooserCombo = BI.inherit(BI.AbstractTreeValueChooser, {
import { shortcut, extend, emptyFn, isNotNull, createWidget, bind } from "@/core";
import { AbstractTreeValueChooser } from "./abstract.treevaluechooser";
import { MultiTreeCombo } from "@/widget";
_defaultConfig: function () {
return BI.extend(BI.TreeValueChooserCombo.superclass._defaultConfig.apply(this, arguments), {
@shortcut()
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",
width: 200,
height: 24,
items: null,
itemsCreator: BI.emptyFn,
isNeedAdjustWidth: true
itemsCreator: emptyFn,
isNeedAdjustWidth: true,
});
},
}
_init: function () {
BI.TreeValueChooserCombo.superclass._init.apply(this, arguments);
var self = this, o = this.options;
if (BI.isNotNull(o.items)) {
_init() {
super._init(...arguments);
const o = this.options;
if (isNotNull(o.items)) {
this._initData(o.items);
}
this.combo = BI.createWidget({
type: "bi.multi_tree_combo",
this.combo = createWidget({
type: MultiTreeCombo.xtype,
simple: o.simple,
text: o.text,
defaultText: o.defaultText,
@ -33,105 +42,104 @@ BI.TreeValueChooserCombo = BI.inherit(BI.AbstractTreeValueChooser, {
value: this.assertSelectedValue(o.value, o.items),
watermark: o.watermark,
element: this,
itemsCreator: BI.bind(this._itemsCreator, this),
valueFormatter: BI.bind(this._valueFormatter, this),
itemsCreator: bind(this._itemsCreator, this),
valueFormatter: bind(this._valueFormatter, this),
width: o.width,
height: o.height,
isNeedAdjustWidth: o.isNeedAdjustWidth,
listeners: [{
eventName: BI.MultiTreeCombo.EVENT_FOCUS,
action: function () {
self.fireEvent(BI.TreeValueChooserCombo.EVENT_FOCUS);
}
}, {
eventName: BI.MultiTreeCombo.EVENT_BLUR,
action: function () {
self.fireEvent(BI.TreeValueChooserCombo.EVENT_BLUR);
}
}, {
eventName: BI.MultiTreeCombo.EVENT_STOP,
action: function () {
self.fireEvent(BI.TreeValueChooserCombo.EVENT_STOP);
}
}, {
eventName: BI.MultiTreeCombo.EVENT_CLICK_ITEM,
action: function (v) {
self.fireEvent(BI.TreeValueChooserCombo.EVENT_CLICK_ITEM, v);
listeners: [
{
eventName: MultiTreeCombo.EVENT_FOCUS,
action: () => {
this.fireEvent(TreeValueChooserCombo.EVENT_FOCUS);
},
},
{
eventName: MultiTreeCombo.EVENT_BLUR,
action: () => {
this.fireEvent(TreeValueChooserCombo.EVENT_BLUR);
},
},
{
eventName: MultiTreeCombo.EVENT_STOP,
action: () => {
this.fireEvent(TreeValueChooserCombo.EVENT_STOP);
},
},
{
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();
},
}
hideView: function () {
hideView() {
this.combo.hideView();
},
}
getSearcher: function () {
getSearcher() {
return this.combo.getSearcher();
},
}
setValue: function (v) {
setValue(v) {
this.combo.setValue(v);
},
}
getValue: function () {
getValue() {
return this.combo.getValue();
},
}
getAllValue: function () {
getAllValue() {
return this.buildCompleteTree(this.combo.getValue());
},
}
populate: function (items) {
if (BI.isNotNull(items)) {
populate(items) {
if (isNotNull(items)) {
this._initData(items);
}
this.combo.populate();
},
}
focus: function () {
focus() {
this.combo.focus();
},
}
blur: function () {
blur() {
this.combo.blur();
},
}
setWaterMark: function (v) {
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 @@
/**
* 简单的树面板, 适用于数据量少的情况
*
* Created by GUY on 2015/10/29.
* @class BI.TreeValueChooserPane
* @extends BI.AbstractTreeValueChooser
*/
BI.TreeValueChooserPane = BI.inherit(BI.AbstractTreeValueChooser, {
import { shortcut, extend, emptyFn, createWidget, bind, isNotNull } from "@/core";
import { AbstractTreeValueChooser } from "./abstract.treevaluechooser";
import { MultiSelectTree } from "@/widget/multiselecttree/multiselecttree";
import { MultiSelectTreePopup } from "@/widget/multiselecttree/multiselecttree.popup";
_defaultConfig: function () {
return BI.extend(BI.TreeValueChooserPane.superclass._defaultConfig.apply(this, arguments), {
@shortcut()
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",
items: null,
itemsCreator: BI.emptyFn,
showLine: true
itemsCreator: emptyFn,
showLine: true,
});
},
}
_init: function () {
BI.TreeValueChooserPane.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.pane = BI.createWidget({
type: o.hideSearch ? "bi.multi_select_tree_popup" : "bi.multi_select_tree",
_init() {
super._init(...arguments);
const o = this.options;
this.pane = createWidget({
type: o.hideSearch ? MultiSelectTreePopup.xtype : MultiSelectTree.xtype,
element: this,
showLine: o.showLine,
itemsCreator: BI.bind(this._itemsCreator, this)
itemsCreator: bind(this._itemsCreator, this),
});
this.pane.on(BI.MultiSelectTree.EVENT_CHANGE, function () {
self.fireEvent(BI.TreeValueChooserPane.EVENT_CHANGE);
this.pane.on(MultiSelectTree.EVENT_CHANGE, () => {
this.fireEvent(TreeValueChooserPane.EVENT_CHANGE);
});
if (BI.isNotNull(o.value)) {
var selectedValues = this.assertSelectedValue(o.value, o.items);
if (isNotNull(o.value)) {
const selectedValues = this.assertSelectedValue(o.value, o.items);
this.pane.setSelectedValue(selectedValues);
}
if (BI.isNotNull(o.items)) {
if (isNotNull(o.items)) {
this._initData(o.items);
this.pane.populate();
}
},
}
setSelectedValue: function (v) {
setSelectedValue(v) {
this.pane.setSelectedValue(v);
},
}
setValue: function (v) {
setValue(v) {
this.pane.setValue(v);
},
}
getValue: function () {
getValue() {
return this.pane.getValue();
},
}
getAllValue: function() {
getAllValue() {
return this.buildCompleteTree(this.pane.getValue());
},
}
populate: function (items) {
if (BI.isNotNull(items)) {
populate(items) {
if (isNotNull(items)) {
this._initData(items);
}
this.pane.populate();
}
});
BI.TreeValueChooserPane.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.tree_value_chooser_pane", BI.TreeValueChooserPane);
}

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

@ -1,5 +1,3 @@
import { MultiTreeCheckSelectedButton } from "./trigger/multi.tree.button.checkselected";
import { MultiTreeCheckPane } from "./check/multi.tree.check.pane";
import {
shortcut,
extend,
@ -18,6 +16,8 @@ import { MultiTreePopup } from "./multi.tree.popup";
import { MultiSelectTrigger } from "../multiselect/multiselect.trigger";
import { TriggerIconButton } from "@/case";
import { MultiSelectCheckSelectedSwitcher } from "../multiselect/trigger/switcher.checkselected";
import { MultiTreeCheckSelectedButton } from "./trigger/multi.tree.button.checkselected";
import { MultiTreeCheckPane } from "./check/multi.tree.check.pane";
@shortcut()
export class MultiTreeCombo extends Single {
@ -44,6 +44,8 @@ export class MultiTreeCombo extends Single {
}
_init() {
const self = this,
o = this.options;
const triggerBtn = createWidget({
type: TriggerIconButton.xtype,
width: o.height,
@ -52,8 +54,6 @@ export class MultiTreeCombo extends Single {
});
let clear;
let change;
const self = this,
o = this.options;
super._init(...arguments);
let isInit = false;
let want2showCounter = false;
@ -61,7 +61,7 @@ export class MultiTreeCombo extends Single {
this.storeValue = { value: o.value || {} };
this.trigger = createWidget({
type: MultiSelectTrigger.xtype,
type: "bi.multi_select_trigger",
allowEdit: o.allowEdit,
height: toPix(o.height, o.simple ? 1 : 2),
valueFormatter: o.valueFormatter,
@ -77,7 +77,7 @@ export class MultiTreeCombo extends Single {
},
},
searcher: {
type: MultiTreeSearcher.xtype,
type: "bi.multi_tree_searcher",
itemsCreator: o.itemsCreator,
listeners: [
{
@ -99,7 +99,7 @@ export class MultiTreeCombo extends Single {
el: this.trigger,
adjustLength: 1,
popup: {
type: MultiTreePopup.xtype,
type: "bi.multi_tree_popup_view",
ref() {
self.popup = this;
self.trigger.setAdapter(this);
@ -127,7 +127,10 @@ export class MultiTreeCombo extends Single {
self.trigger.getSearcher().setState(val);
self.numberCounter.setButtonChecked(val);
self.storeValue = { value: self.combo.getValue() };
self.fireEvent(MultiTreeCombo.EVENT_CLICK_ITEM, self.combo.getValue());
self.fireEvent(
MultiTreeCombo.EVENT_CLICK_ITEM,
self.combo.getValue()
);
self._dataChange = true;
},
},
@ -230,9 +233,14 @@ export class MultiTreeCombo extends Single {
type: BI.Selection.Multi,
value: checked ? { 1: 1 } : {},
};
this.getSearcher().setState(checked ? BI.Selection.Multi : BI.Selection.None);
this.getSearcher().setState(
checked ? BI.Selection.Multi : BI.Selection.None
);
self.numberCounter.setButtonChecked(val);
self.fireEvent(MultiTreeCombo.EVENT_CLICK_ITEM, self.combo.getValue());
self.fireEvent(
MultiTreeCombo.EVENT_CLICK_ITEM,
self.combo.getValue()
);
self._dataChange = true;
});
@ -255,7 +263,8 @@ export class MultiTreeCombo extends Single {
this.combo.on(Combo.EVENT_BEFORE_HIDEVIEW, () => {
if (isSearching()) {
self._stopEditing();
self._dataChange && self.fireEvent(MultiTreeCombo.EVENT_CONFIRM);
self._dataChange &&
self.fireEvent(MultiTreeCombo.EVENT_CONFIRM);
} else {
if (isPopupView()) {
self._stopEditing();
@ -263,7 +272,8 @@ export class MultiTreeCombo extends Single {
if (clear === true) {
self.storeValue = { value: {} };
}
self._dataChange && self.fireEvent(MultiTreeCombo.EVENT_CONFIRM);
self._dataChange &&
self.fireEvent(MultiTreeCombo.EVENT_CONFIRM);
}
}
clear = false;
@ -283,11 +293,13 @@ export class MultiTreeCombo extends Single {
});
this.numberCounter = createWidget({
type: MultiSelectCheckSelectedSwitcher.xtype,
type: "bi.multi_select_check_selected_switcher",
el: {
// type: "bi.multi_tree_check_selected_button",
type: MultiTreeCheckSelectedButton.xtype,
},
popup: {
// type: "bi.multi_tree_check_pane",
type: MultiTreeCheckPane.xtype,
},
masker: {
@ -302,34 +314,45 @@ export class MultiTreeCombo extends Single {
valueFormatter: o.valueFormatter,
value: { value: o.value || {} },
});
this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, () => {
if (!self.combo.isViewVisible()) {
self.combo.showView();
}
});
this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW, () => {
if (want2showCounter === false) {
want2showCounter = true;
this.numberCounter.on(
MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE,
() => {
if (!self.combo.isViewVisible()) {
self.combo.showView();
}
}
if (isInit === true) {
want2showCounter = null;
showCounter();
);
this.numberCounter.on(
MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW,
() => {
if (want2showCounter === false) {
want2showCounter = true;
}
if (isInit === true) {
want2showCounter = null;
showCounter();
}
}
});
);
this.numberCounter.on(Events.VIEW, b => {
nextTick(() => {
// 自动调整宽度
self.trigger.refreshPlaceHolderWidth(b === true ? self.numberCounter.element.outerWidth() + 8 : 0);
self.trigger.refreshPlaceHolderWidth(
b === true ? self.numberCounter.element.outerWidth() + 8 : 0
);
});
});
this.numberCounter.on(MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW, () => {
nextTick(() => {
// 收起时自动调整宽度
self.trigger.refreshPlaceHolderWidth(0);
});
});
this.numberCounter.on(
MultiSelectCheckSelectedSwitcher.EVENT_AFTER_HIDEVIEW,
() => {
nextTick(() => {
// 收起时自动调整宽度
self.trigger.refreshPlaceHolderWidth(0);
});
}
);
this.trigger.element.click(e => {
if (self.trigger.element.find(e.target).length > 0) {

Loading…
Cancel
Save