知识
助手
最大化  清空记录  历史记录
   1419  
查询码: 00000113
树形模板增加移动分类功能
作者: 系统管理员 于 2019年12月01日 发布在分类 / 二次开发 / 开发模板 ,于 2019年12月01日 编辑

前台页面

1.添加功能按钮

, {
	id : 'move',
	text : '移动',
	iconCls : 'icon-communication',
	handler : moveTree}

2.打开移动窗口

//移动节点
function moveTree() {
    var selectedArray = $(gridTasktype).datagrid('getSelections');
    if (selectedArray.length > 0) {

        $.farm.openWindow({
            id : 'taskTypeTreeNodeWin',
            width : 250,
            height : 300,
            modal : true,
            url : "tasktype/treeNodeTreeView.do",
            title : '移动分类'
        });
        chooseWindowCallBackHandle = function(node) {
            $.messager.confirm('确认对话框', '确定移动该节点么?', function(falg1) {
                if (falg1) {
                    $.post('tasktype/moveTreeNodeSubmit.do', {
                        ids : $.farm.getCheckedIds(gridTasktype, 'ID'),
                        id : node.id
                    }, function(flag) {
                        if (flag.STATE == 0) {
                            $(gridTasktype).datagrid('reload');
                            $('#taskTypeTreeNodeWin').window('close');
                            $.messager.confirm('确认对话框', '数据更新,是否重新加载左侧树?',
                                    function(r) {
                                        if (r) {
                                            $('#TaskTypeTree').tree(
                                                    'reload');
                                        }
                                    });
                        } else {
                            var str = MESSAGE_PLAT.ERROR_SUBMIT
                                    + flag.MESSAGE;
                            $.messager.alert(MESSAGE_PLAT.ERROR, str,
                                    'error');
                        }
                    }, 'json');
                }
            });
        };
    } else {
        $.messager.alert(MESSAGE_PLAT.PROMPT, MESSAGE_PLAT.CHOOSE_ONE,
                'info');
    }
}

3.添加选择树窗口页面  ChooseProjectTypeTree.jsp

<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/view/conf/farmtag.tld" prefix="PF"%>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'north',border:false">
		<div class="TREE_COMMON_BOX_SPLIT_DIV">
			<a id="ChooseProjectTreeReload" href="javascript:void(0)"
				class="easyui-linkbutton" data-options="plain:true"
				iconCls="icon-reload">刷新菜单</a> <a id="ChooseProjectTreeOpenAll"
				href="javascript:void(0)" class="easyui-linkbutton"
				data-options="plain:true" iconCls="icon-sitemap">全部展开</a>
		</div>
	</div>
	<div data-options="region:'center',border:false">
		<ul id="ChooseProjectTree"></ul>
	</div>
</div>
<script type="text/javascript">
	var currentType, currentTypeName;
	$(function() {
		$('#ChooseProjectTree').tree({
			url : 'projecttype/projectTypeTree.do',
			onSelect : function(node) {
				//$('#PARENTID_RULE').val(node.id);
				//$('#PARENTTITLE_RULE').val(node.text);
				chooseWindowCallBackHandle(node);
			}
		});
		$('#ChooseProjectTreeReload').bind('click', function() {
			$('#ChooseProjectTree').tree('reload');
		});
		$('#ChooseProjectTreeOpenAll').bind('click', function() {
			$('#ChooseProjectTree').tree('expandAll');
		});
	});
</script>

后台

1.controller添加打开窗口方法

/**
* 跳转树选择页面
* 
* @return
 */
@RequestMapping("/treeNodeTreeView")
public ModelAndView forSend() {
	return ViewMode.getInstance().returnModelAndView("project/ChooseProjectTypeTree");
}

/**
* 移动节点
* 
 * @return
 */
@RequestMapping("/moveTreeNodeSubmit")
@ResponseBody
public Map<String, Object> moveTreeNodeSubmit(String ids, String id, HttpSession session) {
	try {
		projectTypeServiceImpl.moveTreeNode(ids, id, getCurrentUser(session));
		return ViewMode.getInstance().returnObjMode();
	} catch (Exception e) {
		log.error(e.getMessage());
		return ViewMode.getInstance().setError(e.getMessage(), e).returnObjMode();
	}
}

2.dao增加查询字节点方法

	@Override
	public List<ProjectType> getAllSubNodes(String typeid) {
		Session session = sessionFatory.getCurrentSession();
		Query sqlquery = session.createQuery(" from ProjectType where TREECODE like ? order by ctime ");
		sqlquery.setString(0, getEntity(typeid).getTreecode() + "%");
		return sqlquery.list();
	}

3.server增加移动节点烦方


@Override
@Transactional
public void moveTreeNode(String ids, String targetId, LoginUser currentUser) {
    String[] idArray = ids.split(",");
    TaskType target = getTasktypeEntity(targetId);
    if (target != null && target.getModel().equals("1")) {
        throw new RuntimeException("'类型'节点下禁止创建子节点!");
    }
    for (int i = 0; i < idArray.length; i++) {
        // 移动节点
        TaskType node = getTasktypeEntity(idArray[i]);
        if (target != null && target.getTreecode().indexOf(node.getTreecode()) >= 0) {
            throw new RuntimeException("不能够移动到其子节点下!");
        }
        if (target == null) {
            node.setParentid("NONE");
        } else {
            node.setParentid(targetId);
        }
        tasktypeDaoImpl.editEntity(node);
        // 构造所有树TREECODE
        List<TaskType> list = tasktypeDaoImpl.getAllSubNodes(idArray[i]);
        for (TaskType org : list) {
            initTreeCode(org.getId());
        }
    }
}






0人参与

 关联资源



 历史版本

修改日期 修改人 备注
2019-12-01 19:33:48[当前版本] 系统管理员 格式调整
2019-12-01 19:32:19 系统管理员 格式调整
2019-12-01 14:30:35 系统管理员 格式调整
2019-12-01 14:22:23 系统管理员 格式调整

wcp知识库系统-京ICP备15024440号-1 -V 5.1.3 -wcp