|
|
@ -1,94 +1,112 @@ |
|
|
|
/** |
|
|
|
import { |
|
|
|
* guy |
|
|
|
cjkEncodeDO, |
|
|
|
* 异步树 |
|
|
|
Controller, |
|
|
|
* @class BI.TreeView |
|
|
|
createWidget, |
|
|
|
* @extends BI.Pane |
|
|
|
emptyFn, |
|
|
|
*/ |
|
|
|
Events, |
|
|
|
BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
extend, |
|
|
|
_defaultConfig: function () { |
|
|
|
UUID, |
|
|
|
return BI.extend(BI.TreeView.superclass._defaultConfig.apply(this, arguments), { |
|
|
|
isNotNull, |
|
|
|
|
|
|
|
jsonEncode, |
|
|
|
|
|
|
|
delay, each, replaceAll, |
|
|
|
|
|
|
|
isUndefined, isNotEmptyArray, deepClone, map, Tree, |
|
|
|
|
|
|
|
isNull, shortcut |
|
|
|
|
|
|
|
} from "@/core"; |
|
|
|
|
|
|
|
import { Msg, Pane } from "@/base"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@shortcut() |
|
|
|
|
|
|
|
export class TreeView extends Pane { |
|
|
|
|
|
|
|
static xtype = "bi.tree_view"; |
|
|
|
|
|
|
|
static REQ_TYPE_INIT_DATA = 1; |
|
|
|
|
|
|
|
static REQ_TYPE_ADJUST_DATA = 2; |
|
|
|
|
|
|
|
static REQ_TYPE_SELECT_DATA = 3; |
|
|
|
|
|
|
|
static REQ_TYPE_GET_SELECTED_DATA = 4; |
|
|
|
|
|
|
|
static EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
|
|
|
|
static EVENT_INIT = Events.INIT; |
|
|
|
|
|
|
|
static EVENT_AFTERINIT = Events.AFTERINIT; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_defaultConfig() { |
|
|
|
|
|
|
|
return extend(super._defaultConfig(...arguments), { |
|
|
|
_baseCls: "bi-tree", |
|
|
|
_baseCls: "bi-tree", |
|
|
|
paras: { |
|
|
|
paras: { |
|
|
|
selectedValues: {} |
|
|
|
selectedValues: {}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
itemsCreator: BI.emptyFn, |
|
|
|
itemsCreator: emptyFn, |
|
|
|
showLine: true |
|
|
|
showLine: true, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
_init: function () { |
|
|
|
|
|
|
|
BI.TreeView.superclass._init.apply(this, arguments); |
|
|
|
_init() { |
|
|
|
var o = this.options; |
|
|
|
super._init(...arguments); |
|
|
|
|
|
|
|
const o = this.options; |
|
|
|
this._stop = false; |
|
|
|
this._stop = false; |
|
|
|
|
|
|
|
|
|
|
|
this._createTree(); |
|
|
|
this._createTree(); |
|
|
|
this.tip = BI.createWidget({ |
|
|
|
this.tip = createWidget({ |
|
|
|
type: "bi.loading_bar", |
|
|
|
type: "bi.loading_bar", |
|
|
|
invisible: true, |
|
|
|
invisible: true, |
|
|
|
handler: BI.bind(this._loadMore, this) |
|
|
|
handler: () => this._loadMore(), |
|
|
|
}); |
|
|
|
}); |
|
|
|
BI.createWidget({ |
|
|
|
createWidget({ |
|
|
|
type: "bi.vertical", |
|
|
|
type: "bi.vertical", |
|
|
|
scrollable: true, |
|
|
|
scrollable: true, |
|
|
|
scrolly: false, |
|
|
|
scrolly: false, |
|
|
|
element: this, |
|
|
|
element: this, |
|
|
|
items: [this.tip] |
|
|
|
items: [this.tip], |
|
|
|
}); |
|
|
|
}); |
|
|
|
if (BI.isNotNull(o.value)) { |
|
|
|
if (isNotNull(o.value)) { |
|
|
|
this.setSelectedValue(o.value); |
|
|
|
this.setSelectedValue(o.value); |
|
|
|
} |
|
|
|
} |
|
|
|
if (BI.isIE9Below && BI.isIE9Below()) { |
|
|
|
|
|
|
|
this.element.addClass("hack"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_createTree: function () { |
|
|
|
_createTree() { |
|
|
|
this.id = "bi-tree" + BI.UUID(); |
|
|
|
this.id = `bi-tree${UUID()}`; |
|
|
|
if (this.nodes) { |
|
|
|
if (this.nodes) { |
|
|
|
this.nodes.destroy(); |
|
|
|
this.nodes.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.tree) { |
|
|
|
if (this.tree) { |
|
|
|
this.tree.destroy(); |
|
|
|
this.tree.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
this.tree = BI.createWidget({ |
|
|
|
this.tree = createWidget({ |
|
|
|
type: "bi.layout", |
|
|
|
type: "bi.layout", |
|
|
|
element: "<ul id='" + this.id + "' class='ztree" + (BI.STYLE_CONSTANTS.LINK_LINE_TYPE === "solid" ? " solid'" : "'") + "></ul>" |
|
|
|
element: `<ul id='${this.id}' class='ztree${BI.STYLE_CONSTANTS.LINK_LINE_TYPE === "solid" ? " solid'" : "'"}></ul>`, |
|
|
|
}); |
|
|
|
}); |
|
|
|
BI.createWidget({ |
|
|
|
createWidget({ |
|
|
|
type: "bi.default", |
|
|
|
type: "bi.default", |
|
|
|
element: this, |
|
|
|
element: this, |
|
|
|
items: [this.tree] |
|
|
|
items: [this.tree], |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 选择节点触发方法
|
|
|
|
// 选择节点触发方法
|
|
|
|
_selectTreeNode: function (treeId, treeNode) { |
|
|
|
_selectTreeNode(treeId, treeNode) { |
|
|
|
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CLICK, treeNode, this); |
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, Events.CLICK, treeNode, this); |
|
|
|
this.fireEvent(BI.TreeView.EVENT_CHANGE, treeNode, this); |
|
|
|
this.fireEvent(TreeView.EVENT_CHANGE, treeNode, this); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 配置属性
|
|
|
|
// 配置属性
|
|
|
|
_configSetting: function () { |
|
|
|
_configSetting() { |
|
|
|
var paras = this.options.paras; |
|
|
|
const paras = this.options.paras; |
|
|
|
var self = this; |
|
|
|
const self = this; |
|
|
|
var o = this.options; |
|
|
|
const o = this.options; |
|
|
|
var setting = { |
|
|
|
const setting = { |
|
|
|
async: { |
|
|
|
async: { |
|
|
|
enable: true, |
|
|
|
enable: true, |
|
|
|
url: getUrl, |
|
|
|
url: getUrl, |
|
|
|
autoParam: ["id", "name"], // 节点展开异步请求自动提交id和name
|
|
|
|
autoParam: ["id", "name"], // 节点展开异步请求自动提交id和name
|
|
|
|
otherParam: BI.cjkEncodeDO(paras) // 静态参数
|
|
|
|
otherParam: cjkEncodeDO(paras), // 静态参数
|
|
|
|
}, |
|
|
|
}, |
|
|
|
check: { |
|
|
|
check: { |
|
|
|
enable: true |
|
|
|
enable: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
data: { |
|
|
|
data: { |
|
|
|
key: { |
|
|
|
key: { |
|
|
|
title: "title", |
|
|
|
title: "title", |
|
|
|
name: "text" // 节点的name属性替换成text
|
|
|
|
name: "text", // 节点的name属性替换成text
|
|
|
|
}, |
|
|
|
}, |
|
|
|
simpleData: { |
|
|
|
simpleData: { |
|
|
|
enable: true // 可以穿id,pid属性的对象数组
|
|
|
|
enable: true, // 可以穿id,pid属性的对象数组
|
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
view: { |
|
|
|
view: { |
|
|
|
showIcon: false, |
|
|
|
showIcon: false, |
|
|
@ -98,22 +116,22 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
showLine: o.showLine, |
|
|
|
showLine: o.showLine, |
|
|
|
}, |
|
|
|
}, |
|
|
|
callback: { |
|
|
|
callback: { |
|
|
|
beforeExpand: beforeExpand, |
|
|
|
beforeExpand, |
|
|
|
onAsyncSuccess: onAsyncSuccess, |
|
|
|
onAsyncSuccess, |
|
|
|
onAsyncError: onAsyncError, |
|
|
|
onAsyncError, |
|
|
|
beforeCheck: beforeCheck, |
|
|
|
beforeCheck, |
|
|
|
onCheck: onCheck, |
|
|
|
onCheck, |
|
|
|
onExpand: onExpand, |
|
|
|
onExpand, |
|
|
|
onCollapse: onCollapse, |
|
|
|
onCollapse, |
|
|
|
onClick: onClick |
|
|
|
onClick, |
|
|
|
} |
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
var className = "dark", perTime = 100; |
|
|
|
const className = "dark", perTime = 100; |
|
|
|
|
|
|
|
|
|
|
|
function onClick(event, treeId, treeNode) { |
|
|
|
function onClick(event, treeId, treeNode) { |
|
|
|
// 当前点击节点的状态是半选,且为true_part, 则将其改为false_part,使得点击半选后切换到的是全选
|
|
|
|
// 当前点击节点的状态是半选,且为true_part, 则将其改为false_part,使得点击半选后切换到的是全选
|
|
|
|
var checked = treeNode.checked; |
|
|
|
let checked = treeNode.checked; |
|
|
|
var status = treeNode.getCheckStatus(); |
|
|
|
const status = treeNode.getCheckStatus(); |
|
|
|
if (status.half === true && status.checked === true) { |
|
|
|
if (status.half === true && status.checked === true) { |
|
|
|
checked = false; |
|
|
|
checked = false; |
|
|
|
} |
|
|
|
} |
|
|
@ -122,14 +140,14 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getUrl(treeId, treeNode) { |
|
|
|
function getUrl(treeId, treeNode) { |
|
|
|
var parentNode = self._getParentValues(treeNode); |
|
|
|
const parentNode = self._getParentValues(treeNode); |
|
|
|
treeNode.times = treeNode.times || 1; |
|
|
|
treeNode.times = treeNode.times || 1; |
|
|
|
var param = "id=" + treeNode.id |
|
|
|
const param = `id=${treeNode.id |
|
|
|
+ "×=" + (treeNode.times++) |
|
|
|
}×=${treeNode.times++ |
|
|
|
+ "&parentValues= " + _global.encodeURIComponent(BI.jsonEncode(parentNode)) |
|
|
|
}&parentValues= ${_global.encodeURIComponent(jsonEncode(parentNode)) |
|
|
|
+ "&checkState=" + _global.encodeURIComponent(BI.jsonEncode(treeNode.getCheckStatus())); |
|
|
|
}&checkState=${_global.encodeURIComponent(jsonEncode(treeNode.getCheckStatus()))}`;
|
|
|
|
|
|
|
|
|
|
|
|
return "&" + param; |
|
|
|
return `&${param}`; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function beforeExpand(treeId, treeNode) { |
|
|
|
function beforeExpand(treeId, treeNode) { |
|
|
@ -138,13 +156,14 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
treeNode.times = 1; |
|
|
|
treeNode.times = 1; |
|
|
|
ajaxGetNodes(treeNode, "refresh"); |
|
|
|
ajaxGetNodes(treeNode, "refresh"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
BI.Msg.toast("Please Wait。", { |
|
|
|
Msg.toast("Please Wait。", { |
|
|
|
level: "warning" |
|
|
|
level: "warning", |
|
|
|
}); // 不展开节点,也不触发onExpand事件
|
|
|
|
}); // 不展开节点,也不触发onExpand事件
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function onAsyncSuccess(event, treeId, treeNode, msg) { |
|
|
|
function onAsyncSuccess(event, treeId, treeNode, msg) { |
|
|
@ -152,14 +171,14 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
if (!msg || msg.length === 0 || /^<html>[\s,\S]*<\/html>$/gi.test(msg) || self._stop) { |
|
|
|
if (!msg || msg.length === 0 || /^<html>[\s,\S]*<\/html>$/gi.test(msg) || self._stop) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var zTree = self.nodes; |
|
|
|
const zTree = self.nodes; |
|
|
|
var totalCount = treeNode.count || 0; |
|
|
|
const totalCount = treeNode.count || 0; |
|
|
|
|
|
|
|
|
|
|
|
// 尝试去获取下一组节点,若获取值为空数组,表示获取完成
|
|
|
|
// 尝试去获取下一组节点,若获取值为空数组,表示获取完成
|
|
|
|
// TODO by GUY
|
|
|
|
// TODO by GUY
|
|
|
|
if (treeNode.children.length > totalCount) { |
|
|
|
if (treeNode.children.length > totalCount) { |
|
|
|
treeNode.count = treeNode.children.length; |
|
|
|
treeNode.count = treeNode.children.length; |
|
|
|
BI.delay(function () { |
|
|
|
delay(() => { |
|
|
|
ajaxGetNodes(treeNode); |
|
|
|
ajaxGetNodes(treeNode); |
|
|
|
}, perTime); |
|
|
|
}, perTime); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -171,15 +190,15 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) { |
|
|
|
function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) { |
|
|
|
var zTree = self.nodes; |
|
|
|
const zTree = self.nodes; |
|
|
|
BI.Msg.toast("Error!", "warning"); |
|
|
|
Msg.toast("Error!", "warning"); |
|
|
|
// treeNode.icon = "";
|
|
|
|
// treeNode.icon = "";
|
|
|
|
// zTree.updateNode(treeNode);
|
|
|
|
// zTree.updateNode(treeNode);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function ajaxGetNodes(treeNode, reloadType) { |
|
|
|
function ajaxGetNodes(treeNode, reloadType) { |
|
|
|
var zTree = self.nodes; |
|
|
|
const zTree = self.nodes; |
|
|
|
if (reloadType == "refresh") { |
|
|
|
if (reloadType === "refresh") { |
|
|
|
zTree.updateNode(treeNode); // 刷新一下当前节点,如果treeNode.xxx被改了的话
|
|
|
|
zTree.updateNode(treeNode); // 刷新一下当前节点,如果treeNode.xxx被改了的话
|
|
|
|
} |
|
|
|
} |
|
|
|
zTree.reAsyncChildNodes(treeNode, reloadType, true); // 强制加载子节点,reloadType === refresh为先清空再加载,否则为追加到现有子节点之后
|
|
|
|
zTree.reAsyncChildNodes(treeNode, reloadType, true); // 强制加载子节点,reloadType === refresh为先清空再加载,否则为追加到现有子节点之后
|
|
|
@ -190,13 +209,13 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
// 下面主动修改了node的halfCheck属性, 节点属性的判断依赖halfCheck,改之前就获取一下
|
|
|
|
// 下面主动修改了node的halfCheck属性, 节点属性的判断依赖halfCheck,改之前就获取一下
|
|
|
|
var status = treeNode.getCheckStatus(); |
|
|
|
const status = treeNode.getCheckStatus(); |
|
|
|
treeNode.halfCheck = false; |
|
|
|
treeNode.halfCheck = false; |
|
|
|
if (treeNode.checked === true) { |
|
|
|
if (treeNode.checked === true) { |
|
|
|
// 将展开的节点halfCheck设为false,解决展开节点存在halfCheck=true的情况 guy
|
|
|
|
// 将展开的节点halfCheck设为false,解决展开节点存在halfCheck=true的情况 guy
|
|
|
|
// 所有的半选状态都需要取消halfCheck=true的情况
|
|
|
|
// 所有的半选状态都需要取消halfCheck=true的情况
|
|
|
|
function track(children) { |
|
|
|
function track(children) { |
|
|
|
BI.each(children, function (i, ch) { |
|
|
|
each(children, (i, ch) => { |
|
|
|
if (ch.halfCheck === true) { |
|
|
|
if (ch.halfCheck === true) { |
|
|
|
ch.halfCheck = false; |
|
|
|
ch.halfCheck = false; |
|
|
|
track(ch.children); |
|
|
|
track(ch.children); |
|
|
@ -205,9 +224,9 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
track(treeNode.children); |
|
|
|
track(treeNode.children); |
|
|
|
var treeObj = self.nodes; |
|
|
|
const treeObj = self.nodes; |
|
|
|
var nodes = treeObj.getSelectedNodes(); |
|
|
|
const nodes = treeObj.getSelectedNodes(); |
|
|
|
BI.$.each(nodes, function (index, node) { |
|
|
|
BI.$.each(nodes, (index, node) => { |
|
|
|
node.halfCheck = false; |
|
|
|
node.halfCheck = false; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -232,102 +251,106 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return setting; |
|
|
|
return setting; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_getParentValues: function (treeNode) { |
|
|
|
_getParentValues(treeNode) { |
|
|
|
if (!treeNode.getParentNode()) { |
|
|
|
if (!treeNode.getParentNode()) { |
|
|
|
return []; |
|
|
|
return []; |
|
|
|
} |
|
|
|
} |
|
|
|
var parentNode = treeNode.getParentNode(); |
|
|
|
const parentNode = treeNode.getParentNode(); |
|
|
|
var result = this._getParentValues(parentNode); |
|
|
|
let result = this._getParentValues(parentNode); |
|
|
|
result = result.concat([this._getNodeValue(parentNode)]); |
|
|
|
result = result.concat([this._getNodeValue(parentNode)]); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_getNodeValue: function (node) { |
|
|
|
_getNodeValue(node) { |
|
|
|
// 去除标红
|
|
|
|
// 去除标红
|
|
|
|
return BI.isUndefined(node.value) ? BI.replaceAll(node.text.replace(/<[^>]+>/g, ""), " ", " ") : node.value; |
|
|
|
return isUndefined(node.value) ? replaceAll(node.text.replace(/<[^>]+>/g, ""), " ", " ") : node.value; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取半选框值
|
|
|
|
// 获取半选框值
|
|
|
|
_getHalfSelectedValues: function (map, node) { |
|
|
|
_getHalfSelectedValues(map, node) { |
|
|
|
var self = this; |
|
|
|
const self = this; |
|
|
|
var checkState = node.getCheckStatus(); |
|
|
|
const checkState = node.getCheckStatus(); |
|
|
|
// 将未选的去掉
|
|
|
|
// 将未选的去掉
|
|
|
|
if (checkState.checked === false && checkState.half === false) { |
|
|
|
if (checkState.checked === false && checkState.half === false) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// 如果节点已展开,并且是半选
|
|
|
|
// 如果节点已展开,并且是半选
|
|
|
|
if (BI.isNotEmptyArray(node.children) && checkState.half === true) { |
|
|
|
if (isNotEmptyArray(node.children) && checkState.half === true) { |
|
|
|
var children = node.children; |
|
|
|
const children = node.children; |
|
|
|
BI.each(children, function (i, ch) { |
|
|
|
each(children, (i, ch) => { |
|
|
|
self._getHalfSelectedValues(map, ch); |
|
|
|
self._getHalfSelectedValues(map, ch); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var parent = node.parentValues || self._getParentValues(node); |
|
|
|
const parent = node.parentValues || self._getParentValues(node); |
|
|
|
var path = parent.concat(this._getNodeValue(node)); |
|
|
|
const path = parent.concat(this._getNodeValue(node)); |
|
|
|
// 当前节点是全选的,因为上面的判断已经排除了不选和半选
|
|
|
|
// 当前节点是全选的,因为上面的判断已经排除了不选和半选
|
|
|
|
if (BI.isNotEmptyArray(node.children) || checkState.half === false) { |
|
|
|
if (isNotEmptyArray(node.children) || checkState.half === false) { |
|
|
|
this._buildTree(map, path); |
|
|
|
this._buildTree(map, path); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// 剩下的就是半选不展开的节点,因为不知道里面是什么情况,所以借助selectedValues(这个是完整的选中情况)
|
|
|
|
// 剩下的就是半选不展开的节点,因为不知道里面是什么情况,所以借助selectedValues(这个是完整的选中情况)
|
|
|
|
var storeValues = BI.deepClone(this.options.paras.selectedValues); |
|
|
|
const storeValues = deepClone(this.options.paras.selectedValues); |
|
|
|
var treeNode = this._getTree(storeValues, path); |
|
|
|
const treeNode = this._getTree(storeValues, path); |
|
|
|
this._addTreeNode(map, parent, this._getNodeValue(node), treeNode); |
|
|
|
this._addTreeNode(map, parent, this._getNodeValue(node), treeNode); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取的是以values最后一个节点为根的子树
|
|
|
|
// 获取的是以values最后一个节点为根的子树
|
|
|
|
_getTree: function (map, values) { |
|
|
|
_getTree(map, values) { |
|
|
|
var cur = map; |
|
|
|
let cur = map; |
|
|
|
BI.any(values, function (i, value) { |
|
|
|
some(values, (i, value) => { |
|
|
|
if (cur[value] == null) { |
|
|
|
if (cur[value] == null) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
cur = cur[value]; |
|
|
|
cur = cur[value]; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return cur; |
|
|
|
return cur; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 以values为path一路向里补充map, 并在末尾节点添加key: value节点
|
|
|
|
// 以values为path一路向里补充map, 并在末尾节点添加key: value节点
|
|
|
|
_addTreeNode: function (map, values, key, value) { |
|
|
|
_addTreeNode(map, values, key, value) { |
|
|
|
var cur = map; |
|
|
|
let cur = map; |
|
|
|
BI.each(values, function (i, value) { |
|
|
|
each(values, (i, value) => { |
|
|
|
if (cur[value] == null) { |
|
|
|
if (cur[value] == null) { |
|
|
|
cur[value] = {}; |
|
|
|
cur[value] = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
cur = cur[value]; |
|
|
|
cur = cur[value]; |
|
|
|
}); |
|
|
|
}); |
|
|
|
cur[key] = value; |
|
|
|
cur[key] = value; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 构造树节点
|
|
|
|
// 构造树节点
|
|
|
|
_buildTree: function (map, values) { |
|
|
|
_buildTree(map, values) { |
|
|
|
var cur = map; |
|
|
|
let cur = map; |
|
|
|
BI.each(values, function (i, value) { |
|
|
|
each(values, (i, value) => { |
|
|
|
if (cur[value] == null) { |
|
|
|
if (cur[value] == null) { |
|
|
|
cur[value] = {}; |
|
|
|
cur[value] = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
cur = cur[value]; |
|
|
|
cur = cur[value]; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取选中的值
|
|
|
|
// 获取选中的值
|
|
|
|
_getSelectedValues: function () { |
|
|
|
_getSelectedValues() { |
|
|
|
var self = this; |
|
|
|
const self = this; |
|
|
|
var hashMap = {}; |
|
|
|
const hashMap = {}; |
|
|
|
var rootNoots = this.nodes.getNodes(); |
|
|
|
const rootNoots = this.nodes.getNodes(); |
|
|
|
track(rootNoots); // 可以看到这个方法没有递归调用,所以在_getHalfSelectedValues中需要关心全选的节点
|
|
|
|
track(rootNoots); // 可以看到这个方法没有递归调用,所以在_getHalfSelectedValues中需要关心全选的节点
|
|
|
|
function track(nodes) { |
|
|
|
function track(nodes) { |
|
|
|
BI.each(nodes, function (i, node) { |
|
|
|
each(nodes, (i, node) => { |
|
|
|
var checkState = node.getCheckStatus(); |
|
|
|
const checkState = node.getCheckStatus(); |
|
|
|
if (checkState.checked === true || checkState.half === true) { |
|
|
|
if (checkState.checked === true || checkState.half === true) { |
|
|
|
if (checkState.half === true) { |
|
|
|
if (checkState.half === true) { |
|
|
|
self._getHalfSelectedValues(hashMap, node); |
|
|
|
self._getHalfSelectedValues(hashMap, node); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var parentValues = node.parentValues || self._getParentValues(node); |
|
|
|
const parentValues = node.parentValues || self._getParentValues(node); |
|
|
|
var values = parentValues.concat([self._getNodeValue(node)]); |
|
|
|
const values = parentValues.concat([self._getNodeValue(node)]); |
|
|
|
self._buildTree(hashMap, values); |
|
|
|
self._buildTree(hashMap, values); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -335,27 +358,28 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return hashMap; |
|
|
|
return hashMap; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 处理节点
|
|
|
|
// 处理节点
|
|
|
|
_dealWidthNodes: function (nodes) { |
|
|
|
_dealWidthNodes(nodes) { |
|
|
|
var self = this, o = this.options; |
|
|
|
const self = this, o = this.options; |
|
|
|
var ns = BI.Tree.arrayFormat(nodes); |
|
|
|
const ns = Tree.arrayFormat(nodes); |
|
|
|
return BI.map(ns, function (i, n) { |
|
|
|
|
|
|
|
var newNode = BI.extend({}, n); |
|
|
|
return map(ns, (i, n) => { |
|
|
|
|
|
|
|
const newNode = extend({}, n); |
|
|
|
newNode.isParent = newNode.isParent || newNode.parent; |
|
|
|
newNode.isParent = newNode.isParent || newNode.parent; |
|
|
|
// n.value = BI.isUndefined(n.value) ? n.text : n.value;
|
|
|
|
// n.value = BI.isUndefined(n.value) ? n.text : n.value;
|
|
|
|
// n.text = BI.isUndefined(n.text) ? n.value : n.text;
|
|
|
|
// n.text = BI.isUndefined(n.text) ? n.value : n.text;
|
|
|
|
// if (n.text === null) {
|
|
|
|
// if (n.text === null) {
|
|
|
|
// n.text = "";
|
|
|
|
// n.text = "";
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
if (BI.isNull(newNode.title)) { |
|
|
|
if (isNull(newNode.title)) { |
|
|
|
newNode.title = newNode.text; |
|
|
|
newNode.title = newNode.text; |
|
|
|
} |
|
|
|
} |
|
|
|
if (newNode.disabled) { |
|
|
|
if (newNode.disabled) { |
|
|
|
newNode.title = newNode.warningTitle || newNode.title; |
|
|
|
newNode.title = newNode.warningTitle || newNode.title; |
|
|
|
} |
|
|
|
} |
|
|
|
var text = BI.createWidget(BI.extend({ |
|
|
|
const text = createWidget(extend({ |
|
|
|
cls: "tree-node-text", |
|
|
|
cls: "tree-node-text", |
|
|
|
tagName: "span", |
|
|
|
tagName: "span", |
|
|
|
whiteSpace: "nowrap", |
|
|
|
whiteSpace: "nowrap", |
|
|
@ -363,9 +387,9 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
keyword: o.paras.keyword, |
|
|
|
keyword: o.paras.keyword, |
|
|
|
}, newNode, { |
|
|
|
}, newNode, { |
|
|
|
type: "bi.text", |
|
|
|
type: "bi.text", |
|
|
|
text: BI.replaceAll(newNode.text, "\n", " ") |
|
|
|
text: replaceAll(newNode.text, "\n", " "), |
|
|
|
})); |
|
|
|
})); |
|
|
|
var fragment = BI.Widget._renderEngine.createElement("<div>"); |
|
|
|
const fragment = BI.Widget._renderEngine.createElement("<div>"); |
|
|
|
fragment.append(text.element[0]); |
|
|
|
fragment.append(text.element[0]); |
|
|
|
newNode.text = fragment.html(); |
|
|
|
newNode.text = fragment.html(); |
|
|
|
// // 处理标红
|
|
|
|
// // 处理标红
|
|
|
@ -376,21 +400,22 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
// n.text = BI.htmlEncode(BI.Text.formatText(n.text + ""));
|
|
|
|
// n.text = BI.htmlEncode(BI.Text.formatText(n.text + ""));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
return newNode; |
|
|
|
return newNode; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_loadMore: function () { |
|
|
|
_loadMore() { |
|
|
|
var self = this, o = this.options; |
|
|
|
const self = this, o = this.options; |
|
|
|
this.tip.setLoading(); |
|
|
|
this.tip.setLoading(); |
|
|
|
var op = BI.extend({}, o.paras, { |
|
|
|
const op = extend({}, o.paras, { |
|
|
|
times: ++this.times |
|
|
|
times: ++this.times, |
|
|
|
}); |
|
|
|
}); |
|
|
|
o.itemsCreator(op, function (res) { |
|
|
|
o.itemsCreator(op, res => { |
|
|
|
if (self._stop === true) { |
|
|
|
if (self._stop === true) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var hasNext = !!res.hasNext, nodes = res.items || []; |
|
|
|
const hasNext = !!res.hasNext, nodes = res.items || []; |
|
|
|
|
|
|
|
|
|
|
|
if (!hasNext) { |
|
|
|
if (!hasNext) { |
|
|
|
self.tip.setEnd(); |
|
|
|
self.tip.setEnd(); |
|
|
@ -401,32 +426,34 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
self.nodes.addNodes(null, self._dealWidthNodes(nodes)); |
|
|
|
self.nodes.addNodes(null, self._dealWidthNodes(nodes)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 生成树内部方法
|
|
|
|
// 生成树内部方法
|
|
|
|
_initTree: function (setting) { |
|
|
|
_initTree(setting) { |
|
|
|
var self = this, o = this.options; |
|
|
|
const self = this, o = this.options; |
|
|
|
self.fireEvent(BI.Events.INIT); |
|
|
|
self.fireEvent(Events.INIT); |
|
|
|
this.times = 1; |
|
|
|
this.times = 1; |
|
|
|
var tree = this.tree; |
|
|
|
const tree = this.tree; |
|
|
|
tree.empty(); |
|
|
|
tree.empty(); |
|
|
|
this.loading(); |
|
|
|
this.loading(); |
|
|
|
this.tip.setVisible(false); |
|
|
|
this.tip.setVisible(false); |
|
|
|
var callback = function (nodes) { |
|
|
|
|
|
|
|
|
|
|
|
function callback(nodes) { |
|
|
|
if (self._stop === true) { |
|
|
|
if (self._stop === true) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
self.nodes = BI.$.fn.zTree.init(tree.element, setting, nodes); |
|
|
|
self.nodes = BI.$.fn.zTree.init(tree.element, setting, nodes); |
|
|
|
}; |
|
|
|
} |
|
|
|
var op = BI.extend({}, o.paras, { |
|
|
|
|
|
|
|
times: 1 |
|
|
|
const op = extend({}, o.paras, { |
|
|
|
|
|
|
|
times: 1, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
o.itemsCreator(op, function (res) { |
|
|
|
o.itemsCreator(op, res => { |
|
|
|
if (self._stop === true) { |
|
|
|
if (self._stop === true) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var hasNext = !!res.hasNext, nodes = res.items || []; |
|
|
|
const hasNext = !!res.hasNext, nodes = res.items || []; |
|
|
|
if (nodes.length > 0) { |
|
|
|
if (nodes.length > 0) { |
|
|
|
callback(self._dealWidthNodes(nodes)); |
|
|
|
callback(self._dealWidthNodes(nodes)); |
|
|
|
} |
|
|
|
} |
|
|
@ -437,68 +464,69 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
self.tip.setLoaded(); |
|
|
|
self.tip.setLoaded(); |
|
|
|
} |
|
|
|
} |
|
|
|
op.times === 1 && self.fireEvent(BI.Events.AFTERINIT); |
|
|
|
op.times === 1 && self.fireEvent(Events.AFTERINIT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 构造树结构,
|
|
|
|
// 构造树结构,
|
|
|
|
initTree: function (nodes, setting) { |
|
|
|
initTree(nodes, setting) { |
|
|
|
var setting = setting || { |
|
|
|
const defaultSetting = { |
|
|
|
async: { |
|
|
|
async: { |
|
|
|
enable: false |
|
|
|
enable: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
check: { |
|
|
|
check: { |
|
|
|
enable: false |
|
|
|
enable: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
data: { |
|
|
|
data: { |
|
|
|
key: { |
|
|
|
key: { |
|
|
|
title: "title", |
|
|
|
title: "title", |
|
|
|
name: "text" |
|
|
|
name: "text", |
|
|
|
}, |
|
|
|
}, |
|
|
|
simpleData: { |
|
|
|
simpleData: { |
|
|
|
enable: true |
|
|
|
enable: true, |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
view: { |
|
|
|
view: { |
|
|
|
showIcon: false, |
|
|
|
showIcon: false, |
|
|
|
expandSpeed: "", |
|
|
|
expandSpeed: "", |
|
|
|
nameIsHTML: true |
|
|
|
nameIsHTML: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
callback: {} |
|
|
|
callback: {}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
this.nodes = BI.$.fn.zTree.init(this.tree.element, setting, nodes); |
|
|
|
this.nodes = BI.$.fn.zTree.init(this.tree.element, setting || defaultSetting, nodes); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
start: function () { |
|
|
|
start() { |
|
|
|
this._stop = false; |
|
|
|
this._stop = false; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stop: function () { |
|
|
|
stop() { |
|
|
|
this._stop = true; |
|
|
|
this._stop = true; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 生成树方法
|
|
|
|
// 生成树方法
|
|
|
|
stroke: function (config) { |
|
|
|
stroke(config) { |
|
|
|
delete this.options.keyword; |
|
|
|
delete this.options.keyword; |
|
|
|
BI.extend(this.options.paras, config); |
|
|
|
extend(this.options.paras, config); |
|
|
|
var setting = this._configSetting(); |
|
|
|
const setting = this._configSetting(); |
|
|
|
this._createTree(); |
|
|
|
this._createTree(); |
|
|
|
this.start(); |
|
|
|
this.start(); |
|
|
|
this._initTree(setting); |
|
|
|
this._initTree(setting); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
populate: function () { |
|
|
|
populate() { |
|
|
|
this.stroke.apply(this, arguments); |
|
|
|
this.stroke(...arguments); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hasChecked() { |
|
|
|
|
|
|
|
const treeObj = this.nodes; |
|
|
|
|
|
|
|
|
|
|
|
hasChecked: function () { |
|
|
|
|
|
|
|
var treeObj = this.nodes; |
|
|
|
|
|
|
|
return treeObj.getCheckedNodes(true).length > 0; |
|
|
|
return treeObj.getCheckedNodes(true).length > 0; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
checkAll: function (checked) { |
|
|
|
checkAll(checked) { |
|
|
|
function setNode(children) { |
|
|
|
function setNode(children) { |
|
|
|
BI.each(children, function (i, child) { |
|
|
|
each(children, (i, child) => { |
|
|
|
child.halfCheck = false; |
|
|
|
child.halfCheck = false; |
|
|
|
setNode(child.children); |
|
|
|
setNode(child.children); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -508,68 +536,58 @@ BI.TreeView = BI.inherit(BI.Pane, { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BI.each(this.nodes.getNodes(), function (i, node) { |
|
|
|
each(this.nodes.getNodes(), (i, node) => { |
|
|
|
node.halfCheck = false; |
|
|
|
node.halfCheck = false; |
|
|
|
setNode(node.children); |
|
|
|
setNode(node.children); |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.nodes.checkAllNodes(checked); |
|
|
|
this.nodes.checkAllNodes(checked); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
expandAll: function (flag) { |
|
|
|
expandAll(flag) { |
|
|
|
this.nodes && this.nodes.expandAll(flag); |
|
|
|
this.nodes && this.nodes.expandAll(flag); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 设置树节点的状态
|
|
|
|
// 设置树节点的状态
|
|
|
|
setValue: function (value, param) { |
|
|
|
setValue(value, param) { |
|
|
|
this.checkAll(false); |
|
|
|
this.checkAll(false); |
|
|
|
this.updateValue(value, param); |
|
|
|
this.updateValue(value, param); |
|
|
|
this.refresh(); |
|
|
|
this.refresh(); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setSelectedValue: function (value) { |
|
|
|
setSelectedValue(value) { |
|
|
|
this.options.paras.selectedValues = BI.deepClone(value || {}); |
|
|
|
this.options.paras.selectedValues = deepClone(value || {}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
updateValue: function (values, param) { |
|
|
|
updateValue(values, param) { |
|
|
|
if (!this.nodes) { |
|
|
|
if (!this.nodes) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
param || (param = "value"); |
|
|
|
param || (param = "value"); |
|
|
|
var treeObj = this.nodes; |
|
|
|
const treeObj = this.nodes; |
|
|
|
BI.each(values, function (v, op) { |
|
|
|
each(values, (v, op) => { |
|
|
|
var nodes = treeObj.getNodesByParam(param, v, null); |
|
|
|
const nodes = treeObj.getNodesByParam(param, v, null); |
|
|
|
BI.each(nodes, function (j, node) { |
|
|
|
each(nodes, (j, node) => { |
|
|
|
BI.extend(node, { checked: true }, op); |
|
|
|
extend(node, { checked: true }, op); |
|
|
|
treeObj.updateNode(node); |
|
|
|
treeObj.updateNode(node); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
refresh: function () { |
|
|
|
refresh() { |
|
|
|
this.nodes && this.nodes.refresh(); |
|
|
|
this.nodes && this.nodes.refresh(); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getValue: function () { |
|
|
|
getValue() { |
|
|
|
if (!this.nodes) { |
|
|
|
if (!this.nodes) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return this._getSelectedValues(); |
|
|
|
return this._getSelectedValues(); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
destroyed: function () { |
|
|
|
destroyed() { |
|
|
|
this.stop(); |
|
|
|
this.stop(); |
|
|
|
this.nodes && this.nodes.destroy(); |
|
|
|
this.nodes && this.nodes.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
BI.extend(BI.TreeView, { |
|
|
|
|
|
|
|
REQ_TYPE_INIT_DATA: 1, |
|
|
|
|
|
|
|
REQ_TYPE_ADJUST_DATA: 2, |
|
|
|
|
|
|
|
REQ_TYPE_SELECT_DATA: 3, |
|
|
|
|
|
|
|
REQ_TYPE_GET_SELECTED_DATA: 4 |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BI.TreeView.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
|
|
|
|
BI.TreeView.EVENT_INIT = BI.Events.INIT; |
|
|
|
|
|
|
|
BI.TreeView.EVENT_AFTERINIT = BI.Events.AFTERINIT; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BI.shortcut("bi.tree_view", BI.TreeView); |
|
|
|
|