Browse Source

菜单按钮管理功能

git-svn-id: https://192.168.57.71/svn/jsgkj@823 931142cf-59ea-a443-aa0e-51397b428577
ld_zhouk 8 years ago
parent
commit
ec94cc2bfa

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

@@ -0,0 +1,71 @@
+package com.xt.js.gkaq.web.ctl;
+
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import com.xt.js.gkaq.common.BaseCtl;
+import com.xt.js.gkaq.frame.model.ButtonModel;
+import com.xt.js.gkaq.frame.service.ButtonService;
+import com.xt.js.gkaq.web.vo.ButtonVo;
+import com.yuanxd.tools.utils.WebJsonResult;
+import com.yuanxd.tools.utils.string.StringUtils;
+
+@Controller
+@RequestMapping(value = "/btn")
+public class MenuButtonCtl extends BaseCtl {
+    @Autowired
+    private ButtonService buttonService;
+
+    @RequestMapping("")
+    public String index(Model model) {
+        return "menu/menu";
+    }
+
+    @RequestMapping("getRecord")
+    @ResponseBody
+    public ButtonVo getRecord(String id) {
+
+    	ButtonModel btnModel = buttonService.findById(id);
+    	ButtonVo btnVo = new ButtonVo();
+    	btnVo.setBtnId(btnModel.getId());
+    	btnVo.setBtnCode(btnModel.getCode());
+    	btnVo.setBtnName(btnModel.getName());
+    	btnVo.setBtnSortno(btnModel.getSortno());
+        return btnVo;
+    }
+
+    /**
+     * ±£´æ
+     * @param vo
+     * @return
+     */
+    @RequestMapping("save")
+    @ResponseBody
+    public WebJsonResult save(ButtonVo btnVo) {
+
+    	if(StringUtils.isEmpty(btnVo.getBtnId())) {
+        	// ÐÂÔö
+    		ButtonModel btnModel = new ButtonModel();
+    		btnModel.setCode(btnVo.getBtnCode());
+    		btnModel.setName(btnVo.getBtnName());
+    		btnModel.setSortno(btnVo.getBtnSortno());
+    		btnModel.setMenu(btnVo.getMenuId());
+    		
+    		buttonService.add(btnModel);
+    	} else {
+    		// ¸üÐÂ
+    		ButtonModel btnModel = buttonService.findById(btnVo.getBtnId());
+    		btnModel.setCode(btnVo.getBtnCode());
+    		btnModel.setName(btnVo.getBtnName());
+    		btnModel.setSortno(btnVo.getBtnSortno());
+    		btnModel.setMenu(btnVo.getMenuId());
+    		buttonService.update(btnModel);
+    	}
+        return success();
+    }
+
+}

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

@@ -13,6 +13,7 @@ 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.ButtonService;
 import com.xt.js.gkaq.frame.service.MenuService;
 import com.xt.js.gkaq.web.vo.MenuVo;
 import com.yuanxd.tools.utils.WebJsonResult;
