contlist.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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-content-list'
  14. ,url: layui.setter.base + 'json/content/list.js' //模拟接口
  15. ,cols: [[
  16. {type: 'checkbox', fixed: 'left'}
  17. ,{field: 'id', width: 100, title: '文章ID', sort: true}
  18. ,{field: 'label', title: '文章标签', minWidth: 100}
  19. ,{field: 'title', title: '文章标题'}
  20. ,{field: 'author', title: '作者'}
  21. ,{field: 'uploadtime', title: '上传时间', sort: true}
  22. ,{field: 'status', title: '发布状态', templet: '#buttonTpl', minWidth: 80, align: 'center'}
  23. ,{title: '操作', minWidth: 150, align: 'center', fixed: 'right', toolbar: '#table-content-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-content-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. layer.open({
  40. type: 2
  41. ,title: '编辑文章'
  42. ,content: '../../../views/app/content/listform.html?id='+ data.id
  43. ,maxmin: true
  44. ,area: ['550px', '550px']
  45. ,btn: ['确定', '取消']
  46. ,yes: function(index, layero){
  47. var iframeWindow = window['layui-layer-iframe'+ index]
  48. ,submit = layero.find('iframe').contents().find("#layuiadmin-app-form-edit");
  49. //监听提交
  50. iframeWindow.layui.form.on('submit(layuiadmin-app-form-edit)', function(data){
  51. var field = data.field; //获取提交的字段
  52. //提交 Ajax 成功后,静态更新表格中的数据
  53. //$.ajax({});
  54. obj.update({
  55. label: field.label
  56. ,title: field.title
  57. ,author: field.author
  58. ,status: field.status
  59. }); //数据更新
  60. form.render();
  61. layer.close(index); //关闭弹层
  62. });
  63. submit.trigger('click');
  64. }
  65. });
  66. }
  67. });
  68. //分类管理
  69. table.render({
  70. elem: '#LAY-app-content-tags'
  71. ,url: layui.setter.base + 'json/content/tags.js' //模拟接口
  72. ,cols: [[
  73. {type: 'numbers', fixed: 'left'}
  74. ,{field: 'id', width: 100, title: 'ID', sort: true}
  75. ,{field: 'tags', title: '分类名', minWidth: 100}
  76. ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#layuiadmin-app-cont-tagsbar'}
  77. ]]
  78. ,text: '对不起,加载出现异常!'
  79. });
  80. //监听工具条
  81. table.on('tool(LAY-app-content-tags)', function(obj){
  82. var data = obj.data;
  83. if(obj.event === 'del'){
  84. layer.confirm('确定删除此分类?', function(index){
  85. obj.del();
  86. layer.close(index);
  87. });
  88. } else if(obj.event === 'edit'){
  89. var tr = $(obj.tr);
  90. layer.open({
  91. type: 2
  92. ,title: '编辑分类'
  93. ,content: '../../../views/app/content/tagsform.html?id='+ data.id
  94. ,area: ['450px', '200px']
  95. ,btn: ['确定', '取消']
  96. ,yes: function(index, layero){
  97. //获取iframe元素的值
  98. var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags")
  99. ,tags = othis.find('input[name="tags"]').val();
  100. if(!tags.replace(/\s/g, '')) return;
  101. obj.update({
  102. tags: tags
  103. });
  104. layer.close(index);
  105. }
  106. ,success: function(layero, index){
  107. //给iframe元素赋值
  108. var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags").click();
  109. othis.find('input[name="tags"]').val(data.tags);
  110. }
  111. });
  112. }
  113. });
  114. //评论管理
  115. table.render({
  116. elem: '#LAY-app-content-comm'
  117. ,url: layui.setter.base + 'json/content/comment.js' //模拟接口
  118. ,cols: [[
  119. {type: 'checkbox', fixed: 'left'}
  120. ,{field: 'id', width: 100, title: 'ID', sort: true}
  121. ,{field: 'reviewers', title: '评论者', minWidth: 100}
  122. ,{field: 'content', title: '评论内容', minWidth: 100}
  123. ,{field: 'commtime', title: '评论时间', minWidth: 100, sort: true}
  124. ,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-content-com'}
  125. ]]
  126. ,page: true
  127. ,limit: 10
  128. ,limits: [10, 15, 20, 25, 30]
  129. ,text: '对不起,加载出现异常!'
  130. });
  131. //监听工具条
  132. table.on('tool(LAY-app-content-comm)', function(obj){
  133. var data = obj.data;
  134. if(obj.event === 'del'){
  135. layer.confirm('确定删除此条评论?', function(index){
  136. obj.del();
  137. layer.close(index);
  138. });
  139. } else if(obj.event === 'edit') {
  140. layer.open({
  141. type: 2
  142. ,title: '编辑评论'
  143. ,content: '../../../views/app/content/contform.html'
  144. ,area: ['450px', '300px']
  145. ,btn: ['确定', '取消']
  146. ,yes: function(index, layero){
  147. var iframeWindow = window['layui-layer-iframe'+ index]
  148. ,submitID = 'layuiadmin-app-comm-submit'
  149. ,submit = layero.find('iframe').contents().find('#'+ submitID);
  150. //监听提交
  151. iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
  152. var field = data.field; //获取提交的字段
  153. //提交 Ajax 成功后,静态更新表格中的数据
  154. //$.ajax({});
  155. table.reload('LAY-app-content-comm'); //数据刷新
  156. layer.close(index); //关闭弹层
  157. });
  158. submit.trigger('click');
  159. }
  160. ,success: function(layero, index){
  161. }
  162. });
  163. }
  164. });
  165. exports('contlist', {})
  166. });