node.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form'], function(){
  2. var laypage = layui.laypage //分页
  3. ,layer = layui.layer //弹层
  4. ,table = layui.table //表格
  5. ,element = layui.element //元素操作
  6. ,form = layui.form;
  7. //第一个实例
  8. table.render({
  9. elem: '#nodelist'
  10. ,url: '/auth/nodelistfrom' //数据接口
  11. ,where:{token:csrfToken}
  12. ,method:'post'
  13. // ,id:'id'
  14. ,page: true //开启分页
  15. ,text:'数据加载中'
  16. ,height : 600
  17. ,limit:20
  18. ,cols: [[ //表头
  19. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  20. {type:'numbers',title:'序号'}
  21. ,{field: 'controller', title: '控制器', align:'center'}
  22. ,{field: 'action', title: '方法',align:'center'}
  23. ,{field: 'describe', title: '描述', width:200,align:'center'}
  24. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  25. ]]
  26. });
  27. //列表操作
  28. table.on('tool(nodelist)', function(obj){
  29. var layEvent = obj.event,
  30. data = obj.data;
  31. if(layEvent === 'edit'){
  32. layer.open({
  33. type: 2,
  34. title: '编辑节点',
  35. closeBtn: 1, //不显示关闭按钮
  36. shade: [0],
  37. area: ['600px', '500px'],
  38. anim: 2,
  39. content: ['/auth/editnode?id='+data.id, 'yes'], //iframe的url,no代表不显示滚动条
  40. });
  41. } else if(layEvent === 'del') {
  42. layer.confirm('确定要删除吗?',{btn: ['确定', '取消']},function () {
  43. $.post('/auth/delfrom',{'token':csrfToken,'id':data.id},function (data) {
  44. if(data.code == 200){
  45. layer.msg(data.msg);
  46. table.reload('nodelist');
  47. return ;
  48. }
  49. layer.msg(data.msg);
  50. })
  51. })
  52. }
  53. });
  54. var $ = layui.$, active = {
  55. addData: function(){ //获取选中数据
  56. layer.open({
  57. type: 2,
  58. title: '添加菜单',
  59. closeBtn: 1, //不显示关闭按钮
  60. shade: [0],
  61. area: ['600px', '500px'],
  62. anim: 2,
  63. content: ['/auth/addnode', 'no'], //iframe的url,no代表不显示滚动条
  64. // end: function(){ //此处用于演示
  65. // layer.open({
  66. // type: 2,
  67. // title: '很多时候,我们想最大化看,比如像这个页面。',
  68. // shadeClose: true,
  69. // shade: false,
  70. // maxmin: true, //开启最大化最小化按钮
  71. // area: ['893px', '600px'],
  72. // content: '//fly.layui.com/'
  73. // });
  74. // }
  75. });
  76. // var checkStatus = table.checkStatus('idTest')
  77. // ,data = checkStatus.data;
  78. // layer.alert(JSON.stringify(data));
  79. },
  80. addDataall:function () {
  81. $.post('/auth/allcontroller',function (data) {
  82. console.log(data);
  83. if(data.code == 200)
  84. {
  85. layer.msg(data.msg);
  86. parent.layui.table.reload('nodelist');
  87. } else if(data.code == 300 ) {
  88. layer.msg(data.msg);
  89. }
  90. })
  91. }
  92. };
  93. $('.demoTable .layui-btn').on('click', function(){
  94. var type = $(this).data('type');
  95. active[type] ? active[type].call(this) : '';
  96. });
  97. //添加
  98. form.on('submit(tijiao)', function(data){
  99. $.post('/auth/addnodefrom',{'data':data.field},function (data) {
  100. console.log(data);
  101. if(data.code == 200)
  102. {
  103. layer.msg(data.msg);
  104. parent.layui.table.reload('nodelist');
  105. } else if(data.code == 300 ) {
  106. layer.msg(data.msg);
  107. }
  108. })
  109. return false;
  110. });
  111. //修改
  112. form.on('submit(editsubmit)', function(data){
  113. $.post('/auth/editnodefrom',{'data':data.field},function (data) {
  114. if(data.code == 200)
  115. {
  116. layer.msg('修改成功');
  117. parent.layui.table.reload('nodelist');
  118. setTimeout(function () {
  119. var index = parent.layer.getFrameIndex(window.name);
  120. parent.layer.close(index);
  121. },1000)
  122. } else if(data.code == 300 ) {
  123. layer.msg(data.msg);
  124. }
  125. })
  126. return false;
  127. });
  128. //删除
  129. });