2025-02-15 12:13:10 +08:00

4947 lines
251 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
*@Name dtree 树形组件
*@Author 智慧的小西瓜
*@DOCS http://www.wisdomelon.com/DTreeHelper/
*@License https://www.layui.com/
*@LASTTIME 2019/10/24
*@VERSION v2.5.6
*/
layui.define(['jquery','layer','form'], function(exports) {
var $ = layui.$,
layer = layui.layer,
form = layui.form;
// 树的公共定义样式汇总
var LI_NAV_CHILD = "dtree-nav-ul-sid", LI_NAV_ITEM = "dtree-nav-item",
LI_DIV_ITEM = "dtree-nav-div", DTREEFONTSPECIAL="dtreefont-special", NONETITLE="dtree-none-text",
LI_DIV_MENUBAR = "dtree-menubar",
LI_DIV_TOOLBAR = "dtree-toolbar", TOOLBAR_TOOL = "dtree-toolbar-tool", TOOLBAR_TOOL_EM = "dtree-toolbar-fixed",
LI_DIV_CHECKBAR = "dtree-nav-checkbox-div",
LI_CLICK_CHECKBAR = "d-click-checkbar", //绑定点击复选框时需要用到
LI_DIV_TEXT_CLASS = "t-click", UL_ROOT="dtree",
LI_NAV_FIRST_LINE = "dtree-nav-first-line", LI_NAV_LINE = "dtree-nav-line", LI_NAV_LAST_LINE = "dtree-nav-last-line";
// 树的公共指定
var NAV_THIS = "dtree-nav-this", //当前节点
NAV_SHOW = "dtree-nav-show", //显示子节点
NAV_HIDE = "dtree-nav-hide", //隐藏节点
NAV_DIS = "dtree-disabled", //禁用节点
ICON_HIDE = "dtree-icon-hide", //隐藏图标
$BODY = $("body"), //body选择器
$WIN = $(window), //window窗口
$DOC = $(document), //当前文档
MOD_NAME = "dtree", //模块名称
VERSION = "v2.5.6", //版本
OPTIONS = {}, //全局属性配置
DTrees = {}; //当前被实例化的树的集合
// 树的自定义图标
var DTREEFONT = "dtreefont", //默认使用图标字体
LI_DIV_CHECKBAR_ON = "dtree-icon-fuxuankuangxuanzhong", //复选框选中图标
LI_DIV_CHECKBAR_OUT = "dtree-icon-fuxuankuang", //复选框未选中图标
LI_DIV_CHECKBAR_NOALL = "dtree-icon-fuxuankuang-banxuan", //复选框半选图标
LI_DIV_MENUBAR_DOWN = "dtree-icon-move-down", //menubar的展开全部的图标
LI_DIV_MENUBAR_UP = "dtree-icon-move-up", //menubar的收缩全部的图标
LI_DIV_MENUBAR_REFRESH = "dtree-icon-refresh", //menubar的刷新图标
LI_DIV_MENUBAR_CHECKALL = "dtree-icon-roundcheckfill", //menubar的全选图标
LI_DIV_MENUBAR_UNCHECKALL = "dtree-icon-roundclosefill", //menubar的全不选图标
LI_DIV_MENUBAR_INVERTALL = "dtree-icon-roundcheck", //menubar的反选图标
LI_DIV_MENUBAR_DELETE = "dtree-icon-delete1", //menubar的删除图标
LI_DIV_MENUBAR_SEARCH = "dtree-icon-search_list_light", //menubar的搜索图标
LI_DIV_TOOLBAR_PULLDOWN = "dtree-icon-pulldown", //toolbar的展开图标
LI_DIV_TOOLBAR_PULLUP = "dtree-icon-pullup", //toolbar的收缩图标
LI_DIV_TOOLBAR_ADD = "dtree-icon-roundadd", //toolbar的新增图标
LI_DIV_TOOLBAR_EDIT = "dtree-icon-bianji", //toolbar的编辑图标
LI_DIV_TOOLBAR_DEL = "dtree-icon-roundclose"; //toolbar的删除图标
// 树的非叶子节点图标集合
var nodeIconArray = {
"-1": {"open": "dtree-icon-null-open", "close": "dtree-icon-null-close"}, //未指定
"0" : {"open": "dtree-icon-wenjianjiazhankai", "close": "dtree-icon-weibiaoti5"}, //文件夹(二级图标默认样式)
"1" : {"open": "dtree-icon-jian", "close": "dtree-icon-jia"}, //+-图标(一级图标默认样式)
"2" : {"open": "dtree-icon-xiangxia1", "close": "dtree-icon-xiangyou"} //箭头图标
};
// 树的叶子节点图标集合
var leafIconArray = {
"-1": "dtree-icon-null", //未指定
"0" : "dtree-icon-weibiaoti5", //文件夹
"1" : "dtree-icon-yonghu", //人员
"2" : "dtree-icon-fenzhijigou", //机构
"3" : "dtree-icon-fenguangbaobiao", //报表
"4" : "dtree-icon-xinxipilu", //信息
"5" : "dtree-icon-shuye1", //叶子(二级图标默认样式)
"6" : "dtree-icon-caidan_xunzhang", //勋章
"7" : "dtree-icon-normal-file", //文件
"8" : "dtree-icon-dian", //小圆点(一级图标默认样式)
"9" : "dtree-icon-set-sm", //齿轮
"10" : "dtree-icon-rate" //星星
};
// 树的自定义样式
var DTREE = "dtree-", //自定义样式前缀
ITEMTHIS = "-item-this", //自定义样式当前行选中后缀
ITEM = "-item", //自定义样式当前行后缀
DFONT = "-dtreefont", //自定义样式图标样式后缀
FICON = "-ficon", //自定义样式一级图标样式后缀
ICON = "-icon", //自定义样式二级图标样式后缀
CBOX = "-checkbox", //自定义样式复选框样式后缀
CHS = "-choose"; //自定义样式复选框选中样式后缀
// 树自定义操作事件名称集合 绑定dtree-click的事件
var eventName = {
checkNodeClick: "checkNodeClick", //点击复选框
itemNodeClick: "itemNodeClick" //点击子节点div
};
// 树默认toolbar提供的功能集合 绑定dtree-tool的事件
var defaultTool = {
pulldown: "pulldown", //点击展开当前节点下的全部节点
pullup: "pullup", //点击收缩当前节点下的全部节点
addTool: "addToolbar", //点击toolbar新增
editTool: "editToolbar", //点击toolbar编辑
delTool: "delToolbar" //点击toolbar删除
};
// 树默认menubar提供的功能集合 绑定dtree-menu的事件
var defaultMenu = {
moveDown: "moveDown", //menubar展开全部节点
moveUp: "moveUp", //menubar收缩全部节点
refresh: "refresh", //menubar刷新树
checkAll: "checkAll", //menubar全选
unCheckAll: "unCheckAll", //menubar全不选
invertAll: "invertAll", //menubar反选
remove: "remove", //menubar删除选中节点
searchNode: "searchNode" //menubar查询节点
};
// 树的公共事件
var event = {
getElemId: function(options){ // 根据传入的参数获取ID
var elem = options.elem || "";
var obj = options.obj || $(elem);
if (obj.length == 0) { //页面中未找到绑定id
return "";
} else {
return $(obj)[0].id;
}
},
escape: function(html){
if(typeof html !== 'string') return '';
return html.replace(entityReg.escape, function(match){return entityMap.escape[match];});
},
unescape: function(str){
if(typeof str !== 'string') return '';
return str.replace(entityReg.unescape, function(match){return entityMap.unescape[match];});
},
cloneObj: function (obj, filter) { //深复制对象方法
var newObj = {};
if (obj instanceof Array) {
newObj = [];
}
var str = "";
if(typeof filter !== 'undefined') {str = filter.join(",");}
for (var key in obj) {
if(str.indexOf(key) == -1){
var val = obj[key];
newObj[key] = typeof val === 'object' ? event.cloneObj(val, typeof filter !== undefined ? filter : []): val;
}
}
return newObj;
},
trimToDot: function(str){
return str.replace(/ /g, ".");
}
};
// 特殊符号转义
var keys = Object.keys || function(obj) {
obj = Object(obj);
var arr = [];
for(var a in obj) arr.push(a);
return arr;
};
var invert = function(obj){
obj = Object(obj);
var result = {};
for(var a in obj) result[obj[a]] = a;
return result;
};
var entityMap = {
escape: {
"&" : "&",
"<" : "&lt;",
">" : "&gt;",
"'" : "&quo;"
}
};
entityMap.unescape = invert(entityMap.escape);
var entityReg = {
escape: RegExp('[' + keys(entityMap.escape).join('') + ']', 'g'),
unescape: RegExp('(' + keys(entityMap.unescape).join('|') + ')', 'g')
};
//异步加载接口
var AjaxHelper = {
request : function(config) {
var data = config.data ? config.data : {};
var async = (typeof (config.async) === "boolean") ? config.async : true;
$.ajax({
type : config.type ? config.type : "POST",
headers : config.headers,
url : config.url,
dataType : config.dataType ? config.dataType : "json",
data : data,
async : async,
contentType : config.contentType,
xhrFields: {withCredentials: config.withCredentials},
success : config.success,
error : function(XMLHttpRequest, textStatus, errorThrown) {
if (typeof (config.error) === "function") {
config.error(XMLHttpRequest, textStatus, errorThrown);
} else {
layer.msg("异步加载失败: " + textStatus,{icon:5, shift:6});
}
},
statusCode : {
404 : function() {
layer.msg('未找到指定请求,请检查访问路径!',{icon:5, shift:6});
},
500 : function() {
layer.msg('系统错误!',{icon:5, shift:6});
}
},
complete : function(XMLHttpRequest, textStatus) {
if (typeof (config.complete) === "function") {
config.complete(XMLHttpRequest, textStatus);
}
}
});
},
serialize: function(param){ //json序列化 key=value&key1=value1
var p = "?";
for (var key in param) {
p += key + "=" + param[key] + "&";
}
p = p.substring(0, p.length-1);
return p;
}
};
// 树类
var DTree = function(options){
var _this = this;
/** 默认赋值**/
this.formatter = { // 数据过滤
title: false // 文字,默认不开启
};
this.response = { // 树返回的json格式
statusName: "code", //返回标识
statusCode: 200, //返回码
message: "message", //返回信息
rootName: "data", //根节点名称
treeId: "id", //节点ID
parentId: "parentId", //父节点ID
title: "title", //节点名称
ficonClass: "ficonClass", //自定义一级图标
iconClass: "iconClass", //自定义二级图标
childName: "children", //子节点名称
last: "last", //是否最后一级节点
// level: "level", //层级
spread: "spread", //展开
disabled: "disabled", //禁用
hide: "hide", //隐藏
checkArr: "checkArr", //复选框列表
checked: "checked", //是否选中
type: "type", //复选框标记
basicData: "basicData" //表示用户自定义需要存储在树节点中的数据
};
this.defaultRequest = { // 树的默认发起请求参数格式最后会将value作为参数名称传递
nodeId: "nodeId", //节点ID
parentId: "parentId", //父节点ID
context: "context", //节点内容
leaf: "leaf", //是否叶子节点
level: "level", //层级
spread: "spread", //节点展开状态
dataType: "dataType", //节点标记
checked: "checked", //节点复选框选中状态
initchecked: "initchecked", //节点复选框初始状态
basicData: "basicData", //用户自定义的记录节点数据
recordData: "recordData", //当前data数据排除basicData和children字段
};
this.toolbarFun = {
addTreeNode: function(param, $div) { //添加树节点后调用的函数,用于用户自定义,如未指定则树不会发生变化
return ;
},
editTreeNode: function(param, $div) { //编辑树节点后调用的函数,用于用户自定义,如未指定则树不会发生变化
return ;
},
editTreeLoad: function(param){ // 编辑树的数据回显,用于打开编辑时,回填数据
return ;
},
delTreeNode: function(param, $div){ //删除树后调用的函数,用于用户自定义,如未指定则树不会发生变化
return ;
},
loadToolbarBefore: function(buttons, param, $div){ // 右键菜单加载前的函数
return buttons;
}
};
this.toolbarStyle = {
title: "节点",
area: ["60%","80%"]
};
this.menubarFun = {
remove: function(checkbarNodes){ //删除复选框选中节点,需要用户自定义,如未指定则树只是页面上做了修改
return true;
}
};
this.menubarTips = {
toolbar: [],
group: [defaultMenu.moveDown, defaultMenu.moveUp, defaultMenu.refresh, defaultMenu.checkAll, defaultMenu.unCheckAll, defaultMenu.invertAll, defaultMenu.remove, defaultMenu.searchNode],
freedom: []
};
this.checkbarFun = {
chooseBefore: function($i, node){ // 复选框点击前回调
return true;
},
chooseDone: function(checkbarNodesParam) { //复选框点击事件完毕后,返回该树关于复选框操作的全部信息,用于用户自定义,如未指定则树只是页面上做了修改
return ;
}
};
this.iframeDefaultRequest = { //iframe的默认参数,目的是与加载树的参数不一样
nodeId: "nodeId", //节点ID
parentId: "parentId", //父节点ID
context: "context", //节点内容
leaf: "leaf", //是否叶子节点
level: "level", //层级
spread: "spread", //节点展开状态
dataType: "dataType", //节点标记
checked: "checked", //节点复选框选中状态
initchecked: "initchecked", //节点复选框初始状态
basicData: "basicData", //用户自定义的记录节点数据
recordData: "recordData", //当前data数据排除basicData和children字段
};
this.iframeFun = {
iframeDone: function(iframeParam){ //iframe加载完毕后用于用户自定义事件
return ;
}
};
this.style = { //树最终使用的样式集合
item: "", //每一项div的样式
itemThis: "", //选中div的样式
dfont: "", //一级图标的样式
icon: "", //二级图标的样式
cbox: "", //复选框的样式
chs: "" //复选框选中的样式
};
this.usefontStyle = { //树最终使用的图标集合
fnode:{ //一级节点
node:{ //非叶子节点
open:"", //节点展开
close:"" //节点关闭
},
leaf:"" //叶子节点
},
snode:{ //二级节点
node:{ //非叶子节点
open:"", //节点展开
close:"" //节点关闭
},
leaf:"" //叶子节点
},
checkbox:{ //复选框
on:"", //复选框选中
out:"", //未选中
noall:"" //半选
},
menubar:{ //菜单栏
movedown:"", //全部展开
moveup:"", //全部收缩
refresh:"", //刷新
checkAll:"", //全选
unCheckAll:"", //全不选
invertAll:"", //反选
remove:"", //删除
search:"" //搜索
},
menubarExt:"", //扩展菜单栏
toolbar:{ //工具栏
menubar:{ //依附在菜单栏的工具栏
movedown:"", //全部展开
moveup:"", //全部收缩
refresh:"", //刷新
checkAll:"", //全选
unCheckAll:"", //全不选
invertAll:"", //反选
remove:"", //删除
search:"" //搜索
},
menubarExt:"", //依附在菜单栏的扩展菜单栏
pulldown:"", //展开
pullup:"", //收缩
add:"", //添加
edit:"", //编辑
del:"" //删除
},
toolbarExt:"" //扩展工具栏
}
/** 数据绑定**/
this.node = { // 树节点选中时,包含当前节点的全部信息
nodeId: "", //节点ID
parentId: "", //父节点ID
context: "", //节点内容
leaf: "", //是否叶子节点
level: "", //层级
spread: "", //节点展开状态
dataType: "", //节点标记
checked: "", //节点复选框选中状态
initchecked: "", //节点复选框初始状态
basicData: "", //用户自定义的记录节点数据
recordData: "", //当前data数据排除basicData和children字段
};
this.toolbarMenu = {}; // 工具栏右键菜单绑定的所有元素
this.checkbarNode = []; // 复选框标记的全部节点数据
this.errData = []; // 记录在渲染节点时有问题的数据
this.checkArrLen = 0; //添加节点的时判断复选框个数
this.temp = []; // 临时变量
this.bak = ""; // 临时变量
this.setting(options);
};
/******************** 初始参数加载 ********************/
// 设置基本参数值
DTree.prototype.setting = function(options) {
this.options = options || {};
/** 绑定元素参数必填2个参数项必填一个**/
this.elem = this.options.elem || OPTIONS.elem || ""; //树绑定的元素ID#elem
if(typeof this.options.obj === 'undefined'){
if(this.elem) {
if($(this.elem).length > 0) {
this.obj = $(this.elem);
}
}
} else {
this.obj = this.options.obj || OPTIONS.obj || this.obj; //树绑定的jquery元素用于当元素是延迟加载出来的话可以用这个找到
this.elem = "#" + this.obj[0].id;
}
/** 基本参数**/
this.scroll = this.options.scroll || OPTIONS.scroll || this.elem; //树的上级div容器让树可以显示滚动条的div容器的ID
this.accordion = (typeof (this.options.accordion) === "boolean") ? this.options.accordion : (typeof (OPTIONS.accordion) === "boolean") ? OPTIONS.accordion : false; //手风琴加载, 默认false
if(this.accordion) {
this.initLevel = 1; //默认展开节点 1节
} else {
this.initLevel = this.options.initLevel || OPTIONS.initLevel || 2; //默认展开节点 2节
}
this.type = this.options.type || OPTIONS.type || "load"; //树的加载方式 all全量树 load增量树默认load
this.cache = (typeof (this.options.cache) === "boolean") ? this.options.cache : (typeof (OPTIONS.cache) === "boolean") ? OPTIONS.cache : true; //数据缓存默认true
this.record = this.options.record || OPTIONS.record || false; //开启数据记录模式默认false
this.load = (typeof (this.options.load) === "boolean") ? this.options.load : (typeof (OPTIONS.load) === "boolean") ? OPTIONS.load : true; //开启加载动画默认true
this.none = this.options.none || OPTIONS.nont || "无数据"; //初始加载无记录时显示文字
this.tempHeight = this.options.height || OPTIONS.height; //临时转换高度变量
if(this.tempHeight) { // 设置高度
if(/^full-\d+$/.test(this.tempHeight)) {
this.fullHeightGap = this.tempHeight.split('-')[1];
this.height = $WIN.height() - this.fullHeightGap; //设置高度
} else {
this.fullHeightGap = this.tempHeight;
this.height = this.tempHeight;
}
} else {
this.fullHeightGap = "";
this.height = "";
}
this.width = this.options.width || OPTIONS.width || "260"; //宽度
this.obj.css("width", this.width);
/** 样式相关参数**/
this.iconfont = this.options.iconfont || OPTIONS.iconfont || DTREEFONT; //默认图标字体 dtreefont
this.iconfontStyle = this.options.iconfontStyle || OPTIONS.iconfontStyle || {}; //用于自定义树的每个关键部位使用的图标
this.nodeIconArray = $.extend(nodeIconArray, this.options.nodeIconArray || OPTIONS.nodeIconArray) || nodeIconArray; //用户自定义非叶子节点图标集合node
this.leafIconArray = $.extend(leafIconArray, this.options.leafIconArray || OPTIONS.leafIconArray) || leafIconArray; //用户自定义叶子节点图标集合leaf
this.skin = this.options.skin || OPTIONS.skin || "theme"; // 自定义样式
if(this.skin == "layui"){ // layui主题
this.line = (typeof (this.options.line) === "boolean") ? this.options.line : (typeof (OPTIONS.line) === "boolean") ? OPTIONS.line : true; //开启树线,默认开启
this.ficon = this.options.ficon || OPTIONS.ficon || "7"; //一级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示一级图标。默认'7'
this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "1") : this.ficon[0]; //一级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示一级图标默认'1'
this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1]; //一级图标中的leaf节点图标
this.icon = this.options.icon || OPTIONS.icon || "-1"; //二级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示二级图标。默认'-1'
this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "-1") : this.icon[0]; //二级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示二级图标默认'-1'
this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
} else if(this.skin == "laySimple"){ // laySimple主题
this.line = this.options.line || OPTIONS.line || false; //开启树线,默认不开启
this.ficon = this.options.ficon || OPTIONS.ficon || ["2","-1"]; //一级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示一级图标。默认'-1'
this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "2") : this.ficon[0]; //一级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示一级图标默认'2'
this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1]; // 一级图标中的leaf节点图标
this.icon = this.options.icon || OPTIONS.icon || "-1"; //二级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示二级图标。默认'-1'
this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "-1") : this.icon[0]; //二级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示二级图标默认'-1'
this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
} else { // 默认主题 或者自定义主题
this.line = this.options.line || OPTIONS.line || false; //开启树线,默认不开启
this.ficon = this.options.ficon || OPTIONS.ficon || "8"; //一级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示一级图标。默认'8'
this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "1") : this.ficon[0]; //一级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示一级图标默认'1'
this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1]; // 一级图标中的leaf节点图标
this.icon = this.options.icon || OPTIONS.icon || "5"; //二级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示二级图标。默认'5'
this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "0") : this.icon[0]; //二级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示二级图标默认'0'
this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
}
/** 数据加载参数**/
this.url = this.options.url || OPTIONS.url || ""; //请求地址
this.async = (typeof (this.options.async) === "boolean") ? this.options.async : (typeof (OPTIONS.async) === "boolean") ? OPTIONS.async : true; //异步同步加载,默认异步加载
this.headers = this.options.headers || OPTIONS.headers || {}; //ajax header属性
this.method = this.options.method || OPTIONS.method || "post"; //请求类型
this.dataType = this.options.dataType || OPTIONS.dataType || "json"; //参数类型
this.contentType = this.options.contentType || OPTIONS.contentType || "application/x-www-form-urlencoded"; //发送信息至服务器时内容编码类型
this.defaultRequest = $.extend(this.defaultRequest, this.options.defaultRequest || OPTIONS.defaultRequest) || this.defaultRequest; //默认请求参数
this.filterRequest = this.options.filterRequest || OPTIONS.filterRequest || []; //过滤请求参数
this.request = this.options.request || OPTIONS.request || {}; //用户自定义请求参数
this.response = $.extend(this.response, this.options.response || OPTIONS.response) || this.response; //返回json格式
this.data = this.options.data || OPTIONS.data || null; //初始化指定该参数,则不会访问异步接口
this.dataFormat = this.options.dataFormat || OPTIONS.dataFormat || "levelRelationship"; //用于用户配置的data数据格式list列表 levelRelationship层级关系默认
this.dataStyle = this.options.dataStyle || OPTIONS.dataStyle || "defaultStyle"; //用于用户配置layui通用的json数据风格,layuiStyle:layui风格defaultStyle默认风格
this.errDataShow = this.options.errDataShow || OPTIONS.errDataShow || false; //是否在递归数据出现错误后显示错误信息默认false
this.withCredentials = this.options.withCredentials || OPTIONS.withCredentials || false; //是否允许跨域请求默认false
this.success = this.options.success || OPTIONS.success || function(data, obj){}; //树加载完毕后执行解析树之前的回调
this.done = this.options.done || OPTIONS.done || function(data, obj){}; //树加载完毕后的回调
this.formatter = $.extend(this.formatter, this.options.formatter || OPTIONS.formatter) || this.formatter; //数据过滤
this.error = this.options.error || OPTIONS.error || function(XMLHttpRequest, textStatus, errorThrown){}; // 异步加载异常回调
this.complete = this.options.complete || OPTIONS.complete || function(XMLHttpRequest, textStatus){}; // 异步加载完成回调
/** 复选框参数**/
this.checkbar = this.options.checkbar || OPTIONS.checkbar || false; //是否开启复选框模式
this.checkbarLoad = this.options.checkbarLoad || OPTIONS.checkbarLoad || "node"; //复选框作用范围node所有节点 leaf最后一级默认所有节点
this.checkbarType = this.options.checkbarType || OPTIONS.checkbarType || "all"; //复选框选中形式 all子集选中父级也选中 no-all子集选中父级半选中子集全选父级选中p-casc父级选中子集全选子集无法改变父级选中状态 self没有任何级联关系only只能选中一个复选框。 默认all
this.checkbarData = this.options.checkbarData || OPTIONS.checkbarData || "choose"; //复选框记录数据类型形式, change表示记录变更数据choose表示记录选中数据all记录全部数据halfChoose记录选中和半选中的数据默认choose
this.checkbarFun = $.extend(this.checkbarFun, this.options.checkbarFun || OPTIONS.checkbarFun) || this.checkbarFun; //checkbar事件加载
/** 菜单栏参数**/
this.menubar = this.options.menubar || OPTIONS.menubar || false; //是否打开菜单栏
this.menubarTips = $.extend(this.menubarTips, this.options.menubarTips || OPTIONS.menubarTips) || this.menubarTips; //菜单栏吸附, toolbar依附在工具栏group依附在按钮组freedom自由
this.menubarFun = $.extend(this.menubarFun, this.options.menubarFun || OPTIONS.menubarFun) || this.menubarFun; //menubar事件加载
/** 工具栏参数**/
this.toolbar = this.options.toolbar || OPTIONS.toolbar || false; //是否开启可编辑模式
this.toolbarWay = this.options.toolbarWay || OPTIONS.toolbarWay || "contextmenu"; //工具栏显示方式contextmenu:右键follow:跟随节点fixed:固定在节点右侧
this.toolbarStyle = $.extend(this.toolbarStyle, this.options.toolbarStyle || OPTIONS.toolbarStyle) || this.toolbarStyle; //toolbar的自定义风格标题弹框大小
this.toolbarLoad = this.options.toolbarLoad || OPTIONS.toolbarLoad || "node"; //toolbar作用范围node:所有节点noleaf:非最后一级节点leaf:最后一级
this.toolbarShow = this.options.toolbarShow || OPTIONS.toolbarShow || ["add","edit","delete"]; //toolbar三个按钮自定义加载
this.toolbarBtn = this.options.toolbarBtn || OPTIONS.toolbarBtn || null; //toolbar增删改中内容的自定义加载
this.toolbarExt = this.options.toolbarExt || OPTIONS.toolbarExt || []; //toolbar按钮扩展
this.toolbarFun = $.extend(this.toolbarFun, this.options.toolbarFun || OPTIONS.toolbarFun) || this.toolbarFun; //toolbar事件加载
/** iframe模式参数**/
this.useIframe = this.options.useIframe || OPTIONS.useIframe || false; //是否加载iframe 默认false
this.iframeElem = this.options.iframeElem || OPTIONS.iframeElem || ""; //iframe的ID
this.iframeUrl = this.options.iframeUrl || OPTIONS.iframeUrl || ""; //树关联的iframe地址
this.iframeLoad = this.options.iframeLoad || OPTIONS.iframeLoad || "leaf"; //点击哪一层加载frame node所有节点 leaf默认最后一级
this.iframeDefaultRequest = $.extend(this.iframeDefaultRequest, this.options.iframeDefaultRequest || OPTIONS.iframeDefaultRequest) || this.iframeDefaultRequest; //iframe的默认传递参数
this.iframeRequest = $.extend(this.iframeRequest, this.options.iframeRequest) || $.extend(this.iframeRequest, OPTIONS.iframeRequest) || this.iframeRequest; //iframe的自定义参数
this.iframeFun = $.extend(this.iframeFun, this.options.iframeFun) || $.extend(this.iframeFun, OPTIONS.iframeFun) || this.iframeFun; //iframe事件加载
/** 下拉树模式参数**/
this.select = this.options.select || false;
if(this.select) {
// 重置下拉树
this.selectSetting();
}
/** 调用确认最终主题方法*/
this.ensureTheme();
};
// 设置基本参数值
DTree.prototype.reloadSetting = function(options) {
this.options = $.extend(this.options, options) || this.options;
/** 绑定元素参数**/
this.elem = this.options.elem || this.elem; //树绑定的元素ID#elem
if(typeof this.options.obj === 'undefined'){
if(this.elem) {
if($(this.elem).length > 0) {
this.obj = $(this.elem);
}
}
} else {
this.obj = this.options.obj || this.obj; //树绑定的jquery元素用于当元素是延迟加载出来的话可以用这个找到
this.elem = "#" + this.obj[0].id;
}
/** 基本参数**/
this.scroll = this.options.scroll || this.scroll; //树的上级div容器让树可以显示滚动条的div容器
this.accordion = (typeof (this.options.accordion) === "boolean") ? this.options.accordion : this.accordion; //开启手风琴加载
if(this.accordion) {
this.initLevel = 1; //默认展开节点 1节
} else {
this.initLevel = this.options.initLevel || this.initLevel; //默认展开节点 2节
}
this.type = this.options.type || this.type; //树的加载方式 all全量树 load增量树默认load
this.cache = (typeof (this.options.cache) === "boolean") ? this.options.cache : this.cache; //开启数据缓存
this.record = (typeof (this.options.record) === "boolean") ? this.options.record : this.record; //开启数据记录模式
this.load = (typeof (this.options.load) === "boolean") ? this.options.load : this.load; //开启加载动画
this.none = this.options.none || this.none; //初始节点加载无数据时显示文字
this.tempHeight = this.options.height || this.height; //临时转换高度变量
if(this.tempHeight) { //设置高度
if(/^full-\d+$/.test(this.tempHeight)) {
this.fullHeightGap = this.tempHeight.split('-')[1];
this.height = $WIN.height() - this.fullHeightGap;
} else {
this.fullHeightGap = this.tempHeight;
this.height = this.tempHeight;
}
}
this.width = this.options.width || this.width; //宽度
this.obj.css("width", this.width);
/** 样式相关参数**/
this.line = (typeof (this.options.line) === "boolean") ? this.options.line : this.line; //开启树线,默认不开启
this.iconfont = this.options.iconfont || this.iconfont; //默认图标字体 dtreefont
this.iconfontStyle = this.options.iconfontStyle || this.iconfontStyle; //用于自定义树的每个关键部位使用的图标
this.nodeIconArray = $.extend(nodeIconArray, this.options.nodeIconArray) || this.nodeIconArray; //用户自定义非叶子节点图标集合node
this.leafIconArray = $.extend(leafIconArray, this.options.leafIconArray) || this.leafIconArray; //用户自定义叶子节点图标集合leaf
this.skin = this.options.skin || this.skin; //自定义样式
if(this.skin == "layui"){ //layui主题
this.line = (typeof (this.options.line) === "boolean") ? this.options.line : true; //开启树线,默认开启
this.ficon = this.options.ficon || this.ficon; //一级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示一级图标。默认'7'
this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "1") : this.ficon[0]; //一级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示二级图标默认'1'
this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1]; //一级图标中的leaf节点图标
this.icon = this.options.icon || this.icon; //二级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示二级图标。默认'-1'
this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "-1") : this.icon[0]; //二级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示二级图标默认'-1'
this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
} else if(this.skin == "laySimple"){ //laySimple主题
this.line = (typeof (this.options.line) === "boolean") ? this.options.line : false; //开启树线,默认不开启
this.ficon = this.options.ficon || this.ficon; //一级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示一级图标。默认'-1'
this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "2") : this.ficon[0]; //一级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示二级图标默认'2'
this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1];//一级图标中的leaf节点图标
this.icon = this.options.icon || this.icon; //二级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示二级图标。默认'-1'
this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "-1") : this.icon[0]; //二级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示二级图标默认'-1'
this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
} else { // 默认主题 或者自定义主题
this.line = (typeof (this.options.line) === "boolean") ? this.options.line : false; //开启树线,默认不开启
this.ficon = this.options.ficon || this.ficon; //一级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示一级图标。默认'8'
this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "1") : this.ficon[0]; //一级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示二级图标默认'1'
this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1]; // 一级图标中的leaf节点图标
this.icon = this.options.icon || this.icon; //二级图标样式0文件夹1人员2机构3报表4信息5叶子6勋章7文件8小圆点9齿轮10星星 -1不显示二级图标。默认'5'
this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "0") : this.icon[0]; //二级图标中的node节点图标。0文件夹1+、-2三角形 -1不显示二级图标默认'0'
this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
}
/** 数据加载参数**/
this.url = this.options.url || this.url; //请求地址
this.async = (typeof (this.options.async) === "boolean") ? this.options.async : this.async; //异步同步加载,默认异步加载
this.headers = this.options.headers || this.headers; //ajax header属性
this.method = this.options.method || this.method; //请求类型
this.dataType = this.options.dataType || this.dataType; //参数类型
this.contentType = this.options.contentType || this.contentType; //发送信息至服务器时内容编码类型
this.defaultRequest = $.extend(this.defaultRequest, this.options.defaultRequest) || this.defaultRequest; //默认请求参数
this.filterRequest = this.options.filterRequest || this.filterRequest; //过滤请求参数
this.request = this.options.request || this.request; //用户自定义请求参数
this.response = $.extend(this.response, this.options.response) || this.response; //返回json格式
this.data = this.options.data || this.data; //初始化指定该参数,则不会访问异步接口
this.dataFormat = this.options.dataFormat || this.dataFormat; //用于用户配置的data数据格式list列表 levelRelationship层级关系默认
this.dataStyle = this.options.dataStyle || this.dataStyle; //用于用户配置layui通用的json数据风格,layuiStyle:layui风格defaultStyle默认风格
this.errDataShow = (typeof (this.options.errDataShow) === "boolean") ? this.options.errDataShow : this.errDataShow; //是否在使用list模式递归数据出现错误时显示错误信息
this.withCredentials = (typeof (this.options.withCredentials) === "boolean") ? this.options.withCredentials : this.withCredentials; //是否允许跨域请求
this.success = this.options.success || this.success; //树加载完毕后执行解析树之前的回调
this.done = this.options.done || this.done; //树加载完毕后的回调
this.formatter = $.extend(this.formatter, this.options.formatter)|| this.formatter; //数据过滤
this.error = this.options.error || this.error; //异步加载异常回调
this.complete = this.options.complete || this.complete; //异步加载完成回调
/** 复选框参数**/
this.checkbar = this.options.checkbar || this.checkbar; //是否开启复选框模式
this.checkbarLoad = this.options.checkbarLoad || this.checkbarLoad; //复选框作用范围node所有节点 leaf最后一级默认所有节点
this.checkbarType = this.options.checkbarType || this.checkbarType; //复选框选中形式 all子集选中父级也选中 no-all子集选中父级半选中子集全选父级选中p-casc父级选中子集全选子集无法改变父级选中状态 self没有任何级联关系only只能选中一个复选框。 默认all
this.checkbarData = this.options.checkbarData || this.checkbarData; //复选框记录数据类型形式, change表示记录变更数据choose表示记录选中数据all记录全部数据halfChoose记录选中和半选中的数据默认choose
this.checkbarFun = $.extend(this.checkbarFun, this.options.checkbarFun)|| this.checkbarFun; //checkbar事件加载
/** 菜单栏参数**/
this.menubar = this.options.menubar || this.menubar; //是否打开菜单栏
this.menubarTips = $.extend(this.menubarTips, this.options.menubarTips) || this.menubarTips; //菜单栏吸附, toolbar依附在工具栏group依附在按钮组freedom自由
this.menubarFun = $.extend(this.menubarFun, this.options.menubarFun) || this.menubarFun; //menubar事件加载
/** 工具栏参数**/
this.toolbar = this.options.toolbar || this.toolbar; //是否开启工具栏
this.toolbarWay = this.options.toolbarWay || this.toolbarWay; //工具栏显示方式contextmenu:右键follow:跟随节点fixed:固定在节点右侧
this.toolbarStyle = $.extend(this.toolbarStyle, this.options.toolbarStyle) || this.toolbarStyle; //toolbar的自定义风格标题弹框大小
this.toolbarLoad = this.options.toolbarLoad || this.toolbarLoad; //toolbar作用范围node:所有节点noleaf:非最后一级节点leaf:最后一级
this.toolbarShow = this.options.toolbarShow || this.toolbarShow; //toolbar三个按钮
this.toolbarBtn = this.options.toolbarBtn || this.toolbarBtn; //toolbar增删改中内容的自定义加载
this.toolbarExt = this.options.toolbarExt || this.toolbarExt; //toolbar按钮扩展
this.toolbarFun = $.extend(this.toolbarFun, this.options.toolbarFun) || this.toolbarFun; //toolbar事件加载
/** iframe模式参数**/
this.useIframe = this.options.useIframe || this.useIframe;//是否加载iframe 默认false
this.iframeElem = this.options.iframeElem || this.iframeElem; //iframe的ID
this.iframeUrl = this.options.iframeUrl || this.iframeUrl; //树关联的iframe地址
this.iframeLoad = this.options.iframeLoad || this.iframeLoad; //点击哪一层加载frame node所有节点 leaf默认最后一级
this.iframeDefaultRequest = $.extend(this.iframeDefaultRequest, this.options.iframeDefaultRequest) || this.iframeDefaultRequest; //iframe的默认传递参数
this.iframeRequest = $.extend(this.iframeRequest, this.options.iframeRequest) || this.iframeRequest; //iframe的自定义参数
this.iframeFun = $.extend(this.iframeFun, this.options.iframeFun) || this.iframeFun; //iframe事件加载
/** 下拉树模式参数**/
if(this.select) {
// 重置下拉树
this.reloadSelectSetting();
}
/** 调用确认最终主题方法*/
this.ensureTheme();
};
// 设置下拉树的基本参数值
DTree.prototype.selectSetting = function() {
/** select模式参数*/
this.select = true; //配置成select模式
this.selectInitVal = this.obj.attr("data-value") || this.options.selectInitVal || ""; //输入框的值
this.selectTreeDiv = this.obj[0].id + "_tree_div"; // 上级DIV节点
this.selectCardDiv = this.obj[0].id + "_select_card_div"; // 上级layui卡片节点
this.selectDiv = this.obj[0].id + "_select_div"; // 模拟的select节点
this.selectTipsName = this.obj[0].id + "_select_input"; // select的提示输入框名称
this.selectTips = this.options.selectTips || "请选择"; // 输入框的提示语
this.selectInputName = this.options.selectInputName || {nodeId: this.obj[0].id + "_select_nodeId"}; // select表单中的元素
// 调取下拉树的特殊处理页面元素标识
this.renderSelectDom();
}
// 重新设置下拉树的基本参数值
DTree.prototype.reloadSelectSetting = function() {
this.selectInitVal = this.obj.attr("data-value") || this.options.selectInitVal || this.selectInitVal; //输入框的值
this.selectTips = this.options.selectTips || this.selectTips; // 输入框的提示语
this.selectInputName = $.extend(this.selectInputName, this.options.selectInputName) || this.selectInputName; // select表单中的元素
// 调取下拉树的特殊处理页面元素标识
this.reloadSelectDom();
}
/******************** 下拉树设置区域 ********************/
// 渲染下拉树的Dom结构
DTree.prototype.renderSelectDom = function() {
var _this = this;
var rootId = _this.obj[0].id;
// 设置自定义表单隐藏域
var selectInputName = _this.selectInputName;
var selectInput = [];
for(var key in selectInputName) {
selectInput.push('<input type="hidden" dtree-id="' + rootId + '" dtree-node="' + key + '" name="' + selectInputName[key] + '" value="" readonly>');
}
// 设置html
var prevHtml = ['<div class="layui-unselect layui-form-select" dtree-id="' + rootId + '" dtree-select="' + _this.selectDiv + '">',
'<div class="layui-select-title">', selectInput.join(""),
'<input type="text" dtree-id="' + rootId + '" id="' + _this.selectTipsName +'_id" name="' + _this.selectTipsName + '" placeholder="' + _this.selectTips + '" value="" readonly class="layui-input layui-unselect">',
'<i class="layui-edge"></i>',
'</div></div>'].join('');
_this.obj.before(prevHtml);
_this.obj.wrap('<div class="layui-card dtree-select" dtree-id="' + rootId + '" dtree-card="' + _this.selectCardDiv + '"></div>').wrap('<div class="layui-card-body"></div>').wrap('<div id="' + _this.selectTreeDiv + '"></div>');
}
// 重新渲染下拉树的Dom结构
DTree.prototype.reloadSelectDom = function() {
var _this = this;
var rootId = _this.obj[0].id;
// 设置自定义表单隐藏域
var selectInputName = _this.selectInputName;
var selectInput = [];
for(var key in selectInputName) {
selectInput.push('<input type="hidden" dtree-id="' + rootId + '" dtree-node="' + key + '" name="' + selectInputName[key] + '" value="" readonly>');
}
$("div[dtree-id='"+rootId+"'][dtree-select='"+_this.selectDiv+"']").find("div.layui-select-title").html("");
// 设置html
var prevHtml = [selectInput.join(""),
'<input type="text" dtree-id="' + rootId + '" id="' + _this.selectTipsName +'_id" name="' + _this.selectTipsName + '" placeholder="' + _this.selectTips + '" value="" readonly class="layui-input layui-unselect">',
'<i class="layui-edge"></i>'].join('');
$("div[dtree-id='"+rootId+"'][dtree-select='"+_this.selectDiv+"']").find("div.layui-select-title").html(prevHtml);
}
// 设置输入框的值
DTree.prototype.selectVal = function(param) {
var _this = this;
var rootId = _this.obj[0].id;
var selectInputName = _this.selectInputName;
var selectTipsNameValue = "";
var selectValues = {};
// 如果开启了复选框,则此方法用来取值
if(_this.checkbar) {
$("div[dtree-select='" + _this.selectDiv + "']").find("input[dtree-id='" + rootId + "']").each(function(){
var name = $(this).attr("name");
var val = $(this).val();
selectValues[name] = val;
});
} else {
if(typeof param === 'undefined') { // 不传则为当前树中记录的ID
param = _this.getNowParam();
}
if(typeof param === 'string') { // 传递ID则查询树节点ID对应的值
param = _this.getParam(param);
}
selectTipsNameValue = param["context"];
for(var key in selectInputName) {
selectValues[selectInputName[key]] = param[key];
$("div[dtree-select='" + _this.selectDiv + "']").find("input[dtree-id='" + rootId + "'][name='"+selectInputName[key]+"']").val(param[key] || "");
}
if(param["nodeId"] && !param["context"]) {
selectTipsNameValue = _this.getParam(param["nodeId"]);
}
// 返显提示输入框值
$("div[dtree-select='" + _this.selectDiv + "']").find("input[dtree-id='" + rootId + "'][name='"+_this.selectTipsName+"']").val(selectTipsNameValue || "");
}
// 返回隐藏域中的值
return selectValues;
}
// 设置复选框模式中的下拉树的值
DTree.prototype.selectCheckboxVal = function() {
var _this = this;
var rootId = _this.obj[0].id;
var selectInputName = _this.selectInputName;
// 获取全部复选框选中节点
var param = _this.getCheckbarJsonArrParam();
selectTipsNameValue = param["context"];
var selectValues = {};
for(var key in selectInputName) {
var value = param[key].join(",");
selectValues[selectInputName[key]] = value;
$("div[dtree-select='" + _this.selectDiv + "']").find("input[dtree-id='" + rootId + "'][name='"+selectInputName[key]+"']").val(value);
}
$("div[dtree-select='" + _this.selectDiv + "']").find("input[dtree-id='" + rootId + "'][name='"+_this.selectTipsName+"']").val(selectTipsNameValue);
// 返回隐藏域中的值
return selectValues;
}
// 重置下拉树的值
DTree.prototype.selectResetVal = function() {
var _this = this;
var rootId = _this.obj[0].id;
// 表单清空
$("input[dtree-id='"+rootId+"']").val("");
// 节点重置
_this.cancelNavThis();
if(_this.checkbar) {
// 复选框重置
_this.cancelCheckedNode();
}
}
/******************** 字体及图标区域 ********************/
// 确认最终主题
DTree.prototype.ensureTheme = function(){
var _this = this;
// 确认style
this.style.item = DTREE + this.skin + ITEM;
this.style.itemThis = DTREE + this.skin + ITEMTHIS;
this.style.dfont = DTREE + this.skin + DFONT;
this.style.ficon = DTREE + this.skin + FICON;
this.style.icon = DTREE + this.skin + ICON;
this.style.cbox = DTREE + this.skin + CBOX;
this.style.chs = DTREE + this.skin + CHS;
// 确认usefontStyle
var iconfont = this.iconfont;
var iconfonts = [];
if(typeof iconfont === 'string') {
iconfonts.push(iconfont);
} else {
iconfonts = iconfont;
}
var iconfontStyle = this.iconfontStyle;
var iconfontStyles = [];
if(iconfontStyle.length == undefined) {
iconfontStyles.push(iconfontStyle);
} else {
iconfontStyles = iconfontStyle;
}
for(var i=0; i<iconfonts.length; i++){
var ifont = iconfonts[i];
var ifontStyle = iconfontStyles[i];
if(typeof ifontStyle !== 'undefined') {
// 判断,赋值
this.useDefaultOrUserDefineFnodeStyle(ifont, ifontStyle.fnode);
this.useDefaultOrUserDefineSnodeStyle(ifont, ifontStyle.snode);
this.useDefaultOrUserDefineCheckboxStyle(ifont, ifontStyle.checkbox);
this.useDefaultOrUserDefineMenubarStyle(ifont, ifontStyle.menubar);
this.useDefaultOrUserDefineMenubarExtStyle(ifont, ifontStyle.menubarExt);
this.useDefaultOrUserDefineToolbarStyle(ifont, ifontStyle.toolbar);
this.useDefaultOrUserDefineToolbarExtStyle(ifont, ifontStyle.toolbarExt);
}
}
};
// 赋值一级图标
DTree.prototype.useDefaultOrUserDefineFnodeStyle = function(ifont, fnode){
var _this = this;
var tempOpen = this.usefontStyle.fnode.node.open;
var tempClose = this.usefontStyle.fnode.node.close;
var tempLeaf = this.usefontStyle.fnode.leaf;
if(typeof fnode === 'undefined'){
this.usefontStyle.fnode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["open"]) : tempOpen; // 一级图标中的node节点open图标
this.usefontStyle.fnode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["close"]) : tempClose; // 一级图标中的node节点close图标
this.usefontStyle.fnode.leaf = (tempLeaf == "") ? (ifont + " " + this.leafIconArray[this.fleafIcon]) : tempLeaf; // 一级图标中的node节点的leaf图标
} else {
var node = fnode.node;
var leaf = fnode.leaf;
if(typeof node === 'undefined'){
this.usefontStyle.fnode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["open"]) : tempOpen; // 一级图标中的node节点open图标
this.usefontStyle.fnode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["close"]) : tempClose; // 一级图标中的node节点close图标
} else {
var open = node.open;
var close = node.close;
if(typeof open === 'undefined'){
this.usefontStyle.fnode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["open"]) : tempOpen; // 一级图标中的node节点open图标
} else {
this.usefontStyle.fnode.node.open = ifont + " " + open;
}
if(typeof close === 'undefined') {
this.usefontStyle.fnode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["close"]) : tempClose; // 一级图标中的node节点close图标
} else {
this.usefontStyle.fnode.node.close = ifont + " " + close;
}
}
if(typeof leaf === 'undefined'){
this.usefontStyle.fnode.leaf = (tempLeaf == "") ? (ifont + " " + this.leafIconArray[this.fleafIcon]) : tempLeaf; // 一级图标中的node节点的leaf图标
} else {
this.usefontStyle.fnode.leaf = ifont + " " + leaf;
}
}
};
// 赋值二级图标
DTree.prototype.useDefaultOrUserDefineSnodeStyle = function(ifont, snode){
var _this = this;
var tempOpen = this.usefontStyle.snode.node.open;
var tempClose = this.usefontStyle.snode.node.close;
var tempLeaf = this.usefontStyle.snode.leaf;
if(typeof snode === 'undefined'){
this.usefontStyle.snode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["open"]) : tempOpen; // 二级图标中的node节点open图标
this.usefontStyle.snode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["close"]) : tempClose; // 二级图标中的node节点close图标
this.usefontStyle.snode.leaf = (tempLeaf == "") ? (ifont + " " + this.leafIconArray[this.leafIcon]) : tempLeaf; // 二级图标中的leaf节点图标
} else {
var node = snode.node;
var leaf = snode.leaf;
if(typeof node === 'undefined') {
this.usefontStyle.snode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["open"]) : tempOpen; // 二级图标中的node节点open图标
this.usefontStyle.snode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["close"]) : tempClose; // 二级图标中的node节点close图标
} else {
var open = node.open;
var close = node.close;
if(typeof open === 'undefined'){
this.usefontStyle.snode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["open"]) : tempOpen; // 二级图标中的node节点open图标
} else {
this.usefontStyle.snode.node.open = ifont + " " + open;
}
if(typeof close === 'undefined') {
this.usefontStyle.snode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["close"]) : tempClose; // 二级图标中的node节点close图标
} else {
this.usefontStyle.snode.node.close = ifont + " " + close;
}
}
if(typeof leaf === 'undefined') {
this.usefontStyle.snode.leaf = (tempLeaf == "") ? (ifont + " " + this.leafIconArray[this.leafIcon]) : tempLeaf; // 二级图标中的leaf节点图标
} else {
this.usefontStyle.snode.leaf = ifont + " " + leaf;
}
}
};
// 赋值复选框图标
DTree.prototype.useDefaultOrUserDefineCheckboxStyle = function(ifont, checkbox){
var _this = this;
var tempOn = this.usefontStyle.checkbox.on;
var tempOut = this.usefontStyle.checkbox.out;
var tempNoall = this.usefontStyle.checkbox.noall;
if(typeof checkbox === 'undefined'){
this.usefontStyle.checkbox.on = (tempOn == "") ? (ifont + " " + LI_DIV_CHECKBAR_ON) : tempOn;
this.usefontStyle.checkbox.out = (tempOut == "") ? (ifont + " " + LI_DIV_CHECKBAR_OUT) : tempOut;
this.usefontStyle.checkbox.noall = (tempNoall == "") ? (ifont + " " + LI_DIV_CHECKBAR_NOALL) : tempNoall;
} else {
var on = checkbox.on;
var out = checkbox.out;
var noall = checkbox.noall;
if(typeof on === 'undefined') {
this.usefontStyle.checkbox.on = (tempOn == "") ? (ifont + " " + LI_DIV_CHECKBAR_ON) : tempOn;
} else {
this.usefontStyle.checkbox.on = ifont + " " + on;
}
if(typeof out === 'undefined') {
this.usefontStyle.checkbox.out = (tempOut == "") ? (ifont + " " + LI_DIV_CHECKBAR_OUT) : tempOut;
} else {
this.usefontStyle.checkbox.out = ifont + " " + out;
}
if(typeof noall === 'undefined') {
this.usefontStyle.checkbox.noall = (tempNoall == "") ? (ifont + " " + LI_DIV_CHECKBAR_NOALL) : tempNoall;
} else {
this.usefontStyle.checkbox.noall = ifont + " " + noall;
}
}
};
// 赋值菜单栏图标
DTree.prototype.useDefaultOrUserDefineMenubarStyle = function(ifont, menubar){
var _this = this;
var tempMovedown = this.usefontStyle.menubar.movedown;
var tempMoveup = this.usefontStyle.menubar.moveup;
var tempRefresh = this.usefontStyle.menubar.refresh;
var tempCheckAll = this.usefontStyle.menubar.checkAll;
var tempUncheckAll = this.usefontStyle.menubar.unCheckAll;
var tempInvertAll = this.usefontStyle.menubar.invertAll;
var tempRemove = this.usefontStyle.menubar.remove;
var tempSearch = this.usefontStyle.menubar.search;
if(typeof menubar === 'undefined'){
this.usefontStyle.menubar.movedown = (tempMovedown == "") ? (ifont + " " + LI_DIV_MENUBAR_DOWN) : tempMovedown;
this.usefontStyle.menubar.moveup = (tempMoveup == "") ? (ifont + " " + LI_DIV_MENUBAR_UP) : tempMoveup;
this.usefontStyle.menubar.refresh = (tempRefresh == "") ? (ifont + " " + LI_DIV_MENUBAR_REFRESH) : tempRefresh;
this.usefontStyle.menubar.checkAll = (tempCheckAll == "") ? (ifont + " " + LI_DIV_MENUBAR_CHECKALL) : tempCheckAll;
this.usefontStyle.menubar.unCheckAll = (tempUncheckAll == "") ? (ifont + " " + LI_DIV_MENUBAR_UNCHECKALL) : tempUncheckAll;
this.usefontStyle.menubar.invertAll = (tempInvertAll == "") ? (ifont + " " + LI_DIV_MENUBAR_INVERTALL) : tempInvertAll;
this.usefontStyle.menubar.remove = (tempRemove == "") ? (ifont + " " + LI_DIV_MENUBAR_DELETE) : tempRemove;
this.usefontStyle.menubar.search = (tempSearch == "") ? (ifont + " " + LI_DIV_MENUBAR_SEARCH) : tempSearch;
} else {
var movedown = menubar.movedown;
var moveup = menubar.moveup;
var refresh = menubar.refresh;
var checkAll = menubar.checkAll;
var unCheckAll = menubar.unCheckAll;
var invertAll = menubar.invertAll;
var remove = menubar.remove;
var search = menubar.search;
if(typeof movedown === 'undefined') {
this.usefontStyle.menubar.movedown = (tempMovedown == "") ? (ifont + " " + LI_DIV_MENUBAR_DOWN) : tempMovedown;
} else {
this.usefontStyle.menubar.movedown = ifont + " " + movedown;
}
if(typeof moveup === 'undefined') {
this.usefontStyle.menubar.moveup = (tempMoveup == "") ? (ifont + " " + LI_DIV_MENUBAR_UP) : tempMoveup;
} else {
this.usefontStyle.menubar.moveup = ifont + " " + moveup;
}
if(typeof refresh === 'undefined') {
this.usefontStyle.menubar.refresh = (tempRefresh == "") ? (ifont + " " + LI_DIV_MENUBAR_REFRESH) : tempRefresh;
} else {
this.usefontStyle.menubar.refresh = ifont + " " + refresh;
}
if(typeof checkAll === 'undefined') {
this.usefontStyle.menubar.checkAll = (tempCheckAll == "") ? (ifont + " " + LI_DIV_MENUBAR_CHECKALL) : tempCheckAll;
} else {
this.usefontStyle.menubar.checkAll = ifont + " " + checkAll;
}
if(typeof unCheckAll === 'undefined') {
this.usefontStyle.menubar.unCheckAll = (tempUncheckAll == "") ? (ifont + " " + LI_DIV_MENUBAR_UNCHECKALL) : tempUncheckAll;
} else {
this.usefontStyle.menubar.unCheckAll = ifont + " " + unCheckAll;
}
if(typeof invertAll === 'undefined') {
this.usefontStyle.menubar.invertAll = (tempInvertAll == "") ? (ifont + " " + LI_DIV_MENUBAR_INVERTALL) : tempInvertAll;
} else {
this.usefontStyle.menubar.invertAll = ifont + " " + invertAll;
}
if(typeof remove === 'undefined') {
this.usefontStyle.menubar.remove = (tempRemove == "") ? (ifont + " " + LI_DIV_MENUBAR_DELETE) : tempRemove;
} else {
this.usefontStyle.menubar.remove = ifont + " " + remove;
}
if(typeof search === 'undefined') {
this.usefontStyle.menubar.search = (tempSearch == "") ? (ifont + " " + LI_DIV_MENUBAR_SEARCH) : tempSearch;
} else {
this.usefontStyle.menubar.search = ifont + " " + search;
}
}
};
// 赋值扩展菜单栏图标
DTree.prototype.useDefaultOrUserDefineMenubarExtStyle = function(ifont, menubarExt){
var _this = this;
var tempExt = this.usefontStyle.menubarExt;
if(typeof menubarExt === 'undefined'){
this.usefontStyle.menubarExt = (tempExt == "") ? ifont : tempExt;
} else {
this.usefontStyle.menubarExt = menubarExt;
}
};
// 赋值工具栏图标
DTree.prototype.useDefaultOrUserDefineToolbarStyle = function(ifont, toolbar){
var _this = this;
var tempMovedown = this.usefontStyle.toolbar.menubar.movedown;
var tempMoveup = this.usefontStyle.toolbar.menubar.moveup;
var tempRefresh = this.usefontStyle.toolbar.menubar.refresh;
var tempCheckAll = this.usefontStyle.toolbar.menubar.checkAll;
var tempUnCheckAll = this.usefontStyle.toolbar.menubar.unCheckAll;
var tempInvertAll = this.usefontStyle.toolbar.menubar.invertAll;
var tempRemove = this.usefontStyle.toolbar.menubar.remove;
var tempSearch = this.usefontStyle.toolbar.menubar.search;
var tempExt = this.usefontStyle.toolbar.menubarExt;
var tempPulldown = this.usefontStyle.toolbar.pulldown;
var tempPullup = this.usefontStyle.toolbar.pullup;
var tempAdd = this.usefontStyle.toolbar.add;
var tempEdit = this.usefontStyle.toolbar.edit;
var tempDel = this.usefontStyle.toolbar.del;
if(typeof toolbar === 'undefined'){
this.usefontStyle.toolbar.menubar.movedown = (tempMovedown == "") ? (ifont + " " + this.usefontStyle.menubar.movedown) : tempMovedown;
this.usefontStyle.toolbar.menubar.moveup = (tempMoveup == "") ? (ifont + " " + this.usefontStyle.menubar.moveup) : tempMoveup;
this.usefontStyle.toolbar.menubar.refresh = (tempRefresh == "") ? (ifont + " " + this.usefontStyle.menubar.refresh) : tempRefresh;
this.usefontStyle.toolbar.menubar.checkAll = (tempCheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.checkAll) : tempCheckAll;
this.usefontStyle.toolbar.menubar.unCheckAll = (tempUnCheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.unCheckAll) : tempUnCheckAll;
this.usefontStyle.toolbar.menubar.invertAll = (tempInvertAll == "") ? (ifont + " " + this.usefontStyle.menubar.invertAll) : tempInvertAll;
this.usefontStyle.toolbar.menubar.remove = (tempRemove == "") ? (ifont + " " + this.usefontStyle.menubar.remove) : tempRemove;
this.usefontStyle.toolbar.menubar.search = (tempSearch == "") ? (ifont + " " + this.usefontStyle.menubar.search) : tempSearch;
this.usefontStyle.toolbar.menubarExt = (tempExt == "") ? this.usefontStyle.menubarExt : tempExt;
this.usefontStyle.toolbar.pulldown = (tempPulldown == "") ? (ifont + " " + LI_DIV_TOOLBAR_PULLDOWN) : tempPulldown;
this.usefontStyle.toolbar.pullup = (tempPullup == "") ? (ifont + " " + LI_DIV_TOOLBAR_PULLUP) : tempPullup;
this.usefontStyle.toolbar.add = (tempAdd == "") ? (ifont + " " + LI_DIV_TOOLBAR_ADD) : tempAdd;
this.usefontStyle.toolbar.edit = (tempEdit == "") ? (ifont + " " + LI_DIV_TOOLBAR_EDIT) : tempEdit;
this.usefontStyle.toolbar.del = (tempDel == "") ? (ifont + " " + LI_DIV_TOOLBAR_DEL) : tempDel;
} else {
var menubar = toolbar.menubar;
var menubarExt = toolbar.menubarExt;
var pulldown = toolbar.pulldown;
var pullup = toolbar.pullup;
var add = toolbar.add;
var edit = toolbar.edit;
var del = toolbar.del;
if(typeof menubar === 'undefined'){
this.usefontStyle.toolbar.menubar.movedown = (tempMovedown == "") ? (ifont + " " + this.usefontStyle.menubar.movedown) : tempMovedown;
this.usefontStyle.toolbar.menubar.moveup = (tempMoveup == "") ? (ifont + " " + this.usefontStyle.menubar.moveup) : tempMoveup;
this.usefontStyle.toolbar.menubar.refresh = (tempRefresh == "") ? (ifont + " " + this.usefontStyle.menubar.refresh) : tempRefresh;
this.usefontStyle.toolbar.menubar.checkAll = (tempCheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.checkAll) : tempCheckAll;
this.usefontStyle.toolbar.menubar.unCheckAll = (tempUncheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.unCheckAll) : tempUncheckAll;
this.usefontStyle.toolbar.menubar.invertAll = (tempInvertAll == "") ? (ifont + " " + this.usefontStyle.menubar.invertAll) : tempInvertAll;
this.usefontStyle.toolbar.menubar.remove = (tempRemove == "") ? (ifont + " " + this.usefontStyle.menubar.remove) : tempRemove;
this.usefontStyle.toolbar.menubar.search = (tempSearch == "") ? (ifont + " " + this.usefontStyle.menubar.search) : tempSearch;
} else {
var movedown = menubar.movedown;
var moveup = menubar.moveup;
var refresh = menubar.refresh;
var checkAll = menubar.checkAll;
var unCheckAll = menubar.unCheckAll;
var invertAll = menubar.invertAll;
var remove = menubar.remove;
var search = menubar.search;
if(typeof movedown === 'undefined') {
this.usefontStyle.toolbar.menubar.movedown = (tempMovedown == "") ? (ifont + " " + this.usefontStyle.menubar.movedown) : tempMovedown;
} else {
this.usefontStyle.toolbar.menubar.movedown = ifont + " " + movedown;
}
if(typeof moveup === 'undefined') {
this.usefontStyle.toolbar.menubar.moveup = (tempMoveup == "") ? (ifont + " " + this.usefontStyle.menubar.moveup) : tempMoveup;
} else {
this.usefontStyle.toolbar.menubar.moveup = ifont + " " + moveup;
}
if(typeof refresh === 'undefined') {
this.usefontStyle.toolbar.menubar.refresh = (tempRefresh == "") ? (ifont + " " + this.usefontStyle.menubar.refresh) : tempRefresh;
} else {
this.usefontStyle.toolbar.menubar.refresh = ifont + " " + refresh;
}
if(typeof checkAll === 'undefined') {
this.usefontStyle.toolbar.menubar.checkAll = (tempCheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.checkAll) : tempCheckAll;
} else {
this.usefontStyle.toolbar.menubar.checkAll = ifont + " " + checkAll;
}
if(typeof unCheckAll === 'undefined') {
this.usefontStyle.toolbar.menubar.unCheckAll = (tempUncheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.unCheckAll) : tempUncheckAll;
} else {
this.usefontStyle.toolbar.menubar.unCheckAll = ifont + " " + unCheckAll;
}
if(typeof invertAll === 'undefined') {
this.usefontStyle.toolbar.menubar.invertAll = (tempInvertAll == "") ? (ifont + " " + this.usefontStyle.menubar.invertAll) : tempInvertAll;
} else {
this.usefontStyle.toolbar.menubar.invertAll = ifont + " " + invertAll;
}
if(typeof remove === 'undefined') {
this.usefontStyle.toolbar.menubar.remove = (tempRemove == "") ? (ifont + " " + this.usefontStyle.menubar.remove) : tempRemove;
} else {
this.usefontStyle.toolbar.menubar.remove = ifont + " " + remove;
}
if(typeof search === 'undefined') {
this.usefontStyle.toolbar.menubar.search = (tempSearch == "") ? (ifont + " " + this.usefontStyle.menubar.search) : tempSearch;
} else {
this.usefontStyle.toolbar.menubar.search = ifont + " " + search;
}
}
if(typeof menubarExt === 'undefined'){
this.usefontStyle.toolbar.menubarExt = (tempExt == "") ? this.usefontStyle.menubarExt : tempExt;
} else {
this.usefontStyle.toolbar.menubarExt = menubarExt;
}
if(typeof pulldown === 'undefined'){
this.usefontStyle.toolbar.pulldown = (tempPulldown == "") ? (ifont + " " + LI_DIV_TOOLBAR_PULLDOWN) : tempPulldown;
} else {
this.usefontStyle.toolbar.pulldown = ifont + " " + pulldown;
}
if(typeof pullup === 'undefined'){
this.usefontStyle.toolbar.pullup = (tempPullup == "") ? (ifont + " " + LI_DIV_TOOLBAR_PULLUP) : tempPullup;
} else {
this.usefontStyle.toolbar.pullup = ifont + " " + pullup;
}
if(typeof add === 'undefined'){
this.usefontStyle.toolbar.add = (tempAdd == "") ? (ifont + " " + LI_DIV_TOOLBAR_ADD) : tempAdd;
} else {
this.usefontStyle.toolbar.add = ifont + " " + add;
}
if(typeof edit === 'undefined'){
this.usefontStyle.toolbar.edit = (tempEdit == "") ? (ifont + " " + LI_DIV_TOOLBAR_EDIT) : tempEdit;
} else {
this.usefontStyle.toolbar.edit = ifont + " " + edit;
}
if(typeof del === 'undefined'){
this.usefontStyle.toolbar.del = (tempDel == "") ? (ifont + " " + LI_DIV_TOOLBAR_DEL) : tempDel;
} else {
this.usefontStyle.toolbar.del = ifont + " " + del;
}
}
};
// 赋值扩展工具栏图标
DTree.prototype.useDefaultOrUserDefineToolbarExtStyle = function(ifont, toolbarExt){
var _this = this;
var tempExt = this.usefontStyle.toolbarExt;
if(typeof toolbarExt === 'undefined'){
this.usefontStyle.toolbarExt = (tempExt == "") ? ifont : tempExt;
} else {
this.usefontStyle.toolbarExt = toolbarExt;
}
};
// 设置图标的展开关闭,以及展开时/关闭时是最后一级图标的处理
DTree.prototype.operateIcon = function($i_spread, $i_node){
var _this = this;
var ficonClass = $i_spread.attr("data-iconClass");
var iconClass = $i_node.attr("data-iconClass");
return{
open: function(){
$i_spread.attr("data-spread","open");
$i_node.attr("data-spread","open");
if(!ficonClass) {
$i_spread.removeClass(_this.usefontStyle.fnode.node.close);
$i_spread.addClass(_this.usefontStyle.fnode.node.open);
}
if(!iconClass) {
$i_node.removeClass(_this.usefontStyle.snode.node.close);
$i_node.addClass(_this.usefontStyle.snode.node.open);
}
},
close: function(){
$i_spread.attr("data-spread","close");
$i_node.attr("data-spread","close");
if(!ficonClass) {
$i_spread.removeClass(_this.usefontStyle.fnode.node.open);
$i_spread.addClass(_this.usefontStyle.fnode.node.close);
}
if(!iconClass) {
$i_node.removeClass(_this.usefontStyle.snode.node.open);
$i_node.addClass(_this.usefontStyle.snode.node.close);
}
},
openWithLeaf: function(){
$i_spread.attr("data-spread","open");
$i_node.attr("data-spread","open");
if(!ficonClass) {
$i_spread.removeClass(_this.usefontStyle.fnode.leaf);
$i_spread.addClass(_this.usefontStyle.fnode.node.open);
}
if(!iconClass) {
$i_node.removeClass(_this.usefontStyle.snode.leaf);
$i_node.addClass(_this.usefontStyle.snode.node.open);
}
},
closeWithLeaf: function(){
$i_spread.attr("data-spread","last");
$i_node.attr("data-spread","last");
if(!ficonClass) {
$i_spread.removeClass(_this.usefontStyle.fnode.node.open);
$i_spread.removeClass(_this.usefontStyle.fnode.node.close);
$i_spread.addClass(_this.usefontStyle.fnode.leaf);
}
if(!iconClass) {
$i_node.removeClass(_this.usefontStyle.snode.node.open);
$i_node.removeClass(_this.usefontStyle.snode.node.close);
$i_node.addClass(_this.usefontStyle.snode.leaf);
}
}
}
};
// 显示树线
DTree.prototype.showLine = function($lis){
var _this = this;
if(_this.line){
if($lis && $lis.length > 0) {
$lis.each(function(){
_this.showLineLi($(this));
});
} else {
_this.obj.find("li[data-id]").each(function(){
_this.showLineLi($(this));
});
}
}
}
// 真正显示树线的方法
DTree.prototype.showLineLi = function($li){
var _this = this;
var $div = $li.children("div"),
$nextLi = $li.next("li"),
$ul = $li.parent("ul");
if($ul[0].id == _this.obj[0].id) {
// 根节点下的节点
$li.removeClass(LI_NAV_LINE);
$li.removeClass(LI_NAV_LAST_LINE);
$li.addClass(LI_NAV_FIRST_LINE);
} else {
// 非根节点下的节点
var $pnextLi = $ul.parent("li").next("li");
if($pnextLi.length == 0) {
if($nextLi.length == 0){
$li.removeClass(LI_NAV_LINE);
$li.removeClass(LI_NAV_FIRST_LINE);
$li.addClass(LI_NAV_LAST_LINE);
} else {
$li.removeClass(LI_NAV_FIRST_LINE);
$li.removeClass(LI_NAV_LAST_LINE);
$li.addClass(LI_NAV_LINE);
}
}else {
var $pnextdiv = $pnextLi.children("div");
if($nextLi.length == 0 && $div.children("cite").attr("data-leaf") == "leaf" && $pnextdiv.children("cite").attr("data-leaf") == "leaf") {
$li.removeClass(LI_NAV_FIRST_LINE);
$li.removeClass(LI_NAV_LINE);
$li.addClass(LI_NAV_LAST_LINE);
} else {
$li.removeClass(LI_NAV_FIRST_LINE);
$li.removeClass(LI_NAV_LAST_LINE);
$li.addClass(LI_NAV_LINE);
}
}
}
}
/******************** 初始化数据区域 ********************/
// 设置高度
DTree.prototype.autoHeight = function(){
var _this = this;
var height = _this.height;
if(height != "") {
if(_this.elem == _this.scroll){
_this.obj.parent().css("height", height + "px");
} else {
var $toolbarDiv = _this.obj.closest(_this.scroll);
$toolbarDiv.css("height", height + "px");
}
}
};
// 重载树
DTree.prototype.reload = function(options){
var _this = this;
_this.reloadSetting(options);
_this.init();
};
// 初始化树
DTree.prototype.init = function(){
var _this = this;
if (typeof _this !== "object") {
//_this.obj.html(_this.getNoneDom().errText("树组件未成功加载,请检查配置"));
layer.msg("树组件未成功加载,请检查配置", {icon:5});
return ;
}
// 设置组件高度
_this.autoHeight();
if(_this.data) {
if(typeof _this.data.length === 'undefined'){
//_this.obj.html(_this.getNoneDom().errText("数据解析异常data数据格式不正确"));
layer.msg("数据解析异常data数据格式不正确", {icon:5});
return ;
}
if(_this.data.length == 0) {
_this.obj.html(_this.getNoneDom().text());
return ;
}
//先将ul中的元素清空
_this.obj.html("");
setTimeout(function () {
// 加载完毕后执行树解析前的回调
_this.success(_this.data, _this.obj);
// 第一次解析树
if (_this.dataFormat == 'list'){
//1.识别根节点ul中的data-id标签判断顶级父节点
var pid = _this.obj.attr("data-id");
//2.构建一个存放节点的树组
var rootListData = _this.queryListTreeByPid(pid, _this.data);
_this.loadListTree(rootListData, _this.data, 1);
} else {
_this.loadTree(_this.data, 1);
}
// 显示树线
_this.showLine();
// 这种情况下需要一开始就将toolbar显示在页面上
if(_this.toolbar && _this.toolbarWay != 'contextmenu') {
_this.setToolbarDom().setToolbarPlace(_this.toolbarMenu);
}
// 判断是否存在错误数据,并是否打印错误数据
_this.msgErrData();
// 设置复选框的初始值
if(_this.select){
_this.selectVal(_this.selectInitVal);
}
// 保存树副本
_this.bak = _this.obj.html();
// 加载完毕后的回调
_this.done(_this.data, _this.obj);
}, 100);
} else {
if (!_this.url) {
//_this.obj.html(_this.getNoneDom().errText("数据请求异常url参数未指定"));
layer.msg("数据请求异常url参数未指定", {icon:5});
return ;
}
//先将ul中的元素清空
_this.obj.html("");
var index = _this.load ? layer.load(1) : "";
AjaxHelper.request({
async: _this.async,
headers: _this.headers,
type: _this.method,
url: _this.url,
dataType: _this.dataType,
contentType: _this.contentType,
withCredentials: _this.withCredentials,
data: _this.getFilterRequestParam(_this.getRequestParam()),
success: function(result) {
if (typeof result === 'string') {
result = $.parseJSON(result);
}
// 加载完毕后执行树解析前的回调
_this.success(result, _this.obj);
var code = "";
if (_this.dataStyle == 'layuiStyle'){
code = result[_this.response.statusName];
} else {
code = result.status[_this.response.statusName];
}
if (code == _this.response.statusCode) {
var d = result[_this.response.rootName];
if(typeof d.length === 'undefined'){
_this.obj.html(_this.getNoneDom().errText("数据解析异常url回调后的数据格式不正确"));
//layer.msg("数据解析异常url回调后的数据格式不正确", {icon:5});
return ;
}
if(d.length == 0) {
_this.obj.html(_this.getNoneDom().text());
return ;
}
// 第一次解析树
if (_this.dataFormat == 'list'){
//1.识别根节点ul中的data-id标签判断顶级父节点
var pid = _this.obj.attr("data-id");
//2.构建一个存放节点的树组
var rootListData = _this.queryListTreeByPid(pid, d);
_this.loadListTree(rootListData, d, 1);
} else {
_this.loadTree(d, 1);
}
// 显示树线
_this.showLine();
// 这种情况下需要一开始就将toolbar显示在页面上
if(_this.toolbar && _this.toolbarWay != 'contextmenu') {
_this.setToolbarDom().setToolbarPlace(_this.toolbarMenu);
}
// 判断是否存在错误数据,并是否打印错误数据
_this.msgErrData();
// 设置复选框的初始值
if(_this.select){
_this.selectVal(_this.selectInitVal);
}
// 保存树副本
_this.bak = _this.obj.html();
// 加载完毕后的回调
_this.done(result, _this.obj);
} else {
// 如果打印不出任何信息说明是在这里,用了错误的数据格式, 或返回码不正确
if (_this.dataStyle == 'layuiStyle'){
_this.obj.html(_this.getNoneDom().errText(result[_this.response.message]));
_this.error(null, code, result[_this.response.message]);
//layer.msg(result[_this.response.message], {icon:2});
} else {
_this.obj.html(_this.getNoneDom().errText(result.status[_this.response.message]));
_this.error(null, code, result.status[_this.response.message]);
//layer.msg(result.status[_this.response.message], {icon:2});
}
}
},
error: function(XMLHttpRequest, textStatus, errorThrown){// 异步加载异常回调
_this.obj.html(_this.getNoneDom().errText(textStatus + ": " + errorThrown));
_this.error(XMLHttpRequest, textStatus, errorThrown);
},
complete: function(XMLHttpRequest, textStatus){// 异步加载完成回调
if(_this.load){layer.close(index);}
_this.complete(XMLHttpRequest, textStatus);
}
});
}
};
// 加载子节点
DTree.prototype.getChild = function($div, data) {
var _this = this, $ul = $div.next("ul");
_this.setNodeParam($div);
if(typeof data !== 'undefined') {
if(typeof data.length === 'undefined'){
//_this.obj.html(_this.getNoneDom().errText("数据解析异常data数据格式不正确"));
layer.msg("数据解析异常data数据格式不正确", {icon:5});
return ;
}
//先将ul中的元素清空
$ul.html("");
// 解析树
if (_this.dataFormat == 'list'){
var pid = _this.node.nodeId;
var level = parseInt(_this.node.level)+1;
var listData = _this.queryListTreeByPid(pid, data);
_this.loadListTree(listData, _this.data, level);
} else {
_this.loadTree(data, level);
}
// 显示树线
_this.showLine();
// 这种情况下需要一开始就将toolbar显示在页面上
if(_this.toolbar && _this.toolbarWay != 'contextmenu') {
_this.setToolbarDom().setToolbarPlace(_this.toolbarMenu);
}
// 判断是否存在错误数据,并是否打印错误数据
_this.msgErrData();
// 保存树副本
_this.bak = _this.obj.html();
} else {
if (!_this.url) {
//_this.obj.html(_this.getNoneDom().errText("数据请求异常url参数未指定"));
layer.msg("数据请求异常url参数未指定", {icon:5});
return ;
}
$ul.html("");
var index = _this.load ? layer.load(1) : "";
AjaxHelper.request({
async: _this.async,
headers: _this.headers,
type: _this.method,
url: _this.url,
dataType: _this.dataType,
withCredentials: _this.withCredentials,
data: _this.getFilterRequestParam(_this.getRequestParam()),
success: function(result) {
if (typeof result === 'string') {
result = $.parseJSON(result);
}
var code = "";
if (_this.dataStyle == 'layuiStyle'){
code = result[_this.response.statusName];
} else {
code = result.status[_this.response.statusName];
}
if (code == _this.response.statusCode) {
// 解析树
var pid = _this.node.nodeId;
var level = parseInt(_this.node.level)+1;
if (_this.dataFormat == 'list'){
var pListData = _this.queryListTreeByPid(pid, result[_this.response.rootName]);
_this.loadListTree(pListData, result[_this.response.rootName], level, $ul);
} else {
_this.loadTree(result[_this.response.rootName], level, $ul);
}
// 显示树线
_this.showLine();
// 这种情况下需要一开始就将toolbar显示在页面上
if(_this.toolbar && _this.toolbarWay != 'contextmenu') {
_this.setToolbarDom().setToolbarPlace(_this.toolbarMenu);
}
// 判断是否存在错误数据,并是否打印错误数据
_this.msgErrData();
$ul.addClass(NAV_SHOW);
// 保存树副本
_this.bak = _this.obj.html();
} else {
if (_this.dataStyle == 'layuiStyle'){
_this.obj.html(_this.getNoneDom().errText(result[_this.response.message]));
_this.error(null, code, result[_this.response.message]);
//layer.msg(result[_this.response.message], {icon:2});
} else {
_this.obj.html(_this.getNoneDom().errText(result.status[_this.response.message]));
_this.error(null, code, result.status[_this.response.message]);
//layer.msg(result.status[_this.response.message], {icon:2});
}
}
},
error: function(XMLHttpRequest, textStatus, errorThrown){// 异步加载异常回调
_this.obj.html(_this.getNoneDom().errText(textStatus + ": " + errorThrown));
_this.error(XMLHttpRequest, textStatus, errorThrown);
},
complete: function(XMLHttpRequest, textStatus){// 异步加载完成回调
if(_this.load){layer.close(index);}
_this.complete(XMLHttpRequest, textStatus);
}
});
}
};
// 初始化树或者拼接树
DTree.prototype.loadListTree = function(pListData, listData, level, $ul){
var _this = this;
$ul = $ul || _this.getNodeDom().nowOrRootUl(); //当前选中的节点或根节点
if (pListData.length > 0){
for (var i = 0; i < pListData.length; i++) {
// 1.获取已知节点的全部数据
var data = pListData[i];
if(typeof data !== "object") continue;
var parseData = _this.parseData(data);
var childListData = _this.queryListTreeByPid(parseData.treeId(), listData); // 根据已知数据的id判断该条数据是否还有子数据
// 3. 页面元素加载数据
$ul.append(_this.getLiItemDom(parseData.treeId(), parseData.parentId(), parseData.title(), parseData.fmtTitle(), parseData.last(childListData.length), parseData.ficonClass(), parseData.iconClass(), parseData.checkArr(), level, parseData.spread(level), parseData.disabled(), parseData.hide(), parseData.basicData(), parseData.recordData(), ($ul.hasClass(UL_ROOT) ? "root" : "item")));
// 4.有子数据的元素加载子节点
if(childListData.length > 0){
var cLevel = parseInt(level)+1;
_this.loadListTree(childListData, listData, cLevel, _this.obj.find("ul[data-id='"+parseData.treeId()+"']"));
}
}
}
};
// 根据父ID查找list数据中匹配的元素
DTree.prototype.queryListTreeByPid = function(pid, listData){
var _this = this;
var rootListData = [];
if (listData) {
for (var i = 0; i < listData.length; i++) {
var data = listData[i];
if(typeof data !== "object") continue;
if(pid == "null" || pid == null){
if(data[_this.response.parentId] == null) { rootListData.push(data); }
} else {
if (data[_this.response.parentId] == pid){
if (data[_this.response.treeId] == pid){
_this.errData.push(data);
} else {
rootListData.push(data);
}
}
}
}
}
return rootListData;
};
// 初始化树或者拼接树
DTree.prototype.loadTree = function(root, level, $ul){
var _this = this;
if (root) {
$ul = $ul || _this.getNodeDom().nowOrRootUl(); //当前选中的节点或根节点
for (var i = 0; i < root.length; i++) { // 遍历跟节点或追加的跟节点
var data = root[i];
if(typeof data !== "object") continue;
if(data[_this.response.treeId] == data[_this.response.parentId]) { _this.errData.push(data); }
var parseData = _this.parseData(data);
var children = parseData.children();
$ul.append(_this.getLiItemDom(parseData.treeId(), parseData.parentId(), parseData.title(), parseData.fmtTitle(), parseData.last(children.length), parseData.ficonClass(), parseData.iconClass(), parseData.checkArr(), level, parseData.spread(level), parseData.disabled(), parseData.hide(), parseData.basicData(), parseData.recordData(), ($ul.hasClass(UL_ROOT) ? "root" : "item")));
if (children.length != 0) {
var cLevel = parseInt(level)+1;
_this.loadTree(children, cLevel, _this.obj.find("ul[data-id='"+parseData.treeId()+"']"));
}
}
}
};
// 判断在数据加载时是否存在错误数据,并是否打印错误数据
DTree.prototype.msgErrData = function() {
var _this = this;
if(_this.errData.length > 0 && _this.errDataShow) {
var title = "";
for(var i=0; i<_this.errData.length; i++) {
var edata = _this.errData[i];
title += "数据:【"+edata[_this.response.title]+"】中节点id和上级id值一致 \n";
}
layer.msg(title, {icon:2,time:5000});
}
// 显示之后,将错误数据制空
_this.errData = [];
};
// 解析data数据
DTree.prototype.parseData = function(data) {
var _this = this;
return {
treeId: function(){
return data[_this.response.treeId];
},
parentId: function(){
return data[_this.response.parentId];
},
fmtTitle: function(){
if(typeof _this.formatter.title === 'function'){
var ftitle = _this.formatter.title(data);
var tt = data[_this.response.title];
tt = (ftitle == "" || ftitle == undefined || ftitle == null) ? tt : ftitle;
return tt || "";
}
return data[_this.response.title];
},
title: function(){
return data[_this.response.title];
},
level: function(){
return data[_this.response.level] || "";
},
ficonClass: function(){
return data[_this.response.ficonClass] || "";
},
iconClass: function(){
return data[_this.response.iconClass] || "";
},
last: function(len){
return ((len == 0) ?
((typeof (data[_this.response.last]) === "boolean") ? data[_this.response.last] : true) :
((typeof (data[_this.response.last]) === "boolean") ? data[_this.response.last] : false));
},
spread: function(level){
return ((level < _this.initLevel) ?
((typeof (data[_this.response.spread]) === "boolean") ? data[_this.response.spread] : true) :
((typeof (data[_this.response.spread]) === "boolean") ? data[_this.response.spread] : false));
},
disabled: function(){
return (typeof (data[_this.response.disabled]) === "boolean") ? data[_this.response.disabled] : false;
},
hide: function(){
return (typeof (data[_this.response.hide]) === "boolean") ? data[_this.response.hide] : false;
},
checkArr: function(){
var checkArr = [];
var checkArrData = data[_this.response.checkArr];
if(typeof checkArrData === 'string'){
if(checkArrData.indexOf("{") > -1 && checkArrData.indexOf("}") > -1){
checkArrData = JSON.parse(checkArrData);
} else {
checkArrData = {"type":"0","checked":checkArrData};
}
}
if(typeof checkArrData === 'object'){
if(typeof checkArrData.length === 'undefined'){
checkArr.push(checkArrData);
} else {
checkArr = checkArrData;
}
}
if(checkArr.length > 0 && checkArr.length > _this.checkArrLen){
_this.checkArrLen = checkArr.length; // 获取复选框个数
}
return checkArr;
},
children: function(){
return data[_this.response.childName] || [];
},
basicData: function(){
return event.escape(JSON.stringify(data[_this.response.basicData])) || JSON.stringify({});
},
recordData: function(){
var recordData = _this.record ? event.cloneObj(data, [_this.response.treeId,
_this.response.parentId,
_this.response.title,
_this.response.iconClass,
_this.response.childName,
_this.response.last,
_this.response.spread,
_this.response.disabled,
_this.response.hide,
_this.response.checkArr,
_this.response.checked,
_this.response.type,
_this.response.basicData]) : {};
return event.escape(JSON.stringify(recordData));
},
data: function(){
return data;
}
}
};
//当无节点数据时显示dom
DTree.prototype.getNoneDom = function(){
var _this = this,
rootId = _this.obj[0].id,
noneTitle = _this.none;
return {
text: function(){
return "<div class='"+NONETITLE+"' dtree-id='"+rootId+"'>"+noneTitle+"</div>";
},
errText: function(errInfo){
return "<div class='"+NONETITLE+"' dtree-id='"+rootId+"'>"+errInfo+"</div>";
}
}
};
//新增节点的dom值
DTree.prototype.getDom = function(treeId, parentId, title, fmtTitle, last, ficonClass, iconClass, checkArr, level, spread, disabled, hide) {
var _this = this,
rootId = _this.obj[0].id,
toolbar = _this.toolbar,
checkbar = _this.checkbar;
return {
fnode: function() { // + - 图标
// 获取图标的变量
var fnodeIcon = _this.fnodeIcon,
fleafIcon = _this.fleafIcon;
var fleafIconLeaf = _this.usefontStyle.fnode.leaf,
fnodeIconOpen = _this.usefontStyle.fnode.node.open,
fnodeIconClose = _this.usefontStyle.fnode.node.close;
if(ficonClass){
var iconfont = _this.iconfont;
if(typeof iconfont === 'string') {
fleafIconLeaf = iconfont + " " + ficonClass;
fnodeIconOpen = iconfont + " " + ficonClass;
fnodeIconClose = iconfont + " " + ficonClass;
} else {
fleafIconLeaf = iconfont[0] + " " + ficonClass;
fnodeIconOpen = iconfont[0] + " " + ficonClass;
fnodeIconClose = iconfont[0] + " " + ficonClass;
}
}
if(fnodeIcon != "-1" && fleafIcon != "-1"){ // 都加载
return last ? "<i class='"+fleafIconLeaf+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" :
(spread ? "<i class='"+fnodeIconOpen+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" : "<i class='"+fnodeIconClose+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
}
if(fnodeIcon != "-1" && fleafIcon == "-1"){ // 加载node 隐藏leaf
return last ? "<i class='"+fleafIconLeaf+" "+ICON_HIDE+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" :
(spread ? "<i class='"+fnodeIconOpen+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" : "<i class='"+fnodeIconClose+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
}
if(fnodeIcon == "-1" && fleafIcon != "-1"){ // 隐藏node 加载leaf
return last ? "<i class='"+fleafIconLeaf+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" :
(spread ? "<i class='"+fnodeIconOpen+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" : "<i class='"+fnodeIconClose+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
}
if(fnodeIcon == "-1" && fleafIcon == "-1"){ // 都隐藏
return last ? "<i class='"+fleafIconLeaf+" "+ICON_HIDE+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' style='display:none;'></i>" :
(spread ? "<i class='"+fnodeIconOpen+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" : "<i class='"+fnodeIconClose+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
}
},
node: function() { // 二级图标样式
// 获取图标的变量
var nodeIcon = _this.nodeIcon,
leafIcon = _this.leafIcon;
var sleafIconLeaf = _this.usefontStyle.snode.leaf,
snodeIconOpen = _this.usefontStyle.snode.node.open,
snodeIconClose = _this.usefontStyle.snode.node.close;
if(iconClass){
var iconfont = _this.iconfont;
if(typeof iconfont === 'string') {
sleafIconLeaf = iconfont + " " + iconClass;
snodeIconOpen = iconfont + " " + iconClass;
snodeIconClose = iconfont + " " + iconClass;
} else {
sleafIconLeaf = iconfont[0] + " " + iconClass;
snodeIconOpen = iconfont[0] + " " + iconClass;
snodeIconClose = iconfont[0] + " " + iconClass;
}
}
if(nodeIcon != "-1" && leafIcon != "-1"){ // 都加载
return last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
}
if(nodeIcon != "-1" && leafIcon == "-1"){ // 加载node 隐藏leaf
return last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
}
if(nodeIcon == "-1" && leafIcon != "-1"){ // 隐藏node 加载leaf
return last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
}
if(nodeIcon == "-1" && leafIcon == "-1"){ // 都隐藏
return last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
}
},
checkbox: function() { // 复选框
var flag = false;
if(_this.checkbarLoad == "node"){if (checkbar) {flag = true;}} else {if (last) {if (checkbar) {flag = true;}}}
if(flag){
var result = "<div class='"+LI_DIV_CHECKBAR+"' data-id='"+treeId+"' dtree-id='"+rootId+"'>";
if(checkArr && checkArr.length > 0){
for (var i = 0; i < checkArr.length; i++) {
var checkData = checkArr[i];
var checked = checkData.checked;
var CHOOSE_CLASS = _this.usefontStyle.checkbox.out;
if (checked == "2") { //半选择
CHOOSE_CLASS = _this.usefontStyle.checkbox.noall + " " + _this.style.chs;
} else if (checked == "1") { //选择
CHOOSE_CLASS = _this.usefontStyle.checkbox.on + " " + _this.style.chs;
} else { //未选择或者无值
CHOOSE_CLASS = _this.usefontStyle.checkbox.out;
}
var disClass = "";
if(disabled){disClass = NAV_DIS;}
result += "<i class='"+CHOOSE_CLASS+" "+_this.style.dfont+" "+_this.style.cbox+" "+disClass+"' data-id='"+treeId+"' dtree-id='"+rootId+"' data-checked='"+checkData.checked+"' data-initchecked='"+checkData.checked+"' data-type='"+checkData.type+"' dtree-click='"+eventName.checkNodeClick+"' data-par='."+LI_CLICK_CHECKBAR+"' dtree-disabled='"+disabled+"'></i>";
}
}
result += "</div>";
return result;
}
return "";
},
text: function() { // 文字显示
var disClass = "";
if(disabled){disClass = NAV_DIS;}
return "<cite class='"+LI_DIV_TEXT_CLASS+" "+disClass+"' data-id='"+treeId+"' data-leaf='"+(last ? "leaf" : "node")+"' dtree-disabled='"+disabled+"' data-title='"+title+"' >"+fmtTitle+"</cite>";
},
ul: function() { //子节点ul
return last ? "<ul class='"+LI_NAV_CHILD+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>" :
(spread ? "<ul class='"+LI_NAV_CHILD+" "+NAV_SHOW+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>" : "<ul class='"+LI_NAV_CHILD+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>");
}
};
};
//替换节点的dom值或指定值
DTree.prototype.replaceDom = function($div, treeId, last, spread, disabled, hide) {
var _this = this,
rootId = _this.obj[0].id,
toolbar = _this.toolbar,
checkbar = _this.checkbar;
return {
fnode: function(ficonClass) { // + - 图标
var fnode = "";
// 获取图标的变量
var fnodeIcon = _this.fnodeIcon,
fleafIcon = _this.fleafIcon;
var fleafIconLeaf = _this.usefontStyle.fnode.leaf,
fnodeIconOpen = _this.usefontStyle.fnode.node.open,
fnodeIconClose = _this.usefontStyle.fnode.node.close;
if(ficonClass){
var iconfont = _this.iconfont;
if(typeof iconfont === 'string') {
fleafIconLeaf = iconfont + " " + ficonClass;
fnodeIconOpen = iconfont + " " + ficonClass;
fnodeIconClose = iconfont + " " + ficonClass;
} else {
fleafIconLeaf = iconfont[0] + " " + ficonClass;
fnodeIconOpen = iconfont[0] + " " + ficonClass;
fnodeIconClose = iconfont[0] + " " + ficonClass;
}
}
if(fnodeIcon != "-1" && leafIcon != "-1"){ // 都加载
fnode = last ? "<i class='"+fleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+fnodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+fnodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
}else if(nodeIcon != "-1" && leafIcon == "-1"){ // 加载node 隐藏leaf
fnode = last ? "<i class='"+fleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+fnodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+fnodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
}else if(nodeIcon == "-1" && leafIcon != "-1"){ // 隐藏node 加载leaf
fnode = last ? "<i class='"+fleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+fnodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+fnodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
}else if(nodeIcon == "-1" && leafIcon == "-1"){ // 都隐藏
fnode = last ? "<i class='"+fleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+fnodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+fnodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
}
if(fnode != ""){_this.getNodeDom($div).fnode().replaceWith($(fnode));}
},
node: function(iconClass) { // 二级图标样式
var snode = "";
// 获取图标的变量
var nodeIcon = _this.nodeIcon,
leafIcon = _this.leafIcon;
var sleafIconLeaf = _this.usefontStyle.snode.leaf,
snodeIconOpen = _this.usefontStyle.snode.node.open,
snodeIconClose = _this.usefontStyle.snode.node.close;
if(iconClass){
var iconfont = _this.iconfont;
if(typeof iconfont === 'string') {
sleafIconLeaf = iconfont + " " + iconClass;
snodeIconOpen = iconfont + " " + iconClass;
snodeIconClose = iconfont + " " + iconClass;
} else {
sleafIconLeaf = iconfont[0] + " " + iconClass;
snodeIconOpen = iconfont[0] + " " + iconClass;
snodeIconClose = iconfont[0] + " " + iconClass;
}
}
if(nodeIcon != "-1" && leafIcon != "-1"){ // 都加载
snode = last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
}else if(nodeIcon != "-1" && leafIcon == "-1"){ // 加载node 隐藏leaf
snode = last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
}else if(nodeIcon == "-1" && leafIcon != "-1"){ // 隐藏node 加载leaf
snode = last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
}else if(nodeIcon == "-1" && leafIcon == "-1"){ // 都隐藏
snode = last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
(spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
}
if(snode != ""){_this.getNodeDom($div).snode().replaceWith($(snode));}
},
checkbox: function(checkArr) { // 复选框
var flag = false;
if(_this.checkbarLoad == "node"){if (checkbar) {flag = true;}} else {if (last) {if (checkbar) {flag = true;}}}
if(flag){
var result = "<div class='"+LI_DIV_CHECKBAR+"' data-id='"+treeId+"' dtree-id='"+rootId+"'>";
if(checkArr && checkArr.length > 0){
for (var i = 0; i < checkArr.length; i++) {
var checkData = checkArr[i];
var checked = checkData.checked;
var CHOOSE_CLASS = _this.usefontStyle.checkbox.out;
if (checked == "2") { //半选择
CHOOSE_CLASS = _this.usefontStyle.checkbox.noall + " " + _this.style.chs;
} else if (checked == "1") { //选择
CHOOSE_CLASS = _this.usefontStyle.checkbox.on + " " + _this.style.chs;
} else { //未选择或者无值
CHOOSE_CLASS = _this.usefontStyle.checkbox.out;
}
var disClass = "";
if(disabled){disClass = NAV_DIS;}
result += "<i class='"+CHOOSE_CLASS+" "+_this.style.dfont+" "+_this.style.cbox+" "+disClass+"' data-id='"+treeId+"' dtree-id='"+rootId+"' data-checked='"+checkData.checked+"' data-initchecked='"+checkData.checked+"' data-type='"+checkData.type+"' dtree-click='"+eventName.checkNodeClick+"' data-par='."+LI_CLICK_CHECKBAR+"' dtree-disabled='"+disabled+"'></i>";
}
}
result += "</div>";
_this.getNodeDom($div).snode().next("div").replaceWith($(result));
}
},
text: function(title) { // 文字显示
var disClass = "";
if(disabled){disClass = NAV_DIS;}
var cite = "<cite class='"+LI_DIV_TEXT_CLASS+" "+disClass+"' data-id='"+treeId+"' data-leaf='"+(last ? "leaf" : "node")+"' dtree-disabled='"+disabled+"' >"+title+"</cite>"
_this.getNodeDom($div).cite().replaceWith($(cite));
},
ul: function() { //子节点ul
var ul = last ? "<ul class='"+LI_NAV_CHILD+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>" :
(spread ? "<ul class='"+LI_NAV_CHILD+" "+NAV_SHOW+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>" : "<ul class='"+LI_NAV_CHILD+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>");
_this.getNodeDom($div).nextUl().replaceWith($(ul));
},
div: function(){
$div.attr("data-id", treeId);
},
basicData: function(basicData){
basicData = (basicData == "{}") ? "" : basicData;
$div.attr("data-basic", basicData);
},
recordData: function(recordData){
recordData = (recordData == "{}") ? "" : recordData;
$div.attr("data-record", recordData);
},
p_li: function(pId){
var $li = $div.parent("li");
$li.attr("data-id", treeId);
if(pId) {
$li.attr("data-pid", pId);
}
return $li;
}
};
};
// 获取拼接好的li
DTree.prototype.getLiItemDom = function(treeId, parentId, title, fmtTitle, last, ficonClass, iconClass, checkArr, level, spread, disabled, hide, basicData, recordData, flag) {
var _this = this,
rootId = _this.obj[0].id;
var dom = _this.getDom(treeId, parentId, title, fmtTitle, last, ficonClass, iconClass, checkArr, level, spread, disabled, hide);
basicData = (basicData == "{}") ? "" : basicData;
recordData = (recordData == "{}") ? "" : recordData;
var div = "<div class='"+LI_DIV_ITEM+" "+_this.style.item+"' data-id='"+treeId+"' dtree-id='"+rootId+"' dtree-click='"+eventName.itemNodeClick+"' data-basic='"+basicData+"' data-record='"+recordData+"' dtree-disabled='"+disabled+"' dtree-hide='"+hide+"' ";
if(_this.toolbar){
if(_this.toolbarWay == "contextmenu") {
if(_this.toolbarLoad == "node") { div += " d-contextmenu='true'>"; }
if(_this.toolbarLoad == "noleaf") { if(!last){ div += " d-contextmenu='true'>"; } else { div += " d-contextmenu='false'>";} }
if(_this.toolbarLoad == "leaf") { if(last){ div += " d-contextmenu='true'>"; } else { div += " d-contextmenu='false'>";} }
} else { div += " d-contextmenu='false'>"; }
} else { div += " d-contextmenu='false'>"; }
var hideClass = "";
var lineClass = "";
if(hide){hideClass = NAV_HIDE;}
var li = ["<li " + "class='"+LI_CLICK_CHECKBAR+" "+LI_NAV_ITEM+" "+hideClass+" "+lineClass+"'" + "data-id='"+treeId+"'" + "data-pid='"+(flag == "root" ? ((typeof parentId !== undefined && parentId != "") ? parentId : "-1") : parentId)+"'" + "dtree-id='"+rootId+"'" + "data-index='"+level+"'" + "dtree-hide='"+hide+"'" +">" +
div ,
dom.fnode(),
dom.node(),
dom.checkbox(),
dom.text(),
"</div>", dom.ul(), "</li>"].join("");
return li;
};
// 初始化节点,用于数据回显
DTree.prototype.dataInit = function(chooseId){
var _this = this;
var $div = _this.obj.find("div[data-id='"+chooseId+"']");
_this.getNodeDom($div).parentLi().find("."+NAV_THIS).removeClass(NAV_THIS);
_this.getNodeDom($div).parentLi().find("."+_this.style.itemThis).removeClass(_this.style.itemThis);
$div.addClass(NAV_THIS);
$div.addClass(_this.style.itemThis);
_this.setNodeParam($div);
// 将该节点的父节点全部展开
var $li_parents = $div.parents("."+LI_NAV_ITEM);
$li_parents.children("ul").addClass(NAV_SHOW);
$li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.fnode.node.close)).addClass(_this.usefontStyle.fnode.node.open);
$li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.fnode.node.close)).removeClass(_this.usefontStyle.fnode.node.close);
$li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.snode.node.close)).addClass(_this.usefontStyle.snode.node.open);
$li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.snode.node.close)).removeClass(_this.usefontStyle.snode.node.close);
return _this.getNowParam();
};
// 基于备份的Html数据回滚
DTree.prototype.rollbackHtml = function(chooseId){
var _this = this;
if(_this.bak) {
_this.obj.html(_this.bak);
// 取消全部选中状态
_this.cancelNavThis();
if(_this.checkbar) {
_this.cancelCheckedNode();
_this.chooseDataInit(chooseId);
} else {
_this.dataInit(chooseId);
}
_this.bak = _this.obj.html();
}
};
/******************** 基础事件区域 ********************/
// 数据格式化
DTree.prototype.escape = function(html){
return event.escape(html);
};
// 格式化数据转回正常数据
DTree.prototype.unescape = function(str){
return event.unescape(str);
};
// 取消选中div
DTree.prototype.cancelNavThis = function(){
var _this = this;
_this.obj.find("div[data-id]").parent().find("."+NAV_THIS).removeClass(NAV_THIS);
_this.obj.find("div[data-id]").parent().find("."+_this.style.itemThis).removeClass(_this.style.itemThis);
}
// 选中div
DTree.prototype.navThis = function(id){
var _this = this;
var $div = (typeof id === 'object') ? id : (_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']").length == 0) ? null : _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']");
if($div != null) {
_this.cancelNavThis();
$div.addClass(NAV_THIS);
$div.addClass(_this.style.itemThis);
}
}
// 手风琴模式操作其他节点
DTree.prototype.accordionUL = function($ul) {
var _this = this;
if(_this.accordion) {
$ul.closest("li[data-index]").siblings("li[data-index]").children("ul[data-id]").removeClass(NAV_SHOW);
var $divs = $ul.closest("li[data-index]").siblings("li[data-index]").children("ul[data-id]").prev("div");
if($divs.length && $divs.length > 0) {
for (var i=0; i<$divs.length; i++) {
var $div = $($divs[i]);
var $i_spread = _this.getNodeDom($div).fnode(),
$i_node = _this.getNodeDom($div).snode();
if($i_spread.attr("data-spread") != 'last'){
_this.operateIcon($i_spread, $i_node).close();
}
}
}
}
};
// 展开或隐藏节点 作用点: div
DTree.prototype.clickSpread = function($div) {
var _this = this;
var $i_spread = _this.getNodeDom($div).fnode(),
$i_node = _this.getNodeDom($div).snode(),
$cite = _this.getNodeDom($div).cite(),
spread = $i_spread.attr("data-spread"),
$ul = $div.next("ul");
if ($ul.length > 0) {
if (spread == "close") {
if (_this.type=="load") { //增加加载
if (_this.cache) { //开启缓存
if ($ul.html()) {
$ul.addClass(NAV_SHOW);
_this.accordionUL($ul);
} else { //加载节点
_this.getChild($div);
_this.accordionUL($ul);
}
}else { //每次取新的数据
$ul.html("");
_this.getChild($div);
_this.accordionUL($ul);
}
} else { // 全量加载
$ul.addClass(NAV_SHOW);
_this.accordionUL($ul);
}
_this.operateIcon($i_spread, $i_node).open();
} else if (spread == "open") {
$ul.removeClass(NAV_SHOW);
_this.operateIcon($i_spread, $i_node).close();
}
}
};
// 设置节点为disabled
DTree.prototype.setDisabledNodes = function(disabledIds){
var _this = this;
var disabledId = disabledIds.split(",");
for (var i=0; i<disabledId.length; i++) {
var $div = _this.getNodeDom(disabledId[i]).div();
var $i = $div.children("div."+LI_DIV_CHECKBAR).children("i[data-par]");
var $cite = $div.children("cite[data-leaf]");
if($div != null && $div.attr("dtree-disabled") != "true") {
$div.attr("dtree-disabled", "true");
$i.attr("dtree-disabled", "true");
$i.addClass(NAV_DIS);
$cite.attr("dtree-disabled", "true");
$cite.addClass(NAV_DIS);
}
}
};
// 设置全部节点为disabled
DTree.prototype.setDisabledAllNodes = function(){
var _this = this;
_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"']").each(function(){
var $div = $(this);
var $i = $div.children("div."+LI_DIV_CHECKBAR).children("i[data-par]");
var $cite = $div.children("cite[data-leaf]");
if($div != null && $div.attr("dtree-disabled") != "true") {
$div.attr("dtree-disabled", "true");
$i.attr("dtree-disabled", "true");
$i.addClass(NAV_DIS);
$cite.attr("dtree-disabled", "true");
$cite.addClass(NAV_DIS);
}
});
};
// 将节点的disabled取消
DTree.prototype.cancelDisabledNodes = function(disabledIds){
var _this = this;
var disabledId = disabledIds.split(",");
for (var i=0; i<disabledId.length; i++) {
var $div = _this.getNodeDom(disabledId[i]).div();
var $i = $div.children("div."+LI_DIV_CHECKBAR).children("i[data-par]");
var $cite = $div.children("cite[data-leaf]");
if($div != null && $div.attr("dtree-disabled") == "true") {
$div.attr("dtree-disabled", "false");
$i.attr("dtree-disabled", "false");
$i.removeClass(NAV_DIS);
$cite.attr("dtree-disabled", "false");
$cite.removeClass(NAV_DIS);
}
}
};
// 获取指定disabled节点的值
DTree.prototype.getDisabledNodesParam = function(disabledIds){
var _this = this;
var disabledId = disabledIds.split(",");
var disabledNodes = [];
for (var i=0; i<disabledId.length; i++) {
var $div = _this.getNodeDom(disabledId[i]).div();
if($div != null && $div.attr("dtree-disabled") == "true") {
disabledNodes.push(_this.getRequestParam(_this.getTempNodeParam($div)));
}
}
return disabledNodes;
};
// 获取全部disabled节点的值
DTree.prototype.getAllDisabledNodesParam = function(){
var _this = this;
var disabledNodes = [];
_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][dtree-disabled='true']").each(function(){
var $div = $(this);
disabledNodes.push(_this.getRequestParam(_this.getTempNodeParam($div)));
});
return disabledNodes;
};
// 设置节点为hide