123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <div id="menuList" class="plg-tab-container">
- <div id="menu" class="grid-container-full"></div>
-
- <div id="menuList_mywin" style="display: none;">
- <div id="menuList_g1"></div>
- <div class="ccf">
- <button class="layui-btn layui-btn-primary" data-event="delAuthorities">
- <i class="layui-icon layui-icon-down"></i>
- </button>
- <button class="layui-btn layui-btn-primary" data-event="addAuthorities">
- <i class="layui-icon layui-icon-up"></i>
- </button>
- </div>
- <div id="menuList_g2"></div>
- </div>
- <input id="menuId" type="hidden" />
- </div>
- <style type="text/css">
- #menuList_mywin{padding:15px;}
- #menuList_mywin .ccf{width: 100%;margin: 10px;}
- #menuList_mywin .b button{float:left;margin: 10px;}
- .layui-form-label{width:210px;}
- .layui-input{width:66%;}
- </style>
-
- <script type="text/javascript">
- (function(){
- var form=$("#menuList #form1");
- var grid1;
- var grid2;
-
- $("#menuList").on("click","button",function(e){
- e.preventDefault();
- e.stopPropagation();
- // if($(this).data("event")=="search"){
- // search();
- // }
- if($(this).data("event")=="delAuthorities"){
- delAuthorities();
- }
- if($(this).data("event")=="addAuthorities"){
- addAuthorities();
- }
- });
-
- window.menuList_aclick=aclick;
- window.menuList_update=update;
- window.menuList_del=del;
-
- var opts = {
- skin:"terrace",
- columns:[
- {id:"id",name:"id",type:'txt',hidden:true},
- {id:"name",name:"名称",type:'ro',width:200},
- {id:"numbers",name:"编号",type:'ro',width:200},
- {id:"parentId",name:"父节点",type:'ro',width:150},
- {id:"leaf",name:"是否子节点",type:'ro',width:150,render:function(v,d){if(v==0) return '否';if(v==1) return '是'}},
- {id:"type",name:"类型",type:'ro',width:150,render:function(v,d){if(v==0) return '菜单';if(v==1) return '按钮'}},
- {id:"systemId",name:"系统",type:'ro',width:150},
- {id:"op",name:"操作",type:'button',width:"*",render:function(){
- return "分配权限^menuList_aclick,修改^menuList_update,删除^menuList_del";
- }}
- ],
- toolbar:[
- {type:"combo", name:"systemId", label:"系统id:",offsetLeft:10},{type: "newcolumn"},
- {type:"button", name:"addBtn",className:"plg-toolbar-right",value:"<i class='layui-icon layui-icon-add-1'></i>添加"},{type: "newcolumn"},
- {type:"input", name:"name", label:"名称:",offsetLeft:10},{type: "newcolumn"},
- {type:"input", name:"numbers", label:"编号:",offsetLeft:10},{type: "newcolumn"},
- {type:"button", name:"searchBtn",width:50,className:"danger", value:"查询"},{type: "newcolumn"},
- {type:"button", name:"all",width:50, value:"所有"}
- ],
- formData:[
- {type:"settings",inputWidth :300,width:400,labelWidth:80,position:"label-left",labelAlign:"left"},
- {type: "hidden", name:"id", value:""},
- {type: "input", name: "name", label: '名称:'},
- {type: "input", name:"numbers", label:"编号:"},
- {type: "input", name:"parentId", label:"父节点:"},
- {type: "input", name:"systemId", label:"系统id:"},
- {type: "block", width: 380,offsetLeft:0,blockOffset:0,list:[
- {type: "label", label: "类型:",className:"normalfont"},{type: "newcolumn"},
- {type: "radio", name: "type", label: "菜单",value:0, checked: true, position:"label-right"},
- {type: "newcolumn"},
- {type: "radio", name: "type", label: "按钮",value:1, position:"label-right"}
- ]},
- {type: "block", width: 380,offsetLeft:0,blockOffset:0,list:[
- {type: "label", label: "是否子节点:",className:"normalfont"},{type: "newcolumn"},
- {type: "radio", name: "leaf", label: "是",value:true, checked: true, position:"label-right"},
- {type: "newcolumn"},
- {type: "radio", name: "leaf", label: "否",value:false, position:"label-right"}
- ]}
- ],
- pagebar:{
- buttons:[{text:"<i class='layui-icon layui-icon-delete '></i>删除",className:"layui-btn-danger",name:"delete"}]
- },
- url:"/api/service-user/menu",//数据接口
- type:"get",//数据提交方式,默认为get
- params:{pageNum:1,pageSize:10,name:"",numbers:""},//查询提交参数,分页参数默认为pageNum,pageSize
- multiselect:true,//是否支持多选
- page:true, //是否启用分页
- imagePath:"../../prologui/assets/PlgGrid/",
- totalCount:"totalCount" //总记录数字段,默认totalCount
- };
- var menu = new PlgGrid(opts);
- menu.renderTo("menu");
- menu.loadData();
-
- menu.attachToolBarEvent("onButtonClick", function(name){
- if(name=="searchBtn"){
- var fdata = menu.getToolBarForm().getFormData();
- menu.setParams(fdata);
- menu.reload();
- }
- if(name=="all"){
- menu.setParams({pageNum:1,pageSize:10,name:"",numbers:""});
- menu.reload();
- }else if(name=="addBtn"){
- menuList_add();
- }
- });
-
- menu.attachPageBarEvent(function(name,ids){
- if(name=="delete"){
- if(ids==""){
- return;
- }
- PlgDialog.confirm('确定删除?', {
- title:'删除提示',
- btnAlign:'c',
- btn: ['确定', '取消'] //可以无限个按钮
- }, function(index, layero){
- $.ajax({
- url: '/api/service-user/menu/del/'+ids,
- type: 'delete',
- success:function (data) {
- PlgDialog.close(index);
- menu.reload();
- PlgDialog.msg(data.message);
- }
- });
- });
- }
- });
-
- function delAuthorities(){
- var id=grid1.getCheckedIds();
- var uid = $("#menuList #menuId").val();
- if(id==""){
- PlgDialog.msg('请选择一条数据',{
- zIndex:PlgDialog.zIndex
- });
- return false;
- }
- $.ajax({
- type: 'delete',
- url: "/api/service-user/menu/delMenuAndAuthorities?menuId="+uid+"&authorityIds="+id,
- async: true,
- success: function (data) {
- grid1.reload();
- grid2.reload();
- }
- });
- }
-
- function addAuthorities(){
- var id=grid2.getCheckedIds();
- var uid = $("#menuList #menuId").val();
- if(id==""){
- PlgDialog.msg('请选择一条数据',{
- zIndex:PlgDialog.zIndex
- });
- return false;
- }
- $.ajax({
- type: 'POST',
- url: "/api/service-user/menu/addMenuAndAuthorities",
- data: {menuId:uid,authorityIds:id},
- async: true,
- success: function (data) {
- // if (data.success == 1) {
- // location.replace("main");
- // } else if(data.success == 0){
- // PlgDialog.msg(data.msg);
- // }
- grid1.reload();
- grid2.reload();
- }
- });
- }
-
- function del(id){
- PlgDialog.confirm('确定删除?', {
- title:'删除提示',
- btnAlign:'c',
- btn: ['确定', '取消'] //可以无限个按钮
- }, function(index, layero){
- $.ajax({
- url: '/api/service-user/menu/'+id,
- type: 'delete',
- success:function (data) {
- PlgDialog.close(index);
- menu.reload();
- PlgDialog.msg(data.message);
- }
- });
- });
- }
-
- function aclick(menuId){
- $("#menuList #menuId").val(menuId);
- var index = PlgDialog.open({
- type: 1
- ,title: '分配权限'
- ,area: ['790px', '680px']
- ,shade: 0.5
- ,skin: 'layui-layer-lan'
- ,content: $("#menuList_mywin")
- ,closeBtn:1
- ,btn: []
- ,success: function(layero){
- var opts1 = {
- title:'已分配权限',
- columns:[
- {id:"id",name:"id",type:'txt',hidden:true},
- {id:"authorityNo",name:"权限编号",type:'ro',width:150},
- {id:"resources",name:"资源",type:'ro',width:200},
- {id:"systemId",name:"系统id",type:'ro',width:150},
- {id:"description",name:"描述",type:'ro',width:150}
- ],
- url:"/api/service-user/menu/getAuthorityListByMenuId?menuId="+menuId,//数据接口
- type:"get",//数据提交方式,默认为get
- params:{type:"1",pageNum:1,pageSize:10},//查询提交参数,分页参数默认为pageNum,pageSize
- page:true, //是否启用分页
- multiselect:true,//是否支持多选
- imagePath:"../../prologui/assets/PlgGrid/",
- totalCount:"totalCount" //总记录数字段,默认totalCount
- };
- var opts2 = {
- title:'未分配权限',
- columns:[
- {id:"id",name:"id",type:'txt',hidden:true},
- {id:"authorityNo",name:"权限编号",type:'ro',width:150},
- {id:"resources",name:"资源",type:'ro',width:200},
- {id:"systemId",name:"系统id",type:'ro',width:150},
- {id:"description",name:"描述",type:'ro',width:150}
- ],
- url:"/api/service-user/menu/getAuthorityListByMenuId?menuId="+menuId,//数据接口
- type:"get",//数据提交方式,默认为get
- params:{type:"2",pageNum:1,pageSize:10},//查询提交参数,分页参数默认为pageNum,pageSize
- page:true, //是否启用分页
- multiselect:true,//是否支持多选
- imagePath:"../../prologui/assets/PlgGrid/",
- totalCount:"totalCount" //总记录数字段,默认totalCount
- };
- grid1 =new PlgGrid(opts1);
- grid1.renderTo("menuList_g1");
- grid1.loadData();
- grid2 =new PlgGrid(opts2);
- grid2.renderTo("menuList_g2");
- grid2.loadData();
- }
- ,end:function(){
- $("#menuList_g1").empty();
- $("#menuList_g2").empty();
- $("#menuList_mywin").hide();
-
- }
- });
- }
-
- function menuList_add(){
- menu.showDialog(0,"添加",450,380,{url:"/api/service-user/menu",type:"post",contentType:"application/json"});
- }
-
- function update(id){
- $("#menuList #id").val(id);
- menu.selectRowById(id);
- menu.showDialog(1,"编辑",450,380,{url:"/api/service-user/menu",type:"put",contentType:"application/json"});
- }
- var f = menu.getToolBarForm();
- f.loadComboData("systemId",{url:'/api/service-user/system/getAllList',data:{},valueField:"systemId",textField:"systemId",method:"get"});
-
- })()
- </script>
|