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