Selaa lähdekoodia

菜单管理功能

git-svn-id: https://192.168.57.71/svn/jsgkj@816 931142cf-59ea-a443-aa0e-51397b428577
ld_zhouk 8 vuotta sitten
vanhempi
commit
f11ee34f4f

+ 93 - 0
gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/web/ctl/MenuCtl.java

@@ -0,0 +1,93 @@
+package com.xt.js.gkaq.web.ctl;
+
+import java.util.List;
+
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import com.alibaba.fastjson.JSONArray;
+import com.xt.js.gkaq.common.BaseCtl;
+import com.xt.js.gkaq.frame.model.MenuModel;
+import com.xt.js.gkaq.frame.service.MenuService;
+import com.xt.js.gkaq.web.vo.MenuVo;
+import com.yuanxd.tools.utils.WebJsonResult;
+import com.yuanxd.tools.utils.string.StringUtils;
+
+@Controller
+@RequestMapping(value = "/menu", produces = "application/json; charset=utf-8")
+public class MenuCtl extends BaseCtl {
+    @Autowired
+    private MenuService menuService;
+
+    @RequestMapping("")
+    public String index(Model model) {
+        return "menu/menu";
+    }
+
+	/**
+	 * 初始化页面加载数据
+	 */
+    @RequestMapping("list")
+    @ResponseBody
+	public String selectList() {
+
+		List<MenuModel> list = menuService.selectInitMenu();
+		JSONArray.toJSONString(list);
+		return JSONArray.toJSONString(list);
+	}
+
+    @RequestMapping("getRecord")
+    @ResponseBody
+    public MenuVo getRecord(String id) {
+    	MenuModel menuModel = menuService.findById(id);
+    	MenuVo menuVo = new MenuVo();
+    	BeanUtils.copyProperties(menuModel, menuVo);
+        return menuVo;
+    }
+
+    @RequestMapping("delRecodes")
+    @ResponseBody
+    @Transactional
+	public int delRecodes(String ids) {
+		int cnt = 0;
+		if (StringUtils.isNotEmpty(ids)) {
+			String[] idArr = ids.split(",");
+			for (String id : idArr) {
+				if (StringUtils.isNotEmpty(id)) {
+					// 先删除关联的子菜单
+					cnt += menuService.deleteByPid(id);
+					cnt += menuService.deleteByID(id);
+				}
+			}
+		}
+		return cnt;
+	}
+
+    /**
+     * 保存
+     * @param vo
+     * @return
+     */
+    @RequestMapping("save")
+    @ResponseBody
+    public WebJsonResult save(MenuVo menuVo) {
+    	// 新增
+    	if(StringUtils.isEmpty(menuVo.getId())) {
+            MenuModel menuModel = new MenuModel();
+            BeanUtils.copyProperties(menuVo, menuModel);
+            menuService.add(menuModel);
+    	} else {
+    		// 更新
+    		MenuModel menuModel = menuService.findById(menuVo.getId());
+    		BeanUtils.copyProperties(menuVo, menuModel, new String[] {"remark"});
+            menuService.update(menuModel);
+    	}
+        return success();
+    }
+
+}

+ 127 - 0
gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/web/vo/MenuVo.java

