special.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. //设置弹窗宽高
  3. Fast.config.openArea = ['80%', '80%'];
  4. var Controller = {
  5. index: function () {
  6. // 初始化表格参数配置
  7. Table.api.init({
  8. extend: {
  9. index_url: 'cms/special/index' + location.search,
  10. add_url: 'cms/special/add',
  11. edit_url: 'cms/special/edit',
  12. del_url: 'cms/special/del',
  13. multi_url: 'cms/special/multi',
  14. table: 'cms_special',
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'id',
  23. fixedColumns: true,
  24. fixedRightNumber: 1,
  25. columns: [
  26. [
  27. {checkbox: true},
  28. {field: 'id', title: __('Id')},
  29. {field: 'title', title: __('Title'), operate: 'like'},
  30. {field: 'flag', title: __('Flag'), searchList: {"hot": __('Hot'), "new": __('New'), "recommend": __('Recommend'), "top": __('Top')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
  31. {field: 'label', title: __('Label')},
  32. {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
  33. {field: 'banner', title: __('Banner'), events: Table.api.events.image, formatter: Table.api.formatter.image},
  34. {
  35. field: 'url', title: __('Url'), formatter: function (value, row, index) {
  36. return '<div class=""><a href="' + row.url + '" class="btn btn-xs btn-default" target="_blank"><i class="fa fa-link"></i></a></div>';
  37. }
  38. },
  39. {field: 'views', title: __('Views')},
  40. {
  41. field: 'comments', title: __('Comments'), operate: 'BETWEEN', sortable: true, formatter: function (value, row, index) {
  42. return '<a href="javascript:" data-url="cms/comment/index?type=special&aid=' + row['id'] + '" title="评论列表" class="dialogit">' + value + '</a>';
  43. }
  44. },
  45. {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  46. {field: 'updatetime', title: __('Updatetime'), visible: false, operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  47. {field: 'status', title: __('Status'), searchList: {"normal": __('Normal'), "hidden": __('Hidden')}, formatter: Table.api.formatter.status},
  48. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  49. ]
  50. ]
  51. });
  52. // 为表格绑定事件
  53. Table.api.bindevent(table);
  54. },
  55. recyclebin: function () {
  56. // 初始化表格参数配置
  57. Table.api.init({
  58. extend: {
  59. 'dragsort_url': ''
  60. }
  61. });
  62. var table = $("#table");
  63. // 初始化表格
  64. table.bootstrapTable({
  65. url: 'cms/special/recyclebin',
  66. pk: 'id',
  67. sortName: 'id',
  68. columns: [
  69. [
  70. {checkbox: true},
  71. {field: 'id', title: __('Id')},
  72. {field: 'title', title: __('Title'), formatter: Table.api.formatter.search},
  73. {
  74. field: 'deletetime',
  75. title: __('Deletetime'),
  76. operate: 'RANGE',
  77. addclass: 'datetimerange',
  78. formatter: Table.api.formatter.datetime
  79. },
  80. {
  81. field: 'operate',
  82. width: '130px',
  83. title: __('Operate'),
  84. table: table,
  85. events: Table.api.events.operate,
  86. buttons: [
  87. {
  88. name: 'Restore',
  89. text: __('Restore'),
  90. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  91. icon: 'fa fa-rotate-left',
  92. url: 'cms/special/restore',
  93. refresh: true
  94. },
  95. {
  96. name: 'Destroy',
  97. text: __('Destroy'),
  98. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  99. icon: 'fa fa-times',
  100. url: 'cms/special/destroy',
  101. refresh: true
  102. }
  103. ],
  104. formatter: Table.api.formatter.operate
  105. }
  106. ]
  107. ]
  108. });
  109. // 为表格绑定事件
  110. Table.api.bindevent(table);
  111. },
  112. add: function () {
  113. Controller.api.bindevent();
  114. },
  115. edit: function () {
  116. Controller.api.bindevent();
  117. },
  118. api: {
  119. bindevent: function () {
  120. $.validator.config({
  121. rules: {
  122. diyname: function (element) {
  123. if (element.value.toString().match(/^\d+$/)) {
  124. return __('Can not be only digital');
  125. }
  126. if (!element.value.toString().match(/^[a-zA-Z0-9\-_]+$/)) {
  127. return __('Please input character or digital');
  128. }
  129. return $.ajax({
  130. url: 'cms/special/check_element_available',
  131. type: 'POST',
  132. data: {id: $("#special-id").val(), name: element.name, value: element.value},
  133. dataType: 'json'
  134. });
  135. }
  136. }
  137. });
  138. //获取标题拼音
  139. var si;
  140. $(document).on("keyup", "#c-title", function () {
  141. var value = $(this).val();
  142. if (value != '' && !value.match(/\n/)) {
  143. clearTimeout(si);
  144. si = setTimeout(function () {
  145. Fast.api.ajax({
  146. loading: false,
  147. url: "cms/ajax/get_title_pinyin",
  148. data: {title: value}
  149. }, function (data, ret) {
  150. $("#c-diyname").val(data.pinyin.substr(0, 100));
  151. return false;
  152. }, function (data, ret) {
  153. return false;
  154. });
  155. }, 200);
  156. }
  157. });
  158. Form.api.bindevent($("form[role=form]"));
  159. }
  160. }
  161. };
  162. return Controller;
  163. });