Uoutline.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 loadoutLineList(page, size, searchTitle) {
  14. if (page === null || page === undefined) page = defaultPage;
  15. if (size === null || size === undefined) size = defaultSize;
  16. var tableOption = {
  17. elem: "#outLineList",
  18. height: "full-81",
  19. limit: size,
  20. cols: [
  21. [
  22. {
  23. field: "outline_name",
  24. title: "大纲名称",
  25. align: "center"
  26. },
  27. {
  28. fixed: "right",
  29. title: "操作",
  30. toolbar: "#operationToolbar",
  31. align: "center"
  32. }
  33. ]
  34. ]
  35. };
  36. if (searchTitle === null || searchTitle === undefined || searchTitle === "") {
  37. fetchJSON("api/outline/listpage?page=" + (page + 1) + "&size=" + size, {}, "get", function(data) {
  38. if (data.status === 0) {
  39. if (tableFirstLoad) {
  40. tableFirstLoad = false;
  41. laypage.render({
  42. curr: page + 1,
  43. elem: "pagination",
  44. count: data.data.total,
  45. layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"],
  46. jump: function(obj, first) {
  47. if (first) return;
  48. currentPage = obj.curr - 1;
  49. currentSize = obj.limit;
  50. loadoutLineList(currentPage, currentSize, searchTitleKey);
  51. }
  52. });
  53. }
  54. tableOption.data = data.data.list;
  55. table.render(tableOption);
  56. } else {
  57. showMsg(data.msg, 2, 2000);
  58. }
  59. });
  60. } else {
  61. fetchJSON("api/outline/getByName?name=" + searchTitle + "&page=" + (page + 1) + "&size=" + size, {}, "get", function(data) {
  62. if (data.status === 0) {
  63. if (tableFirstLoad) {
  64. tableFirstLoad = false;
  65. laypage.render({
  66. curr: page + 1,
  67. elem: "pagination",
  68. count: data.data.total,
  69. layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"],
  70. jump: function(obj, first) {
  71. if (first) return;
  72. currentPage = obj.curr - 1;
  73. currentSize = obj.limit;
  74. loadoutLineList(currentPage, currentSize, searchTitleKey);
  75. }
  76. });
  77. }
  78. tableOption.data = data.data.list;
  79. table.render(tableOption);
  80. } else {
  81. showMsg(data.msg, 2, 2000);
  82. }
  83. });
  84. }
  85. }
  86. loadoutLineList();
  87. $("#searchArticle").on("click", function(e) {
  88. e.preventDefault();
  89. tableFirstLoad = true;
  90. searchTitleKey = title.val().trim();
  91. if (searchTitleKey === "")
  92. loadoutLineList(0, currentSize);
  93. else
  94. loadoutLineList(0, currentSize, searchTitleKey);
  95. });
  96. $("#keyword").on("keyup", function(e) {
  97. e.preventDefault();
  98. if (e.keyCode === 13) {
  99. $("#searchArticle").click();
  100. }
  101. });
  102. // 监听表内工具条
  103. table.on("tool(outLineList)", function(obj) {
  104. var data = obj.data;
  105. if (obj.event === "edit") {
  106. x_admin_show(
  107. "在线预览",
  108. encodeURI(
  109. "../admin/Uoutline-edit.html?file_path=" + data.file_path
  110. ),
  111. 1444,
  112. 685,
  113. function() {
  114. loadoutLineList(currentPage, currentSize);
  115. }
  116. );
  117. // console.log(data.file_path)
  118. var data = obj.data.file_path
  119. flie = urlBase + data
  120. console.log(flie)
  121. sessionStorage.setItem("url", flie)
  122. } else if (obj.event === "delete") {
  123. // console.log(data)
  124. // 删除
  125. var ids = [];
  126. ids.push(data.id);
  127. layer.confirm("确认要删除吗?", function() {
  128. fetchJSON("api/outline/delete", {
  129. ids: ids
  130. }, "post", function(data) {
  131. if (data.status === 0) {
  132. showMsg("已删除!", 1, 2000);
  133. tableFirstLoad = true;
  134. loadoutLineList(currentPage, currentSize);
  135. } else {
  136. showMsg(data.msg, 2, 2000);
  137. }
  138. });
  139. });
  140. }
  141. });
  142. // 批量删除
  143. $("#batchDelete").on("click", function(e) {
  144. e.preventDefault();
  145. var checkedData = table.checkStatus("outLineList").data;
  146. if (checkedData.length === 0) {
  147. showMsg("未选择需要删除的日志", 2, 2000);
  148. return;
  149. }
  150. layer.confirm("确认要删除吗?", function() {
  151. var ids = [];
  152. for (var i = 0; i < checkedData.length; i++) {
  153. ids.push(checkedData[i].id);
  154. }
  155. fetchJSON("api/outline/delete", {
  156. ids: ids
  157. }, "post", function(data) {
  158. if (data.status === 0) {
  159. showMsg("已删除!");
  160. tableFirstLoad = true;
  161. loadoutLineList(currentPage, currentSize);
  162. } else {
  163. showMsg(data.msg, 2, 2000);
  164. }
  165. });
  166. });
  167. });
  168. // 新建用户
  169. $("#addair").on("click", function(e) {
  170. e.preventDefault();
  171. tableFirstLoad = true;
  172. x_admin_show("添加",
  173. "../admin/outline-add.html?id=0&outline_name=&aircraft_type=&major_type=&description=&file_path=&input_time=&remarks=",
  174. 800,
  175. 400,
  176. function() {
  177. loadoutLineList(currentPage, currentSize);
  178. });
  179. });
  180. });
  181. });