client.resource.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <div class="plg-flex">
  2. <div id="notclientRes" 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="notclientResBtn" href="javascript:void(0)" class="disable">
  6. <i class="layui-icon layui-icon-right" style="font-size: 28px;"></i>
  7. </a>
  8. <a id="clientResBtn" 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="clientRes" class="plg-flex-item" style="flex:1;height: 100%;">2</div>
  14. </div>
  15. <script>
  16. window.global_fun.clientResource={}
  17. //分配资源权限
  18. !function () {
  19. var notGroupOpts = {
  20. renderer: "notclientRes",
  21. skin: 2,
  22. className: "flex_panel",
  23. header: {
  24. isShow: true,
  25. title: "未分配资源",
  26. },
  27. url: APIS.resource.notlistbyclient(),
  28. params: { clientId: window.global_fun.clientResource.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: "clientRes",
  81. url: APIS.resource.listbyclient(),
  82. params: { clientId: window.global_fun.clientResource.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("notclientResBtn");
  92. notGroupList.groupBtnText = "添加资源";
  93. notGroupList.resUrl = APIS.client.addResource();
  94. GroupList.groupBtn = document.getElementById("clientResBtn");
  95. GroupList.groupBtnText = "删除资源";
  96. GroupList.resUrl = APIS.client.removeResource();
  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.serviceName,
  120. },
  121. {
  122. className: "layui-col-md3",
  123. name: "model",
  124. type: "template",
  125. value: item.method,
  126. style: "text-align: center"
  127. },
  128. {
  129. className: "right link layui-col-md2",
  130. type: "button",
  131. value: groupitem.groupBtnText,
  132. name: "id-" + item.id
  133. },
  134. {
  135. className: "layui-col-md12 color-999 mt-10",
  136. type: "template",
  137. value: item.source,
  138. }
  139. ]
  140. })
  141. });
  142. return setEventList(groupitem)
  143. }
  144. self.page = false;
  145. self.getToolbar.disableItem("isAll");
  146. });
  147. groupitem.getToolbar.on("onButtonClick", function (name) {
  148. if (name == "selectAllBtn") {
  149. var linkMap = groupitem.getToolbar.getItemValue("likeMap");
  150. groupitem.listReload({ serviceName: linkMap, source: linkMap, method: linkMap })
  151. }
  152. });
  153. groupitem.getToolbar.on("onChange", function (name) {
  154. if (name == "isAll") {
  155. this.checkIds = [];
  156. this.getListForm.forEachItem(function (names) {
  157. if (names.indexOf("_check") !== -1) {
  158. if (this.getToolbar.getDForm().isItemChecked(name)) {
  159. this.getListForm.getDForm().checkItem(names);
  160. this.checkIds.push(names.substr(7))
  161. this.groupBtn.classList.remove("disable")
  162. } else {
  163. this.getListForm.getDForm().uncheckItem(names);
  164. this.groupBtn.classList.add("disable");
  165. }
  166. }
  167. }.bind(this))
  168. }
  169. }.bind(groupitem));
  170. groupitem.groupBtn.onclick = function (e) {
  171. if (this.classList.value == "disable" && groupitem.checkId.length > 0) return false
  172. addResByGroup(groupitem.resUrl,groupitem.params.clientId, groupitem.checkIds.join(","))
  173. groupitem.checkIds = [];
  174. groupitem.getToolbar.getDForm().uncheckItem("isAll");
  175. this.classList.add("disable");
  176. }
  177. })
  178. function setEventList(paramsGropu) {
  179. var getDForm = paramsGropu.getListForm.getDForm();
  180. paramsGropu.getListForm.on("onButtonClick", function (name) {
  181. if (name.indexOf("id") !== -1) {
  182. getDForm.checkItem("_check-" + name.substr(3));
  183. layer.confirm("是否" + paramsGropu.groupBtnText + "?", {
  184. btn: [_t("确定"), _t("取消")],
  185. btn1: function (index) {
  186. addResByGroup(paramsGropu.resUrl, paramsGropu.params.clientId, name.substr(3));
  187. },
  188. btn2: function (index) {
  189. getDForm.uncheckItem("_check-" + name.substr(3));
  190. }
  191. })
  192. }
  193. });
  194. paramsGropu.getListForm.on("onChange", function (name) {
  195. paramsGropu.checkIds = [];
  196. if (name.indexOf("_check-") !== -1) {
  197. this.checkIds = [];
  198. var index = 0;
  199. this.getListForm.forEachItem(function (names) {
  200. if (names.indexOf("_check") !== -1) {
  201. index += 1
  202. var Checkname = names.substr(7);
  203. var checkItem = getDForm.isItemChecked(names)
  204. if (checkItem) {
  205. this.checkIds.push(Checkname)
  206. }
  207. }
  208. }.bind(this))
  209. if (this.checkIds.length > 0) {
  210. if (this.checkIds.length === index) {
  211. this.getToolbar.getDForm().checkItem("isAll");
  212. } else {
  213. this.getToolbar.getDForm().uncheckItem("isAll");
  214. }
  215. this.groupBtn.classList.remove("disable")
  216. } else {
  217. this.groupBtn.classList.add("disable");
  218. }
  219. }
  220. //console.log(this.checkIds)
  221. }.bind(paramsGropu))
  222. }
  223. //分配资源给资源组方法
  224. function addResByGroup(url, ids, resIds) {
  225. Prolog.ajax({
  226. url: url,
  227. type: "post",
  228. data: {
  229. id: ids,
  230. resourceIds: resIds
  231. },
  232. success: function (resource) {
  233. if (resource.success) {
  234. PlgDialog.msg("分配成功");
  235. GroupList.listReload();
  236. notGroupList.listReload();
  237. } else {
  238. PlgDialog.msg(resource.message);
  239. }
  240. }
  241. })
  242. }
  243. }()
  244. </script>