article.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'ask/article/index',
  8. add_url: 'ask/article/add',
  9. edit_url: 'ask/article/edit',
  10. del_url: 'ask/article/del',
  11. multi_url: 'ask/article/multi',
  12. table: 'ask_article',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. fixedColumns: true,
  22. fixedRightNumber: 1,
  23. columns: [
  24. [
  25. {checkbox: true},
  26. {field: 'id', title: __('Id')},
  27. {field: 'user_id', title: __('User_id'), formatter: Table.api.formatter.search},
  28. {field: 'user.nickname', title: __('Nickname'), operate: false},
  29. {field: 'category_id', title: __('Category_id'), formatter: Table.api.formatter.search},
  30. {field: 'category.name', title: __('Category_name'), operate: false},
  31. {field: 'title', title: __('Title')},
  32. {field: 'keywords', title: __('Keywords'), visible: false},
  33. {field: 'flag', title: __('Flag'), searchList: {"index": __('Index'), "hot": __('Hot'), "recommend": __('Recommend')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
  34. {field: 'image', title: __('Image'), formatter: Table.api.formatter.image},
  35. {field: 'price', title: __('Price'), operate: 'BETWEEN'},
  36. {field: 'comments', title: __('Comments')},
  37. {field: 'sales', title: __('Sales')},
  38. {field: 'shares', title: __('Shares'), visible: false},
  39. {field: 'views', title: __('Views'), visible: false},
  40. {field: 'thanks', title: __('Thanks'), visible: false},
  41. {field: 'reports', title: __('Reports'), visible: false},
  42. {field: 'collections', title: __('Collections'), visible: false},
  43. {field: 'isanonymous', title: __('Isanonymous'), visible: false},
  44. {
  45. field: 'url', title: __('Url'), formatter: function (value, row, index) {
  46. return '<a href="' + row['url'] + '" target="_blank" class="btn btn-xs btn-warning">查看</a>'
  47. }, operate: false
  48. },
  49. {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  50. {field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime, visible: false},
  51. {field: 'status', title: __('Status'), searchList: {"normal": __('Normal'), "hidden": __('Hidden')}, formatter: Table.api.formatter.status},
  52. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  53. ]
  54. ]
  55. });
  56. // 为表格绑定事件
  57. Table.api.bindevent(table);
  58. },
  59. recyclebin: function () {
  60. // 初始化表格参数配置
  61. Table.api.init({
  62. extend: {
  63. 'dragsort_url': ''
  64. }
  65. });
  66. var table = $("#table");
  67. // 初始化表格
  68. table.bootstrapTable({
  69. url: 'ask/article/recyclebin',
  70. pk: 'id',
  71. sortName: 'id',
  72. columns: [
  73. [
  74. {checkbox: true},
  75. {field: 'id', title: __('Id')},
  76. {field: 'title', title: __('Title'), align: 'left'},
  77. {
  78. field: 'deletetime',
  79. title: __('Deletetime'),
  80. operate: 'RANGE',
  81. addclass: 'datetimerange',
  82. formatter: Table.api.formatter.datetime
  83. },
  84. {
  85. field: 'operate',
  86. width: '130px',
  87. title: __('Operate'),
  88. table: table,
  89. events: Table.api.events.operate,
  90. buttons: [
  91. {
  92. name: 'Restore',
  93. text: __('Restore'),
  94. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  95. icon: 'fa fa-rotate-left',
  96. url: 'ask/article/restore',
  97. refresh: true
  98. },
  99. {
  100. name: 'Destroy',
  101. text: __('Destroy'),
  102. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  103. icon: 'fa fa-times',
  104. url: 'ask/article/destroy',
  105. refresh: true
  106. }
  107. ],
  108. formatter: Table.api.formatter.operate
  109. }
  110. ]
  111. ]
  112. });
  113. // 为表格绑定事件
  114. Table.api.bindevent(table);
  115. },
  116. add: function () {
  117. Controller.api.bindevent();
  118. },
  119. edit: function () {
  120. Controller.api.bindevent();
  121. },
  122. api: {
  123. bindevent: function () {
  124. Form.api.bindevent($("form[role=form]"));
  125. }
  126. }
  127. };
  128. return Controller;
  129. });