@@ -23,6 +24,8 @@ import com.yuanxd.tools.utils.string.StringUtils;
 public class MenuCtl extends BaseCtl {
     @Autowired
     private MenuService menuService;
+    @Autowired
+    private ButtonService buttonService;
 
     @RequestMapping("")
     public String index(Model model) {
@@ -44,6 +47,7 @@ public class MenuCtl extends BaseCtl {
     @RequestMapping("getRecord")
     @ResponseBody
     public MenuVo getRecord(String id) {
+
     	MenuModel menuModel = menuService.findById(id);
     	MenuVo menuVo = new MenuVo();
     	BeanUtils.copyProperties(menuModel, menuVo);
@@ -54,13 +58,19 @@ public class MenuCtl extends BaseCtl {
     @ResponseBody
     @Transactional
 	public int delRecodes(String ids) {
-		int cnt = 0;
+
+    	int cnt = 0;
 		if (StringUtils.isNotEmpty(ids)) {
 			String[] idArr = ids.split(",");
 			for (String id : idArr) {
 				if (StringUtils.isNotEmpty(id)) {
-					// 先删除关联的子菜单
+					// 删除按钮
+					cnt += buttonService.deleteByID(id);
+					// 删除末级菜单关联的按钮
+					cnt += buttonService.deleteByMenu(id);
+					// 删除非末级菜单关联的子菜单
 					cnt += menuService.deleteByPid(id);
+					// 删除菜单
 					cnt += menuService.deleteByID(id);
 				}
 			}
@@ -76,8 +86,9 @@ public class MenuCtl extends BaseCtl {
     @RequestMapping("save")
     @ResponseBody
     public WebJsonResult save(MenuVo menuVo) {
-    	// 新增
+
     	if(StringUtils.isEmpty(menuVo.getId())) {
+        	// 新增
             MenuModel menuModel = new MenuModel();
             BeanUtils.copyProperties(menuVo, menuModel);
             menuService.add(menuModel);

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

@@ -0,0 +1,67 @@
+package com.xt.js.gkaq.web.vo;
+
+import com.xt.js.gkaq.common.BaseVo;
+
+public class ButtonVo extends BaseVo {
+
+	private String btnId;
+
+	private String menuId;
+	
+	private String menuName;
+	
+	private String btnName;
+
+	private String btnCode;
+
+	private Long btnSortno;
+
+	public String getBtnId() {
+		return btnId;
+	}
+
+	public void setBtnId(String btnId) {
+		this.btnId = btnId;
+	}
+
+	public String getMenuId() {
+		return menuId;
+	}
+
+	public void setMenuId(String menuId) {
+		this.menuId = menuId;
+	}
+
+	public String getMenuName() {
+		return menuName;
+	}
+
+	public void setMenuName(String menuName) {
+		this.menuName = menuName;
+	}
+
+	public String getBtnName() {
+		return btnName;
+	}
+
+	public void setBtnName(String btnName) {
+		this.btnName = btnName;
+	}
+
+	public String getBtnCode() {
+		return btnCode;
+	}
+
+	public void setBtnCode(String btnCode) {
+		this.btnCode = btnCode;
+	}
+
+	public Long getBtnSortno() {
+		return btnSortno;
+	}
+
+	public void setBtnSortno(Long btnSortno) {
+		this.btnSortno = btnSortno;
+	}
+
+}

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

@@ -118,10 +118,10 @@
 						</div>
 						<div class="row">
 						   <div class="center-block" style="width:160px;">
-						      	<button id="btnSave" class="btn btn-success btn-round btn-sm" onclick="save()">
+						      	<button 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()">
+								<button class="btn btn-grey btn-round btn-sm" onclick="closeWin()">
 									<i class="glyphicon glyphicon-remove"></i> ¹Ø±Õ
 								</button>
 						   </div>
@@ -173,10 +173,10 @@
 						</div>
 						<div class="row">
 						   <div class="center-block" style="width:160px;">
-						      	<button id="btnSave" class="btn btn-success btn-round btn-sm" onclick="btnSave()">
+						      	<button 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()">
+								<button class="btn btn-grey btn-round btn-sm" onclick="closeBtnWin()">
 									<i class="glyphicon glyphicon-remove"></i> ¹Ø±Õ
 								</button>
 						   </div>

+ 13 - 8
gkaqv2/trunk/modules/web/src/main/webapp/static/js/menu/menu.js

@@ -64,6 +64,11 @@ function addInfo() {
 			// 弹出菜单模态框
 			showModelDialog("editWin", "新增");
 		}
+	} else { // 根级菜单节点
+		// 清空菜单表单信息
+		comClearFormData("#editForm");
+		// 弹出菜单模态框
+		showModelDialog("editWin", "新增");
 	}
 };
 
@@ -84,14 +89,14 @@ function editInfo() {
 				type : 'POST',
 				dataType : "json",
 				data : {"id" : node.id},
-				url : basePath + '/btn/getRecord', // TODO
+				url : basePath + '/btn/getRecord',
 				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);
+					$("#btnId").val(data.btnId);
+					$("#btnName").val(data.btnName);
+					$("#btnCode").val(data.btnCode);
+					$("#btnSortno").val(data.btnSortno);
 					showModelDialog("editBtnWin", "编辑");
 				},
 				error: function (XMLHttpRequest, textStatus, errorThrown) {
@@ -149,7 +154,7 @@ function delInfo() {
 				type : 'POST',
 				dataType : "json",
 				data : {"ids" : chkIds},
-				url : basePath + '/menu/delRecodes', // TODO
+				url : basePath + '/menu/delRecodes',
 				success : function(data) {
 					layer.close(index);
 					menuTree.reAsyncChildNodes(null, "refresh");
@@ -210,14 +215,14 @@ function closeWin() {
 function btnSave() {
 	$.ajax({
 		type : "post",
-		url : basePath + '/btn/save', // TODO
+		url : basePath + '/btn/save',
 		dataType:'json',
 		data : $('#editBtnForm').serialize(), //表单序列化,获取数据
 		success : function(data) {
 			// 成功删除后刷新页面
 			if (data && data.success == true) {
 				layer.alert("数据已成功保存!");
-				closeWin();
+				closeBtnWin();
 				menuTree.reAsyncChildNodes(null, "refresh");
 			} else {
 				layer.alert("数据保存失败!");