menuTree.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <!-- 【菜单管理 -->
  2. <div id="menuList2" class="plg-flex plg-tab-container">
  3. <div class="grid-container-full">
  4. <div class="plg-grid-panel">
  5. <div id="basemenuconfig_tool" class="plg-toolbar" style="float: right;"></div><div style="clear: both"></div>
  6. <div class="layui-row layui-col-space2">
  7. <div id="basemenuconfig_tree_01" class="layui-col-md4" style="border: #E3E3E3 solid 1px;margin-bottom: 10px;"></div>
  8. <div id="basemenuconfig_grid_01" class="layui-col-md8" style="border: #E3E3E3 solid 1px;margin-bottom: 10px;"></div>
  9. </div>
  10. <div style="clear: both"></div>
  11. </div>
  12. </div>
  13. </div>
  14. <script type="text/javascript">
  15. /**
  16. * jiw
  17. * 2018.11.05
  18. * 菜单管理界面
  19. */
  20. (function () {
  21. //获取数据
  22. var rsp_opert_type = [{ value: "", text: "" }, { value: "0", text: "操作" }, { value: "1", text: "查询" }],
  23. rsp_sys_id = [], rsp_tree = [],
  24. rsp_menu_type = [{ value: "", text: "" }, { value: "GET", text: "GET" }, { value: "POST", text: "POST" }, { value: "DELETE", text: "DELETE" }, { value: "PUT", text: "PUT" }, { value: "OPTIONS", text: "OPTIONS" }],
  25. rsp_apptype = [{ value: -1, text: "" }, { value: 0, text: "系统应用" }, { value: 1, text: "公有应用" }, { value: 2, text: "行业应用" }, { value: 3, text: "BI应用" }],
  26. rsp_factype = [{ value: -1, text: "" }, { value: 0, text: "PC" }, { value: 1, text: "RF" }, { value: 2, text: "APP" }],
  27. rsp_type = [{ value: -1, text: "" }, { value: 0, text: "菜单" }, { value: 1, text: "按钮" }, { value: 2, text: "静态资源" }];
  28. var m = $(document.body).height();
  29. Prolog.ajax({
  30. url: "/api/service-users/menu/getMenu/v1.0", type: "post", contentType: "application/x-www-form-urlencoded", data: {}, async: false,
  31. success: function (data) {
  32. if (data.success) {
  33. for (var i = 0; i < data.data.length; i++) {
  34. rsp_tree.push({
  35. id: data.data[i].id,
  36. name: "[" + data.data[i].id + "]" + data.data[i].name,
  37. menuId: data.data[i].id,
  38. nlevel: data.data[i].level,
  39. parentMenuId: data.data[i].parentid,
  40. isParent: (data.data[i].leaf === 0) ? true : false,
  41. systemid: data.data[i].systemid,
  42. exttype: data.data[i].exttype
  43. });
  44. }
  45. }
  46. else {
  47. layer.msg("获取菜单数据失败!");
  48. }
  49. }, error: function () { }
  50. });
  51. Prolog.ajax({
  52. url: "/api/service-users/sys/getSelectSystem/v1.0", type: "get", contentType: "application/x-www-form-urlencoded", data: {},
  53. success: function (data) {
  54. if (data.success) {
  55. rsp_sys_id.push({ text: "", value: "" });
  56. for (var i = 0; i < data.data.length; i++) {
  57. rsp_sys_id.push({ text: data.data[i].text, value: data.data[i].val });
  58. }
  59. }
  60. }, error: function () { }
  61. });
  62. var tool, p1, p2, tree1, form1, grid1;
  63. var toolcfg = {
  64. renderer: "basemenuconfig_tool",
  65. items: [{ type: "newcolumn", offset: 20 }, { type: "button", className: "plg-toolbar-right", name: "btn_add_grid", value: "<i class='layui-icon layui-icon-add-1'></i>新增资源" },
  66. { type: "newcolumn", offset: 20 }, { type: "button", className: "plg-toolbar-right", name: "btn_del_tree", value: "<i class='layui-icon layui-icon-delete'></i>删除菜单" },
  67. { type: "newcolumn", offset: 20 }, { type: "button", className: "plg-toolbar-right", name: "btn_add_tree", value: "<i class='layui-icon layui-icon-add-1'></i>新增菜单" }]
  68. };
  69. tool = new PlgForm(toolcfg);
  70. p1 = $("#basemenuconfig_tree_01").PlgPanel({
  71. title: "菜单项",
  72. content: '<div id="basemenuconfig_tree_02"></div>',
  73. style: "overflow:auto"
  74. });
  75. p2 = $("#basemenuconfig_grid_01").PlgPanel({
  76. title: "资源",
  77. content: '<div id="basemenuconfig_grid_02"></div>',
  78. style: ""
  79. });
  80. var param = { "pageNum": 1, "pageSize": 10 };
  81. var gridOpts = {
  82. skin: "terrace",
  83. rowId: "p_id",
  84. columns: [
  85. { id: "p_id", name: "资源ID", type: 'ro', hidden: true },
  86. { id: "p_systemid", name: "所属系统", type: 'ro', hidden: true , render: function (v) { return getNameByID(rsp_sys_id, v); } },
  87. { id: "p_name", name: "资源名称", type: 'ro' },
  88. { id: "p_flg", name: "是否启用", type: 'ch' },
  89. { id: "p_methodtype", name: "请求类型", type: 'ro' },
  90. { id: "p_requesturl", name: "资源地址", type: 'ro' },
  91. {
  92. id: "op", name: "操作", type: 'button', align: "center", width: 150, render: function () {
  93. return "修改^res_BaseMenuConfig_editClick,删除^res_BaseMenuConfig_delClick";
  94. }
  95. }
  96. ],
  97. multiselect: false,
  98. formData: [
  99. { type: "settings", labelWidth: 80, position: "label-left", labelAlign: "left" },
  100. {
  101. type: "block", list: [
  102. { type: "input", name: "p_menuid", label: "菜单ID:", width: 150, disabled: true },
  103. { type: "newcolumn", offset: 60 },
  104. { type: "combo", name: "p_systemid", label: "所属系统:", options: rsp_sys_id, width: 152, disabled: true }]
  105. },
  106. {
  107. type: "block", list: [
  108. { type: "input", name: "p_name", label: "菜单名称:", validate: "NotEmpty", required: true, width: 150 },
  109. { type: "newcolumn", offset: 60 },
  110. { type: "combo", name: "p_methodtype", label: "请求类型:", validate: "NotEmpty", required: true, options: rsp_menu_type, width: 152 }]
  111. },
  112. {
  113. type: "block", list: [
  114. { type: "input", name: "p_requesturl", label: "资源地址:", validate: "NotEmpty", required: true, width: 150 },
  115. { type: "newcolumn", offset: 60 },
  116. { type: "checkbox", name: "p_flg", label: "是否启用:", width: 90 }]
  117. },
  118. {
  119. type: "block", list: [
  120. { type: "input", name: "p_remark", label: "备注 :", width: 150 }]
  121. },
  122. {
  123. type: "block", list: [
  124. { type: "hidden", name: "p_id" },
  125. { type: "hidden", name: "p_authorityno" },
  126. { type: "input", name: "p_imagepath", label: "菜单图标:", width: 150 },
  127. { type: "newcolumn", offset: 60 },
  128. { type: "input", name: "p_sort", label: "排序:", width: 150 }]
  129. }
  130. ],
  131. imagePath: "/prologui/assets/PlgGrid",
  132. url: "/api/service-users/menu/getMenuAuth/v1.0",
  133. type: "post",
  134. params: param,
  135. contentType: "application/x-www-form-urlencoded",
  136. page: true,
  137. totalCount: "totalCount"
  138. };
  139. var zreecfg = {
  140. renderer: "basemenuconfig_tree_02",
  141. skin: "menu-tree",
  142. toolBar: false,
  143. delMenu: null,
  144. setData: rsp_tree,
  145. setting: {
  146. check: {
  147. enable: false
  148. },
  149. callback: {
  150. //单击事件的回调
  151. onClick: function (event, treeId, treeNode) {
  152. if (grid1 != undefined) {
  153. grid1.getGrid().clearAll();
  154. if (treeNode.isParent == false) {
  155. var p = { "pageNum": 1, "pageSize": 10, "menuid": treeNode.id };
  156. grid1.setParams(p);
  157. grid1.reload();
  158. }
  159. }
  160. else {
  161. gridOpts.params.menuid = treeNode.id;
  162. grid1 = new PlgGrid(gridOpts);
  163. grid1.renderTo("basemenuconfig_grid_02");
  164. grid1.loadData();
  165. grid1.on("onRowDblClicked", function () {
  166. res_BaseMenuConfig_editClick(grid1.getSelectedRowId(), grid1.getSelectedRowData());
  167. });
  168. }
  169. },
  170. onDblClick: treeOnDblClick
  171. }
  172. }
  173. };
  174. tree1 = new PlgZtree(zreecfg);
  175. $("body").bind("mousedown", function (event) {
  176. if (event.target.className == "layui-card-header") {
  177. tree1.treeObj.cancelSelectedNode();
  178. }
  179. });
  180. $("#basemenuconfig_tree_02").height((m > 530) ? m - 280 : m);
  181. $("#basemenuconfig_grid_02").height((m > 530) ? m - 280 : m);
  182. //工具栏事件
  183. tool.getDForm().attachEvent("onButtonClick", function (name) {
  184. var sd = tree1.treeObj.getSelectedNodes();
  185. if (name === "btn_add_grid") {
  186. if (sd[0].length < 1) {
  187. layer.msg("请选择菜单");
  188. return;
  189. }
  190. if (sd[0].isParent) {
  191. layer.msg("不能新增资源");
  192. return;
  193. }
  194. grid1.showDialog(0, "新增", 650, 400, {
  195. url: "/api/service-users/menu/insertPlgFxMenuAuth/v1.0",
  196. type: "post",
  197. dataType: "json",
  198. contentType: "application/x-www-form-urlencoded"
  199. });
  200. grid1.getGridForm().setItemValue("p_systemid", sd[0].systemid);
  201. grid1.getGridForm().setItemValue("p_parentid", sd[0].id);
  202. grid1.getGridForm().setItemValue("p_exttype", sd[0].exttype);
  203. }
  204. else if (name === "btn_add_tree") {
  205. if (sd.length < 1) {
  206. menuWnd(0, null);
  207. return;
  208. }
  209. if (!sd[0].isParent) {
  210. layer.msg("不能新增子节点");
  211. return;
  212. }
  213. menuWnd(0, sd[0]);
  214. }
  215. else if (name === "btn_del_tree") {
  216. if (sd[0].length < 1) {
  217. layer.msg("请选择删除项");
  218. return;
  219. }
  220. layer.confirm(`确认删除"${sd[0].name}"吗?`, function (index) {
  221. layer.close(index);
  222. Prolog.ajax({
  223. url: "/api/service-users/menu/deletePlgFxMenuById/v1.0", type: "post", contentType: "application/x-www-form-urlencoded", data: { "id": sd[0].id },
  224. success: function (data) {
  225. if (data.success) {
  226. tree1.treeObj.removeNode(sd[0]);
  227. }
  228. else {
  229. layer.msg(data.message);
  230. }
  231. }, error: function () { }
  232. });
  233. });
  234. }
  235. });
  236. //菜单双击事件
  237. function treeOnDblClick(event, treeId, treeNode) {
  238. if (treeNode != null)
  239. menuWnd(1, treeNode);
  240. }
  241. function menuWnd(type, treeNode) {
  242. var rsp = {
  243. "p_id": "", "p_number": "", "p_name": "", "p_parentid": 0, "p_leaf": 0, "p_type": 0, "p_systemid": "", "p_requesturl": "",
  244. "p_methodtype": "", "p_operttype": "", "p_queryid": "", "p_level": 1, "p_remark": "", "p_flg": 0
  245. };
  246. var title = "";
  247. if (type === 0) {
  248. title = "新增菜单";
  249. }
  250. else {
  251. title = "修改菜单";
  252. }
  253. var wnd_opt = {
  254. title: title,
  255. shadeClose: true,
  256. area: ['650px', '550px'],
  257. btn: '保存',
  258. btnAlign: 'r',
  259. content: '<div id="basemenuconfig_tree_02_1" style=""></div>',
  260. yes: function (index) {
  261. var b = form1.validate();
  262. if (!b) return;
  263. var fd = form1.getFormData();
  264. if (type === 0) {
  265. Prolog.ajax({
  266. url: "/api/service-users/menu/insertPlgFxMenu/v1.0", type: "post", contentType: "application/x-www-form-urlencoded", data: fd,
  267. success: function (data) {
  268. if (data.success) {
  269. var node = { id: "", name: "", menuId: "", parentMenuId: 0, isParent: false, level: 1, enable: true, systemid: "", exttype: "" };
  270. node.id = fd.p_id;
  271. node.isParent = (fd.p_leaf === 0) ? true : false;
  272. node.name = "[" + fd.p_id + "]" + fd.p_name;
  273. node.menuId = fd.p_id;
  274. node.parentMenuId = fd.p_parentid;
  275. node.level = fd.p_level;
  276. node.systemid = fd.p_systemid;
  277. node.exttype = fd.p_exttype;
  278. var newTreeNode = tree1.treeObj.addNodes(treeNode, node);
  279. tree1.treeObj.selectNode(newTreeNode[0]);
  280. PlgDialog.close(index);
  281. }
  282. else {
  283. layer.msg(data.message);
  284. return false;
  285. }
  286. }, error: function () { }
  287. });
  288. }
  289. else if (type === 1) {
  290. Prolog.ajax({
  291. url: "/api/service-users/menu/updatePlgFxMenu/v1.0", type: "put", contentType: "application/x-www-form-urlencoded", data: fd,
  292. success: function (data) {
  293. if (data.success) {
  294. treeNode.name = "[" + fd.p_id + "]" + fd.p_name;
  295. tree1.treeObj.updateNode(treeNode);
  296. tree1.treeObj.selectNode(treeNode);
  297. PlgDialog.close(index);
  298. }
  299. else {
  300. layer.msg(data.message);
  301. return false;
  302. }
  303. }, error: function () { }
  304. });
  305. }
  306. },
  307. success: function () {
  308. if (treeNode != null && type === 0) {
  309. rsp.p_level = (treeNode.nlevel + 1);
  310. rsp.p_parentid = treeNode.id;
  311. rsp.p_id = treeNode.id;
  312. rsp.p_systemid = treeNode.systemid;
  313. rsp.p_exttype = treeNode.exttype;
  314. }
  315. if (type === 1 && treeNode.id.length > 1) {
  316. Prolog.ajax({
  317. url: "/api/service-users/menu/getPlgFxMenuById/v1.0", type: "get", contentType: "application/x-www-form-urlencoded", data: { "id": treeNode.id }, async: false,
  318. success: function (data) {
  319. if (data.success) {
  320. rsp = data.data;
  321. }
  322. else {
  323. layer.msg(data.message);
  324. return false;
  325. }
  326. }, error: function () { }
  327. });
  328. }
  329. var formcfg = {
  330. renderer: "basemenuconfig_tree_02_1",
  331. items: [
  332. { type: "settings", position: "label-left", labelWidth: 80 },
  333. {
  334. type: "block", list: [
  335. { type: "input", name: "p_id", label: "菜单 ID:", width: 150, validate: "NotEmpty", required: true, editable: false },
  336. { type: "newcolumn", offset: 60 },
  337. { type: "checkbox", name: "p_flg", label: "是否启用:", width: 90 },
  338. { type: "newcolumn", offset: 40 },
  339. { type: "checkbox", name: "p_leaf", label: "是否子节点:", validate: "NotEmpty", required: true, width: 90 }]
  340. },
  341. {
  342. type: "block", list: [
  343. { type: "input", name: "p_name", label: "菜单名称:", width: 150, validate: "NotEmpty", required: true, required: true, editable: false },
  344. { type: "newcolumn", offset: 60 },
  345. { type: "combo", name: "p_systemid", label: "所属系统:", validate: "NotEmpty", required: true, options: rsp_sys_id, width: 152 }]
  346. },
  347. {
  348. type: "block", list: [
  349. { type: "combo", name: "p_operttype", label: "操作分类:", options: rsp_opert_type, width: 152 },
  350. { type: "newcolumn", offset: 60 },
  351. { type: "combo", name: "p_methodtype", label: "请求类型:", validate: "NotEmpty", required: true, options: rsp_menu_type, width: 152 }]
  352. },
  353. {
  354. type: "block", list: [
  355. { type: "combo", name: "p_apptype", label: "应用分类:", validate: comboVal, required: true, options: rsp_apptype, width: 152 },
  356. { type: "newcolumn", offset: 60 },
  357. { type: "combo", name: "p_factype", label: "设备分类:", validate: comboVal, required: true, options: rsp_factype, width: 152 }]
  358. },
  359. {
  360. type: "block", list: [
  361. { type: "input", name: "p_remark", label: "备注 :", width: 150 },
  362. { type: "newcolumn", offset: 60 },
  363. { type: "checkbox", name: "p_exttype", label: "外部资源:", width: 90 }]
  364. },
  365. {
  366. type: "block", list: [
  367. { type: "input", name: "p_parentid", label: "父级菜单代码:", width: 150, disabled: true },
  368. { type: "newcolumn", offset: 60 },
  369. { type: "input", name: "p_level", label: "菜单层级:", validate: "NotEmpty", required: true, width: 150, disabled: true }]
  370. },
  371. {
  372. type: "block", list: [
  373. { type: "input", name: "p_requesturl", label: "资源地址:", validate: "NotEmpty", required: true, width: 150 },
  374. { type: "newcolumn", offset: 60 },
  375. { type: "input", name: "p_imagepath", label: "菜单图标:", width: 100 },
  376. { type: "newcolumn", offset: 2 },
  377. { type: "button", name: "btn_upload", className: "btn_upload", value: "上传", width: 50 }]
  378. },
  379. {
  380. type: "block", list: [
  381. { type: "input", name: "p_queryid", label: "报表ID:", width: 150 },
  382. { type: "newcolumn", offset: 60 },
  383. { type: "input", name: "p_sort", label: "排序:", width: 150 }]
  384. }
  385. ]
  386. };
  387. form1 = new PlgForm(formcfg);
  388. form1.setFormData(rsp);
  389. if (type === 0) {
  390. form1.setItemFocus("p_id");
  391. }
  392. else {
  393. form1.getDForm().disableItem("p_id");
  394. }
  395. var $ = layui.jquery, upload = layui.upload;
  396. //设定文件大小限制
  397. upload.render({
  398. elem: '.btn_upload'
  399. , url: '/upload/'
  400. , size: 60 //限制文件大小,单位 KB
  401. , done: function (res) {
  402. //console.log(res)
  403. }
  404. });
  405. }
  406. };
  407. PlgDialog.open(wnd_opt);
  408. }
  409. //验证下拉框是否为空
  410. function comboVal(data) {
  411. if (data.toString() === "-1") return false;
  412. return true;
  413. }
  414. //根据ID获取中文名称,rsp数据集合,code数据值
  415. function getNameByID(rsp, code) {
  416. var str = code;
  417. if (code === null) {
  418. str = "";
  419. }
  420. else if (rsp === null) {
  421. str = code;
  422. }
  423. else {
  424. for (var i = 0; i < rsp.length; i++) {
  425. if (rsp[i].value === code) str = rsp[i].text;
  426. }
  427. }
  428. return str;
  429. }
  430. window.res_BaseMenuConfig_delClick = function (rid, rdata) {
  431. Prolog.delGridRowData(grid1, "/api/service-users/menu/deletePlgFxMenuAuthById/v1.0", "", "", { "id": rid }, false);
  432. return false;
  433. };
  434. window.res_BaseMenuConfig_editClick = function (rid, rdata) {
  435. grid1.selectRowById(rid);
  436. grid1.showDialog(1, "编辑", 650, 400, {
  437. url: "/api/service-users/menu/updatePlgFxMenuAuth/v1.0",
  438. type: "put",
  439. dataType: "json",
  440. contentType: "application/x-www-form-urlencoded"
  441. });
  442. return false;
  443. };
  444. })();
  445. </script>