@@ -0,0 +1,127 @@
+package com.xt.js.gkaq.web.vo;
+
+import com.xt.js.gkaq.common.BaseVo;
+
+public class MenuVo extends BaseVo {
+
+	private String id;
+
+	private String pid;
+	
+	private String pname;
+	
+	private String pcode;
+
+	private String name;
+
+	private String code;
+
+	private String icon;
+
+	private String url;
+
+	private String leaf;
+
+	private String outLink;
+
+	private String remark;
+
+	private Long sortno;
+
+	public final String getId() {
+		return this.id;
+	}
+
+	public final void setId(String id) {
+		this.id = id;
+	}
+
+	public String getPid() {
+		return pid;
+	}
+
+	public void setPid(String pid) {
+		this.pid = pid;
+	}
+
+	public String getPname() {
+		return pname;
+	}
+
+	public void setPname(String pname) {
+		this.pname = pname;
+	}
+
+	public String getPcode() {
+		return pcode;
+	}
+
+	public void setPcode(String pcode) {
+		this.pcode = pcode;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public String getIcon() {
+		return icon;
+	}
+
+	public void setIcon(String icon) {
+		this.icon = icon;
+	}
+
+	public String getUrl() {
+		return url;
+	}
+
+	public void setUrl(String url) {
+		this.url = url;
+	}
+
+	public String getLeaf() {
+		return leaf;
+	}
+
+	public void setLeaf(String leaf) {
+		this.leaf = leaf;
+	}
+
+	public String getOutLink() {
+		return outLink;
+	}
+
+	public void setOutLink(String outLink) {
+		this.outLink = outLink;
+	}
+
+	public String getRemark() {
+		return remark;
+	}
+
+	public void setRemark(String remark) {
+		this.remark = remark;
+	}
+
+	public Long getSortno() {
+		return sortno;
+	}
+
+	public void setSortno(Long sortno) {
+		this.sortno = sortno;
+	}
+
+}

+ 1 - 1
gkaqv2/trunk/modules/web/src/main/webapp/WEB-INF/view/layouts/sidebar.jsp

@@ -2,4 +2,4 @@
     pageEncoding="GBK"%>
 [系统管理]<br>
 &emsp;&emsp;<a href="#" onclick="linkUrl('user')">用户管理</a><br>
-&emsp;&emsp;<a href="#" onclick="linkUrl('user')">菜单管理</a><br>
+&emsp;&emsp;<a href="#" onclick="linkUrl('menu')">菜单管理</a><br>

+ 193 - 0
gkaqv2/trunk/modules/web/src/main/webapp/WEB-INF/view/menu/menu.jsp

@@ -0,0 +1,193 @@
+<%@ page language="java" contentType="text/html;charset=GBK" pageEncoding="GBK"%>
+<!DOCTYPE html>
+<html>
+<head>
+<title>菜单管理</title>
+
+<%@ include file="../layouts/header.jsp"%>
+<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/static/js/common/zTree_v3/css/zTreeStyle/zTreeStyle.css" />
+<script type="text/javascript" src="<%=request.getContextPath()%>/static/js/common/zTree_v3/js/jquery.ztree.all-3.5.min.js"></script>
+<script src="<%=base%>/static/js/menu/menu.js"></script>
+</head>
+<body class="p_body">
+<div class="easyui-layout" data-options="fit:true">
+<!-- 头部 -->
+<div id="regionNorth" data-options="region:'north'" class="regionNorthStyle">
+	<%@ include file="../layouts/navbar.jsp"%>
+</div>
+<!-- 左边部分 -->
+<div id="regionWest" data-options="region:'west'" class="regionWestStyle">
+	<%@ include file="../layouts/sidebar.jsp"%>
+</div>
+<!-- 底部 -->
+<div id="regionFooter" data-options="region:'south'" class="regionFooterStyle">
+	<%@ include file="../layouts/footer.jsp"%>
+</div>
+<!-- 内容部分 -->
+<div id="regionCenter" data-options="region:'center'" class="regionCenterStyle">
+	<div class="p_all">
+	<div class="p_block">
+		<div class="p_headdiv">
+			<div class="p_headblock">
+				<div class="p_headleft">菜单管理</div>
+			</div>
+		</div>
+		<div class="p_buttondiv">
+			<div class="p_buttonbg">
+				<img class="p_buttonimg" src="<%=base%>/static/images/list/add.png" 
+					onclick="addInfo()" title="新增"/>
+			</div>
+			<div class="p_buttonbg">
+				<img class="p_buttonimg" src="<%=base%>/static/images/list/delete.png" 
+					onclick="delInfo()" title="删除"/>
+			</div>
+			<div class="p_buttonbg">
+				<img class="p_buttonimg" src="<%=base%>/static/images/list/edit.png" 
+					onclick="editInfo()" title="修改"/>
+			</div>
+			<div class="p_buttonbg">
+				<img class="p_buttonimg" src="<%=base%>/static/images/list/reload.png" 
+					onclick="refresh()" title="刷新"/>
+			</div>
+		</div>
+		<div class="page-content" style="margin-left: 20px; height : 400px; width: 92%; overflow-x: auto; overflow-y: scroll;">
+			<!--菜单树-->
+			<div id="menuTree" class="ztree"></div>
+		</div>
+	</div>
+	</div>
+
+	<div class="modal fade" id="editWin" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+		<div class="modal-dialog">
+			<div class="modal-content">
+				<div class="modal-header">
+					<button type="button" class="close" data-dismiss="modal">
+						<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
+					</button>
+					<h6 class="modal-title" id="myModalLabel"></h6>
+				</div>
+				<!-- form 表单信息 -->
+				<div class="modal-body">
+					<form class="form-horizontal" id="editForm" method="post" onsubmit="return false;">
+						<input type="hidden" id="id" name="id">
+						<input type="hidden" id="pid" name="pid">
+						<div class="form-group">
+							<label class="col-sm-2 control-label" for="pname">上级名称</label>
+							<div class="col-sm-9">
+								<input class="form-control" id="pname" name="pname" type="text" readonly="readonly" />
+							</div>
+						</div>
+						<div class="form-group">
+							<label class="col-sm-2 control-label" for="pcode">上级编码</label>
+							<div class="col-sm-9">
+								<input class="form-control" id="pcode" name="pcode" type="text" readonly="readonly" />
+							</div>
+						</div>
+						<div class="form-group">
+							<label class="col-sm-2 control-label" for="name">名称</label>
+							<div class="col-sm-9">
+								<input class="form-control" id="name" name="name" type="text" />
+							</div>
+						</div>
+						<div class="form-group">
+							<label class="col-sm-2 control-label" for="code">编码</label>
+							<div class="col-sm-9">
+								<input class="form-control" id="code" name="code" type="text" />
+							</div>
+						</div>
+						<div class="form-group">
+							<label class="col-sm-2 control-label" for="leaf">类型</label>
+							<div class="col-sm-9">
+								<select class="form-control" id="leaf" name="leaf">
+									<option value="N">目录</option>
+									<option value="Y">页面</option>
+								</select>
+							</div>
+						</div>
+						<div class="form-group">
+							<label class="col-sm-2 control-label" for="url">路径</label>
+							<div class="col-sm-9">
+								<input class="form-control" id="url" name="url" type="text" />
+							</div>
+						</div>
+						<div class="form-group">
+							<label class="col-sm-2 control-label" for="sortno">序号</label>
+							<div class="col-sm-9">
+								<input class="form-control" id="sortno" name="sortno" type="text" />
+							</div>
+						</div>
+						<div class="row">
+						   <div class="center-block" style="width:160px;">
+						      	<button id="btnSave" class="btn btn-success btn-round btn-sm" onclick="save()">
+									<i class="glyphicon glyphicon-ok"></i> 保存
+								</button>
+								<button type="button" class="btn btn-grey btn-round btn-sm" onclick="closeWin()">
+									<i class="glyphicon glyphicon-remove"></i> 关闭
+								</button>
+						   </div>
+						</div>
+					</form>
+				</div>
+				<!-- form 表单信息 -->
+			</div>
+		</div>
+	</div>
+
+	<div class="modal fade" id="editBtnWin" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+		<div class="modal-dialog">
+			<div class="modal-content">
+				<div class="modal-header">
+					<button type="button" class="close" data-dismiss="modal">
+						<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
+					</button>
+					<h6 class="modal-title" id="myModalLabel"></h6>
+				</div>
+				<!-- form 表单信息 -->
+				<div class="modal-body">
+					<form class="form-horizontal" id="editBtnForm" method="post" onsubmit="return false;">
+						<input type="hidden" id="btnId" name="btnId">
+						<input type="hidden" id="menuId" name="menuId">
+						<div class="form-group">
+							<label class="col-sm-2 control-label" for="menuName">菜单名称</label>
+							<div class="col-sm-9">
+								<input class="form-control" id="menuName" name="menuName" type="text" readonly="readonly" />
+							</div>
+						</div>
+						<div class="form-group">
+							<label class="col-sm-2 control-label" for="btnName">名称</label>
+							<div class="col-sm-9">
+								<input class="form-control" id="btnName" name="btnName" type="text" />
+							</div>
+						</div>
+						<div class="form-group">
+							<label class="col-sm-2 control-label" for="btnCode">编码</label>
+							<div class="col-sm-9">
+								<input class="form-control" id="btnCode" name="btnCode" type="text" />
+							</div>
+						</div>
+						<div class="form-group">
+							<label class="col-sm-2 control-label" for="btnSortno">序号</label>
+							<div class="col-sm-9">
+								<input class="form-control" id="btnSortno" name="btnSortno" type="text" />
+							</div>
+						</div>
+						<div class="row">
+						   <div class="center-block" style="width:160px;">
+						      	<button id="btnSave" class="btn btn-success btn-round btn-sm" onclick="btnSave()">
+									<i class="glyphicon glyphicon-ok"></i> 保存
+								</button>
+								<button type="button" class="btn btn-grey btn-round btn-sm" onclick="closeBtnWin()">
+									<i class="glyphicon glyphicon-remove"></i> 关闭
+								</button>
+						   </div>
+						</div>
+					</form>
+				</div>
+				<!-- form 表单信息 -->
+			</div>
+		</div>
+	</div>
+</div>
+</div>
+</body>
+</html>

+ 1 - 1
gkaqv2/trunk/modules/web/src/main/webapp/static/js/common/common.js

@@ -276,7 +276,7 @@ function comClearFormData(formId) {
     $(':input', formId).each(function () {
         var type = this.type;
         var tag = this.tagName.toLowerCase();
-        if (type == 'text' || type == 'password' || tag == 'textarea')
+        if (type == 'text' || type == 'password' || type == 'hidden' || tag == 'textarea')
             this.value = "";
         else if (type == 'checkbox' || type == 'radio')
             this.checked = false;

+ 237 - 0
gkaqv2/trunk/modules/web/src/main/webapp/static/js/menu/menu.js

@@ -0,0 +1,237 @@
+var menuTree;
+// zTree的参数配置,setting主要是设置一些tree的属性,是本地数据源,还是远程,动画效果,是否含有复选框等等
+var setting = {
+	// 复选框
+	check : {
+		enable : true,
+		chkboxType: { "Y": "", "N": "" }
+	},
+	async : {
+		enable : true,
+		type : 'post',
+		url : basePath + "/menu/list"
+	},
+	data : {
+		// 简单的数据源
+		simpleData : {
+			enable : true,
+			idKey : "id",
+			pIdKey : "pid",
+			rootPId : 0 // 根节点
+		}
+	},
+	callback : {
+		// onCheck : onCheck
+	}
+};
+
+function onCheck(e, treeId, treeNode) {
+	alert("onCheck");
+}
+
+$(document).ready(function() {
+	// 初始化zTree对象
+	menuTree = $.fn.zTree.init($("#menuTree"), setting);
+});
+
+/**
+ * 新增菜单
+ */
+function addInfo() {
+	// 获取勾选节点
+	var nodes = menuTree.getCheckedNodes(true);
+	if (nodes.length > 1) {
+		layer.alert("请选择一条记录!");
+		return;
+	} else if (nodes.length == 1) {
+		var node = nodes[0];
+		if (node.leaf == 'B') { // 按钮节点
+			layer.alert("只能在菜单下新增!");
+			return;
+		} else if (node.leaf == 'Y') { // 末级菜单节点
+			// 清空按钮表单信息
+			comClearFormData("#editBtnForm");
+			$("#menuId").val(node.id);
+			$("#menuName").val(node.name);
+			// 弹出按钮模态框
+			showModelDialog("editBtnWin", "新增");
+		} else { // 非末级菜单节点
+			// 清空菜单表单信息
+			comClearFormData("#editForm");
+			$("#pid").val(node.id);
+			$("#pname").val(node.name);
+			$("#pcode").val(node.code);
+			// 弹出菜单模态框
+			showModelDialog("editWin", "新增");
+		}
+	}
+};
+
+/**
+ * 编辑菜单
+ */
+function editInfo() {
+	// 获取勾选节点
+	var nodes = menuTree.getCheckedNodes(true);
+	if (nodes.length != 1) {
+		layer.alert("请选择一条记录!");
+		return;
+	} else {
+		var node = nodes[0];
+		if (node.leaf == 'B') { // 按钮节点
+			var pnode = node.getParentNode();
+		    $.ajax({
+				type : 'POST',
+				dataType : "json",
+				data : {"id" : node.id},
+				url : basePath + '/btn/getRecord', // TODO
+				success : function(data) {
+					$("#menuId").val(pnode.id);
+					$("#menuName").val(pnode.name);
+					$("#btnId").val(data.id);
+					$("#btnName").val(data.name);
+					$("#btnCode").val(data.code);
+					$("#btnSortno").val(data.sortno);
+					showModelDialog("editBtnWin", "编辑");
+				},
+				error: function (XMLHttpRequest, textStatus, errorThrown) {
+					layer.alert("error:" + errorThrown);
+		        }
+			});
+		} else { // 菜单节点
+			var pnode = node.getParentNode();
+		    $.ajax({
+				type : 'POST',
+				dataType : "json",
+				data : {"id" : node.id},
+				url : basePath + '/menu/getRecord',
+				success : function(data) {
+					if (!isNull(pnode)) {
+						$("#pid").val(pnode.id);
+						$("#pcode").val(pnode.code);
+						$("#pname").val(pnode.name);
+					}
+					$("#id").val(data.id);
+					$("#name").val(data.name);
+					$("#code").val(data.code);
+					$("#leaf").val(data.leaf);
+					$("#url").val(data.url);
+					$("#sortno").val(data.sortno);
+					showModelDialog("editWin", "编辑");
+				},
+				error: function (XMLHttpRequest, textStatus, errorThrown) {
+					layer.alert("error:" + errorThrown);
+		        }
+			});
+		}
+	}
+};
+
+/**
+ * 删除菜单及其子菜单
+ */
+function delInfo() {
+	// 获取选择节点
+	var nodes = menuTree.getCheckedNodes(true);
+	if(nodes.length > 0) {
+		var chkIds = "";
+		var chkNames = "";
+		for (var i = 0; i < nodes.length; i++) {
+			if (i != 0) {
+				chkIds += ",";
+				chkNames += ",";
+			}
+			chkIds += nodes[i].id;
+			chkNames += nodes[i].name;
+		}
+		layer.confirm('删除所选记录及其下级记录:<br>' + chkNames, {icon: 3, title:'提示'}, function(index){
+			$.ajax({
+				type : 'POST',
+				dataType : "json",
+				data : {"ids" : chkIds},
+				url : basePath + '/menu/delRecodes', // TODO
+				success : function(data) {
+					layer.close(index);
+					menuTree.reAsyncChildNodes(null, "refresh");
+				},
+				error: function (XMLHttpRequest, textStatus, errorThrown) {
+					layer.close(index);
+					layer.alert("error:" + errorThrown);
+		        }
+			});
+		});
+	} else {
+		layer.alert("请选择记录");
+	}
+};
+
+/**
+ * 刷新菜单
+ */
+function refresh() {
+	menuTree.reAsyncChildNodes(null, "refresh");
+};
+
+/**
+ * 保存数据
+ */
+function save() {
+	$.ajax({
+		type : "post",
+		url : basePath + '/menu/save',
+		dataType:'json',
+		data : $('#editForm').serialize(), //表单序列化,获取数据
+		success : function(data) {
+			// 成功删除后刷新页面
+			if (data && data.success == true) {
+				layer.alert("数据已成功保存!");
+				closeWin();
+				menuTree.reAsyncChildNodes(null, "refresh");
+			} else {
+				layer.alert("数据保存失败!");
+			}
+		}, //操作成功后的操作!data是后台传过来的值 
+		error: function (XMLHttpRequest, textStatus, errorThrown) {
+			layer.alert("error:" + errorThrown);
+        }
+	});
+}
+
+/**
+ * 关闭窗口
+ */
+function closeWin() {
+	hideModelDialog("editWin");
+}
+
+/**
+ * 保存按钮数据
+ */
+function btnSave() {
+	$.ajax({
+		type : "post",
+		url : basePath + '/btn/save', // TODO
+		dataType:'json',
+		data : $('#editBtnForm').serialize(), //表单序列化,获取数据
+		success : function(data) {
+			// 成功删除后刷新页面
+			if (data && data.success == true) {
+				layer.alert("数据已成功保存!");
+				closeWin();
+				menuTree.reAsyncChildNodes(null, "refresh");
+			} else {
+				layer.alert("数据保存失败!");
+			}
+		}, //操作成功后的操作!data是后台传过来的值 
+		error: function (XMLHttpRequest, textStatus, errorThrown) {
+			layer.alert("error:" + errorThrown);
+        }
+	});
+}
+
+/**
+ * 关闭按钮窗口
+ */
+function closeBtnWin() {
+	hideModelDialog("editBtnWin");
+}