page.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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'), formatter: Table.api.formatter.flag},
  30. {field: 'image', title: __('Image'), 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'), 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. {field: 'createtime', sortable: true, title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  43. {field: 'updatetime', sortable: true, visible: false, title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  44. {field: 'weigh', sortable: true, title: __('Weigh')},
  45. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  46. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  47. ]
  48. ]
  49. });
  50. // 为表格绑定事件
  51. Table.api.bindevent(table);
  52. },
  53. recyclebin: function () {
  54. // 初始化表格参数配置
  55. Table.api.init({
  56. extend: {
  57. 'dragsort_url': ''
  58. }
  59. });
  60. var table = $("#table");
  61. // 初始化表格
  62. table.bootstrapTable({
  63. url: 'cms/page/recyclebin',
  64. pk: 'id',
  65. sortName: 'id',
  66. columns: [
  67. [
  68. {checkbox: true},
  69. {field: 'id', title: __('Id')},
  70. {field: 'title', title: __('Title'), formatter: Table.api.formatter.search},
  71. {
  72. field: 'deletetime',
  73. title: __('Deletetime'),
  74. operate: 'RANGE',
  75. addclass: 'datetimerange',
  76. formatter: Table.api.formatter.datetime
  77. },
  78. {
  79. field: 'operate',
  80. width: '130px',
  81. title: __('Operate'),
  82. table: table,
  83. events: Table.api.events.operate,
  84. buttons: [
  85. {
  86. name: 'Restore',
  87. text: __('Restore'),
  88. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  89. icon: 'fa fa-rotate-left',
  90. url: 'cms/page/restore',
  91. refresh: true
  92. },
  93. {
  94. name: 'Destroy',
  95. text: __('Destroy'),
  96. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  97. icon: 'fa fa-times',
  98. url: 'cms/page/destroy',
  99. refresh: true
  100. }
  101. ],
  102. formatter: Table.api.formatter.operate
  103. }
  104. ]
  105. ]
  106. });
  107. // 为表格绑定事件
  108. Table.api.bindevent(table);
  109. },
  110. select: function () {
  111. // 初始化表格参数配置
  112. Table.api.init({
  113. extend: {
  114. index_url: 'cms/page/select',
  115. add_url: 'cms/page/add',
  116. edit_url: 'cms/page/edit',
  117. table: 'page',
  118. }
  119. });
  120. var table = $("#table");
  121. // 初始化表格
  122. table.bootstrapTable({
  123. url: $.fn.bootstrapTable.defaults.extend.index_url,
  124. pk: 'id',
  125. sortName: 'weigh',
  126. columns: [
  127. [
  128. {checkbox: true},
  129. {field: 'id', sortable: true, title: __('Id')},
  130. {field: 'title', title: __('Title')},
  131. {field: 'image', title: __('Image'), formatter: Table.api.formatter.image},
  132. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  133. {
  134. field: 'select', title: __('Operate'), table: table, formatter: Table.api.formatter.buttons,
  135. events: {
  136. 'click .btn-select-one': function (e, value, row) {
  137. Fast.api.close(row);
  138. }
  139. },
  140. buttons: [
  141. {
  142. name: "select",
  143. text: __("Select"),
  144. classname: "btn btn-xs btn-success btn-select-one"
  145. }
  146. ]
  147. },
  148. ]
  149. ]
  150. });
  151. // 为表格绑定事件
  152. Table.api.bindevent(table);
  153. },
  154. add: function () {
  155. Controller.api.bindevent();
  156. },
  157. edit: function () {
  158. Controller.api.bindevent();
  159. },
  160. api: {
  161. bindevent: function () {
  162. //获取标题拼音
  163. var si;
  164. $(document).on("keyup", "#c-title", function () {
  165. var value = $(this).val();
  166. if (value != '' && !value.match(/\n/)) {
  167. clearTimeout(si);
  168. si = setTimeout(function () {
  169. Fast.api.ajax({
  170. loading: false,
  171. url: "cms/ajax/get_title_pinyin",
  172. data: {title: value}
  173. }, function (data, ret) {
  174. $("#c-diyname").val(data.pinyin.substr(0, 100));
  175. return false;
  176. }, function (data, ret) {
  177. return false;
  178. });
  179. }, 200);
  180. }
  181. });
  182. $(document).on("click", ".btn-legal", function (a) {
  183. Fast.api.ajax({
  184. url: "cms/ajax/check_content_islegal",
  185. data: {content: $("#c-content").val()}
  186. }, function (data, ret) {
  187. }, function (data, ret) {
  188. if ($.isArray(data)) {
  189. Layer.alert(__('Banned words') + ":" + data.join(","));
  190. }
  191. });
  192. });
  193. $(document).on("click", ".btn-keywords", function (a) {
  194. Fast.api.ajax({
  195. url: "cms/ajax/get_content_keywords",
  196. data: {title: $("#c-title").val(), content: $("#c-content").val()}
  197. }, function (data, ret) {
  198. $("#c-keywords").val(data.keywords);
  199. $("#c-description").val(data.description);
  200. });
  201. });
  202. $(document).on("keyup", "#c-type_text", function () {
  203. $("#c-type").val($(this).val());
  204. });
  205. $.validator.config({
  206. rules: {
  207. diyname: function (element) {
  208. if (element.value.toString().match(/^\d+$/)) {
  209. return __('Can not be only digital');
  210. }
  211. if (!element.value.toString().match(/^[a-zA-Z0-9\-_]+$/)) {
  212. return __('Please input character or digital');
  213. }
  214. return $.ajax({
  215. url: 'cms/page/check_element_available',
  216. type: 'POST',
  217. data: {id: $("#page-id").val(), name: element.name, value: element.value},
  218. dataType: 'json'
  219. });
  220. }
  221. }
  222. });
  223. Form.api.bindevent($("form[role=form]"));
  224. }
  225. }
  226. };
  227. return Controller;
  228. });