groupResource.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <div class="plg-tab-container ">
  2. <div class="plg-flex" style="height: 100%">
  3. <div class="layui-card plg-flex-item" style="flex: 0 0 auto;width: 33vw;">
  4. <div class="layui-card-header">资源组列表</div>
  5. <div class="layui-card-body" style="height: calc(100% - 0.42rem);">
  6. <div id="group_list"></div>
  7. </div>
  8. </div>
  9. <div class="layui-card plg-flex-item">
  10. <div class="layui-card-header">分配资源信息</div>
  11. <div class="layui-card-body plg-flex" style="height: calc(100% - 0.42rem); overflow: auto;">
  12. <div id="notGrouplist" class="plg-flex-item" style="flex:1; height: 100%"></div>
  13. <div class="plg-flex-item" style="height: 100%; flex: 0 0 auto;width:50px;">
  14. <div class="btnForm">
  15. <a id="notGroupListBtn" href="javascript:void(0)" class="disable">
  16. <i class="layui-icon layui-icon-right"></i>
  17. </a>
  18. <a id="GroupListBtn" href="javascript:void(0)" class="disable">
  19. <i class="layui-icon layui-icon-left"></i>
  20. </a>
  21. </div>
  22. </div>
  23. <div id="Grouplist" class="plg-flex-item" style="flex:1;height: 100%;"></div>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. <style>
  29. </style>
  30. <script>
  31. (function () {
  32. window.global_fun.groupResource = {};
  33. var res_opts = {
  34. fixedLast: true,
  35. renderer: "group_list",
  36. url: APIS.groupResource.getList(),
  37. type: "get",
  38. formDataArea: [430, 250]
  39. //pageNum: "pageNo",//设置分页参数页码key值,默认为pageNum
  40. };
  41. res_opts.columns = [
  42. {
  43. name: "id",
  44. id: "id",
  45. hidden: true
  46. },
  47. {
  48. name: "资源组",
  49. id: "name",
  50. align: "left",
  51. type: "ro"
  52. },
  53. {
  54. name: "说明",
  55. id: "notes",
  56. align: "left",
  57. type: "ro"
  58. },
  59. {
  60. id: "op",
  61. name: "操作",
  62. type: 'button',
  63. width: "120",
  64. align: "center",
  65. render: function (v, d) {
  66. return '修改^global_fun.groupResource.editClick,删除^global_fun.groupResource.deleteClick';
  67. }
  68. }
  69. ];
  70. res_opts.toolbar = [{
  71. type: 'row',
  72. blockOffset: 0,
  73. className: "layui-col-md12",
  74. list: [
  75. {
  76. type: "row",
  77. className: "layui-col-md7",
  78. blockOffset: 0,
  79. list: [{
  80. className: "layui-col-md8",
  81. type: "input",
  82. name: "likeMap",
  83. label: "",
  84. placeholder: "服务名/地址"
  85. },
  86. {
  87. type: "button",
  88. className: "left",
  89. name: "selectAllBtn",
  90. value: PLG_BUTTON.value.searchBtn()
  91. },
  92. ]
  93. },
  94. {
  95. type: "block",
  96. className: "layui-col-md5 right",
  97. blockOffset: 0,
  98. list: [
  99. {
  100. type: "button",
  101. name: "addBtn",
  102. value: PLG_BUTTON.value.addBtn()
  103. },
  104. {
  105. type: "newcolumn"
  106. },
  107. {
  108. type: "button",
  109. name: "delBtn",
  110. className: "danger",
  111. value: PLG_BUTTON.value.alldelBtn(),
  112. disabled: true
  113. }
  114. ]
  115. }]
  116. }];
  117. res_opts.formData = [{
  118. type: "row",
  119. list: [{
  120. type: "settings",
  121. labelWidth: 90,
  122. position: "label-left",
  123. labelAlign: "right"
  124. },
  125. {
  126. type: "hidden",
  127. name: "id",
  128. label: "id",
  129. value: 0,
  130. },
  131. {
  132. type: "input",
  133. name: "name",
  134. label: "资源组",
  135. // disable:true,
  136. required: true,
  137. validate: 'NotEmpty',
  138. placeholder: _t("请输入资源组名称")
  139. },
  140. { type: "input", name: "notes", validate: 'NotEmpty', required: true, label: "说明:", rows: 3, labelTop: -20, placeholder: "请填写这个服务是干什么用的" }
  141. ]
  142. }
  143. ]
  144. var res_inst = new GridPlant({
  145. instance: new PlgGrid(setConfig(res_opts)).loadData(),
  146. addBtnUrl: APIS.groupResource.groupAdd(),
  147. editBtnUrl: APIS.groupResource.update(),
  148. delBtnUrl: APIS.groupResource.groupDelete(),
  149. downBtnUrl: APIS.resource.download(),
  150. importBtnUrl: APIS.resource.import(),
  151. }).init();
  152. res_inst.delBtn = function (paramsObj = { ids: res_inst.idS }) {
  153. res_inst.formatForm(3, "POST", _t("是否删除数据"), res_inst.delBtnUrl, paramsObj)
  154. };
  155. res_inst.selectAllBtnAfter(function (obj) {
  156. var likeMap = res_inst.PlgGridInstance.getToolBarForm().getItemValue("likeMap");
  157. obj.name = likeMap
  158. obj.notes = likeMap
  159. delete obj.likeMap
  160. })
  161. //单击行分配资源
  162. res_inst.PlgGridInstance.on("onRowSelect",function(id){
  163. res_inst.PlgGridInstance.selectRowById(id);
  164. notGroupList.url = APIS.resource.listnotingroup(),
  165. notGroupList.params.groupId =id;
  166. notGroupList.listReload();
  167. GroupList.url = APIS.resource.listbygroup();
  168. GroupList.params.groupId =id;
  169. GroupList.listReload();
  170. })
  171. res_inst.editBtnAfter(function (dform) {
  172. dform.disableItem("name")
  173. });
  174. window.global_fun.groupResource.deleteClick = function () {
  175. res_inst.PlgGridInstance.selectRowById(arguments[0]);
  176. res_inst.delBtn()
  177. };
  178. window.global_fun.groupResource.editClick = function () {
  179. res_inst.PlgGridInstance.selectRowById(arguments[0]);
  180. res_inst.editBtn();
  181. };
  182. //分配资源给资源组方法
  183. function addResByGroup(url, ids, resIds) {
  184. Prolog.ajax({
  185. url: url,
  186. type: "post",
  187. data: {
  188. id: ids,
  189. resourceIds: resIds
  190. },
  191. success: function (resource) {
  192. if (resource.success) {
  193. PlgDialog.msg("分配成功");
  194. GroupList.listReload();
  195. notGroupList.listReload();
  196. } else {
  197. PlgDialog.msg(resource.message);
  198. }
  199. }
  200. })
  201. }
  202. var notGroupOpts = {
  203. renderer: "notGrouplist",
  204. skin: 2,
  205. className: "flex_panel",
  206. header: {
  207. isShow: true,
  208. title: "未分配资源",
  209. },
  210. // defaultBody: `<div id="listFrom_A"></div>`,
  211. //page: true,
  212. // url: APIS.resource.getList(),
  213. toolbar: [{
  214. type: "row",
  215. name: "tool",
  216. list: [
  217. {
  218. type: "row",
  219. className: "layui-col-md12",
  220. list: [
  221. {
  222. className: "layui-col-md7",
  223. type: "input",
  224. name: "likeMap",
  225. placeholder: "服务名/地址",
  226. },
  227. {
  228. type: "button",
  229. className: "left",
  230. name: "selectAllBtn",
  231. value: PLG_BUTTON.value.searchBtn(),
  232. },
  233. {
  234. type: "checkbox",
  235. className: "right",
  236. name: "isAll",
  237. labelWidth: "auto",
  238. labelAlign: "left",
  239. position: "label-right",
  240. label: "全选",
  241. disabled: true
  242. }
  243. ]
  244. }
  245. ]
  246. }],
  247. listFormData: [{
  248. type: "row",
  249. name: "res_panel_notgroup",
  250. list: [
  251. {
  252. name: "notData",
  253. type: "template",
  254. className: "layui-col-md12 ",
  255. format: function () {
  256. return `<span>暂无数据</span>`
  257. }
  258. }
  259. ]
  260. }
  261. ]
  262. }
  263. var GroupOpts = Object.assign({}, notGroupOpts, {
  264. renderer: "Grouplist",
  265. skin: 1,
  266. header: {
  267. isShow: true,
  268. title: "已分配资源",
  269. },
  270. });
  271. var notGroupList = new PlgPanel(notGroupOpts);
  272. var GroupList = new PlgPanel(GroupOpts);
  273. notGroupList.groupBtn = document.getElementById("notGroupListBtn");
  274. notGroupList.groupBtnText = "添加资源";
  275. notGroupList.resUrl = APIS.groupResource.addRes();
  276. GroupList.groupBtn = document.getElementById("GroupListBtn");
  277. GroupList.groupBtnText = "删除资源";
  278. GroupList.resUrl = APIS.groupResource.removeRes();
  279. var grouparr = [notGroupList, GroupList];
  280. grouparr.forEach(function (groupitem) {
  281. //请求列表数据的回掉
  282. groupitem.done(function (self, data) {
  283. if (data.list.length > 0) {
  284. self.getListForm.hideItem("notData");
  285. self.getToolbar.getDForm().uncheckItem("isAll");
  286. self.page = true;
  287. self.getToolbar.enableItem("isAll");
  288. data.list.forEach(function (item) {
  289. self.getListForm.getDForm().addItem("res_panel_notgroup",
  290. {
  291. type: "row",
  292. className: "layui-col-md12 accr_list",
  293. list: [
  294. {
  295. className: "layui-col-md7 lab-bold",
  296. name: "_check-" + item.id,
  297. type: "checkbox",
  298. labelWidth: "auto",
  299. labelAlign: "left",
  300. position: "label-right",
  301. label: item.serviceName,
  302. },
  303. {
  304. className: "layui-col-md3",
  305. name: "model",
  306. type: "template",
  307. value: item.method,
  308. style: "text-align: center"
  309. },
  310. {
  311. className: "right link layui-col-md2",
  312. type: "button",
  313. value: groupitem.groupBtnText,
  314. name: "id-" + item.id
  315. },
  316. {
  317. className: "layui-col-md12 color-999 mt-10",
  318. type: "template",
  319. value: item.source,
  320. }
  321. ]
  322. })
  323. });
  324. return setEventList(groupitem)
  325. }
  326. self.page = false;
  327. self.getToolbar.disableItem("isAll");
  328. });
  329. groupitem.getToolbar.on("onButtonClick", function (name) {
  330. if (name == "selectAllBtn") {
  331. var linkMap = groupitem.getToolbar.getItemValue("likeMap");
  332. groupitem.listReload({ serviceName: linkMap, source: linkMap, method: linkMap })
  333. }
  334. });
  335. groupitem.getToolbar.on("onChange", function (name) {
  336. if (name == "isAll") {
  337. this.checkIds = [];
  338. this.getListForm.forEachItem(function (names) {
  339. if (names.indexOf("_check") !== -1) {
  340. if (this.getToolbar.getDForm().isItemChecked(name)) {
  341. this.getListForm.getDForm().checkItem(names);
  342. this.checkIds.push(names.substr(7))
  343. this.groupBtn.classList.remove("disable")
  344. } else {
  345. this.getListForm.getDForm().uncheckItem(names);
  346. this.groupBtn.classList.add("disable");
  347. }
  348. }
  349. }.bind(this))
  350. console.log(this.checkIds)
  351. }
  352. }.bind(groupitem));
  353. groupitem.groupBtn.onclick = function (e) {
  354. if (this.classList.value == "disable" && groupitem.checkId.length > 0) return false
  355. addResByGroup(groupitem.resUrl, groupitem.params.groupId, groupitem.checkIds.join(","))
  356. groupitem.checkIds = [];
  357. groupitem.getToolbar.getDForm().uncheckItem("isAll");
  358. this.classList.add("disable");
  359. }
  360. })
  361. function setEventList(paramsGropu) {
  362. var getDForm = paramsGropu.getListForm.getDForm()
  363. paramsGropu.getListForm.on("onButtonClick", function (name) {
  364. if (name.indexOf("id") !== -1) {
  365. getDForm.checkItem("_check-" + name.substr(3));
  366. layer.confirm("是否" + paramsGropu.groupBtnText + "?", {
  367. btn: [_t("确定"), _t("取消")],
  368. btn1: function (index) {
  369. addResByGroup(paramsGropu.resUrl, paramsGropu.params.groupId, name.substr(3));
  370. },
  371. btn2: function (index) {
  372. getDForm.uncheckItem("_check-" + name.substr(3));
  373. }
  374. })
  375. }
  376. });
  377. paramsGropu.getListForm.on("onChange", function (name) {
  378. paramsGropu.checkIds = [];
  379. if (name.indexOf("_check-") !== -1) {
  380. this.checkIds = [];
  381. var index = 0;
  382. this.getListForm.forEachItem(function (names) {
  383. if (names.indexOf("_check") !== -1) {
  384. index += 1
  385. var Checkname = names.substr(7);
  386. var checkItem = getDForm.isItemChecked(names)
  387. if (checkItem) {
  388. this.checkIds.push(Checkname)
  389. }
  390. }
  391. }.bind(this))
  392. if (this.checkIds.length > 0) {
  393. if (this.checkIds.length === index) {
  394. this.getToolbar.getDForm().checkItem("isAll");
  395. } else {
  396. this.getToolbar.getDForm().uncheckItem("isAll");
  397. }
  398. this.groupBtn.classList.remove("disable")
  399. } else {
  400. this.groupBtn.classList.add("disable");
  401. }
  402. }
  403. //console.log(this.checkIds)
  404. }.bind(paramsGropu))
  405. }
  406. })()
  407. </script>