roleGroupList.html 10 KB

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