forum.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. @Name:layuiAdmin 社区系统
  3. @Author:star1029
  4. @Site:http://www.layui.com/admin/
  5. @License:LPPL
  6. */
  7. layui.define(['table', 'form'], function(exports){
  8. var $ = layui.$
  9. ,table = layui.table
  10. ,form = layui.form;
  11. //帖子管理
  12. table.render({
  13. elem: '#LAY-app-forum-list'
  14. ,url: layui.setter.base + 'json/forum/list.js' //模拟接口
  15. ,cols: [[
  16. {type: 'checkbox', fixed: 'left'}
  17. ,{field: 'id', width: 100, title: 'ID', sort: true}
  18. ,{field: 'poster', title: '发帖人'}
  19. ,{field: 'avatar', title: '头像', width: 100, templet: '#imgTpl'}
  20. ,{field: 'content', title: '发帖内容'}
  21. ,{field: 'posttime', title: '发帖时间', sort: true}
  22. ,{field: 'top', title: '置顶', templet: '#buttonTpl', minWidth: 80, align: 'center'}
  23. ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-forum-list'}
  24. ]]
  25. ,page: true
  26. ,limit: 10
  27. ,limits: [10, 15, 20, 25, 30]
  28. ,text: '对不起,加载出现异常!'
  29. });
  30. //监听工具条
  31. table.on('tool(LAY-app-forum-list)', function(obj){
  32. var data = obj.data;
  33. if(obj.event === 'del'){
  34. layer.confirm('确定删除此条帖子?', function(index){
  35. obj.del();
  36. layer.close(index);
  37. });
  38. } else if(obj.event === 'edit'){
  39. var tr = $(obj.tr);
  40. layer.open({
  41. type: 2
  42. ,title: '编辑帖子'
  43. ,content: '../../../views/app/forum/listform.html'
  44. ,area: ['550px', '400px']
  45. ,btn: ['确定', '取消']
  46. ,resize: false
  47. ,yes: function(index, layero){
  48. var iframeWindow = window['layui-layer-iframe'+ index]
  49. ,submitID = 'LAY-app-forum-submit'
  50. ,submit = layero.find('iframe').contents().find('#'+ submitID);
  51. //监听提交
  52. iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
  53. var field = data.field; //获取提交的字段
  54. //提交 Ajax 成功后,静态更新表格中的数据
  55. //$.ajax({});
  56. table.reload('LAY-app-forum-list'); //数据刷新
  57. layer.close(index); //关闭弹层
  58. });
  59. submit.trigger('click');
  60. }
  61. ,success: function(layero, index){
  62. }
  63. });
  64. }
  65. });
  66. //回帖管理
  67. table.render({
  68. elem: '#LAY-app-forumreply-list'
  69. ,url: layui.setter.base + 'json/forum/replys.js' //模拟接口
  70. ,cols: [[
  71. {type: 'checkbox', fixed: 'left'}
  72. ,{field: 'id', width: 100, title: 'ID', sort: true}
  73. ,{field: 'replyer', title: '回帖人'}
  74. ,{field: 'cardid', title: '回帖ID', sort: true}
  75. ,{field: 'avatar', title: '头像', width: 100, templet: '#imgTpl'}
  76. ,{field: 'content', title: '回帖内容', width: 200}
  77. ,{field: 'replytime', title: '回帖时间', sort: true}
  78. ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-forum-replys'}
  79. ]]
  80. ,page: true
  81. ,limit: 10
  82. ,limits: [10, 15, 20, 25, 30]
  83. ,text: '对不起,加载出现异常!'
  84. });
  85. //监听工具条
  86. table.on('tool(LAY-app-forumreply-list)', function(obj){
  87. var data = obj.data;
  88. if(obj.event === 'del'){
  89. layer.confirm('确定删除此条评论?', function(index){
  90. obj.del();
  91. layer.close(index);
  92. });
  93. } else if(obj.event === 'edit'){
  94. var tr = $(obj.tr);
  95. layer.open({
  96. type: 2
  97. ,title: '编辑评论'
  98. ,content: '../../../views/app/forum/replysform.html'
  99. ,area: ['550px', '350px']
  100. ,btn: ['确定', '取消']
  101. ,resize: false
  102. ,yes: function(index, layero){
  103. //获取iframe元素的值
  104. var othis = layero.find('iframe').contents().find("#layuiadmin-form-replys");
  105. var content = othis.find('textarea[name="content"]').val();
  106. //数据更新
  107. obj.update({
  108. content: content
  109. });
  110. layer.close(index);
  111. }
  112. ,success: function(layero, index){
  113. }
  114. });
  115. }
  116. });
  117. exports('forum', {})
  118. });