menuList.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <div id="menuList" class="plg-tab-container">
  2. <div id="menu" class="grid-container-full"></div>
  3. <div id="menuList_mywin" style="display: none;">
  4. <div id="menuList_g1"></div>
  5. <div class="ccf">
  6. <button class="layui-btn layui-btn-primary" data-event="delAuthorities">
  7. <i class="layui-icon layui-icon-down"></i>
  8. </button>
  9. <button class="layui-btn layui-btn-primary" data-event="addAuthorities">
  10. <i class="layui-icon layui-icon-up"></i>
  11. </button>
  12. </div>
  13. <div id="menuList_g2"></div>
  14. </div>
  15. <input id="menuId" type="hidden" />
  16. </div>
  17. <style type="text/css">
  18. #menuList_mywin{padding:15px;}
  19. #menuList_mywin .ccf{width: 100%;margin: 10px;}
  20. #menuList_mywin .b button{float:left;margin: 10px;}
  21. .layui-form-label{width:210px;}
  22. .layui-input{width:66%;}
  23. </style>
  24. <script type="text/javascript">
  25. (function(){
  26. var form=$("#menuList #form1");
  27. var grid1;
  28. var grid2;
  29. $("#menuList").on("click","button",function(e){
  30. e.preventDefault();
  31. e.stopPropagation();
  32. // if($(this).data("event")=="search"){
  33. // search();
  34. // }
  35. if($(this).data("event")=="delAuthorities"){
  36. delAuthorities();
  37. }
  38. if($(this).data("event")=="addAuthorities"){
  39. addAuthorities();
  40. }
  41. });
  42. window.menuList_aclick=aclick;
  43. window.menuList_update=update;
  44. window.menuList_del=del;
  45. var opts = {
  46. skin:"terrace",
  47. columns:[
  48. {id:"id",name:"id",type:'txt',hidden:true},
  49. {id:"name",name:"名称",type:'ro',width:200},
  50. {id:"numbers",name:"编号",type:'ro',width:200},
  51. {id:"parentId",name:"父节点",type:'ro',width:150},
  52. {id:"leaf",name:"是否子节点",type:'ro',width:150,render:function(v,d){if(v==0) return '否';if(v==1) return '是'}},
  53. {id:"type",name:"类型",type:'ro',width:150,render:function(v,d){if(v==0) return '菜单';if(v==1) return '按钮'}},
  54. {id:"systemId",name:"系统",type:'ro',width:150},
  55. {id:"op",name:"操作",type:'button',width:"*",render:function(){
  56. return "分配权限^menuList_aclick,修改^menuList_update,删除^menuList_del";
  57. }}
  58. ],
  59. toolbar:[
  60. {type:"combo", name:"systemId", label:"系统id:",offsetLeft:10},{type: "newcolumn"},
  61. {type:"button", name:"addBtn",className:"plg-toolbar-right",value:"<i class='layui-icon layui-icon-add-1'></i>添加"},{type: "newcolumn"},
  62. {type:"input", name:"name", label:"名称:",offsetLeft:10},{type: "newcolumn"},
  63. {type:"input", name:"numbers", label:"编号:",offsetLeft:10},{type: "newcolumn"},
  64. {type:"button", name:"searchBtn",width:50,className:"danger", value:"查询"},{type: "newcolumn"},
  65. {type:"button", name:"all",width:50, value:"所有"}
  66. ],
  67. formData:[
  68. {type:"settings",inputWidth :300,width:400,labelWidth:80,position:"label-left",labelAlign:"left"},
  69. {type: "hidden", name:"id", value:""},
  70. {type: "input", name: "name", label: '名称:'},
  71. {type: "input", name:"numbers", label:"编号:"},
  72. {type: "input", name:"parentId", label:"父节点:"},
  73. {type: "input", name:"systemId", label:"系统id:"},
  74. {type: "block", width: 380,offsetLeft:0,blockOffset:0,list:[
  75. {type: "label", label: "类型:",className:"normalfont"},{type: "newcolumn"},
  76. {type: "radio", name: "type", label: "菜单",value:0, checked: true, position:"label-right"},
  77. {type: "newcolumn"},
  78. {type: "radio", name: "type", label: "按钮",value:1, position:"label-right"}
  79. ]},
  80. {type: "block", width: 380,offsetLeft:0,blockOffset:0,list:[
  81. {type: "label", label: "是否子节点:",className:"normalfont"},{type: "newcolumn"},
  82. {type: "radio", name: "leaf", label: "是",value:true, checked: true, position:"label-right"},
  83. {type: "newcolumn"},
  84. {type: "radio", name: "leaf", label: "否",value:false, position:"label-right"}
  85. ]}
  86. ],
  87. pagebar:{
  88. buttons:[{text:"<i class='layui-icon layui-icon-delete '></i>删除",className:"layui-btn-danger",name:"delete"}]
  89. },
  90. url:"/api/service-user/menu",//数据接口
  91. type:"get",//数据提交方式,默认为get
  92. params:{pageNum:1,pageSize:10,name:"",numbers:""},//查询提交参数,分页参数默认为pageNum,pageSize
  93. multiselect:true,//是否支持多选
  94. page:true, //是否启用分页
  95. imagePath:"../../prologui/assets/PlgGrid/",
  96. totalCount:"totalCount" //总记录数字段,默认totalCount
  97.    };
  98. var menu = new PlgGrid(opts);
  99. menu.renderTo("menu");
  100. menu.loadData();
  101. menu.attachToolBarEvent("onButtonClick", function(name){
  102. if(name=="searchBtn"){
  103. var fdata = menu.getToolBarForm().getFormData();
  104. menu.setParams(fdata);
  105. menu.reload();
  106. }
  107. if(name=="all"){
  108. menu.setParams({pageNum:1,pageSize:10,name:"",numbers:""});
  109. menu.reload();
  110. }else if(name=="addBtn"){
  111. menuList_add();
  112. }
  113. });
  114. menu.attachPageBarEvent(function(name,ids){
  115. if(name=="delete"){
  116. if(ids==""){
  117. return;
  118. }
  119. PlgDialog.confirm('确定删除?', {
  120. title:'删除提示',
  121. btnAlign:'c',
  122. btn: ['确定', '取消'] //可以无限个按钮
  123. }, function(index, layero){
  124. $.ajax({
  125. url: '/api/service-user/menu/del/'+ids,
  126. type: 'delete',
  127. success:function (data) {
  128. PlgDialog.close(index);
  129. menu.reload();
  130. PlgDialog.msg(data.message);
  131. }
  132. });
  133. });
  134. }
  135. });
  136. function delAuthorities(){
  137. var id=grid1.getCheckedIds();
  138. var uid = $("#menuList #menuId").val();
  139. if(id==""){
  140. PlgDialog.msg('请选择一条数据',{
  141. zIndex:PlgDialog.zIndex
  142. });
  143. return false;
  144. }
  145. $.ajax({
  146. type: 'delete',
  147. url: "/api/service-user/menu/delMenuAndAuthorities?menuId="+uid+"&authorityIds="+id,
  148. async: true,
  149. success: function (data) {
  150. grid1.reload();
  151. grid2.reload();
  152. }
  153. });
  154. }
  155. function addAuthorities(){
  156. var id=grid2.getCheckedIds();
  157. var uid = $("#menuList #menuId").val();
  158. if(id==""){
  159. PlgDialog.msg('请选择一条数据',{
  160. zIndex:PlgDialog.zIndex
  161. });
  162. return false;
  163. }
  164. $.ajax({
  165. type: 'POST',
  166. url: "/api/service-user/menu/addMenuAndAuthorities",
  167. data: {menuId:uid,authorityIds:id},
  168. async: true,
  169. success: function (data) {
  170. // if (data.success == 1) {
  171. // location.replace("main");
  172. // } else if(data.success == 0){
  173. // PlgDialog.msg(data.msg);
  174. // }
  175. grid1.reload();
  176. grid2.reload();
  177. }
  178. });
  179. }
  180. function del(id){
  181. PlgDialog.confirm('确定删除?', {
  182. title:'删除提示',
  183. btnAlign:'c',
  184. btn: ['确定', '取消'] //可以无限个按钮
  185. }, function(index, layero){
  186. $.ajax({
  187. url: '/api/service-user/menu/'+id,
  188. type: 'delete',
  189. success:function (data) {
  190. PlgDialog.close(index);
  191. menu.reload();
  192. PlgDialog.msg(data.message);
  193. }
  194. });
  195. });
  196. }
  197. function aclick(menuId){
  198. $("#menuList #menuId").val(menuId);
  199. var index = PlgDialog.open({
  200. type: 1
  201. ,title: '分配权限'
  202. ,area: ['790px', '680px']
  203. ,shade: 0.5
  204. ,skin: 'layui-layer-lan'
  205. ,content: $("#menuList_mywin")
  206. ,closeBtn:1
  207. ,btn: []
  208. ,success: function(layero){
  209. var opts1 = {
  210. title:'已分配权限',
  211. columns:[
  212. {id:"id",name:"id",type:'txt',hidden:true},
  213. {id:"authorityNo",name:"权限编号",type:'ro',width:150},
  214. {id:"resources",name:"资源",type:'ro',width:200},
  215. {id:"systemId",name:"系统id",type:'ro',width:150},
  216. {id:"description",name:"描述",type:'ro',width:150}
  217. ],
  218. url:"/api/service-user/menu/getAuthorityListByMenuId?menuId="+menuId,//数据接口
  219. type:"get",//数据提交方式,默认为get
  220. params:{type:"1",pageNum:1,pageSize:10},//查询提交参数,分页参数默认为pageNum,pageSize
  221. page:true, //是否启用分页
  222. multiselect:true,//是否支持多选
  223. imagePath:"../../prologui/assets/PlgGrid/",
  224. totalCount:"totalCount" //总记录数字段,默认totalCount
  225.    };
  226. var opts2 = {
  227. title:'未分配权限',
  228. columns:[
  229. {id:"id",name:"id",type:'txt',hidden:true},
  230. {id:"authorityNo",name:"权限编号",type:'ro',width:150},
  231. {id:"resources",name:"资源",type:'ro',width:200},
  232. {id:"systemId",name:"系统id",type:'ro',width:150},
  233. {id:"description",name:"描述",type:'ro',width:150}
  234. ],
  235. url:"/api/service-user/menu/getAuthorityListByMenuId?menuId="+menuId,//数据接口
  236. type:"get",//数据提交方式,默认为get
  237. params:{type:"2",pageNum:1,pageSize:10},//查询提交参数,分页参数默认为pageNum,pageSize
  238. page:true, //是否启用分页
  239. multiselect:true,//是否支持多选
  240. imagePath:"../../prologui/assets/PlgGrid/",
  241. totalCount:"totalCount" //总记录数字段,默认totalCount
  242.    };
  243. grid1 =new PlgGrid(opts1);
  244. grid1.renderTo("menuList_g1");
  245. grid1.loadData();
  246. grid2 =new PlgGrid(opts2);
  247. grid2.renderTo("menuList_g2");
  248. grid2.loadData();
  249. }
  250. ,end:function(){
  251. $("#menuList_g1").empty();
  252. $("#menuList_g2").empty();
  253. $("#menuList_mywin").hide();
  254. }
  255. });
  256. }
  257. function menuList_add(){
  258. menu.showDialog(0,"添加",450,380,{url:"/api/service-user/menu",type:"post",contentType:"application/json"});
  259. }
  260. function update(id){
  261. $("#menuList #id").val(id);
  262. menu.selectRowById(id);
  263. menu.showDialog(1,"编辑",450,380,{url:"/api/service-user/menu",type:"put",contentType:"application/json"});
  264. }
  265. var f = menu.getToolBarForm();
  266. f.loadComboData("systemId",{url:'/api/service-user/system/getAllList',data:{},valueField:"systemId",textField:"systemId",method:"get"});
  267. })()
  268. </script>