template.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'vbot/template/index' + location.search,
  8. add_url: 'vbot/template/add',
  9. edit_url: 'vbot/template/edit',
  10. del_url: 'vbot/template/del',
  11. multi_url: 'vbot/template/multi',
  12. table: 'vbot_template',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. columns: [
  22. [
  23. {checkbox: true},
  24. {field: 'id', title: __('Id')},
  25. {field: 'name', title: __('Name'), operate: 'LIKE'},
  26. {field: 'code', title: __('Code')},
  27. {
  28. field: 'robot_names',
  29. title: __('Robot_ids'),
  30. formatter: Controller.api.formatter.robot_names,
  31. operate: false
  32. },
  33. {
  34. field: 'typelist',
  35. title: __('Typelist'),
  36. searchList: {
  37. "text": __('Typelist text'),
  38. "markdown": __('Typelist markdown'),
  39. "image": __('Typelist image'),
  40. "news": __('Typelist news')
  41. },
  42. formatter: Table.api.formatter.normal
  43. },
  44. {
  45. field: 'content',
  46. title: __('Content'),
  47. placeholder: '模糊查找',
  48. operate: 'LIKE',
  49. formatter: Controller.api.formatter.content_names
  50. },
  51. {field: 'title', title: __('Title'), placeholder: '模糊查找', operate: 'LIKE'},
  52. {field: 'at_mobiles', title: __('At_mobiles'), operate: 'LIKE', placeholder: '模糊查找'},
  53. {
  54. field: 'is_atall',
  55. title: __('Is_atall'),
  56. searchList: {"0": __('Is_atall 0'), "1": __('Is_atall 1')},
  57. formatter: Table.api.formatter.normal
  58. },
  59. {
  60. field: 'openswitch',
  61. title: __('Openswitch'),
  62. searchList: {"0": __('Openswitch 0'), "1": __('Openswitch 1')},
  63. formatter: Table.api.formatter.toggle
  64. },
  65. {
  66. field: 'updatetime',
  67. title: __('Updatetime'),
  68. operate: 'RANGE',
  69. addclass: 'datetimerange',
  70. formatter: Table.api.formatter.datetime
  71. },
  72. {
  73. field: 'createtime',
  74. title: __('Createtime'),
  75. operate: 'RANGE',
  76. addclass: 'datetimerange',
  77. formatter: Table.api.formatter.datetime
  78. },
  79. {
  80. field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  81. buttons: [
  82. {
  83. name: 'test_msg',
  84. title: __('发送通知消息'),
  85. classname: 'btn btn-xs btn-success btn-magic btn-ajax',
  86. icon: 'fa fa-send-o',
  87. url: 'vbot/template/msg_test',
  88. confirm: '确认发送?',
  89. success: function (data, ret) {
  90. Fast.api.msg(ret.msg);
  91. },
  92. error: function (data, ret) {
  93. Fast.api.msg(ret.msg);
  94. return false;
  95. }
  96. }
  97. ],
  98. formatter: Table.api.formatter.operate
  99. }
  100. ]
  101. ]
  102. });
  103. // 为表格绑定事件
  104. Table.api.bindevent(table);
  105. },
  106. recyclebin: function () {
  107. // 初始化表格参数配置
  108. Table.api.init({
  109. extend: {
  110. 'dragsort_url': ''
  111. }
  112. });
  113. var table = $("#table");
  114. // 初始化表格
  115. table.bootstrapTable({
  116. url: 'vbot/template/recyclebin' + location.search,
  117. pk: 'id',
  118. sortName: 'id',
  119. columns: [
  120. [
  121. {checkbox: true},
  122. {field: 'id', title: __('Id')},
  123. {
  124. field: 'content',
  125. title: __('Content'),
  126. placeholder: '模糊查找',
  127. formatter: Controller.api.formatter.content_names
  128. },
  129. {
  130. field: 'deletetime',
  131. title: __('Deletetime'),
  132. operate: 'RANGE',
  133. addclass: 'datetimerange',
  134. formatter: Table.api.formatter.datetime
  135. },
  136. {
  137. field: 'operate',
  138. width: '130px',
  139. title: __('Operate'),
  140. table: table,
  141. events: Table.api.events.operate,
  142. buttons: [
  143. {
  144. name: 'Restore',
  145. text: __('Restore'),
  146. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  147. icon: 'fa fa-rotate-left',
  148. url: 'vbot/template/restore',
  149. refresh: true
  150. },
  151. {
  152. name: 'Destroy',
  153. text: __('Destroy'),
  154. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  155. icon: 'fa fa-times',
  156. url: 'vbot/template/destroy',
  157. refresh: true
  158. }
  159. ],
  160. formatter: Table.api.formatter.operate
  161. }
  162. ]
  163. ]
  164. });
  165. // 为表格绑定事件
  166. Table.api.bindevent(table);
  167. },
  168. add: function () {
  169. Controller.api.bindevent();
  170. },
  171. edit: function () {
  172. Controller.api.bindevent();
  173. },
  174. api: {
  175. bindevent: function (e) {
  176. Form.api.bindevent($("form[role=form]"));
  177. function need_show(value) {
  178. $('.msg_group').hide();
  179. if (value == 'text') {
  180. $('.msg_content,.msg_at').show(200);
  181. } else if (value == 'markdown') {
  182. $('.msg_title,.msg_content,.markdown_help').show(200);
  183. } else if (value == 'image') {
  184. $('.msg_picurl_image').show(200);
  185. } else if (value == 'news') {
  186. $('.msg_content,.msg_news').show(200);
  187. }
  188. }
  189. need_show($('#c-typelist')[0].value);
  190. // 切换消息类型时,显示不同的输入框
  191. $('#c-typelist').on('change', function () {
  192. need_show(this.value);
  193. })
  194. $('#show_grammar').on('click', function () {
  195. $('.markdown_grammar').show(200);
  196. $('.markdown_help').hide();
  197. })
  198. },
  199. formatter: {
  200. robot_names: function (value, row) {
  201. var value = value.split(',');
  202. var btn_html = '';
  203. for (let i in value) {
  204. btn_html += ' <a href="javascript:;" title="' + value[i] + '" class="btn btn-xs btn-info robot_names">' + value[i] + '</a> ';
  205. }
  206. return btn_html;
  207. },
  208. content_names: function (value, row) {
  209. if (value.length > 30) {
  210. return value.substring(0, 30) + '...';
  211. }
  212. return value;
  213. }
  214. }
  215. }
  216. };
  217. return Controller;
  218. });