list.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. layui.config({
  2. base: '/assets/lib/jplus/treeTable/'
  3. }).use(['form', 'layer', 'table', 'laytpl', 'treeTable'], function () {
  4. var form = layui.form,
  5. layer = parent.layer === undefined ? layui.layer : top.layer,
  6. $ = layui.jquery,
  7. laytpl = layui.laytpl,
  8. table = layui.table,
  9. treeTable = layui.treeTable;
  10. //列表
  11. var tableIns = table.render({
  12. elem: '#list',
  13. url: '/silos/cms/book/info/queryPage',
  14. method: 'POST',
  15. dataType: 'json',
  16. contentType: 'application/json;charset=utf-8',
  17. headers: {token: ''},
  18. cellMinWidth: 95,
  19. page: true,
  20. height: "full-125",
  21. limits: [10, 15, 20, 25],
  22. limit: 15,
  23. id: "listTable",
  24. request: {
  25. pageName: "pageNo",//重新定义当前页码参数名称
  26. limitName: "pageRows"//重新定义每页大小参数名称
  27. },
  28. response: {
  29. statusName: 'code', //数据状态的字段名称,默认:code
  30. statusCode: 200, //成功的状态码,默认:0
  31. msgName: 'msg', //状态信息的字段名称,默认:msg
  32. countName: 'totalRows', //数据总数的字段名称,默认:count
  33. dataName: 'data' //数据列表的字段名称,默认:data
  34. },
  35. where: {
  36. //请求的参数写在where
  37. },
  38. parseData: function (res) {
  39. return {
  40. "code": res.code,
  41. "msg": res.msg, //解析提示文本
  42. "totalRows": res.data.totalRows, //解析数据长度
  43. "data": res.data.dataList, //解析数据列表
  44. };
  45. },
  46. cols: [[
  47. {type: "checkbox", fixed: "left", width: 50},
  48. {field: 'isbn', title: '国际标准书号', minWidth: 100, align: "center"},
  49. {field: 'title', title: '图书正题名', minWidth: 100, align: "center"},
  50. {field: 'subtitle', title: '副题名', minWidth: 100, align: "center"},
  51. {
  52. field: 'parentId', title: '父级分类', align: 'center', templet: function (d) {
  53. if (d.parentId == "0") {
  54. return "顶级分类";
  55. } else if (d.parentId == "1") {
  56. return "一级分类";
  57. } else if (d.parentId == "2") {
  58. return "二级分类";
  59. } else {
  60. return "三级分类";
  61. }
  62. }
  63. },
  64. {field: 'author', title: '第一作者', minWidth: 100, align: "center"},
  65. {field: 'otherAuthors', title: '其他责任者', minWidth: 100, align: "center"},
  66. {field: 'publisher', title: '出版社', align: 'center'},
  67. {field: 'edition', title: '版次', minWidth: 100, align: "center"},
  68. /*{field: 'userAvatar', title: '用户头像', minWidth:100, align:"center",templet:function(d){
  69. return "<img src='"+d.userAvatar+"' style='width: 30px;height: 30px'>";
  70. }},*/
  71. {field: 'categoryCode', title: '分类代码', minWidth: 100, align: "center"},
  72. {field: 'language', title: '正文语种', minWidth: 100, align: "center"},
  73. {field: 'coverImage', title: '封面图片路径', minWidth: 100, align: "center"},
  74. {
  75. field: 'createdAt', title: '创建时间', minWidth: 100, align: "center", templet: function (d) {
  76. return showTime(d.createTime);
  77. }
  78. },
  79. {
  80. field: 'updatedAt', title: '修改时间', minWidth: 100, align: "center", templet: function (d) {
  81. return showTime(d.updateTime);
  82. }
  83. },
  84. {title: '操作', minWidth: 200, templet: '#listBar', fixed: "right", align: "center", toolBar: '#listBar'}
  85. ]]
  86. });
  87. $(".search_btn").click(function () {
  88. const infoName = $("#search_value").val();
  89. renderCategoriesGrid();
  90. table.reload("listTable", {
  91. page: {
  92. curr: 1 //重新从第 1 页开始
  93. },
  94. where: {
  95. infoName: infoName
  96. }
  97. })
  98. })
  99. $('.book-card').click(function (e) {
  100. layer.open({
  101. type: 2,
  102. title: title,
  103. shadeClose: true,
  104. shade: 0.8,
  105. area: ['100%', '100%'],
  106. content: '/silos/cms/book/chapter/chapter.html' // iframe 的 url
  107. })
  108. })
  109. $(".add_btn").click(function () {
  110. edit();
  111. })
  112. // 添加/修改
  113. function edit(edit) {
  114. let title = "添加图书";
  115. if (edit != null) {
  116. title = "添加图书";
  117. }
  118. const index = layui.layer.open({
  119. title: title,
  120. type: 2,
  121. content: "/silos/cms/book/info/edit.html",
  122. scrollbar: false,
  123. success: function (layero, index) {
  124. var body = layui.layer.getChildFrame('body', index);
  125. if (edit) {
  126. body.find(".uid").val(BigInt(edit.id).toString());
  127. body.find(".userName").val(edit.userName); //用户名
  128. body.find(".loginName").val(edit.loginName); //登录名
  129. body.find(".userMobilePhone").val(edit.userMobilePhone);
  130. body.find(".userNickName").val(edit.userNickName);
  131. body.find(".userAddress").val(edit.userAddress);
  132. body.find(".userEmail").val(edit.userEmail); //邮箱
  133. body.find(".userSex input[value=" + edit.userSex + "]").prop("checked", "checked"); //性别
  134. body.find(".allowedNetworkType").val(edit.allowedNetworkType);
  135. body.find(".userType").val(edit.userType); //会员等级
  136. body.find(".userStatus").val(edit.userStatus); //用户状态
  137. body.find(".userDescription").text(edit.userDescription); //用户简介
  138. body.find(".remark").text(edit.remark);
  139. form.render();
  140. }
  141. setTimeout(function () {
  142. layui.layer.tips('点击此处返回分类列表', '.layui-layer-setwin .layui-layer-close', {
  143. tips: 3
  144. });
  145. }, 500)
  146. }
  147. });
  148. layui.layer.full(index);
  149. window.sessionStorage.setItem("index", index);
  150. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  151. $(window).on("resize", function () {
  152. layui.layer.full(window.sessionStorage.getItem("index"));
  153. })
  154. }
  155. //时间转换函数
  156. function showTime(tempDate) {
  157. var d = new Date(tempDate);
  158. var year = d.getFullYear();
  159. var month = d.getMonth();
  160. month++;
  161. var day = d.getDate();
  162. var hours = d.getHours();
  163. var minutes = d.getMinutes();
  164. var seconds = d.getSeconds();
  165. month = month < 10 ? "0" + month : month;
  166. day = day < 10 ? "0" + day : day;
  167. hours = hours < 10 ? "0" + hours : hours;
  168. minutes = minutes < 10 ? "0" + minutes : minutes;
  169. seconds = seconds < 10 ? "0" + seconds : seconds;
  170. var time = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
  171. return time;
  172. }
  173. // 生成分类卡片(网格视图)
  174. function renderCategoriesGrid() {
  175. const booksGrid = document.getElementById('booksGrid');
  176. $.ajax({
  177. url: "/silos/cms/book/info/queryPage",
  178. type: "POST",
  179. dataType: "json",
  180. async: false,
  181. contentType: 'application/json;charset=UTF-8',
  182. data: JSON.stringify({
  183. pageNo:1,
  184. pageRows:100,
  185. infoName:$("#search_value").val()
  186. }),
  187. success: function (res) {
  188. const data = res.data.dataList;
  189. if (data.length === 0) {
  190. booksGrid.innerHTML = `
  191. <div class="empty-state">
  192. <i class="fas fa-book-open"></i>
  193. <h3>暂无图书</h3>
  194. <p>点击"添加图书"按钮开始建立您的图书馆</p>
  195. </div>
  196. `;
  197. return;
  198. }
  199. booksGrid.innerHTML = data.map(book => `
  200. <div class="book-card" bookid="${book.id}" bookTitle="${book.title}">
  201. <div class="book-cover" style="background-color: ${book.coverColor}">
  202. <span style="color: white; font-weight: bold; font-size: 1.5rem;">${book.title.substring(0, 2)}</span>
  203. </div>
  204. <div class="book-info">
  205. <h3 class="book-title">${book.title}</h3>
  206. <p class="book-author">${book.author}</p>
  207. <div class="book-meta">
  208. <span>${book.publisher}</span>
  209. <span>${book.pages}页</span>
  210. </div>
  211. <span class="book-category">${book.category}</span>
  212. <div class="book-actions">
  213. <button class="action-btn edit-btn">
  214. <i class="fas fa-edit"></i> 编辑
  215. </button>
  216. <button class="action-btn delete-btn">
  217. <i class="fas fa-trash"></i> 删除
  218. </button>
  219. </div>
  220. </div>
  221. </div>
  222. `).join('');
  223. },
  224. error: function (e) {
  225. console.log(e);
  226. }
  227. })
  228. }
  229. // 自定义绑定事件方法
  230. function bind_event(dom, fn, type, child,) {
  231. if (typeof dom == 'object' && dom != 'undefined') {
  232. type = type == null ? "click" : type;
  233. if (child != "" && child != 'object') {
  234. return dom.on(type, child, fn);
  235. } else {
  236. return dom.on(type, fn);
  237. }
  238. }
  239. };
  240. // 刷新页面
  241. bind_event($(".search_refresh"), function () {
  242. window.location.reload();
  243. });
  244. $(function () {
  245. renderCategoriesGrid();
  246. //切换tab页的显示
  247. $(document).on('click', '.view-btn', function (e) {
  248. // 视图切换功能
  249. const viewButtons = document.querySelectorAll('.view-btn');
  250. viewButtons.forEach(btn => {
  251. btn.addEventListener('click', function() {
  252. const viewType = this.getAttribute('data-view');
  253. viewButtons.forEach(b => b.classList.remove('active'));
  254. this.classList.add('active');
  255. if (viewType === 'grid') {
  256. document.getElementById('booksGrid').classList.add('active');
  257. document.getElementById('booksTable').classList.remove('active');
  258. } else {
  259. document.getElementById('booksGrid').classList.remove('active');
  260. document.getElementById('booksTable').classList.add('active');
  261. }
  262. });
  263. });
  264. })
  265. });
  266. })