special.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  33. {field: 'banner', title: __('Banner'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  34. {
  35. field: 'url', title: __('Url'), operate: false, 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. {
  40. field: 'spiders', title: __('Spiders'), visible: Config.spiderRecord || false, operate: false, formatter: function (value, row, index) {
  41. if (!$.isArray(value) || value.length === 0) {
  42. return '-';
  43. }
  44. var html = [];
  45. $.each(value, function (i, j) {
  46. var color = 'default', title = '暂无来访记录';
  47. if (j.status === 'today') {
  48. color = 'danger';
  49. title = "今天有来访记录";
  50. } else if (j.status === 'pass') {
  51. color = 'success';
  52. title = "最后来访日期:" + j.date;
  53. }
  54. html.push('<span class="label label-' + color + '" data-toggle="tooltip" data-title="' + j.title + ' ' + title + '">' + j.title.substr(0, 1) + '</span>');
  55. });
  56. return html.join(" ");
  57. }
  58. },
  59. {field: 'views', title: __('Views'), operate: 'BETWEEN', sortable: true},
  60. {
  61. field: 'comments', title: __('Comments'), operate: 'BETWEEN', sortable: true, formatter: function (value, row, index) {
  62. return '<a href="javascript:" data-url="cms/comment/index?type=special&aid=' + row['id'] + '" title="评论列表" class="dialogit">' + value + '</a>';
  63. }
  64. },
  65. {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  66. {field: 'updatetime', title: __('Updatetime'), visible: false, operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  67. {field: 'status', title: __('Status'), searchList: {"normal": __('Normal'), "hidden": __('Hidden')}, formatter: Table.api.formatter.status},
  68. {field: 'operate', title: __('Operate'), clickToSelect: false, table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  69. ]
  70. ]
  71. });
  72. // 为表格绑定事件
  73. Table.api.bindevent(table);
  74. },
  75. recyclebin: function () {
  76. // 初始化表格参数配置
  77. Table.api.init({
  78. extend: {
  79. 'dragsort_url': ''
  80. }
  81. });
  82. var table = $("#table");
  83. // 初始化表格
  84. table.bootstrapTable({
  85. url: 'cms/special/recyclebin',
  86. pk: 'id',
  87. sortName: 'id',
  88. columns: [
  89. [
  90. {checkbox: true},
  91. {field: 'id', title: __('Id')},
  92. {field: 'title', title: __('Title'), formatter: Table.api.formatter.search},
  93. {
  94. field: 'deletetime',
  95. title: __('Deletetime'),
  96. operate: 'RANGE',
  97. addclass: 'datetimerange',
  98. formatter: Table.api.formatter.datetime
  99. },
  100. {
  101. field: 'operate',
  102. width: '130px',
  103. title: __('Operate'),
  104. table: table,
  105. events: Table.api.events.operate,
  106. buttons: [
  107. {
  108. name: 'Restore',
  109. text: __('Restore'),
  110. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  111. icon: 'fa fa-rotate-left',
  112. url: 'cms/special/restore',
  113. refresh: true
  114. },
  115. {
  116. name: 'Destroy',
  117. text: __('Destroy'),
  118. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  119. icon: 'fa fa-times',
  120. url: 'cms/special/destroy',
  121. refresh: true
  122. }
  123. ],
  124. formatter: Table.api.formatter.operate
  125. }
  126. ]
  127. ]
  128. });
  129. // 为表格绑定事件
  130. Table.api.bindevent(table);
  131. },
  132. add: function () {
  133. Controller.api.bindevent();
  134. },
  135. edit: function () {
  136. Controller.api.bindevent();
  137. },
  138. api: {
  139. bindevent: function () {
  140. $.validator.config({
  141. rules: {
  142. diyname: function (element) {
  143. if (element.value.toString().match(/^\d+$/)) {
  144. return __('Can not be only digital');
  145. }
  146. if (!element.value.toString().match(/^[a-zA-Z0-9\-_]+$/)) {
  147. return __('Please input character or digital');
  148. }
  149. return $.ajax({
  150. url: 'cms/special/check_element_available',
  151. type: 'POST',
  152. data: {id: $("#special-id").val(), name: element.name, value: element.value},
  153. dataType: 'json'
  154. });
  155. }
  156. }
  157. });
  158. //获取标题拼音
  159. var si;
  160. $(document).on("keyup", "#c-title", function () {
  161. var value = $(this).val();
  162. if (value != '' && !value.match(/\n/)) {
  163. clearTimeout(si);
  164. si = setTimeout(function () {
  165. Fast.api.ajax({
  166. loading: false,
  167. url: "cms/ajax/get_title_pinyin",
  168. data: {title: value}
  169. }, function (data, ret) {
  170. $("#c-diyname").val(data.pinyin.substr(0, 100));
  171. return false;
  172. }, function (data, ret) {
  173. return false;
  174. });
  175. }, 200);
  176. }
  177. });
  178. Form.api.bindevent($("form[role=form]"));
  179. }
  180. }
  181. };
  182. return Controller;
  183. });