page.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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/page/index',
  10. add_url: 'cms/page/add',
  11. edit_url: 'cms/page/edit',
  12. del_url: 'cms/page/del',
  13. multi_url: 'cms/page/multi',
  14. table: 'cms_page',
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'weigh',
  23. columns: [
  24. [
  25. {checkbox: true},
  26. {field: 'id', sortable: true, title: __('Id')},
  27. {field: 'type', title: __('Type'), formatter: Table.api.formatter.search, searchList: Config.typeList},
  28. {field: 'title', title: __('Title'), operate: 'like'},
  29. {field: 'flag', title: __('Flag'), searchList: Config.flagList, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
  30. {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  31. {field: 'views', sortable: true, title: __('Views'), operate: 'BETWEEN'},
  32. {
  33. field: 'comments', title: __('Comments'), operate: 'BETWEEN', sortable: true, formatter: function (value, row, index) {
  34. return '<a href="javascript:" data-url="cms/comment/index?type=page&aid=' + row['id'] + '" title="评论列表" class="dialogit">' + value + '</a>';
  35. }
  36. },
  37. {
  38. field: 'url', title: __('Url'), operate: false, formatter: function (value, row, index) {
  39. return '<a href="' + value + '" target="_blank" class="btn btn-default btn-xs"><i class="fa fa-link"></i></a>';
  40. }
  41. },
  42. {
  43. field: 'spiders', title: __('Spiders'), visible: Config.spiderRecord || false, operate: false, formatter: function (value, row, index) {
  44. if (!$.isArray(value) || value.length === 0) {
  45. return '-';
  46. }
  47. var html = [];
  48. $.each(value, function (i, j) {
  49. var color = 'default', title = '暂无来访记录';
  50. if (j.status === 'today') {
  51. color = 'danger';
  52. title = "今天有来访记录";
  53. } else if (j.status === 'pass') {
  54. color = 'success';
  55. title = "最后来访日期:" + j.date;
  56. }
  57. html.push('<span class="label label-' + color + '" data-toggle="tooltip" data-title="' + j.title + ' ' + title + '">' + j.title.substr(0, 1) + '</span>');
  58. });
  59. return html.join(" ");
  60. }
  61. },
  62. {field: 'createtime', sortable: true, title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  63. {field: 'updatetime', sortable: true, visible: false, title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  64. {field: 'weigh', operate: false, sortable: true, title: __('Weigh')},
  65. {field: 'status', title: __('Status'), searchList: {"normal": __('Normal'), "hidden": __('Hidden')}, formatter: Table.api.formatter.status},
  66. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  67. ]
  68. ]
  69. });
  70. // 为表格绑定事件
  71. Table.api.bindevent(table);
  72. },
  73. recyclebin: function () {
  74. // 初始化表格参数配置
  75. Table.api.init({
  76. extend: {
  77. 'dragsort_url': ''
  78. }
  79. });
  80. var table = $("#table");
  81. // 初始化表格
  82. table.bootstrapTable({
  83. url: 'cms/page/recyclebin',
  84. pk: 'id',
  85. sortName: 'id',
  86. columns: [
  87. [
  88. {checkbox: true},
  89. {field: 'id', title: __('Id')},
  90. {field: 'title', title: __('Title'), formatter: Table.api.formatter.search},
  91. {
  92. field: 'deletetime',
  93. title: __('Deletetime'),
  94. operate: 'RANGE',
  95. addclass: 'datetimerange',
  96. formatter: Table.api.formatter.datetime
  97. },
  98. {
  99. field: 'operate',
  100. width: '130px',
  101. title: __('Operate'),
  102. table: table,
  103. events: Table.api.events.operate,
  104. buttons: [
  105. {
  106. name: 'Restore',
  107. text: __('Restore'),
  108. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  109. icon: 'fa fa-rotate-left',
  110. url: 'cms/page/restore',
  111. refresh: true
  112. },
  113. {
  114. name: 'Destroy',
  115. text: __('Destroy'),
  116. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  117. icon: 'fa fa-times',
  118. url: 'cms/page/destroy',
  119. refresh: true
  120. }
  121. ],
  122. formatter: Table.api.formatter.operate
  123. }
  124. ]
  125. ]
  126. });
  127. // 为表格绑定事件
  128. Table.api.bindevent(table);
  129. },
  130. select: function () {
  131. // 初始化表格参数配置
  132. Table.api.init({
  133. extend: {
  134. index_url: 'cms/page/select',
  135. add_url: 'cms/page/add',
  136. edit_url: 'cms/page/edit',
  137. table: 'page',
  138. }
  139. });
  140. var table = $("#table");
  141. // 初始化表格
  142. table.bootstrapTable({
  143. url: $.fn.bootstrapTable.defaults.extend.index_url,
  144. pk: 'id',
  145. sortName: 'weigh',
  146. columns: [
  147. [
  148. {checkbox: true},
  149. {field: 'id', sortable: true, title: __('Id')},
  150. {field: 'title', title: __('Title')},
  151. {field: 'image', title: __('Image'), formatter: Table.api.formatter.image},
  152. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  153. {
  154. field: 'select', title: __('Operate'), table: table, formatter: Table.api.formatter.buttons,
  155. events: {
  156. 'click .btn-select-one': function (e, value, row) {
  157. Fast.api.close(row);
  158. }
  159. },
  160. buttons: [
  161. {
  162. name: "select",
  163. text: __("Select"),
  164. classname: "btn btn-xs btn-success btn-select-one"
  165. }
  166. ]
  167. },
  168. ]
  169. ]
  170. });
  171. // 为表格绑定事件
  172. Table.api.bindevent(table);
  173. },
  174. add: function () {
  175. Controller.api.bindevent();
  176. },
  177. edit: function () {
  178. Controller.api.bindevent();
  179. },
  180. api: {
  181. bindevent: function () {
  182. //获取标题拼音
  183. var si;
  184. $(document).on("keyup", "#c-title", function () {
  185. var value = $(this).val();
  186. if (value != '' && !value.match(/\n/)) {
  187. clearTimeout(si);
  188. si = setTimeout(function () {
  189. Fast.api.ajax({
  190. loading: false,
  191. url: "cms/ajax/get_title_pinyin",
  192. data: {title: value}
  193. }, function (data, ret) {
  194. $("#c-diyname").val(data.pinyin.substr(0, 100));
  195. return false;
  196. }, function (data, ret) {
  197. return false;
  198. });
  199. }, 200);
  200. }
  201. });
  202. $(document).on("click", ".btn-legal", function (a) {
  203. Fast.api.ajax({
  204. url: "cms/ajax/check_content_islegal",
  205. data: {content: $("#c-content").val()}
  206. }, function (data, ret) {
  207. }, function (data, ret) {
  208. if ($.isArray(data)) {
  209. Layer.alert(__('Banned words') + ":" + data.join(","));
  210. }
  211. });
  212. });
  213. $(document).on("click", ".btn-keywords", function (a) {
  214. Fast.api.ajax({
  215. url: "cms/ajax/get_content_keywords",
  216. data: {title: $("#c-title").val(), content: $("#c-content").val()}
  217. }, function (data, ret) {
  218. $("#c-keywords").val(data.keywords);
  219. $("#c-description").val(data.description);
  220. });
  221. });
  222. $(document).on("keyup", "#c-type_text", function () {
  223. $("#c-type").val($(this).val());
  224. });
  225. $.validator.config({
  226. rules: {
  227. diyname: function (element) {
  228. if (element.value.toString().match(/^\d+$/)) {
  229. return __('Can not be only digital');
  230. }
  231. if (!element.value.toString().match(/^[a-zA-Z0-9\-_]+$/)) {
  232. return __('Please input character or digital');
  233. }
  234. return $.ajax({
  235. url: 'cms/page/check_element_available',
  236. type: 'POST',
  237. data: {id: $("#page-id").val(), name: element.name, value: element.value},
  238. dataType: 'json'
  239. });
  240. }
  241. }
  242. });
  243. Form.api.bindevent($("form[role=form]"));
  244. }
  245. }
  246. };
  247. return Controller;
  248. });