index.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <extend name="Public:base" />
  2. <block name="javascript">
  3. <script src="__PUBLIC__/ztree/jquery.ztree.all-3.5.min.js"></script>
  4. <link rel="stylesheet" type="text/css" href="__PUBLIC__/ztree/zTreeStyle.css" />
  5. <link rel="stylesheet" type="text/css" href="__PUBLIC__/ztree/demo.css" />
  6. <script>
  7. $(function(){
  8. $('.J_SubmitPL').click(function(e){
  9. //$('#alert').css({'display':'none'});
  10. $("#dialog").css('display','none');
  11. $('.ks-ext-mask').css('display','none');
  12. var zTree = $.fn.zTree.getZTreeObj("menu_tree"),
  13. nodes = zTree.getSelectedNodes(),
  14. treeNode = nodes[0];
  15. if(treeNode!=undefined){
  16. var isp= nodes[0].isParent;
  17. }else{
  18. var isp= true;
  19. }
  20. var id=(treeNode==undefined?0:treeNode.id);
  21. var url;
  22. if($("input[name='action']").val()=='add'){
  23. url='{:U("Menu/add")}';
  24. }else if($("input[name='action']").val()=='edit'){
  25. url='{:U("Menu/edit")}';
  26. }
  27. $.post(
  28. url,
  29. {
  30. 'id':id,
  31. 'title':$("input[name='title']").val(),
  32. 'url':$("input[name='url']").val(),
  33. 'sort_order':$("input[name='sort_order']").val(),
  34. },
  35. function(d){
  36. if($("input[name='action']").val()=='add'){
  37. //有父节点
  38. if(treeNode){
  39. treeNode = zTree.addNodes(treeNode, {id:d.id, pId:id, isParent:isp, name:d.name});
  40. }else{
  41. treeNode = zTree.addNodes(treeNode, {id:d.id, pId:0, isParent:isp, name:d.name});
  42. }
  43. }else{
  44. if(d.success){
  45. nodes[0].name = d.name;
  46. zTree.updateNode(nodes[0]);
  47. }
  48. if(d.err){
  49. alert(d.err);
  50. }
  51. }
  52. }
  53. );
  54. });
  55. });
  56. </script>
  57. <script>
  58. var setting = {
  59. view: {
  60. addHoverDom: false,
  61. removeHoverDom: false,
  62. selectedMulti: false
  63. },
  64. edit: {
  65. enable: true,
  66. editNameSelectAll: true,
  67. showRemoveBtn: false,
  68. showRenameBtn: false
  69. },
  70. data: {
  71. simpleData: {
  72. enable: true
  73. }
  74. }
  75. };
  76. var zNodes ={$list};
  77. function add(e) {
  78. $("input[name='action']").val('add');
  79. $('.title').find('span').text('新增菜单');
  80. $("#dialog").css({'position' : 'fixed','display' : 'block', 'z-index' : '9999'});
  81. }
  82. function edit() {
  83. $("input[name='action']").val('edit');
  84. var zTree = $.fn.zTree.getZTreeObj("menu_tree"),
  85. nodes = zTree.getSelectedNodes(),
  86. treeNode = nodes[0];
  87. if (nodes.length == 0) {
  88. alert("请先选择一个节点");
  89. return;
  90. }else{
  91. var id=treeNode.id;
  92. $.post(
  93. '{:U("Menu/get_info")}',
  94. {
  95. 'id':id,
  96. },
  97. function(d){
  98. $("input[name='title']").val(d.title);
  99. $("input[name='url']").val(d.url);
  100. $("input[name='sort_order']").val(d.sort_order);
  101. }
  102. );
  103. $('.title').find('span').text('编辑菜单');
  104. $("#dialog").css({'position' : 'fixed','display' : 'block', 'z-index' : '9999'});
  105. }
  106. }
  107. function remove(e) {
  108. if(!confirm('确认要删除吗!!')){
  109. return false;
  110. }
  111. var zTree = $.fn.zTree.getZTreeObj("menu_tree"),
  112. nodes = zTree.getSelectedNodes(),
  113. treeNode = nodes[0];
  114. if (nodes.length == 0) {
  115. alert("请先选择一个节点");
  116. return;
  117. }
  118. $.post(
  119. '{:U("Menu/del")}',
  120. {
  121. 'id':treeNode.id,
  122. },
  123. function(d){
  124. if(d.err){
  125. alert(d.err);
  126. }else{
  127. zTree.removeNode(treeNode);
  128. }
  129. }
  130. );
  131. }
  132. $(document).ready(function(){
  133. $.fn.zTree.init($("#menu_tree"), setting, zNodes);
  134. $("#addParent").bind("click", {isParent:true}, add);
  135. $("#edit").bind("click", edit);
  136. $("#remove").bind("click", remove);
  137. //关闭弹出层
  138. $('#dialog').on('click','.ks-ext-close',function(){
  139. $("#dialog").css('display','none');
  140. $('.ks-ext-mask').css('display','none');
  141. return false;
  142. });
  143. //关闭弹出层
  144. $('#dialog').on('click','.J_Cancel',function(){
  145. $("#dialog").css('display','none');
  146. $('.ks-ext-mask').css('display','none');
  147. return false;
  148. });
  149. });
  150. </script>
  151. </block>
  152. <block name="content">
  153. <link rel="stylesheet" href="__CSS__/dialog.css" />
  154. <div class="ks-ext-mask" style="position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 999; display:none"></div>
  155. <div id="dialog" class="dialog" style="z-index: 9999; display:none">
  156. <div class="ks-contentbox">
  157. <div class="title"><span>新增菜单</span><a class="ks-ext-close" href="javascript:void(0)">X</a></div>
  158. <input type="hidden" name="action" value="" />
  159. <dl>
  160. <dt>菜单名称</dt>
  161. <dd><input type="text" name="title" class="text" /></dd>
  162. <dt>URL</dt>
  163. <dd><input name="url" type="text" value="" size="50" /></dd>
  164. <dt>排序</dt>
  165. <dd>
  166. <input name="sort_order" type="text" value="" />
  167. </dd>
  168. </dl>
  169. <div class="J_DefaultMessage"></div>
  170. <div class="bottom">
  171. <a href="javascript:void(0);" class="J_SubmitPL ncsc-btn ncsc-btn-green">确认</a>
  172. <a href="javascript:void(0);" class="J_Cancel ncsc-btn">取消</a> </div>
  173. </div>
  174. </div>
  175. <div class="page-header">
  176. <a id="addParent" class="btn btn-primary">新增</a>
  177. <a id="edit" class="btn btn-primary">编辑</a>
  178. <a id="remove" class="btn btn-primary">删除</a>
  179. </div>
  180. <div class="row">
  181. <div id="menu_tree" class="ztree"></div>
  182. </div>
  183. </block>