Ubook.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 loadAirList(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. field: "img",
  23. title: "预览图",
  24. templet: '#typeTpl',
  25. align: "left",
  26. width: 100,
  27. },
  28. {
  29. field: "book_name",
  30. title: "书相关信息",
  31. templet: '#type',
  32. align: "left",
  33. width: 430,
  34. },
  35. {
  36. field: "author",
  37. title: "书相关信息",
  38. templet: '#book',
  39. width: 250,
  40. align: "left",
  41. },
  42. {
  43. fixed: "right",
  44. title: "操作",
  45. toolbar: "#operationToolbar",
  46. align: "left",
  47. }
  48. ]
  49. ]
  50. };
  51. if (searchTitle === null || searchTitle === undefined || searchTitle === "") {
  52. var url = "api/book/listpage?page=" + (page + 1) + "&size=" + size;
  53. fetchJSON(url, {}, "get", function(data) {
  54. if (data.status === 0) {
  55. if (tableFirstLoad) {
  56. tableFirstLoad = false;
  57. laypage.render({
  58. curr: page + 1,
  59. elem: "pagination",
  60. count: data.data.total,
  61. layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"],
  62. jump: function(obj, first) {
  63. if (first) return;
  64. currentPage = obj.curr - 1;
  65. currentSize = obj.limit;
  66. loadAirList(currentPage, currentSize, searchTitleKey);
  67. }
  68. });
  69. }
  70. tableOption.data = data.data.list;
  71. console.log(data.data)
  72. table.render(tableOption);
  73. } else {
  74. showMsg(data.msg, 2, 2000);
  75. }
  76. });
  77. } else {
  78. // var url = ;
  79. fetchJSON("api/book/getByName?name=" + searchTitle, {}, "get", function(data) {
  80. if (data.status === 0) {
  81. if (tableFirstLoad) {
  82. tableFirstLoad = false;
  83. laypage.render({
  84. curr: page + 1,
  85. elem: "pagination",
  86. count: data.data.total,
  87. layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"],
  88. jump: function(obj, first) {
  89. if (first) return;
  90. currentPage = obj.curr - 1;
  91. currentSize = obj.limit;
  92. loadAirList(currentPage, currentSize, searchTitleKey);
  93. }
  94. });
  95. }
  96. tableOption.data = data.data;
  97. table.render(tableOption);
  98. } else {
  99. showMsg(data.msg, 2, 2000);
  100. }
  101. });
  102. }
  103. }
  104. loadAirList();
  105. $("#searchArticle").on("click", function(e) {
  106. e.preventDefault();
  107. tableFirstLoad = true;
  108. searchTitleKey = title.val().trim();
  109. if (searchTitleKey === "")
  110. loadAirList(0, currentSize);
  111. else
  112. loadAirList(0, currentSize, searchTitleKey);
  113. });
  114. $("#keyword").on("keyup", function(e) {
  115. e.preventDefault();
  116. if (e.keyCode === 13) {
  117. $("#searchArticle").click();
  118. }
  119. });
  120. // 监听表内工具条
  121. table.on("tool(outLineList)", function(obj) {
  122. var data = obj.data;
  123. if (obj.event === "edit") {
  124. x_admin_show(
  125. "在线预览",
  126. encodeURI(
  127. "../admin/Ubookshow.html?bookName=" + data.book_name + "&file_path=" + data.file_path + "&id=" + data.id
  128. ),
  129. 1400,
  130. 700,
  131. function() {
  132. loadAirList(currentPage, currentSize);
  133. }
  134. );
  135. var file_path = data.file_path;
  136. // console.log(file_path)
  137. sessionStorage.setItem("url", file_path)
  138. var book_name = obj.data.book_name
  139. sessionStorage.setItem("book_name", book_name)
  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/book/delete", {
  156. ids: ids
  157. }, "post", function(data) {
  158. if (data.status === 0) {
  159. showMsg("已删除!");
  160. tableFirstLoad = true;
  161. loadAirList(currentPage, currentSize);
  162. } else {
  163. showMsg(data.msg, 2, 2000);
  164. }
  165. });
  166. });
  167. });
  168. // 导入
  169. //表格导入
  170. $("#tolead").on("click", function(e) {
  171. e.preventDefault();
  172. tableFirstLoad = true;
  173. x_admin_show("导入",
  174. "../admin/faul-add.html",
  175. 350,
  176. 200,
  177. function() {
  178. loadAirList(currentPage, currentSize);
  179. });
  180. });
  181. // 新建用户
  182. $("#add").on("click", function(e) {
  183. e.preventDefault();
  184. tableFirstLoad = true;
  185. x_admin_show("添加",
  186. "../admin/book-add.html?id=0&author=&aircraft_type=&book_name=&description=&img=&input_time=&major_type&publish_time=&type_id=&type_name=&file_path=",
  187. 800,
  188. 450,
  189. function() {
  190. loadAirList(currentPage, currentSize);
  191. });
  192. });
  193. });
  194. });