提交 0755a3d7 编写于 作者: doc_wei's avatar doc_wei

树插件更新,添加角色加载树完成

上级 b14382d1
......@@ -9,4 +9,6 @@ public interface SysEveRoleDao {
public List<Map<String, Object>> querySysRoleList(Map<String, Object> map, PageBounds pageBounds) throws Exception;
public List<Map<String, Object>> querySysRoleBandMenuList(Map<String, Object> map) throws Exception;
}
......@@ -7,4 +7,6 @@ public interface SysEveRoleService {
public void querySysRoleList(InputObject inputObject, OutputObject outputObject) throws Exception;
public void querySysRoleBandMenuList(InputObject inputObject, OutputObject outputObject) throws Exception;
}
......@@ -39,5 +39,26 @@ public class SysEveRoleServiceImpl implements SysEveRoleService{
outputObject.setBeans(beans);
outputObject.settotal(total);
}
/**
*
* @Title: querySysRoleBandMenuList
* @Description: 获取角色需要绑定的菜单列表
* @param @param inputObject
* @param @param outputObject
* @param @throws Exception 参数
* @return void 返回类型
* @throws
*/
@Override
public void querySysRoleBandMenuList(InputObject inputObject, OutputObject outputObject) throws Exception {
Map<String, Object> map = inputObject.getParams();
List<Map<String, Object>> beans = sysEveRoleDao.querySysRoleBandMenuList(map);
for(Map<String, Object> bean : beans){
String[] str = bean.get("pId").toString().split(",");
bean.put("pId", str[str.length-1]);
}
outputObject.setBeans(beans);
}
}
......@@ -31,4 +31,20 @@ public class SysEveRoleController {
sysEveRoleService.querySysRoleList(inputObject, outputObject);
}
/**
*
* @Title: querySysRoleBandMenuList
* @Description: 获取角色需要绑定的菜单列表
* @param @param inputObject
* @param @param outputObject
* @param @throws Exception 参数
* @return void 返回类型
* @throws
*/
@RequestMapping("/post/SysEveRoleController/querySysRoleBandMenuList")
@ResponseBody
public void querySysRoleBandMenuList(InputObject inputObject, OutputObject outputObject) throws Exception{
sysEveRoleService.querySysRoleBandMenuList(inputObject, outputObject);
}
}
......@@ -128,7 +128,8 @@
SELECT
a.id,
a.menu_name name,
a.menu_parent_id pId
a.menu_parent_id pId,
'true' isParent
FROM
sys_eve_menu a
<if test="parentId != &quot;0&quot;">
......
......@@ -21,4 +21,15 @@
ORDER BY a.create_time DESC
</select>
<select id="querySysRoleBandMenuList" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
a.id,
a.menu_name name,
a.menu_parent_id pId,
'true' isParent,
(a.menu_level + 1) type
FROM
sys_eve_menu a
</select>
</mapper>
\ No newline at end of file
......@@ -75,5 +75,7 @@
<property id="page" name="page" ref="required" var="分页参数,第几页"/>
<property id="roleName" name="roleName" ref="" var="角色名称"/>
</url>
<url id="sys014" path="/post/SysEveRoleController/querySysRoleBandMenuList" val="获取角色需要绑定的菜单列表">
</url>
</controller>
\ No newline at end of file
layui.define(['layer', 'form', 'fsButtonCommon'], function(exports) {
var form = layui.form,
layer = layui.layer,
fsButtonCommon = layui.fsButtonCommon;
......
......@@ -7,9 +7,12 @@ layui.define(['layer', "fsCommon"], function(exports) {
funcNo: undefined, //功能号
url: undefined, //请求url地址
id: "",
isRoot: true, //是否显示目录,默认显示
isRoot: true, //是否显示目录,默认显示
clickCallback: undefined, //点击回调函数
onDblClick: undefined,//双击之后的回调函数
enable: true,//异步还是同步加载,默认同步
checkEnable: false,//是否显示复选框,默认为否
loadEnable: true,//数据是否异步加载,默认为是
}
};
......@@ -129,15 +132,34 @@ layui.define(['layer', "fsCommon"], function(exports) {
data: {
key: {
name: _this.config.treeName,
isParent: true
},
simpleData: {
enable: true,
enable: _this.config.enable,
idKey: _this.config.treeIdKey,
pIdKey: _this.config.treePIdKey,
rootPId: 0
}
},
async: { //异步加载
type: "get",
enable: _this.config.loadEnable,
url: reqBasePath + _this.config.url,
autoParam : ["id=parentId"],//异步加载时需要自动提交父节点属性的参数
dataType:"json",
dataFilter: function(treeId, treeNode, responseData) {
if (responseData.rows.length > 0) {
$.fn.zTree.getZTreeObj(treeId).addNodes(treeNode, responseData.rows);
}
},
},
check : {
enable : _this.config.checkEnable,
chkStyle : "checkbox", //复选框
chkboxType : {
"Y" : "ps",
"N" : "ps"
}
},
edit: edit,
callback: {
onClick: _this.config.clickCallback,
......@@ -177,7 +199,6 @@ layui.define(['layer', "fsCommon"], function(exports) {
setting["edit"] = edit;
}
$.fn.zTree.init($("#" + _this.config.id), setting, data);
};
......
......@@ -155,35 +155,12 @@ layui.config({
//异步加载的方法
function onClickTree(event, treeId, treeNode) {
var url = reqBasePath + "sys012?parentId=";
if(treeNode == undefined) {
url += "0"; //默认ID是1.
parentId = "";
} else {
url += treeNode.id; //动态获取选中节点的ID
parentId = treeNode.id;
}
AjaxPostUtil.request({url:url, params:"", type:'json', callback:function(jsonData){
if(jsonData.returnCode == 0){
var tree = $.fn.zTree.getZTreeObj(treeId);
if(!isNull(treeNode.children)){
while(treeNode.children.length > 0){
tree.removeNode(treeNode.children[0]);
}
}
if(jsonData.total != 0) {
if(treeNode == undefined) {
$.fn.zTree.getZTreeObj(treeId).addNodes(null, jsonData.rows, true);
} else {
$.fn.zTree.getZTreeObj(treeId).addNodes(treeNode, jsonData.rows, true); //这里注意,不要添加#
}
}
$.fn.zTree.getZTreeObj(treeId).expandAll(true);
loadTable();
}else{
top.winui.window.msg(jsonData.returnMessage, {icon: 2,time: 2000});
}
}});
loadTable();
}
/********* tree 处理 end *************/
......
layui.config({
base: basePath,
version: skyeyeVersion
}).define(['table', 'jquery', 'winui'], function (exports) {
}).define(['table', 'jquery', 'winui', 'fsCommon', 'fsTree'], function (exports) {
winui.renderColor();
layui.use(['form'], function (form) {
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
var $ = layui.$;
var parentId = "0";
form.render();
//菜单级别变化事件
form.on('radio(menuLevel)', function (data) {
var val = data.value;
if(val == '1'){//创世菜单
$("#parentIdBox").addClass("layui-hide");
}else if(val == '2'){
parentId = "0";
$("#lockParentSel").html("");
$("#parentIdBox").removeClass("layui-hide");
loadChildMenu();
}else{
top.winui.window.msg('状态值错误', {icon: 2,time: 2000});
}
});
//系统菜单同步
form.on('switch(isNecessary)', function (data) {
//同步开关值
$(data.elem).val(data.elem.checked);
});
form.on('select(selectParent)', function(data){
if(data.value != parentId){
if(isNull(data.value) || data.value == '请选择'){
layui.$(data.elem).parent('dd').nextAll().remove();
if(layui.$(data.elem).parent('dd').prev().children('select[class=menuParent]').length > 0){
parentId = layui.$(data.elem).parent('dd').prev().children('select[class=menuParent]')[0].value;
}else{
parentId = "0";
}
}else{
layui.$(data.elem).parent('dd').nextAll().remove();
parentId = data.value;
loadChildMenu();
}
}
});
form.on('submit(formAddMenu)', function (data) {
//表单验证
if (winui.verifyForm(data.elem)) {
var params = {
menuName: $("#menuName").val(),
titleName: $("#menuTitle").val(),
menuIcon: $("#menuIcon").val(),
menuUrl: $("#menuUrl").val(),
menuType: data.field.menuType
};
if(data.field.menuLevel == '1'){//创世菜单
params.parentId = '0';
}else if(data.field.menuLevel == '2'){//子菜单
var $menu = layui.$('.menuParent');
var str = "";
for(var i = 0; i < $menu.length; i++){
if(!isNull($menu[i].value) && $menu[i].value != '请选择'){
str += $menu[i].value + ",";
}
}
if(isNull(str)){//父菜单为空
top.winui.window.msg("请至少选择一级父菜单", {icon: 2,time: 2000});
return false;
}else{
params.parentId = str;
}
}else{
top.winui.window.msg('状态值错误', {icon: 2,time: 2000});
}
if($("#menuSysType").val() == 'true'){
params.menuSysType = '1';
}else{
params.menuSysType = '2';
}
AjaxPostUtil.request({url:reqBasePath + "sys007", params:params, type:'json', callback:function(json){
var $ = layui.$,
form = layui.form,
fsTree = layui.fsTree,
fsCommon = layui.fsCommon;
form.render();
form.on('submit(formAddMenu)', function (data) {
//表单验证
if (winui.verifyForm(data.elem)) {
var params = {
menuName: $("#menuName").val(),
titleName: $("#menuTitle").val(),
menuIcon: $("#menuIcon").val(),
menuUrl: $("#menuUrl").val(),
menuType: data.field.menuType
};
AjaxPostUtil.request({url:reqBasePath + "sys007", params:params, type:'json', callback:function(json){
if(json.returnCode == 0){
parent.layer.close(index);
parent.refreshCode = '0';
......@@ -91,43 +33,56 @@ layui.config({
top.winui.window.msg(json.returnMessage, {icon: 2,time: 2000});
}
}});
}
return false;
});
//加载同级菜单
function loadChildMenu(){
AjaxPostUtil.request({url:reqBasePath + "sys009", params:{parentId: parentId}, type:'json', callback:function(json){
if(json.returnCode == 0){
var str = '<dd><select class="menuParent" lay-filter="selectParent" lay-search=""><option value="">请选择</option>';
for(var i = 0; i < json.rows.length; i++){
str += '<option value="' + json.rows[i].id + '">' + json.rows[i].menuName + '---------' + getMenuLevelName(json.rows[i].menuLevel) + '</option>';
}
str += '</select></dd>';
$("#lockParentSel").append(str);
form.render('select');
}else{
top.winui.window.msg(json.returnMessage, {icon: 2,time: 2000});
}
}});
}
//获取菜单级别
function getMenuLevelName(level){
if(level == '0'){
return "创世菜单";
}else{
return level + "级子菜单";
}
}
//初始化加载隐藏创世菜单
$("#parentIdBox").addClass("layui-hide");
}
return false;
});
//取消
/********* tree 处理 start *************/
var trees = {};
var treeDoms = $("ul.fsTree");
if(treeDoms.length > 0) {
$(treeDoms).each(function(i) {
var treeId = $(this).attr("id");
var funcNo = $(this).attr("funcNo");
var url = $(this).attr("url");
var tree = fsTree.render({
id: treeId,
funcNo: funcNo,
url: url,
getTree: getTree,
checkEnable: true,
loadEnable: false
});
if(treeDoms.length == 1) {
trees[treeId] = tree;
} else {
//深度拷贝对象
trees[treeId] = $.extend(true, {}, tree);
}
});
//绑定按钮事件
fsCommon.buttonEvent("tree", getTree);
}
function getTree(treeId) {
if($.isEmpty(trees)) {
fsCommon.warnMsg("未配置tree!");
return;
}
if($.isEmpty(treeId)) {
treeId = "treeDemo";
}
return trees[treeId];
}
/********* tree 处理 end *************/
//取消
$("body").on("click", "#cancle", function(){
parent.layer.close(index);
});
});
});
\ No newline at end of file
......@@ -6,6 +6,8 @@
<link href="../../assets/lib/layui/css/layui.css" rel="stylesheet" />
<link href="../../assets/lib/font-awesome-4.7.0/css/font-awesome.css" rel="stylesheet" />
<link href="../../assets/lib/winui/css/winui.css" rel="stylesheet" />
<link href="../../assets/lib/layui/lay/modules/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
<link href="../../assets/lib/layui/lay/modules/contextMenu/jquery.contextMenu.min.css" rel="stylesheet" />
</head>
<body>
<div style="width:600px;margin:0 auto;padding-top:20px;">
......@@ -25,7 +27,7 @@
<div class="layui-form-item">
<label class="layui-form-label">权限分配</label>
<div class="layui-input-block winui-radio">
<ul id="treeDemo" class="ztree fsTree" method="get" isRoot="1" url="sys012"
<ul id="treeDemo" class="ztree fsTree" method="get" isRoot="1" url="sys014"
treeIdKey="id" inputs="parentId" treePIdKey="pId" clickCallbackInputs="parentId:$id" treeName="name"></ul>
</div>
</div>
......@@ -39,6 +41,9 @@
</div>
<script src="../../assets/lib/layui/layui.js"></script>
<script src="../../assets/lib/layui/custom.js"></script>
<script type="text/javascript" src="../../assets/lib/layui/lay/modules/jquery.min.js"></script>
<script type="text/javascript" src="../../assets/lib/layui/lay/modules/contextMenu/jquery.contextMenu.min.js"></script>
<script type="text/javascript" src="../../assets/lib/layui/lay/modules/ztree/js/jquery.ztree.all.min.js"></script>
<script type="text/javascript">
layui.config({base: '../../js/syseverole/'}).use('syseveroleadd');
</script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册