list.jsp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@taglib prefix="p" uri="http://www.test.com/jsp/permission" %>
  4. <!doctype html>
  5. <html>
  6. <head>
  7. <%@ include file="../../common/head.jsp"%>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  9. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  10. <link rel="stylesheet" href="../res/js/plugins/ztree/demo.css" type="text/css">
  11. <link rel="stylesheet" href="../res/js/plugins/ztree/metroStyle/metroStyle.css" type="text/css">
  12. <script type="text/javascript" src="../res/js/plugins/ztree/jquery.ztree.core.js"></script>
  13. <script type="text/javascript" src="../res/js/plugins/ztree/jquery.ztree.excheck.js"></script>
  14. <script type="text/javascript" src="../res/js/plugins/ztree/jquery.ztree.exedit.js"></script>
  15. <script type="text/javascript">
  16. function test(value,row,index){
  17. // return '<a href="#">' + row['id'] + '</a>';
  18. return '<a href="#">编辑 </a>|<a href="#">删除</a>';
  19. }
  20. var _width = "768px";
  21. var _height = "420px";
  22. function setAction(){
  23. var data = getSelectedRow("tab_menu");
  24. if(null == data){
  25. return;
  26. }
  27. $.openDlg({
  28. url:'transfer.cs?action=setAction&id=' + data.id,
  29. title:"设定操作权限 - " + data.name,
  30. width:'100%',
  31. height:'100%',
  32. });
  33. }
  34. var setting = {
  35. view: {
  36. removeHoverDom: removeHoverDom,
  37. selectedMulti: false
  38. },
  39. check: {
  40. enable: true,
  41. chkStyle: "radio",
  42. radioType: "all"
  43. },
  44. data: {
  45. simpleData: {
  46. enable: true
  47. }
  48. },
  49. edit: {
  50. enable: true,
  51. },
  52. callback: {
  53. // onCheck: zTreeOnCheck
  54. beforeRemove: zTreeBeforeRemove,
  55. beforeEditName: zTreeBeforeEditName
  56. }
  57. };
  58. function addAction(){
  59. var nodes = $.fn.zTree.getZTreeObj("treeMenu").getCheckedNodes(true);
  60. var _id = 0 ;
  61. if(nodes.length > 0){
  62. if(nodes[0].level == 1){
  63. _id = nodes[0].id;
  64. $.openDlg({
  65. url:'transfer2.cs?action=addAction&id=0&menu_id=' + _id,
  66. title:'新增Action',
  67. width:'769px',
  68. height:'240px',
  69. });
  70. }
  71. }
  72. }
  73. var newCount = 1;
  74. function addHoverDom(treeId, treeNode) {
  75. var sObj = $("#" + treeNode.tId + "_span");
  76. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
  77. var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
  78. + "' title='add node' onfocus='this.blur();'></span>";
  79. sObj.after(addStr);
  80. var btn = $("#addBtn_"+treeNode.tId);
  81. if (btn) btn.bind("click", function(){
  82. // var zTree = $.fn.zTree.getZTreeObj("treeMenu");
  83. // zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
  84. // alert(treeNode.id);
  85. /* if(treeNode.level == 2){
  86. $.openDlg({
  87. url:'transfer2.cs?action=addAction&id=0&menu_id=' + treeNode.getParentNode().id,
  88. title:'新增Action',
  89. width:'769px',
  90. height:'240px',
  91. });
  92. }
  93. else{
  94. } */
  95. $.openDlg({
  96. url:'transfer.cs?action=add&id=' + treeNode.id,
  97. title:'新增菜单',
  98. width:_width,
  99. height:_height,
  100. });
  101. return false;
  102. });
  103. };
  104. function removeHoverDom(treeId, treeNode) {
  105. $("#addBtn_"+treeNode.tId).unbind().remove();
  106. // var btn = $("#addBtn_"+treeNode.tId);
  107. // if (btn)btn.bind("click", function(){
  108. // $.confirm("确定删除吗? ", function(){
  109. // $.post('del.cs?id=' + treeId.id,
  110. // function(result){
  111. // window.location.reload();
  112. // }
  113. // );
  114. // });
  115. // });
  116. };
  117. function zTreeBeforeRemove(treeId, treeNode) {
  118. var url = '';
  119. /* if(treeNode.level == 2){
  120. url = 'delAction.cs?id=' + treeNode.id
  121. }
  122. else{
  123. } */
  124. url = 'del.cs?id=' + treeNode.id
  125. $.confirm("确定删除吗? ", function(){
  126. $.post(url,
  127. function(result){
  128. window.location.reload();
  129. }
  130. );
  131. });
  132. return false;
  133. }
  134. function zTreeBeforeEditName(treeId, treeNode) {
  135. $.openDlg({
  136. url:'transfer.cs?action=edit&id=' + treeNode.id,
  137. title:'编辑菜单',
  138. width:_width,
  139. height:_height,
  140. });
  141. /* if(treeNode.level == 2){
  142. $.openDlg({
  143. url:'transfer2.cs?action=editAction&id=' + treeNode.id + '&menu_id=' + treeNode.getParentNode().id,
  144. title:'编辑Action',
  145. width:'769px',
  146. height:'280px',
  147. });
  148. }
  149. else{
  150. } */
  151. return false;
  152. }
  153. $(document).ready(function(){
  154. $.get('list2.cs', function(data){
  155. zNodes = data;
  156. $.fn.zTree.init($("#treeMenu"), setting, zNodes);
  157. });
  158. });
  159. // 预览事件
  160. function view(){
  161. var menu = $.fn.zTree.getZTreeObj("treeMenu");
  162. var nodes;
  163. if(menu != null){
  164. nodes = menu.getCheckedNodes(true);
  165. }else{
  166. layer.msg("请选择要查看的菜单");
  167. return;
  168. }
  169. if(nodes.length < 1 ){
  170. return ;
  171. }
  172. var data = nodes[0];
  173. $.openDlg({
  174. url:'transfer.cs?action=view&id=' + data.id,
  175. title:'查看菜单',
  176. width:_width,
  177. height:_height,
  178. });
  179. }
  180. // 新增事件
  181. function add(){
  182. var _id = 0 ;
  183. var menu = $.fn.zTree.getZTreeObj("treeMenu");
  184. var nodes;
  185. if(menu != null){
  186. nodes = menu.getCheckedNodes(true);
  187. }
  188. if(typeof(nodes) != "undefined" && nodes.length > 0){
  189. if(nodes[0].level == 2){
  190. nodes = nodes[0].getParentNode().getParentNode();
  191. _id = nodes.id;
  192. }
  193. else if(nodes[0].level == 1){
  194. _id = nodes[0].getParentNode().id;
  195. }
  196. // if(nodes[0].level != 0) return;
  197. }
  198. $.openDlg({
  199. // url:'transfer.cs?action=add&id=0',
  200. url:'transfer.cs?action=add&id=' + _id,
  201. title:'新增菜单',
  202. width:_width,
  203. height:_height,
  204. });
  205. }
  206. // 编辑事件
  207. function edit(){
  208. var nodes = $.fn.zTree.getZTreeObj("treeMenu").getCheckedNodes(true);
  209. var _id = 0 ;
  210. if(nodes.length > 0 ){
  211. _id = nodes[0].id;
  212. }
  213. else{
  214. return ;
  215. }
  216. $.openDlg({
  217. url:'transfer.cs?action=edit&id=' + _id,
  218. title:'编辑菜单',
  219. width:_width,
  220. height:_height,
  221. });
  222. }
  223. // 删除事件
  224. function del(){
  225. var nodes = $.fn.zTree.getZTreeObj("treeMenu").getCheckedNodes(true);
  226. var _id = 0 ;
  227. if(nodes.length > 0 ){
  228. _id = nodes[0].id;
  229. }
  230. else{
  231. return ;
  232. }
  233. $.confirm("确定删除吗? ", function(){
  234. $.post('del.cs?id=' + _id,
  235. function(result){
  236. window.location.reload();
  237. }
  238. );
  239. });
  240. }
  241. </script>
  242. </head>
  243. <body class="gray-bg">
  244. <div class="wrapper wrapper-content animated fadeInUp">
  245. <div class="row row-lg">
  246. <div class="col-sm-12">
  247. <p:permission menuCode="${menuCode }" action="1">
  248. <button class="btn btn-sm btn-info" type="button" onclick="view()"><i class="fa fa-info"></i>&nbsp;查看</button>
  249. </p:permission>
  250. <p:permission menuCode="${menuCode }" action="2">
  251. <button class="btn btn-sm btn-success" type="button" onclick="add()"><i class="fa fa-plus"></i>&nbsp;新增菜单</button>
  252. </p:permission>
  253. <ul id="treeMenu" class="ztree" style="width:100%;"></ul>
  254. </div>
  255. </div>
  256. </div>
  257. </body>
  258. </html>