Commit 2f5298bc by fsn

菜单添加和修改更加人性化,不需手动输入父级编号和层级

parent 4eec946f
......@@ -160,6 +160,24 @@ public class ConstantFactory {
}
/**
* 获取菜单名称通过编号
*/
public String getMenuNameByCode(String code) {
if (ToolUtil.isEmpty(code)) {
return "";
} else {
Menu param = new Menu();
param.setCode(code);
Menu menu = menuMapper.selectOne(param);
if (menu == null) {
return "";
} else {
return menu.getName();
}
}
}
/**
* 获取字典名称
*/
public String getDictName(Integer dictId){
......
......@@ -11,13 +11,14 @@ import com.stylefeng.guns.common.controller.BaseController;
import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import com.stylefeng.guns.common.node.ZTreeNode;
import com.stylefeng.guns.common.persistence.dao.MenuMapper;
import com.stylefeng.guns.common.persistence.model.Menu;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.support.BeanKit;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.dao.MenuDao;
import com.stylefeng.guns.modular.system.service.IMenuService;
import com.stylefeng.guns.modular.system.warpper.MenuWarpper;
import com.stylefeng.guns.common.persistence.dao.MenuMapper;
import com.stylefeng.guns.common.persistence.model.Menu;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
......@@ -77,7 +78,9 @@ public class MenuController extends BaseController {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
}
Menu menu = this.menuMapper.selectById(menuId);
model.addAttribute(menu);
Map<String, Object> menuMap = BeanKit.beanToMap(menu);
menuMap.put("pcodeName",ConstantFactory.me().getMenuNameByCode(menu.getPcode()));
model.addAttribute("menu", menuMap);
LogObjectHolder.me().set(menu);
return PREFIX + "menu_edit.html";
}
......@@ -93,6 +96,9 @@ public class MenuController extends BaseController {
if (result.hasErrors()) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
}
//设置父级菜单编号
menuSetPcode(menu);
this.menuMapper.updateById(menu);
return SUCCESS_TIP;
}
......@@ -118,6 +124,9 @@ public class MenuController extends BaseController {
if (result.hasErrors()) {
throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
}
//设置父级菜单编号
menuSetPcode(menu);
menu.setStatus(MenuStatus.ENABLE.getCode());
this.menuMapper.insert(menu);
return SUCCESS_TIP;
......@@ -156,7 +165,7 @@ public class MenuController extends BaseController {
}
/**
* 获取菜单列表
* 获取菜单列表(首页用)
*/
@RequestMapping(value = "/menuTreeList")
@ResponseBody
......@@ -166,6 +175,17 @@ public class MenuController extends BaseController {
}
/**
* 获取菜单列表(选择父级菜单用)
*/
@RequestMapping(value = "/selectMenuTreeList")
@ResponseBody
public List<ZTreeNode> selectMenuTreeList() {
List<ZTreeNode> roleTreeList = this.menuDao.menuTreeList();
roleTreeList.add(ZTreeNode.createParent());
return roleTreeList;
}
/**
* 获取角色列表
*/
@RequestMapping(value = "/menuTreeListByRoleId/{roleId}")
......@@ -181,4 +201,20 @@ public class MenuController extends BaseController {
}
}
/**
* 根据请求的父级菜单编号设置pcode和层级
*/
private void menuSetPcode(@Valid Menu menu) {
if(ToolUtil.isEmpty(menu.getPcode()) || menu.getPcode().equals("0")){
menu.setPcode("0");
menu.setLevels(1);
}else{
int code = Integer.parseInt(menu.getPcode());
Menu pMenu = menuMapper.selectById(code);
Integer pLevels = pMenu.getLevels();
menu.setPcode(pMenu.getCode());
menu.setLevels(pLevels + 1);
}
}
}
......@@ -9,13 +9,16 @@
<div class="col-sm-6 b-r">
<#input id="name" name="名称" underline="true" />
<#input id="code" name="菜单编号" underline="true" />
<#input id="pcode" name="父级编号" underline="true" />
<#input id="icon" name="图标" underline="false" />
<#input id="pcodeName" name="父级编号" underline="true"
hidden="pcode" readonly="readonly"
clickFun="MenuInfoDlg.showMenuSelectTree(); return false;"
style="background-color: #ffffff !important;"
selectFlag="true" selectId="pcodeTreeDiv" selectTreeId="pcodeTree" selectStyle="width:244px !important;"/>
</div>
<div class="col-sm-6">
<#input id="url" name="请求地址" underline="true" />
<#input id="num" name="排序" underline="true" />
<#input id="levels" name="层级" underline="false" />
<#input id="icon" name="图标" underline="false" />
</div>
</div>
......
@layout("/common/_container.html"){
<div class="ibox float-e-margins">
<div class="ibox-content">
<div class="form-horizontal">
<input type="hidden" id="id" value="${menu.id}">
<div class="ibox-content">
<div class="form-horizontal">
<div class="row">
<div class="col-sm-6 b-r">
<#input id="name" name="名称" value="${menu.name}" underline="true" />
<#input id="code" name="菜单编号" value="${menu.code}" underline="true" />
<#input id="pcode" name="父级编号" value="${menu.pcode}" underline="true" />
<#input id="icon" name="图标" underline="false" value="${menu.icon}"/>
</div>
<div class="col-sm-6">
<#input id="url" name="请求地址" value="${menu.url}" underline="true" />
<#input id="num" name="排序" value="${menu.num}" underline="true" />
<#input id="levels" name="层级" value="${menu.levels}" underline="false" />
</div>
</div>
<input type="hidden" id="id" value="${menu.id}">
<div class="row btn-group-m-t">
<div class="col-sm-10">
<#button btnCss="info" name="提交" id="ensure" icon="fa-check" clickFun="MenuInfoDlg.editSubmit()"/>
<#button btnCss="danger" name="取消" id="cancel" icon="fa-eraser" clickFun="MenuInfoDlg.close()"/>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 b-r">
<#input id="name" name="名称" value="${menu.name}" underline="true" />
<#input id="code" name="菜单编号" value="${menu.code}" underline="true" />
<#input id="pcodeName" name="父级编号" value="${menu.pcodeName}" underline="true"
hidden="pcode" readonly="readonly" hiddenValue="${menu.pcode}"
clickFun="MenuInfoDlg.showMenuSelectTree(); return false;"
style="background-color: #ffffff !important;"
selectFlag="true" selectId="pcodeTreeDiv" selectTreeId="pcodeTree" selectStyle="width:244px !important;"/>
</div>
<div class="col-sm-6">
<#input id="url" name="请求地址" value="${menu.url}" underline="true" />
<#input id="num" name="排序" value="${menu.num}" underline="true" />
<#input id="icon" name="图标" underline="false" value="${menu.icon}"/>
</div>
</div>
</div>
<div class="row btn-group-m-t">
<div class="col-sm-10">
<#button btnCss="info" name="提交" id="ensure" icon="fa-check" clickFun="MenuInfoDlg.editSubmit()"/>
<#button btnCss="danger" name="取消" id="cancel" icon="fa-eraser" clickFun="MenuInfoDlg.close()"/>
</div>
</div>
</div>
</div>
</div>
<script src="${ctxPath}/static/modular/system/menu/menu_info.js"></script>
@}
......@@ -64,7 +64,7 @@ var Feng = {
closeBtn: 0
});
},
showInputTree: function (inputId, inputTreeContentId) {
showInputTree: function (inputId, inputTreeContentId, leftOffset, rightOffset) {
var onBodyDown = function (event) {
if (!(event.target.id == "menuBtn" || event.target.id == inputTreeContentId || $(event.target).parents("#" + inputTreeContentId).length > 0)) {
$("#" + inputTreeContentId).fadeOut("fast");
......@@ -72,13 +72,19 @@ var Feng = {
}
};
var inputDiv = $("#" + inputId);
var inputDivOffset = $("#" + inputId).offset();
$("#" + inputTreeContentId).css({
left: inputDivOffset.left + "px",
top: inputDivOffset.top + inputDiv.outerHeight() + "px"
}).slideDown("fast");
if(leftOffset == undefined && rightOffset == undefined){
var inputDiv = $("#" + inputId);
var inputDivOffset = $("#" + inputId).offset();
$("#" + inputTreeContentId).css({
left: inputDivOffset.left + "px",
top: inputDivOffset.top + inputDiv.outerHeight() + "px"
}).slideDown("fast");
}else{
$("#" + inputTreeContentId).css({
left: leftOffset + "px",
top: rightOffset + "px"
}).slideDown("fast");
}
$("body").bind("mousedown", onBodyDown);
},
......
......@@ -2,91 +2,111 @@
* 菜单详情对话框
*/
var MenuInfoDlg = {
menuInfoData : {}
menuInfoData: {},
ztreeInstance: null
};
/**
* 清除数据
*/
MenuInfoDlg.clearData = function() {
this.roleInfoData = {};
MenuInfoDlg.clearData = function () {
this.roleInfoData = {};
}
/**
* 设置对话框中的数据
*
*
* @param key 数据的名称
* @param val 数据的具体值
*/
MenuInfoDlg.set = function(key, val) {
this.roleInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
return this;
MenuInfoDlg.set = function (key, val) {
this.roleInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
return this;
}
/**
* 设置对话框中的数据
*
*
* @param key 数据的名称
* @param val 数据的具体值
*/
MenuInfoDlg.get = function(key) {
return $("#" + key).val();
MenuInfoDlg.get = function (key) {
return $("#" + key).val();
}
/**
* 关闭此对话框
*/
MenuInfoDlg.close = function() {
parent.layer.close(window.parent.Menu.layerIndex);
MenuInfoDlg.close = function () {
parent.layer.close(window.parent.Menu.layerIndex);
}
/**
* 收集数据
*/
MenuInfoDlg.collectData = function() {
this.set('id').set('name').set('code').set('pcode').set('url').set('num').set('levels').set('icon');
MenuInfoDlg.collectData = function () {
this.set('id').set('name').set('code').set('pcode').set('url').set('num').set('levels').set('icon');
}
/**
* 提交添加用户
*/
MenuInfoDlg.addSubmit = function() {
this.clearData();
this.collectData();
//提交信息
var ajax = new $ax(Feng.ctxPath + "/menu/add", function(data){
Feng.success("添加成功!");
window.parent.Menu.table.refresh();
MenuInfoDlg.close();
},function(data){
Feng.error("添加失败!" + data.responseJSON.message + "!");
});
ajax.set(this.roleInfoData);
ajax.start();
MenuInfoDlg.addSubmit = function () {
this.clearData();
this.collectData();
//提交信息
var ajax = new $ax(Feng.ctxPath + "/menu/add", function (data) {
Feng.success("添加成功!");
window.parent.Menu.table.refresh();
MenuInfoDlg.close();
}, function (data) {
Feng.error("添加失败!" + data.responseJSON.message + "!");
});
ajax.set(this.roleInfoData);
ajax.start();
}
/**
* 提交修改
*/
MenuInfoDlg.editSubmit = function() {
this.clearData();
this.collectData();
//提交信息
var ajax = new $ax(Feng.ctxPath + "/menu/edit", function(data){
Feng.success("修改成功!");
window.parent.Menu.table.refresh();
MenuInfoDlg.close();
},function(data){
Feng.error("修改失败!" + data.responseJSON.message + "!");
});
ajax.set(this.roleInfoData);
ajax.start();
MenuInfoDlg.editSubmit = function () {
this.clearData();
this.collectData();
//提交信息
var ajax = new $ax(Feng.ctxPath + "/menu/edit", function (data) {
Feng.success("修改成功!");
window.parent.Menu.table.refresh();
MenuInfoDlg.close();
}, function (data) {
Feng.error("修改失败!" + data.responseJSON.message + "!");
});
ajax.set(this.roleInfoData);
ajax.start();
}
$(function() {
/**
* 点击父级编号input框时
*/
MenuInfoDlg.onClickDept = function (e, treeId, treeNode) {
$("#pcodeName").attr("value", MenuInfoDlg.ztreeInstance.getSelectedVal());
$("#pcode").attr("value", treeNode.id);
};
/**
* 显示父级菜单选择的树
*/
MenuInfoDlg.showMenuSelectTree = function () {
Feng.showInputTree("pcodeName", "pcodeTreeDiv", 15, 34);
};
$(function () {
var ztree = new $ZTree("pcodeTree", "/menu/selectMenuTreeList");
ztree.bindOnClick(MenuInfoDlg.onClickDept);
ztree.init();
MenuInfoDlg.ztreeInstance = ztree;
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment