• 1、加载树,2、无限制节点,3、反键菜单


    1、加载树,2、无限制节点,3、反键菜单

    效果图:

    2、      //加载数据完毕后闭合树结构

    3、              function collapseAll() {

    4、                  tree.collapseAll();

    5、              }

    6、        function getKnowledgeTree(){

    7、             treeManager = $("#tree1").ligerTree({

    8、                   url : "knowledgeclassify!showtree.action",

    9、                   nodeDraggable: false,

    10、                 idFieldName : "classid",

    11、                 parentIDFieldName : "parentid",

    12、                 textFieldName  :  "name",

    13、                 checkbox:false,

    14、                 onAfterAppend:collapseAll,//树默认折叠

    15、                 onSelect : function(node){

    16、                   viewnode(node);[d1] 

    17、                 },

    18、                 single : true,

    19、                 onContextmenu:

    20、                 function (node, e)

    21、                 {

    22、                    actionNodeID = node.data.classid;

    23、                    actionPID = node.data.parentid;

    24、                    menu.show({ top: e.pageY, left: e.pageX });

    25、                    menu2.hide();

    26、    [d2] 

    27、                    return false;

    28、                 }

    29、                

    30、                });

    31、      tree = $("#tree1").ligerGetTreeManager();

    32、      }     

    33、       function inittree(){

    34、              getKnowledgeTree();

    35、              menu = $.ligerMenu({ top: 100, left: 100, 120, items:[

    36、                { id : '1',text: '增加子节点', click: f_menuitemclick, icon: 'add' },

    37、                { id : '4',text: '增加同级节点', click: f_menuitemclick, icon: 'add' },

    38、     

    39、                { id : '2',text: '修改', click: f_menuitemclick },

    40、     

    41、                { line: true },

    42、     

    43、                { id : '3',text: '删除', click: f_menuitemclick }

    44、     

    45、                ]

    46、     

    47、                });

    48、                menu2 = $.ligerMenu({ top: 100, left: 100, 120, items:

    49、                [

    50、                { text: '增加一级分类', click: addroot, icon: 'add' }

    51、                ]

    52、                });

    53、                $("#leftdiv").bind("contextmenu", function (e)

    54、                {

    55、                    menu2.show({ top: e.pageY, left: e.pageX });

    56、                    menu.hide();

    57、     

    58、                    return false;

    59、                });

    60、            }[d3] 

    61、    //工具条按钮响应事件

    62、        function f_menuitemclick(item,i)

    63、        {

    64、            if(item.id)

    65、            {

    66、                switch (item.id)

    67、                {

    68、                    case "1":

    69、                     f_openWindow('business/knowledgeclassify!input.action?parentid='+actionNodeID, '添加知识分类', 460, 250);

    70、                        return;

    71、                  case "4":

    72、                        f_openWindow('business/knowledgeclassify!input.action?parentid=' + actionPID, '增加同级分类', 460, 250);

    73、                        return;                   

    74、                    case "2":

    75、                        f_openWindow('business/knowledgeclassify!input.action?classid=' + actionNodeID, '修改知识分类', 460, 250);

    76、                        return;

    77、                    case "3":

    78、                        $.ligerDialog.confirm('您确定要删除该分类吗?', function (y)

    79、                        {

    80、                            if (!y) return;

    81、                            // var rowsdata = treeManager.getChecked();

    82、                           

    83、                            //if (!rowsdata.length)

    84、                            //{

    85、                            //    $.ligerDialog.alert('请先选择要删除的节点!');

    86、                               

    87、                            //    return;

    88、                            //}

    89、                            //var idStr = "";

    90、                            //$(rowsdata).each(function (i, item)

    91、                            //{

    92、                            //    idStr += this.data.classid;

    93、                                

    94、                            //    if (i < rowsdata.length - 1) idStr += ",";

    95、                            //});

    96、                            //通过节点ID 判断是否有子节点 有子节点的先进行删除子节点的验证

    97、                     if(treeManager.hasChildren(treeManager.getDataByID(actionNodeID))){

    98、                          $.ligerDialog.alert('请先删除子节点');

    99、                          return;

    100、                      }else{

    101、                        $.post("knowledgeclassify!checkKnowledgeclassidIsUse.action","classids="+actionNodeID,function(msg){

    102、                                 if(msg!= ""){

    103、                                   $.ligerDialog.alert('该分类下还关联知识点,不可删除');

    104、                                 }else{

    105、                                   $.ligerDialog.waitting("正在删除中...");

    106、                          $.ajax({

    107、                            type: "POST",

    108、                            url: "knowledgeclassify!delete.action",

    109、                            data: "classids="+actionNodeID,

    110、                            success: function(msg){

    111、                                 $.ligerDialog.success(msg);

    112、                                 $.ligerDialog.closeWaitting();

    113、                                 refreshtree();

    114、                            }

    115、                            });

    116、                                 }

    117、                             });

    118、                             }

    119、                    });   

    120、              }  

    121、          }

    122、      }[d4] 

    var treebaroptions = {};

        $(function (){

            inittree[d5] ();

            $("#layout1").ligerLayout({ leftWidth: 200});

            //知识点分类列表搜索框

            $("#treetoolbar").ligerToolBar(treebaroptions);

            $("#treetoolbar").before("<div style='margin-top:1px' class='l-toolbar-item'><table><tr>"+

            "<td><input type='text' name='classcodeorname' id='classcodeorname'  value='搜索:简码、名称' onkeydown='keyDown(event);' onblur="if(this.value=='') value='搜索:简码、名称';" onfocus="if(this.value=='搜索:简码、名称') value='';" style='' /></td>"+

            "<td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><input type='image' name='imgbuton' src='${ctx}/js/ligerUI/skins/icons/search.gif' border=0 onfocus=this.blur();  style='cursor:pointer' onclick='submitTreeByName();'/></td>"+

            "</tr></table></div>");

            $("#classcodeorname").ligerTextBox({Width:130,Height:5});

           

    123、          });

    124、          function refreshtree(){

    125、            treeManager.clear();

    126、              treeManager.loadData(null,'knowledgeclassify!showtree.action',null);

    127、           } 

    function viewnode[d6] (node){

              $("#nodeinfo").attr("src",'knowledgeclassify!listnode.action?classid='+node.data.classid);

                //document.all("nodeinfo").src="knowledgeclassify!listnode.action?classid="+node.data.classid;

    128、          }

     

    Action:

    public String showtree()  throws Exception{

          List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(Struts2Utils.getRequest());

    //    classcode = Struts2Utils.getRequest().getParameter("classcode");

    //    filters = genFilterList(filters, "LIKES", "classcode", classcode);   

    //    List<KnowledgeClassify> lRet = manager.listclass(filters);

         

          // 判断用户知识分类权限

          String codename=Struts2Utils.getRequest().getParameter("codename");

          SysUser user = getCurrentSysUser();

          //获得搜索name参数

          String str = "";

          List<KnowledgeClassify> resultList = null;

          if(codename!=null && !codename.equals("")){

             str=new String(codename.getBytes("iso-8859-1"), "utf-8");

             //按参数查询

             resultList = manager.searchKnowledge(filters, user,str);

          }else{

            resultList = manager.getKnowledgeClassByUser(filters, user);

          }

          JsonConfig config = new JsonConfig();

          config.setExcludes(new String[] {"subsysid","memo","creator","createtime","lastmodify","updater","orders","roleIds","updateuser","createuser","handler","hibernateLazyInitializer"});

          JSONArray jsonArray = JSONArray.fromObject(resultList,config);

          Struts2Utils.renderText(jsonArray.toString());

          return NONE;

    }

    //查看明细

    public String listnode()throws Exception {

          prepareModel();

          Struts2Utils.getRequest().setAttribute("model", model);

          return "listnode";

    }

    @Override

       protected void prepareModel() throws Exception {

          if(classid[d7] ==null)

            model = new KnowledgeClassify();

          else

            model = manager.getclass(classid);    

       }

    Service:

    /**

        * 根据条件查询知识分类

        * @param filters

        * @param user

        * @param name

        * @return

        */

       @SuppressWarnings("unchecked")

       public List<KnowledgeClassify> searchKnowledge(List<PropertyFilter> filters, SysUser user,String name) {

          List<KnowledgeClassify> kcList=new ArrayList<KnowledgeClassify>();

          // 管理员查询知识权限

          String hql = "select kc from KnowledgeClassify kc where 1=1";

         if (user.getUserid() == 1||Integer.parseInt(user.getTypeid().toString()) == UserType.SEAT) {

            if(name!=null && !"".equals("name")){

               hql += " and (kc.name like '%" + name

                     + "%' or kc.classcode like '%" + name + "%')";

            }

            kcList=classdao.find(hql);

          }

          // 其它用户查询知识权限

          else {

            //有权限的父节点    此处没有对子节点加权限

            kcList=getKnowledgeClassPowerByUser(user);

            List<KnowledgeClassify> sonList=new ArrayList<KnowledgeClassify>();

            List<KnowledgeClassify> parentList=new ArrayList<KnowledgeClassify>();

            HashSet<KnowledgeClassify> parentSet=new HashSet<KnowledgeClassify>();

            //不同用户不同权限查询 树信息

            if(name!=null){

               //过滤查询父节点 此处没用

               //parentSet=getAllParentNodesByName(kcList);

               //全部子节点

               sonList=getAllSonNodes(kcList);

               //子节点按条件过滤

               sonList=getAllSonNodesByName(kcList,sonList,name);

               //父节点按条件过滤

               parentList=getKnowledgeClassPowerByUserByName(user,name);

               if(parentList!=null){

                  parentList.addAll(sonList);

                  return parentList;

               }else{

                  return sonList;

               }

            }else{

               //取所有父节点

               parentSet=getAllParentNodes(kcList);

               //取所有子节点

                  sonList=getAllSonNodes(kcList);

               if(parentSet!=null && parentSet.size()>0){

                  kcList.addAll(parentSet);

                  kcList.addAll(sonList);

               }

            }

          }

         

          return kcList;

    }

    方法二:

    //搜索条件查询知识分类树 按登陆用户查询 不同用户显示不同的树节点

       @Transactional(readOnly = true)

       public List<Menu> searchKnowledgeClassByUser(List<PropertyFilter> filters,SysUser user){

          List<Menu> nl = new ArrayList<Menu>();

          List<KnowledgeClassify> kcList=new ArrayList<KnowledgeClassify>();

          // 管理员查询知识权限

         if (user.getUserid() == 1||Integer.parseInt(user.getTypeid().toString()) == UserType.SEAT) {

            List<KnowledgeClassify> l = classdao.find(filters);[d8] 

            if (l != null && l.size() > 0) {

               for (KnowledgeClassify t : l) {

                  Menu m = new Menu();

                  m.setId(t.getClassid());

                  m.setText(t.getName());

                  m.setPid(t.getParentid());

                  nl.add(m);

               }

            }

            return nl;

          }

          // 其它用户查询知识权限

          else {

            kcList=getKnowledgeClassPowerByUser(user);

            //取所有父节点

            HashSet<KnowledgeClassify> parentSet=new HashSet<KnowledgeClassify>();

            parentSet=getAllParentNodes(kcList);

            //取所有子节点

            List<KnowledgeClassify> sonList=new ArrayList<KnowledgeClassify>();

            sonList=getAllSonNodes(kcList);

           

            kcList.addAll(parentSet);

            kcList.addAll(sonList);

            if (kcList != null && kcList.size() > 0) {

               for (KnowledgeClassify t : kcList) {

                  Menu m = new Menu();

                  m.setId(t.getClassid());

                  m.setText(t.getName());

                  m.setPid(t.getParentid());

                  nl.add(m);

               }

            }

            return nl;

          }

       }

    Dao:

               


     [d1]

     [d2]反键菜单

     [d3]反键菜单

     [d4]反键菜单事件

     [d5]初始化放在toolbar上

     [d6]右侧div

    知识点分类明细,

     [d7]Long classid;

    在action里面申明的公用的classid

     [d8]

  • 相关阅读:
    数据加载存储和文件格式
    基本概率分布图的绘制
    pandas处理各类表格数据
    python时间处理
    matplotlib实现数据可视化
    sql学习笔记:表的运算
    sql杂记:一些坑和数据库恢复
    exists关键词和case表达式
    后台工具screen
    SQL函数小记
  • 原文地址:https://www.cnblogs.com/pujiajia/p/3287350.html
Copyright © 2020-2023  润新知