resource.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <div class="plg-tab-container">
  2. <div class="plg-flex" style="height: 100%">
  3. <div class="flex_item" id="resource">
  4. </div>
  5. </div>
  6. </div>
  7. <style>
  8. </style>
  9. <script>
  10. (function () {
  11. window.global_fun.resource={}
  12. var res_opts = {
  13. fixedLast: true,
  14. renderer: "resource",
  15. url: APIS.resource.getList(),
  16. type: "get",
  17. // pageNum: "pageNo",//设置分页参数页码key值,默认为pageNum
  18. };
  19. res_opts.pagebar = {
  20. buttons: [
  21. { text: PLG_BUTTON.value.delBtn(), className: "layui-btn-danger plg-btn-height-auto", name: "delBtn" }
  22. ]
  23. },
  24. res_opts.columns = [
  25. {
  26. name: "id",
  27. id: "id",
  28. hidden: true
  29. },
  30. {
  31. name: "服务名称",
  32. id: "serviceName",
  33. align: "center",
  34. type: "ro",
  35. width:200
  36. },
  37. {
  38. name: "请求访式",
  39. id: "method",
  40. align: "center",
  41. type: "ro",
  42. width:150
  43. },
  44. {
  45. name: "地址路径",
  46. id: "source",
  47. align: "left",
  48. type: "ro",
  49. width:350
  50. },
  51. {
  52. name: "说明",
  53. id: "notes",
  54. align: "left",
  55. type: "ro",
  56. },
  57. {
  58. id: "op",
  59. name: "操作",
  60. type: 'button',
  61. width: 180,
  62. align: "center",
  63. render: function (v, d) {
  64. return '修改^global_fun.resource.editClick,删除^global_fun.resource.deleteClick';
  65. }
  66. }
  67. ];
  68. res_opts.toolbar = [{
  69. type: 'row',
  70. blockOffset: 0,
  71. className: "layui-col-md12",
  72. list: [
  73. {
  74. type: "row",
  75. className: "layui-col-md6",
  76. blockOffset: 0,
  77. list: [{
  78. className: "layui-col-md4",
  79. type: "input",
  80. name: "likeMap",
  81. label: "搜索",
  82. placeholder: "服务名/请求方式/地址"
  83. },
  84. {
  85. type: "button",
  86. className: "left",
  87. name: "selectAllBtn",
  88. value: PLG_BUTTON.value.searchBtn()
  89. },
  90. {
  91. type: "button",
  92. name: "resetBtn",
  93. className: "left",
  94. value: PLG_BUTTON.value.resetBtn()
  95. },
  96. ]
  97. },
  98. {
  99. type: "block",
  100. className: "layui-col-md6 right",
  101. blockOffset: 0,
  102. list: [
  103. {
  104. type: "button",
  105. name: "addBtn",
  106. value: PLG_BUTTON.value.addBtn()
  107. },
  108. {
  109. type: "newcolumn"
  110. },
  111. {
  112. className: "upload",
  113. type: "button",
  114. name: "importBtn",
  115. value: PLG_BUTTON.value.importBtn()
  116. },
  117. {
  118. type: "newcolumn"
  119. },
  120. {
  121. type: "button",
  122. name: "downBtn",
  123. value: PLG_BUTTON.value.downBtn()
  124. },
  125. {
  126. type: "newcolumn"
  127. },
  128. {
  129. type: "button",
  130. name: "aotuLoadBtn",
  131. value: "加载资源"
  132. }
  133. ]
  134. }]
  135. }];
  136. res_opts.formData = [{
  137. type: "row",
  138. list: [{
  139. type: "settings",
  140. labelWidth: 90,
  141. position: "label-left",
  142. labelAlign: "right"
  143. },
  144. {
  145. type: "hidden",
  146. name: "id",
  147. label: "id",
  148. value: 0,
  149. },
  150. {
  151. type: "input",
  152. name: "serviceName",
  153. label: "服务名",
  154. required: true,
  155. validate: 'NotEmpty',
  156. placeholder: _t("请输入服务名")
  157. },
  158. {
  159. type: "input",
  160. name: "source",
  161. label: "接口地址",
  162. required: true,
  163. validate: "NotEmpty",
  164. placeholder: _t("请输入接口地址")
  165. },
  166. {
  167. type: "select",
  168. name: "method",
  169. label: "提交方式",
  170. required: true,
  171. options: [
  172. { value: "GET", text: "GET", selected: true },
  173. { value: "POST", text: "POST" },
  174. { value: "PUT", text: "PUT" },
  175. { value: "DELETE", text: "DELETE" }
  176. ]
  177. },
  178. { type: "input", name: "notes", validate: 'NotEmpty', required: true, label: "说明:", rows: 3, labelTop: -20, placeholder: "请填写这个服务是干什么用的" }
  179. ]
  180. }
  181. ]
  182. var res_inst = new GridPlant({
  183. instance: new PlgGrid(setConfig(res_opts)).loadData(),
  184. addBtnUrl: APIS.resource.getResource(),
  185. editBtnUrl: APIS.resource.update(),
  186. delBtnUrl: APIS.resource.deleteAll(),
  187. downBtnUrl: APIS.resource.download(),
  188. importBtnUrl: APIS.resource.import(),
  189. }).init();
  190. res_inst.selectAllBtnAfter(function (obj) {
  191. var likeMap = res_inst.PlgGridInstance.getToolBarForm().getItemValue("likeMap");
  192. obj.serviceName = likeMap
  193. obj.method = likeMap
  194. obj.source = likeMap
  195. delete obj.likeMap
  196. })
  197. res_inst.PlgGridInstance.attachPageBarEvent(function () {
  198. this.delBtn({ids:this.idS});
  199. }.bind(res_inst))
  200. window.global_fun.resource.editClick = function () {
  201. res_inst.PlgGridInstance.selectRowById(arguments[0]);
  202. res_inst.editBtn();
  203. }
  204. window.global_fun.resource.deleteClick = function () {
  205. res_inst.PlgGridInstance.selectRowById(arguments[0]);
  206. res_inst.formatForm(3, "POST", _t("是否删除当前数据"), APIS.resource.delete(), { id: arguments[0] })
  207. }
  208. //自动加载配制
  209. var aotu_opts = {
  210. sysOpts: null,
  211. renderer: Prolog.createRandomId(),
  212. url: APIS.resource.getNameByList(),
  213. type: "get",
  214. page: false,
  215. multiselect: false,
  216. params: { serviceName: "" }
  217. };
  218. aotu_opts.toolbar = [
  219. {
  220. type: "row",
  221. className: "layui-col-md12",
  222. list: [
  223. {
  224. className: "layui-col-md12",
  225. type: "combo",
  226. name: "serviceName",
  227. label: "选择服务",
  228. remote: {
  229. url: APIS.resource.getSysNames(),
  230. type: "GET",
  231. success: function (da) {
  232. if (da.success && da.data != null && da.data.length > 0) {
  233. var myForm = res_inst.autoLoadInsta.getToolBarForm();
  234. var myCombo = myForm.getCombo("serviceName");
  235. myCombo.clearAll(false);
  236. var array = new Array();
  237. da.data.map(x => { array.push([x, x]) });
  238. myCombo.addOption(array);
  239. myCombo.setComboValue(da.data[0]);
  240. }
  241. }
  242. },
  243. options: null
  244. }
  245. ]
  246. }
  247. ]
  248. aotu_opts.columns = [{
  249. name: "id",
  250. id: "id",
  251. hidden: true
  252. },
  253. {
  254. name: "服务名",
  255. id: "serviceName",
  256. align: "left",
  257. type: "ro",
  258. width:140,
  259. },
  260. {
  261. name: "请求访式",
  262. width:60,
  263. id: "method",
  264. align: "center",
  265. type: "ro"
  266. },
  267. {
  268. name: "地址路径",
  269. id: "source",
  270. align: "left",
  271. type: "ro"
  272. },
  273. {
  274. name: "说明",
  275. id: "notes",
  276. align: "left",
  277. type: "ro"
  278. }]
  279. res_inst.aotuLoadBtn = function () {
  280. var _this = this;
  281. var v = ""
  282. var winoptions = {
  283. title: "加载资源",
  284. closeBtn: 1,
  285. closeBtn: 1,
  286. type: 1,
  287. resize: true,
  288. tipsMore: true,
  289. btn: [_t("加载"), _t("取消")],
  290. btn1: function (index) {
  291. var close = PlgDialog.loading2();
  292. Prolog.ajax({
  293. type: "post",
  294. url: APIS.resource.importInterface(),
  295. data: { serviceName: v },
  296. success: function (response) {
  297. if (response.success) {
  298. res_inst.PlgGridInstance.reload()
  299. PlgDialog.close(index);
  300. PlgDialog.msg("加载成功")
  301. } else {
  302. PlgDialog.msg(response.message)
  303. }
  304. },
  305. complete :function(){
  306. close()
  307. }
  308. });
  309. },
  310. btn2: function (param) { },
  311. area: [800 + 'px', 600 + 'px'],
  312. content: '<div id="' + aotu_opts.renderer + '"></div>',
  313. success: function (lyaer, index) {
  314. res_inst.autoLoadInsta = new PlgGrid(setConfig(aotu_opts));
  315. var myForm = res_inst.autoLoadInsta.getToolBarForm();
  316. var myCombo = myForm.getCombo("serviceName");
  317. res_inst.autoLoadInsta.getToolBarForm().on("onChange", function () {
  318. v = myCombo.getSelectedValue();
  319. res_inst.autoLoadInsta.setParams({ serviceName: v });
  320. res_inst.autoLoadInsta.reload();
  321. })
  322. myForm.loadComboData("serviceName");
  323. }
  324. }
  325. PlgDialog.open(winoptions);
  326. }
  327. })()
  328. </script>