|
|
|
;layui.define("form",function(e){"use strict";var i=layui.$,a=layui.form,n="tree",r={config:{},index:layui[n]?layui[n].index+1e4:0,set:function(e){var a=this;return a.config=i.extend({},a.config,e),a},on:function(e,i){return layui.onevent.call(this,n,e,i)}},l=function(){var e=this,i=e.config,a=i.id||e.index;return l.that[a]=e,l.config[a]=i,{config:i,reload:function(i){e.reload.call(e,i)},getChecked:function(){return e.getChecked.call(e)},setChecked:function(i){return e.setChecked.call(e,i)}}},t="layui-hide",d="layui-disabled",s="layui-tree-set",c="layui-tree-iconClick",o="layui-icon-addition",h="layui-icon-subtraction",u="layui-tree-entry",f="layui-tree-main",p="layui-tree-txt",y="layui-tree-pack",v="layui-tree-spread",C="layui-tree-setLineShort",m="layui-tree-showLine",k="layui-tree-lineExtend",g=function(e){var a=this;a.index=++r.index,a.config=i.extend({},a.config,r.config,e),a.render()};g.prototype.config={data:[],showCheckbox:!1,showLine:!0,accordion:!1,onlyIconControl:!1,isJump:!1,edit:!1,text:{defaultNodeName:"未命名",none:"无数据"}},g.prototype.reload=function(e){var a=this;layui.each(e,function(e,i){i.constructor===Array&&delete a.config[e]}),a.config=i.extend(!0,{},a.config,e),a.render()},g.prototype.render=function(){var e=this,a=e.config,n=i('<div class="layui-tree'+(a.showCheckbox?" layui-form":"")+(a.showLine?" layui-tree-line":"")+'" lay-filter="LAY-tree-'+e.index+'"></div>');e.tree(n);var r=a.elem=i(a.elem);if(r[0]){if(a.showSearch&&n.prepend('<input type="text" class="layui-input layui-tree-search" placeholder="请输入关键字进行过滤">'),e.key=a.id||e.index,e.elem=n,e.elemNone=i('<div class="layui-tree-emptyText">'+a.text.none+"</div>"),r.html(e.elem),0==e.elem.find(".layui-tree-set").length)return e.elem.append(e.elemNone);a.drag&&e.drag(),a.showCheckbox&&e.renderForm("checkbox"),e.elem.find(".layui-tree-set").each(function(){var e=i(this);e.parent(".layui-tree-pack")[0]||e.addClass("layui-tree-setHide"),!e.next()[0]&&e.parents(".layui-tree-pack").eq(1).hasClass("layui-tree-lineExtend")&&e.addClass(C),e.next()[0]||e.parents(".layui-tree-set").eq(0).next()[0]||e.addClass(C)}),e.events()}},g.prototype.renderForm=function(e){a.render(e,"LAY-tree-"+this.index)},g.prototype.tree=function(e,a){var n=this,r=n.config,l=a||r.data;layui.each(l,function(a,l){var c=l.children&&l.children.length>0,o=i('<div class="layui-tree-pack" '+(l.spread?'style="display: block;"':"")+'"></div>'),h=i(['<div data-id="'+l.id+'" class="layui-tree-set'+(l.spread?" layui-tree-spread":"")+(l.checked?" layui-tree-checkedFirst":"")+'">',"<div "+(r.drag&&!l.fixed?'draggable="true"':"")+' class="layui-tree-entry">','<div class="layui-tree-main">',function(){return r.showLine?c?'<span class="layui-tree-iconClick layui-tree-icon"><i class="layui-icon '+(l.spread?"layui-icon-subtraction":"layui-icon-addition")+'"></i></span>':'<span class="layui-tree-iconClick"><i class="layui-icon layui-icon-file"></i></span>':'<span class="layui-tree-iconClick"><i class="layui-tree-iconArrow '+(c?"":t)+'"></i></span>'}(),function(){return r.showCheckbox?'<input type="checkbox" name="layuiTreeCheck" lay-skin="primary" '+(l.disabled?"disabled":"")+' value="'+l.id+'">':""}(),function(){return r.isJump&&l.href?'<a href="'+l.href+'" target="_blank" class="'+p+'">'+(l.title||l.label||r.text.defaultNodeName)+"</a>":'<span class="'+p+(l.disabled?" "+d:"")+'">'+(l.title||l.label||r.text.defaultNodeName)+"</span>"}(),"</div>",function(){if(!r.edit)return"";var e={add:'<i class="layui-icon layui-icon-add-1" data-type="add"></i>',update:'<i class="layui-icon layui-icon-edit" data-type="update"></i>',del:'<i class="layui-icon layui-icon-delete" data-type="del"></i>'},i=['<div class="layui-btn-group layui-tree-btnGroup">'];return r.edit===!0&&(r.edit=["update","del"]),"object"==typeof r.edit?(layui.each(r.edit,function(a,n){i.push(e[n]||"")}),i.join("")+"</div>"):void 0}(),"</div></div>"].join(""));c&&(h.append(o),n.tree(o,l.children)),e.append(h),h.prev("."+s)[0]&&h.prev().children(".layui-tree-pack").addClass("layui-tree-showLine"),c||h.parent(".layu
|