question.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/question/index',
  8. add_url: 'ask/question/add',
  9. edit_url: 'ask/question/edit',
  10. del_url: 'ask/question/del',
  11. multi_url: 'ask/question/multi',
  12. table: 'ask_question',
  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'), width: "200"},
  32. {field: 'price', title: __('Price'), operate: 'BETWEEN'},
  33. {field: 'score', title: __('Score'), operate: 'BETWEEN'},
  34. {field: 'flag', title: __('Flag'), searchList: {"index": __('Index'), "hot": __('Hot'), "recommend": __('Recommend')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label, visible: false},
  35. {field: 'voteup', title: __('Voteup'), visible: false},
  36. {field: 'votedown', title: __('Votedown'), visible: false},
  37. {field: 'followers', title: __('Followers'), visible: false},
  38. {field: 'views', title: __('Views'), visible: false},
  39. {field: 'collections', title: __('Collections'), visible: false},
  40. {field: 'thanks', title: __('Thanks'), visible: false},
  41. {field: 'reports', title: __('Reports'), visible: false},
  42. {field: 'answers', title: __('Answers')},
  43. {field: 'comments', title: __('Comments'), visible: false},
  44. {field: 'peeps', title: __('Peeps'), visible: false},
  45. {field: 'best_answer_id', title: __('Best_answer_id'), visible: false},
  46. {field: 'isanonymous', title: __('Isanonymous'), visible: false, visible: false},
  47. {
  48. field: 'url', title: __('Url'), formatter: function (value, row, index) {
  49. return '<a href="' + row['url'] + '" target="_blank" class="btn btn-xs btn-warning">查看</a>'
  50. }, operate: false
  51. },
  52. {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  53. {field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  54. {field: 'status', title: __('Status'), searchList: {"normal": __('Normal'), "hidden": __('Hidden'), "solved": __('Solved'), "closed": __('Closed')}, formatter: Table.api.formatter.status},
  55. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  56. ]
  57. ]
  58. });
  59. // 为表格绑定事件
  60. Table.api.bindevent(table);
  61. },
  62. recyclebin: function () {
  63. // 初始化表格参数配置
  64. Table.api.init({
  65. extend: {
  66. 'dragsort_url': ''
  67. }
  68. });
  69. var table = $("#table");
  70. // 初始化表格
  71. table.bootstrapTable({
  72. url: 'ask/question/recyclebin',
  73. pk: 'id',
  74. sortName: 'id',
  75. columns: [
  76. [
  77. {checkbox: true},
  78. {field: 'id', title: __('Id')},
  79. {field: 'user_id', title: __('User_id'), formatter: Table.api.formatter.search},
  80. {field: 'title', title: __('Title'), align: 'left'},
  81. {
  82. field: 'url', title: __('Url'), formatter: function (value, row, index) {
  83. return '<a href="' + row['url'] + '" target="_blank" class="btn btn-xs btn-warning">查看</a>'
  84. }, operate: false
  85. },
  86. {
  87. field: 'deletetime',
  88. title: __('Deletetime'),
  89. operate: 'RANGE',
  90. addclass: 'datetimerange',
  91. formatter: Table.api.formatter.datetime
  92. },
  93. {
  94. field: 'operate',
  95. width: '130px',
  96. title: __('Operate'),
  97. table: table,
  98. events: Table.api.events.operate,
  99. buttons: [
  100. {
  101. name: 'Restore',
  102. text: __('Restore'),
  103. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  104. icon: 'fa fa-rotate-left',
  105. url: 'ask/question/restore'
  106. },
  107. {
  108. name: 'Destroy',
  109. text: __('Destroy'),
  110. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  111. icon: 'fa fa-times',
  112. url: 'ask/question/destroy'
  113. }
  114. ],
  115. formatter: Table.api.formatter.operate
  116. }
  117. ]
  118. ]
  119. });
  120. // 为表格绑定事件
  121. Table.api.bindevent(table);
  122. },
  123. add: function () {
  124. Controller.api.bindevent();
  125. },
  126. edit: function () {
  127. Controller.api.bindevent();
  128. },
  129. api: {
  130. bindevent: function () {
  131. Form.api.bindevent($("form[role=form]"));
  132. }
  133. }
  134. };
  135. return Controller;
  136. });