layer弹出框,zTree树插件,树形图

先看效果图
这里写图片描述

页面部分:

zNodes = '';
    var index = '';
    var index2 = '';
    function for_department() {
        var id = $('#dep_id').val();
        //加载层
        index2 = layer.load(0, {shade: false}); //0代表加载的风格,支持0-2
        //获取权限信息
        $.getJSON('/admin/employee/show_department', {'type' : 'get', 'id' : id}, function(res){
            layer.close(index2);
            if(res.code == 1){
                zNodes = JSON.parse(res.data);  //将字符串转换成obj

                //页面层
                index = layer.open({
                    type: 1,
                    area:['350px', '400px'],
                    title:'请选择',
                    skin: 'layui-layer-demo', //加上边框
                    content: $('#role')
                });
                //设置位置
                layer.style(index, {
                    top: '20%'
                });

                //设置zetree
                var setting = {
                    check:{
                        enable:true,
                        chkStyle:"radio",
                        radioType: "all"
                    },
                    data: {
                        simpleData: {
                            enable: true
                        }
                    }
                };


                $.fn.zTree.init($("#treeType"), setting, zNodes);
                var zTree = $.fn.zTree.getZTreeObj("treeType");
                zTree.expandAll(true);

            }else{
                layer.alert(res.msg);
            }

        });
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

后台部分:

public function show_department()
{
   $param = input('param.');
   $organize = new OrganizeModel();
   //获取现在的部门
   if('get' == $param['type']){
       return json(['code' => 1, 'data' => $organize</span>-&gt;getAll(<span class="hljs-variable">$param), 'msg' => 'success']);
   }

}

public function getAll($param)
{
   $result</span> = <span class="hljs-variable">$this->field('id,name,parent_id')->select();
   $str = "";
   //$role = new UserType();
   //$rule = $role->getRuleById($id);
   $rule</span> = <span class="hljs-variable">$param['id'];

   if(!empty($rule)){
       $rule</span> = explode(<span class="hljs-string">','</span>, <span class="hljs-variable">$rule);
   }
   foreach($result</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$key=>$vo){
       $str</span> .= <span class="hljs-string">'{ "id": "'</span> . <span class="hljs-variable">$vo</span>[<span class="hljs-string">'id'</span>] . <span class="hljs-string">'", "pId":"'</span> . <span class="hljs-variable">$vo</span>[<span class="hljs-string">'parent_id'</span>] . <span class="hljs-string">'", "name":"'</span> . <span class="hljs-variable">$vo['name'].'"';

       if(!empty($rule</span>) &amp;&amp; in_array(<span class="hljs-variable">$vo['id'], $rule)){
           $str .= ' ,"checked":1';
       }

       $str .= '},';
   }

   return "[" . substr($str, 0, -1) . "]";
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

zTree官方文档

http://www.treejs.cn/v3/api.php

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页