special.js 9.3 KB

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