test.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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: 'test/index' + location.search,
  8. add_url: 'test/add',
  9. edit_url: 'test/edit',
  10. del_url: 'test/del',
  11. multi_url: 'test/multi',
  12. import_url: 'test/import',
  13. table: 'test',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'weigh',
  22. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'user_id', title: __('User_id')},
  29. {field: 'admin_id', title: __('Admin_id')},
  30. {field: 'category_id', title: __('Category_id')},
  31. {field: 'category_ids', title: __('Category_ids'), operate: 'LIKE'},
  32. {field: 'tags', title: __('Tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
  33. {field: 'week', title: __('Week'), searchList: {"monday":__('Week monday'),"tuesday":__('Week tuesday'),"wednesday":__('Week wednesday')}, formatter: Table.api.formatter.normal},
  34. {field: 'flag', title: __('Flag'), searchList: {"hot":__('Flag hot'),"index":__('Flag index'),"recommend":__('Flag recommend')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
  35. {field: 'genderdata', title: __('Genderdata'), searchList: {"male":__('Genderdata male'),"female":__('Genderdata female')}, formatter: Table.api.formatter.normal},
  36. {field: 'hobbydata', title: __('Hobbydata'), searchList: {"music":__('Hobbydata music'),"reading":__('Hobbydata reading'),"swimming":__('Hobbydata swimming')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
  37. {field: 'title', title: __('Title'), operate: 'LIKE'},
  38. {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  39. {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
  40. {field: 'attachfile', title: __('Attachfile'), operate: false, formatter: Table.api.formatter.file},
  41. {field: 'keywords', title: __('Keywords'), operate: 'LIKE'},
  42. {field: 'description', title: __('Description'), operate: 'LIKE'},
  43. {field: 'city', title: __('City'), operate: 'LIKE'},
  44. {field: 'price', title: __('Price'), operate:'BETWEEN'},
  45. {field: 'views', title: __('Views')},
  46. {field: 'workrange', title: __('Workrange'), operate: 'LIKE'},
  47. {field: 'startdate', title: __('Startdate'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  48. {field: 'activitytime', title: __('Activitytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  49. {field: 'year', title: __('Year')},
  50. {field: 'times', title: __('Times')},
  51. {field: 'refreshtime', title: __('Refreshtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  52. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  53. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  54. {field: 'weigh', title: __('Weigh'), operate: false},
  55. {field: 'switch', title: __('Switch'), searchList: {"1":__('Yes'),"0":__('No')}, table: table, formatter: Table.api.formatter.toggle},
  56. {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
  57. {field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1'),"2":__('State 2')}, formatter: Table.api.formatter.normal},
  58. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  59. ]
  60. ]
  61. });
  62. // 为表格绑定事件
  63. Table.api.bindevent(table);
  64. },
  65. recyclebin: function () {
  66. // 初始化表格参数配置
  67. Table.api.init({
  68. extend: {
  69. 'dragsort_url': ''
  70. }
  71. });
  72. var table = $("#table");
  73. // 初始化表格
  74. table.bootstrapTable({
  75. url: 'test/recyclebin' + location.search,
  76. pk: 'id',
  77. sortName: 'id',
  78. columns: [
  79. [
  80. {checkbox: true},
  81. {field: 'id', title: __('Id')},
  82. {field: 'title', title: __('Title'), align: 'left'},
  83. {
  84. field: 'deletetime',
  85. title: __('Deletetime'),
  86. operate: 'RANGE',
  87. addclass: 'datetimerange',
  88. formatter: Table.api.formatter.datetime
  89. },
  90. {
  91. field: 'operate',
  92. width: '130px',
  93. title: __('Operate'),
  94. table: table,
  95. events: Table.api.events.operate,
  96. buttons: [
  97. {
  98. name: 'Restore',
  99. text: __('Restore'),
  100. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  101. icon: 'fa fa-rotate-left',
  102. url: 'test/restore',
  103. refresh: true
  104. },
  105. {
  106. name: 'Destroy',
  107. text: __('Destroy'),
  108. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  109. icon: 'fa fa-times',
  110. url: 'test/destroy',
  111. refresh: true
  112. }
  113. ],
  114. formatter: Table.api.formatter.operate
  115. }
  116. ]
  117. ]
  118. });
  119. // 为表格绑定事件
  120. Table.api.bindevent(table);
  121. },
  122. add: function () {
  123. Controller.api.bindevent();
  124. },
  125. edit: function () {
  126. Controller.api.bindevent();
  127. },
  128. api: {
  129. bindevent: function () {
  130. Form.api.bindevent($("form[role=form]"));
  131. }
  132. }
  133. };
  134. return Controller;
  135. });