client.resourceGroup.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <div class="plg-flex">
  2. <div id="notclientGrulp" class="plg-flex-item" style="flex:1; height: 100%"></div>
  3. <div class="plg-flex-item" style="height: 100%; flex: 0 0 auto;width:80px;">
  4. <div class="btnForm">
  5. <a id="notclientGrulpBtn" href="javascript:void(0)" class="disable">
  6. <i class="layui-icon layui-icon-right" style="font-size: 28px;"></i>
  7. </a>
  8. <a id="clientGroupBtn" href="javascript:void(0)" class="disable">
  9. <i class="layui-icon layui-icon-left" style="font-size: 28px;"></i>
  10. </a>
  11. </div>
  12. </div>
  13. <div id="clientGroup" class="plg-flex-item" style="flex:1;height: 100%;">2</div>
  14. </div>
  15. <script>
  16. //分配资源权限
  17. !function () {
  18. window.global_fun.clientResourceGroup={}
  19. var notGroupOpts = {
  20. renderer: "notclientGrulp",
  21. skin: 2,
  22. className: "flex_panel",
  23. header: {
  24. isShow: true,
  25. title: "未分配资源组",
  26. },
  27. url: APIS.groupResource.notlistbyclient(),
  28. params: { clientId: window.global_fun.clientResourceGroup.clientId },
  29. toolbar: [{
  30. type: "row",
  31. name: "tool",
  32. list: [
  33. {
  34. type: "row",
  35. className: "layui-col-md12",
  36. list: [
  37. {
  38. className: "layui-col-md7",
  39. type: "input",
  40. name: "likeMap",
  41. placeholder: "服务名/地址",
  42. },
  43. {
  44. type: "button",
  45. className: "left",
  46. name: "selectAllBtn",
  47. value: PLG_BUTTON.value.searchBtn(),
  48. },
  49. {
  50. type: "checkbox",
  51. className: "right",
  52. name: "isAll",
  53. labelWidth: "auto",
  54. labelAlign: "left",
  55. position: "label-right",
  56. label: "全选",
  57. disabled: true
  58. }
  59. ]
  60. }
  61. ]
  62. }],
  63. listFormData: [{
  64. type: "row",
  65. name: "res_panel_notgroup",
  66. list: [
  67. {
  68. name: "notData",
  69. type: "template",
  70. className: "layui-col-md12 ",
  71. format: function () {
  72. return `<span>暂无数据</span>`
  73. }
  74. }
  75. ]
  76. }
  77. ]
  78. }
  79. var GroupOpts = Object.assign({}, notGroupOpts, {
  80. renderer: "clientGroup",
  81. url: APIS.groupResource.listbyclient(),
  82. params: { clientId: window.global_fun.clientResourceGroup.clientId },
  83. skin: 1,
  84. header: {
  85. isShow: true,
  86. title: "已分配资源组",
  87. },
  88. });
  89. var notGroupList = new PlgPanel(notGroupOpts);
  90. var GroupList = new PlgPanel(GroupOpts);
  91. notGroupList.groupBtn = document.getElementById("notclientGrulpBtn");
  92. notGroupList.groupBtnText = "添加资源组";
  93. notGroupList.resUrl = APIS.client.addGroup();
  94. GroupList.groupBtn = document.getElementById("clientGroupBtn");
  95. GroupList.groupBtnText = "删除资源组";
  96. GroupList.resUrl = APIS.client.removeGroup();
  97. var grouparr = [notGroupList, GroupList];
  98. grouparr.forEach(function (groupitem) {
  99. //请求列表数据的回掉
  100. groupitem.done(function (self, data) {
  101. if (data.list.length > 0) {
  102. self.getListForm.hideItem("notData");
  103. self.getToolbar.getDForm().uncheckItem("isAll");
  104. self.page = true;
  105. self.getToolbar.enableItem("isAll");
  106. data.list.forEach(function (item) {
  107. self.getListForm.getDForm().addItem("res_panel_notgroup",
  108. {
  109. type: "row",
  110. className: "layui-col-md12 accr_list",
  111. list: [
  112. {
  113. className: "layui-col-md7 lab-bold",
  114. name: "_check-" + item.id,
  115. type: "checkbox",
  116. labelWidth: "auto",
  117. labelAlign: "left",
  118. position: "label-right",
  119. label: item.name,
  120. },
  121. {
  122. className: "right link layui-col-md2",
  123. type: "button",
  124. value: groupitem.groupBtnText,
  125. name: "id-" + item.id
  126. },
  127. {
  128. className: "layui-col-md12 color-999 mt-10",
  129. type: "template",
  130. value: item.notes,
  131. }
  132. ]
  133. })
  134. });
  135. return setEventList(groupitem)
  136. }
  137. self.page = false;
  138. self.getToolbar.disableItem("isAll");
  139. });
  140. groupitem.getToolbar.on("onButtonClick", function (name) {
  141. if (name == "selectAllBtn") {
  142. var linkMap = groupitem.getToolbar.getItemValue("likeMap");
  143. groupitem.listReload({ serviceName: linkMap, source: linkMap, method: linkMap })
  144. }
  145. });
  146. groupitem.getToolbar.on("onChange", function (name) {
  147. if (name == "isAll") {
  148. this.checkIds = [];
  149. this.getListForm.forEachItem(function (names) {
  150. if (names.indexOf("_check") !== -1) {
  151. if (this.getToolbar.getDForm().isItemChecked(name)) {
  152. this.getListForm.getDForm().checkItem(names);
  153. this.checkIds.push(names.substr(7))
  154. this.groupBtn.classList.remove("disable")
  155. } else {
  156. this.getListForm.getDForm().uncheckItem(names);
  157. this.groupBtn.classList.add("disable");
  158. }
  159. }
  160. }.bind(this))
  161. }
  162. }.bind(groupitem));
  163. groupitem.groupBtn.onclick = function (e) {
  164. if (this.classList.value == "disable" && groupitem.checkId.length > 0) return false
  165. addResByGroup(groupitem.resUrl,groupitem.params.clientId, groupitem.checkIds.join(","))
  166. groupitem.checkIds = [];
  167. groupitem.getToolbar.getDForm().uncheckItem("isAll");
  168. this.classList.add("disable");
  169. }
  170. })
  171. function setEventList(paramsGropu) {
  172. var getDForm = paramsGropu.getListForm.getDForm();
  173. paramsGropu.getListForm.on("onButtonClick", function (name) {
  174. if (name.indexOf("id") !== -1) {
  175. getDForm.checkItem("_check-" + name.substr(3));
  176. layer.confirm("是否" + paramsGropu.groupBtnText + "?", {
  177. btn: [_t("确定"), _t("取消")],
  178. btn1: function (index) {
  179. addResByGroup(paramsGropu.resUrl, paramsGropu.params.clientId, name.substr(3));
  180. },
  181. btn2: function (index) {
  182. getDForm.uncheckItem("_check-" + name.substr(3));
  183. }
  184. })
  185. }
  186. });
  187. paramsGropu.getListForm.on("onChange", function (name) {
  188. paramsGropu.checkIds = [];
  189. if (name.indexOf("_check-") !== -1) {
  190. this.checkIds = [];
  191. var index = 0;
  192. this.getListForm.forEachItem(function (names) {
  193. if (names.indexOf("_check") !== -1) {
  194. index += 1
  195. var Checkname = names.substr(7);
  196. var checkItem = getDForm.isItemChecked(names)
  197. if (checkItem) {
  198. this.checkIds.push(Checkname)
  199. }
  200. }
  201. }.bind(this))
  202. if (this.checkIds.length > 0) {
  203. if (this.checkIds.length === index) {
  204. this.getToolbar.getDForm().checkItem("isAll");
  205. } else {
  206. this.getToolbar.getDForm().uncheckItem("isAll");
  207. }
  208. this.groupBtn.classList.remove("disable")
  209. } else {
  210. this.groupBtn.classList.add("disable");
  211. }
  212. }
  213. //console.log(this.checkIds)
  214. }.bind(paramsGropu))
  215. }
  216. //分配资源给资源组方法
  217. function addResByGroup(url, ids, resIds) {
  218. Prolog.ajax({
  219. url: url,
  220. type: "post",
  221. data: {
  222. id: ids,
  223. groupIds: resIds
  224. },
  225. success: function (resource) {
  226. if (resource.success) {
  227. PlgDialog.msg("分配成功");
  228. GroupList.listReload();
  229. notGroupList.listReload();
  230. } else {
  231. PlgDialog.msg(resource.message);
  232. }
  233. }
  234. })
  235. }
  236. }()
  237. </script>