kbs.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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: 'kefu/kbs/index' + location.search,
  8. add_url: 'kefu/kbs/add',
  9. edit_url: 'kefu/kbs/edit',
  10. del_url: 'kefu/kbs/del',
  11. multi_url: 'kefu/kbs/multi',
  12. table: 'kefu_kbs',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'weigh',
  21. columns: [
  22. [
  23. {checkbox: true},
  24. {field: 'id', title: __('Id')},
  25. {
  26. field: 'questions',
  27. title: __('Questions'),
  28. formatter: Controller.api.formatter.value_substring,
  29. operate: 'LIKE'
  30. },
  31. {field: 'match', title: __('Match')},
  32. {field: 'admin_id', title: __('Admin_id')},
  33. {field: 'weigh', title: __('Weigh')},
  34. {
  35. field: 'status',
  36. title: __('Status'),
  37. searchList: {"0": __('Status 0'), "1": __('Status 1'), "2": __('Status 2')},
  38. formatter: Table.api.formatter.status
  39. },
  40. {
  41. field: 'createtime',
  42. title: __('Createtime'),
  43. operate: 'RANGE',
  44. addclass: 'datetimerange',
  45. formatter: Table.api.formatter.datetime
  46. },
  47. {
  48. field: 'operate',
  49. title: __('Operate'),
  50. table: table,
  51. events: Table.api.events.operate,
  52. formatter: Table.api.formatter.operate
  53. }
  54. ]
  55. ]
  56. });
  57. // 为表格绑定事件
  58. Table.api.bindevent(table);
  59. },
  60. recyclebin: function () {
  61. // 初始化表格参数配置
  62. Table.api.init({
  63. extend: {
  64. 'dragsort_url': ''
  65. }
  66. });
  67. var table = $("#table");
  68. // 初始化表格
  69. table.bootstrapTable({
  70. url: 'kefu/kbs/recyclebin' + location.search,
  71. pk: 'id',
  72. sortName: 'id',
  73. columns: [
  74. [
  75. {checkbox: true},
  76. {field: 'id', title: __('Id')},
  77. {
  78. field: 'questions',
  79. title: __('Questions'),
  80. formatter: Controller.api.formatter.value_substring,
  81. operate: 'LIKE'
  82. },
  83. {
  84. field: 'deletetime',
  85. title: __('Deletetime'),
  86. operate: 'RANGE',
  87. addclass: 'datetimerange',
  88. formatter: Table.api.formatter.datetime
  89. },
  90. {
  91. field: 'operate',
  92. width: '130px',
  93. title: __('Operate'),
  94. table: table,
  95. events: Table.api.events.operate,
  96. buttons: [
  97. {
  98. name: 'Restore',
  99. text: __('Restore'),
  100. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  101. icon: 'fa fa-rotate-left',
  102. url: 'kefu/kbs/restore',
  103. refresh: true
  104. },
  105. {
  106. name: 'Destroy',
  107. text: __('Destroy'),
  108. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  109. icon: 'fa fa-times',
  110. url: 'kefu/kbs/destroy',
  111. refresh: true
  112. }
  113. ],
  114. formatter: Table.api.formatter.operate
  115. }
  116. ]
  117. ]
  118. });
  119. // 为表格绑定事件
  120. Table.api.bindevent(table);
  121. },
  122. add: function () {
  123. Controller.api.bindevent();
  124. },
  125. edit: function () {
  126. Controller.api.bindevent();
  127. },
  128. testmatch: function () {
  129. $('#str1, #str2').on('change', function () {
  130. Controller.api.test_match();
  131. })
  132. $('.post_test_match').on('click', function () {
  133. Controller.api.test_match(true);
  134. })
  135. },
  136. api: {
  137. test_match: function (mandatory = false) {
  138. var str1 = $('#str1').val();
  139. var str2 = $('#str2').val();
  140. if (str1 && str2) {
  141. $.post("kefu/kbs/testMatch", {
  142. 'str1': str1,
  143. 'str2': str2
  144. }, function (res) {
  145. if (res.code == 1) {
  146. $('.progress').show();
  147. $('#match').css('width', res.data + '%').html('匹配度:' + res.data + '%');
  148. }
  149. })
  150. } else {
  151. if (mandatory) {
  152. layer.msg('请输入要计算匹配度的字符串!');
  153. }
  154. }
  155. },
  156. bindevent: function () {
  157. Form.api.bindevent($("form[role=form]"));
  158. $('.test_match').on('click', function () {
  159. Backend.api.addtabs('kefu/kbs/testMatch', '匹配度测试');
  160. });
  161. },
  162. formatter: {
  163. value_substring: function (value) {
  164. let value_length = value.replace(/[\u0391-\uFFE5]/g, "aa").length;
  165. return value_length > 20 ? value.substring(0, 20) + '...' : value;
  166. }
  167. }
  168. }
  169. };
  170. return Controller;
  171. });