algorithm.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. $(function() {
  2. var defaultPage = 0;
  3. var defaultSize = 10;
  4. var currentPage = defaultPage;
  5. var currentSize = defaultSize;
  6. var tableFirstLoad = true;
  7. layui.use(["form", "table", "laypage", "layer"], function() {
  8. var table = layui.table;
  9. var laypage = layui.laypage;
  10. var layer = layui.layer;
  11. var title = $("#realName");
  12. var searchTitleKey = "";
  13. function loadalgorithm(page, size, searchTitle) {
  14. if (page === null || page === undefined) page = defaultPage;
  15. if (size === null || size === undefined) size = defaultSize;
  16. var tableOption = {
  17. elem: "#algorithm",
  18. height: "full-81",
  19. limit: size,
  20. cols: [
  21. [{
  22. type: "checkbox"
  23. },
  24. {
  25. field: "algorithm_type",
  26. title: "算法类别",
  27. align: "center",
  28. width: 200,
  29. },
  30. {
  31. field: "algorithm_name",
  32. title: "算法名称",
  33. align: "center"
  34. },
  35. {
  36. field: "algorithm_format",
  37. title: "调用格式",
  38. align: "center"
  39. },
  40. {
  41. field: "device_name",
  42. title: "元气件名称",
  43. align: "center"
  44. },
  45. {
  46. field: "create_time",
  47. title: "创建时间",
  48. align: "center"
  49. },
  50. {
  51. field: "algorithm_path",
  52. title: "算法地址",
  53. align: "center"
  54. },
  55. {
  56. field: "remarks",
  57. title: "备注",
  58. align: "center"
  59. },
  60. {
  61. fixed: "right",
  62. title: "操作",
  63. width: 265,
  64. toolbar: "#operationToolbar",
  65. align: "center"
  66. }
  67. ]
  68. ]
  69. };
  70. if (searchTitle === null || searchTitle === undefined || searchTitle === "") {
  71. fetchJSON("api/algorithm/listpage?page=" + (page + 1) + "&size=" + size, {}, "get",
  72. function(data) {
  73. if (data.status === 0) {
  74. if (tableFirstLoad) {
  75. tableFirstLoad = false;
  76. laypage.render({
  77. curr: page + 1,
  78. elem: "pagination",
  79. count: data.data.total,
  80. layout: ["count", "prev", "page", "next", "limit",
  81. "refresh", "skip"
  82. ],
  83. jump: function(obj, first) {
  84. if (first) return;
  85. currentPage = obj.curr - 1;
  86. currentSize = obj.limit;
  87. loadalgorithm(currentPage, currentSize,
  88. searchTitleKey);
  89. }
  90. });
  91. }
  92. tableOption.data = data.data.list;
  93. table.render(tableOption);
  94. } else {
  95. showMsg(data.msg, 2, 2000);
  96. }
  97. });
  98. }
  99. }
  100. loadalgorithm();
  101. $("#searchArticle").on("click", function(e) {
  102. e.preventDefault();
  103. tableFirstLoad = true;
  104. searchTitleKey = title.val().trim();
  105. if (searchTitleKey === "")
  106. loadalgorithm(0, currentSize);
  107. else
  108. loadalgorithm(0, currentSize, searchTitleKey);
  109. });
  110. $("#keyword").on("keyup", function(e) {
  111. e.preventDefault();
  112. if (e.keyCode === 13) {
  113. $("#searchArticle").click();
  114. }
  115. });
  116. // 监听表内工具条
  117. table.on("tool(algorithm)", function(obj) {
  118. var data = obj.data;
  119. if (obj.event === "edit") {
  120. // 打开编辑框 进行详细编辑
  121. x_admin_show(
  122. "编辑",
  123. encodeURI(
  124. "../admin/algorithm-add.html?id=" + data.id + "&algorithm_type=" +
  125. data.algorithm_type + "&algorithm_name=" + data.algorithm_name +
  126. "&algorithm_format=" + data.algorithm_format + "&device_name=" +
  127. data.device_name + "&create_time=" + data.create_time +
  128. "&algorithm_path=" + data.algorithm_path + "&remarks=" + data
  129. .remarks
  130. ),
  131. 468,
  132. 560,
  133. function() {
  134. loadalgorithm(currentPage, currentSize);
  135. }
  136. );
  137. } else if (obj.event === "delete") {
  138. // 删除
  139. var ids = [];
  140. ids.push(data.id);
  141. layer.confirm("确认要删除吗?", function() {
  142. fetchJSON("api/algorithm/delete", {
  143. ids: ids
  144. }, "post", function(data) {
  145. if (data.status === 0) {
  146. showMsg("已删除!", 1, 2000);
  147. tableFirstLoad = true;
  148. loadalgorithm(currentPage, currentSize);
  149. } else {
  150. showMsg(data.msg, 2, 2000);
  151. }
  152. });
  153. });
  154. } else
  155. if (obj.event === 'download') {
  156. var file_path = data.algorithm_path;
  157. var newurl = file_path.substr(1, file_path.length);
  158. file_path = newurl.substr(newurl.indexOf('\\') + 1, file_path.length);
  159. newurl = file_path.substr(0, file_path.indexOf('.'))
  160. newurl = urlBase + "sourcekg/" + newurl + ".rar";
  161. console.log(newurl)
  162. window.open('http://127.0.0.1:11085/sourcekg/1626248784559.rar')
  163. }
  164. });
  165. // 批量删除
  166. $("#batchDelete").on("click", function(e) {
  167. e.preventDefault();
  168. var checkedData = table.checkStatus("algorithm").data;
  169. if (checkedData.length === 0) {
  170. showMsg("未选择需要删除的日志", 2, 2000);
  171. return;
  172. }
  173. layer.confirm("确认要删除吗?", function() {
  174. var ids = [];
  175. for (var i = 0; i < checkedData.length; i++) {
  176. ids.push(checkedData[i].id);
  177. }
  178. fetchJSON("api/algorithm/delete", {
  179. ids: ids
  180. }, "post", function(data) {
  181. if (data.status === 0) {
  182. showMsg("已删除!");
  183. tableFirstLoad = true;
  184. loadalgorithm(currentPage, currentSize);
  185. } else {
  186. showMsg(data.msg, 2, 2000);
  187. }
  188. });
  189. });
  190. });
  191. // 新建用户
  192. $("#addair").on("click", function(e) {
  193. e.preventDefault();
  194. tableFirstLoad = true;
  195. x_admin_show("增加",
  196. "../admin/algorithm-add.html?id=0&algorithm_type=&algorithm_name=&algorithm_format=&device_name=&create_time=&algorithm_path=&remarks=",
  197. 468,
  198. 560,
  199. function() {
  200. loadalgorithm(currentPage, currentSize);
  201. });
  202. });
  203. });
  204. });