menufront.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. layui.use(['layer', 'table','form'], function(){
  2. var layer = layui.layer //弹层
  3. ,table = layui.table //表格
  4. ,form = layui.form;
  5. //第一个实例
  6. table.render({
  7. elem: '#frontmenulist'
  8. ,url: '/menu/fronthomeform' //数据接口
  9. ,where:{token:csrfToken}
  10. ,method:'post'
  11. ,id:'tablerReload'
  12. ,page: true //开启分页
  13. ,text:'数据加载中'
  14. ,cols: [[ //表头
  15. {type:'numbers',title:'序号'}
  16. ,{field: 'name', title: '菜单名称', align:'center'}
  17. ,{field: 'url', title: '地址', width:300,align:'center'}
  18. ,{field: 'sort', title: '排序', width:100,align:'center'}
  19. ,{field: 'status', title: '状态', width:80,align:'center',templet:function (d) {
  20. if(d.status === '2'){
  21. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  22. } else {
  23. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  24. }
  25. }}
  26. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  27. ]]
  28. });
  29. //列表操作
  30. table.on('tool(frontmenulist)', function(obj){
  31. var layEvent = obj.event,
  32. data = obj.data;
  33. if(layEvent === 'edit'){
  34. layer.open({
  35. type: 2,
  36. title: '修改前端菜单',
  37. closeBtn: 1, //不显示关闭按钮
  38. shade: [0],
  39. area: ['600px', '500px'],
  40. anim: 2,
  41. content:'/menu/frontedit?id='+data.id,
  42. end:function(){
  43. table.reload('tablerReload'); //重新加载
  44. }
  45. });
  46. } else if(layEvent === 'del') {
  47. layer.confirm('确定要删除该菜单吗?',{btn: ['确定', '取消']},function () {
  48. $.post('/menu/frontstateform',{id:data.id,type:1},function (data) {
  49. if(data.code == 200)
  50. {
  51. layer.msg(data.msg);
  52. table.reload('tablerReload');
  53. } else if(data.code == 300 ) {
  54. layer.msg(data.msg);
  55. }
  56. })
  57. })
  58. }
  59. });
  60. //监听指定开关
  61. form.on('switch(switchTest)', function(data){
  62. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  63. $.post('/menu/frontstateform',{id:data.value,type:2},function (data) {
  64. if(data.code == 200)
  65. {
  66. layer.msg(data.msg);
  67. table.reload('tablerReload');
  68. } else if(data.code == 300 ) {
  69. layer.msg(data.msg);
  70. }
  71. })
  72. },function (aa) {
  73. table.reload('tablerReload'); //重新加载
  74. })
  75. });
  76. var $ = layui.$, active = {
  77. addData: function(){ //获取选中数据
  78. layer.open({
  79. type: 2,
  80. title: '添加前台菜单',
  81. closeBtn: 1, //不显示关闭按钮
  82. shade: [0],
  83. area: ['600px', '500px'],
  84. anim: 2,
  85. content: '/menu/frontadd',
  86. end: function(){ //此处用于演示
  87. table.reload('tablerReload'); //重新加载
  88. }
  89. });
  90. }
  91. };
  92. $('.demoTable .layui-btn').on('click', function(){
  93. var type = $(this).data('type');
  94. active[type] ? active[type].call(this) : '';
  95. });
  96. form.on('submit(editmenu)', function(data){
  97. $.post('/menu/fronteditform',{'data':data.field},function (data) {
  98. if(data.data != null){
  99. layer.msg(ReturnInfo(data.data),{icon:5});
  100. return ;
  101. }
  102. layer.msg(data.msg)
  103. })
  104. return false;
  105. });
  106. form.on('submit(addmenu)', function(data){
  107. $.post('/menu/frontaddform',{'data':data.field},function (data) {
  108. if(data.data != null){
  109. layer.msg(ReturnInfo(data.data),{icon:5});
  110. return ;
  111. }
  112. layer.msg(data.msg)
  113. })
  114. return false;
  115. });
  116. });