resourcegroup.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <div id="resourcegroup" class="plg-tab-container">
  2. <div class="layui-carousel plg-bgc-transparent" id="resourcegroup-carousel1">
  3. <div carousel-item>
  4. <!--
  5. 作者:chenyongchao1027@163.com
  6. 时间:2018-11-29
  7. 描述:主页面
  8. -->
  9. <div class="layui-row layui-col-space5" id="plg-main-zone">
  10. <div class="layui-col-xs8">
  11. <div class="layui-card">
  12. <div class="layui-card-header">权限组</div>
  13. <div class="layui-card-body" style="height:calc(100vh - 167px);">
  14. <div id="resourcegroup-grid-1"></div>
  15. </div>
  16. </div>
  17. </div>
  18. <div class="layui-col-xs4">
  19. <div class="layui-card">
  20. <div class="layui-card-header">权限</div>
  21. <div class="layui-card-body" style="height:calc(100vh - 167px);">
  22. <div id="resourcegroup-grid-2"></div>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. <div>
  28. <blockquote class="layui-elem-quote layui-text plg-elem-quote" style="background:#fff;">
  29. 为权限组<span id="resourceGroupName" class="plg-mark">Plg</span>分配权限<a href="javascript:void(0)" style="margin-left: 15px;" id="resourcegroup_details_cancel">关闭</a>
  30. </blockquote>
  31. <div id="resourcegroup-resource-grid-1" style="height:500px;" class="layui-form">
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. <div>
  38. <script>
  39. (function () {
  40. // cSpell:ignore layui api resourcegroup sourcegroup sourcegroup closetting pagebar confire makesure multiselect newcolumn prologui fdata cindex layero
  41. var BASE_URL = '/api/service-authorization/group';
  42. var myf = null;
  43. var opts = {
  44. columns: [{
  45. id: "id",
  46. name: "id",
  47. type: 'ro',
  48. width: "50",
  49. hidden: true
  50. },
  51. {
  52. id: "name",
  53. name: "权限组名称",
  54. type: 'ed',
  55. width: "300"
  56. },
  57. {
  58. id: "description",
  59. name: "备注",
  60. type: 'ed',
  61. width: "*"
  62. },
  63. {id:"op",name:"操作",type:'button',align:"center",width:"150",render:function(v,record){
  64. return "选择权限^resourcegroup_detailClick";
  65. }}
  66. ],
  67. multiselect: false,
  68. toolbar: [
  69. {
  70. type: "button",
  71. name: "deleteBtn",
  72. className: "danger plg-toolbar-right",
  73. value: "<i class='layui-icon layui-icon-delete'></i>删除"
  74. }, {
  75. type: "newcolumn"
  76. },
  77. {
  78. type: "button",
  79. name: "updateBtn",
  80. className: "normal plg-toolbar-right",
  81. value: "<i class='layui-icon layui-icon-edit'></i>修改"
  82. }, {
  83. type: "newcolumn"
  84. },
  85. {
  86. type: "button",
  87. name: "addBtn",
  88. offsetLeft: 10,
  89. className: "plg-toolbar-right",
  90. value: "<i class='layui-icon layui-icon-add-1'></i>添加"
  91. }, {
  92. type: "newcolumn"
  93. },
  94. {
  95. type: "input",
  96. name: 'name',
  97. label: '权限组名称:',
  98. width:300,
  99. placeholder:'请输入权限组名称'
  100. }, {
  101. type: "newcolumn"
  102. },
  103. {
  104. type: "button",
  105. name: "searchBtn",
  106. value: "查询"
  107. }, {
  108. type: "newcolumn"
  109. },
  110. {
  111. type: "button",
  112. name: "all",
  113. className:'normal',
  114. value: "所有"
  115. }, {
  116. type: "newcolumn"
  117. }
  118. ],
  119. formData: [{
  120. type: "settings",
  121. inputWidth: 300,
  122. width: 400,
  123. labelWidth: 80,
  124. position: "label-left",
  125. labelAlign: "left"
  126. },
  127. {
  128. type: "hidden",
  129. name: "_method",
  130. value: "put"
  131. },
  132. {
  133. type: "hidden",
  134. name: "id",
  135. value: ""
  136. },
  137. {
  138. type: "input",
  139. name: 'name',
  140. label: '权限组名称:',
  141. placeholder: '请输入权限组名称',
  142. editable: false,
  143. validate: 'NotEmpty',
  144. required: true
  145. },
  146. {
  147. type: "hidden",
  148. name: 'resourceIds',
  149. value:" "
  150. },
  151. {
  152. type: "input",
  153. name: "description",
  154. label: "备注:",
  155. rows: 3,
  156. validate: 'NotEmpty',
  157. required: true,
  158. note: {text:"请尽可能以功能来命名"}
  159. }
  160. ],
  161. imagePath: "../../prologui/assets/PlgGrid",
  162. url: BASE_URL, //数据接口
  163. type: "get", //数据提交方式,默认为get
  164. //filters:["#text_filter", "#select_filter","#numeric_filter","#text_filter","#text_filter"],
  165. pagebar: {
  166. type: 'full' //full simple
  167. },
  168. params: {
  169. pageSize: 20,
  170. pageNum: 1
  171. }, //查询提交参数,分页参数默认为pageNum,pageSize
  172. page: true, //是否启用分页
  173. pageNum: "pageNum", //设置分页参数页码key值,默认为pageNum
  174. totalCount: "totalCount" //总记录数字段,默认totalCount
  175. };
  176. var sourcegroup = new PlgGrid(opts);
  177. sourcegroup.renderTo("resourcegroup-grid-1");
  178. sourcegroup.loadData();
  179. sourcegroup.attachToolBarEvent("onButtonClick", function (name) {
  180. function deleteData() {
  181. var cindex = layer.confirm('确认要删除选中记录吗?', {
  182. title: "",
  183. btn: ['确认删除', '取消'] //可以无限个按钮
  184. }, function (index, layero) {
  185. var loading = PlgDialog.load();
  186. Prolog.ajax({
  187. url: BASE_URL+'/delete',
  188. data: {
  189. id: sourcegroup.getSelectedRowId()
  190. },
  191. type: "POST",
  192. success: function (data) {
  193. if (data.success) {
  194. sourcegroup.reload();
  195. } else {
  196. layer.msg(data.message);
  197. }
  198. PlgDialog.close(loading);
  199. PlgDialog.close(index);
  200. },
  201. error: function () {
  202. PlgDialog.close(loading);
  203. PlgDialog.close(index);
  204. }
  205. });
  206. }, function () {PlgDialog.close(index);});
  207. }
  208. var operationGroup = {
  209. searchBtn: function () {
  210. var fdata = sourcegroup.getToolBarForm().getFormData();
  211. sourcegroup.setParams(fdata);
  212. sourcegroup.reload();
  213. },
  214. all: function () {
  215. sourcegroup.getToolBarForm().clear();
  216. sourcegroup.setParams({});
  217. sourcegroup.reload();
  218. },
  219. addBtn: function () {
  220. //console.log('添加权限组');
  221. sourcegroup.showDialog(0, "添加", 430, 270, {
  222. url: BASE_URL+'/add',
  223. type: "post"
  224. });
  225. var gform = sourcegroup.getGridForm();
  226. gform.setItemValue("_method","post");
  227. },
  228. updateBtn: function () {
  229. sourcegroup.showDialog(1, "编辑", 430, 350, {
  230. url: BASE_URL+'/update',
  231. type: "post"
  232. });
  233. },
  234. deleteBtn: function () {
  235. deleteData();
  236. },
  237. columns: function () {
  238. sourcegroup.showColsSettingDialog(".closetting");
  239. }
  240. }
  241. if (name && operationGroup.hasOwnProperty(name)) {
  242. operationGroup[name]();
  243. }
  244. })
  245. // window.resource_editClick = function (rid, data) {
  246. // ////console.log(JSON.stringify(data));
  247. // sourcegroup.selectRowById(rid);
  248. // sourcegroup.showDialog(1, "编辑", 430, 350, {
  249. // url: BASE_URL,
  250. // type: "put"
  251. // });
  252. // return false;
  253. // }
  254. //window.resource_deleteClick = deleteData;
  255. //权限
  256. var list_options={
  257. columns:[
  258. {id:"id",name:"序列",hidden:true},
  259. {id:"serviceName",name:"服务名"},
  260. {id:"resource",name:"权限"}
  261. ],
  262. page:true,
  263. filters:["","#select_filter","#text_filter"],
  264. pagebar:{
  265. type:'simple' //full simple min
  266. },
  267. imagePath:"../codebase/images/",
  268. toolbar:[]
  269. };
  270. var plgList = $("#resourcegroup-grid-2").initPlgGrid(list_options);
  271. //plgList.loadData();
  272. sourcegroup.on("onRowSelect",function(id){
  273. var rids = sourcegroup.getSelectedRowData()["resourceIds"];
  274. if(!rids){
  275. return;
  276. }
  277. console.log("tttt",rids);
  278. var res = rids.split(",");
  279. var ay = new Array();
  280. for(var i=0;i<res.length;i++){
  281. var data ={};
  282. var tp = res[i];
  283. data["id"] = i+1;
  284. data["serviceName"] = tp.substring(0,tp.indexOf(":"));
  285. data["resource"] = tp.substring(tp.indexOf(":")+1);
  286. ay.push(data);
  287. }
  288. plgList.setParams({pageSize: res.length,pageNum:1});
  289. plgList.reload({"success":true,"message":"","data":{"list":ay,"totalCount":res.length}});
  290. });
  291. var tt = "add";
  292. function changePanel(){
  293. car.slide(tt);
  294. tt = tt=="sub"?"add":"sub";
  295. }
  296. $("#resourcegroup").on("click", "#resourcegroup_details_cancel", function(){
  297. //console.log('监听返回');
  298. sourcegroup.reload();
  299. changePanel();
  300. });
  301. window.resourcegroup_detailClick = function(id,data){
  302. sourcegroup.selectRowById(id);
  303. changePanel();
  304. var selectData = sourcegroup.getSelectedRowData();
  305. initResourcGrid(selectData);
  306. $('#resourceGroupName').html(selectData.name);
  307. }
  308. var carousel = layui.carousel;
  309. var car = carousel.render({
  310. elem: '#resourcegroup-carousel1',
  311. autoplay:false,
  312. index:0,
  313. arrow:'none',
  314. indicator:'none',
  315. anim:"updown",
  316. width: '100%', //设置容器宽度
  317. height:'100%'
  318. });
  319. function initResourcGrid(selectData){
  320. var opts00 = {
  321. //title:"权限管理",
  322. columns:[
  323. {id:"id",name:"id",type:'ro',width:"50",hidden:true},
  324. {id:"op",name:"选择",width:"90",type:"ro",align:"center",render:function(v,record){
  325. // 选中的数据格式 001,002,20181203002test:002
  326. var rids = selectData["resourceIds"];
  327. var checked = '';
  328. if(rids && rids.indexOf(record["id"])>-1){
  329. checked = 'checked=""';
  330. }
  331. return '<input type="checkbox" lay-filter="op" '+ checked +' value="'+(record["id"])+'" lay-skin="switch" lay-text="ON|OFF">';
  332. }},
  333. {id:"serviceName",name:"服务名",type:'ed',width:"200"},
  334. {id:"authNumber",name:"权限编号",type:'ed',width:"200"},
  335. {id:"source",name:"资源地址",type:'ed',width:"100"},
  336. {id:"method",name:"提交方式",type:'ed',width:"100"},
  337. {id:"notes",name:"备注",type:'ed',width:"*"}
  338. ],
  339. multiselect:false,
  340. toolbar:[
  341. {type: "settings", labelAlign:'left', labelWidth: 65},
  342. {type:"block",id:"bk",blockOffset:0,list:[
  343. {type: "input", name: 'serviceName', label: '服务名称:',offsetLeft:5,placeholder:'请输入服务名称', width:300},{type: "newcolumn"},
  344. {type:"input", name:"authNumber", label:"权限编号:",offsetLeft:10,placeholder:'请输入权限编号', width:300},{type: "newcolumn"},
  345. {type:"input", name:"source", label:"资源地址:",offsetLeft:10,placeholder:'请输入资源地址', width:300,hidden:true},{type: "newcolumn"},
  346. {type:"button", name:"searchBtn", value:"查询"}, {type: "newcolumn"},
  347. {type:"button", name:"all", value:"重置",className:"normal"},{type: "newcolumn"},
  348. {type:"button", name:"more2", value:"展开",className:"link toggle"}
  349. ]}
  350. ],
  351. imagePath:"../../prologui/assets/PlgGrid",
  352. url:"/api/service-authorization/resource/list",//数据接口
  353. type:"get",//数据提交方式,默认为get
  354. pagebar:{
  355. type:'full' //full simple min
  356. },
  357. params:{pageSize:10,pageNum:1},//查询提交参数,分页参数默认为pageNum,pageSize
  358. page:true, //是否启用分页
  359. pageNum:"pageNum",//设置分页参数页码key值,默认为pageNum
  360. totalCount:"totalCount" //总记录数字段,默认totalCount
  361.    };
  362. var augrid00 = new PlgGrid(opts00);
  363. augrid00.renderTo("resourcegroup-resource-grid-1");
  364. augrid00.loadData(null,function(){
  365. form.render();
  366. });
  367. augrid00.attachToolBarEvent("onButtonClick",function(name){
  368. if(name=="searchBtn"){
  369. var fdata = augrid00.getToolBarForm().getFormData();
  370. augrid00.setParams(fdata);
  371. augrid00.reload();
  372. }
  373. });
  374. }
  375. var form = layui.form;
  376. form.on('switch(op)', function(data){
  377. var sid = sourcegroup.getSelectedRowId();
  378. // //console.log('sid::' + sid);
  379. //console.log(data);
  380. if(data.elem.checked){
  381. var ld = PlgDialog.load();
  382. Prolog.ajax({
  383. url:"/api/service-authorization/group/recources/add",
  384. type:"post",
  385. data:{"id":sid,"resourceIds":data.value},
  386. success:function(da){
  387. PlgDialog.close(ld);
  388. if(!da.success){
  389. PlgDialog.alert("操作失败,"+da.message);
  390. }
  391. },
  392. error:function(){
  393. PlgDialog.close(ld);
  394. }
  395. });
  396. ////console.log(data.value); //开关value值,也可以通过data.elem.value得到
  397. }else{
  398. var ld = PlgDialog.load();
  399. Prolog.ajax({
  400. url:"/api/service-authorization/service-resource/resourcegroup/"+sid+"/removeresource ",
  401. type:"post",
  402. data:{"resource":data.value},
  403. success:function(da){
  404. PlgDialog.close(ld);
  405. if(!da.success){
  406. PlgDialog.alert("操作失败,"+da.message);
  407. }
  408. },
  409. error:function(){
  410. PlgDialog.close(ld);
  411. }
  412. });
  413. }
  414. });
  415. }());
  416. </script>
  417. </div>