From 2703c23f5a3cf7e7c526ba5af7f02eac1f98298e Mon Sep 17 00:00:00 2001 From: wyl <wangyulong990316@outlook.com> Date: Fri, 29 Nov 2024 15:00:27 +0000 Subject: [PATCH] update page select of commonAdmin --- .../admin/SuperAdminController.java | 11 ++++++++ .../service/SuperAdminService.java | 2 ++ .../service/imp/SuperAdminServiceImp.java | 20 +++++++++++++ .../resources/static/js/mainHospitalView.js | 2 +- .../resources/static/js/mainSupAdminView.js | 28 +++++++++++++++---- .../resources/templates/mainHospitalView.html | 2 +- .../resources/templates/mainSupAdminView.html | 15 ++++++++-- 7 files changed, 70 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/cardiff/client_project/controller/admin/SuperAdminController.java b/src/main/java/com/cardiff/client_project/controller/admin/SuperAdminController.java index a33e0be..1c01ed8 100644 --- a/src/main/java/com/cardiff/client_project/controller/admin/SuperAdminController.java +++ b/src/main/java/com/cardiff/client_project/controller/admin/SuperAdminController.java @@ -71,4 +71,15 @@ public class SuperAdminController { Result result= superAdminService.update(selectDTO); return result; } + + /** + * page selete + */ + @GetMapping("/pageSelect") + public Result pageSelect(@RequestParam String type,@RequestParam Integer pageSize,@RequestParam Integer pageNumber){ + Result result=superAdminService.selectPage(type,pageSize,pageNumber); + return result; + } } + + diff --git a/src/main/java/com/cardiff/client_project/service/SuperAdminService.java b/src/main/java/com/cardiff/client_project/service/SuperAdminService.java index 02968ed..94d22a2 100644 --- a/src/main/java/com/cardiff/client_project/service/SuperAdminService.java +++ b/src/main/java/com/cardiff/client_project/service/SuperAdminService.java @@ -46,4 +46,6 @@ public interface SuperAdminService { * @return */ Result selectByItem(SelectDTO selectDTO); + + Result selectPage(String type, Integer pageSize, int i); } diff --git a/src/main/java/com/cardiff/client_project/service/imp/SuperAdminServiceImp.java b/src/main/java/com/cardiff/client_project/service/imp/SuperAdminServiceImp.java index 4589db4..d238ec4 100644 --- a/src/main/java/com/cardiff/client_project/service/imp/SuperAdminServiceImp.java +++ b/src/main/java/com/cardiff/client_project/service/imp/SuperAdminServiceImp.java @@ -200,5 +200,25 @@ public class SuperAdminServiceImp implements SuperAdminService { } } + + @Override + public Result selectPage(String type, Integer pageSize, int pageNumber) { + if(type.equals("commonAdmin")){ + List<CommonAdmin> commonAdmins = superAdminMapper.selectPageCommonAdmin(pageSize, pageNumber); + //get all and count items + List<AdminVO> adminVOS = superAdminMapper.selectAllAdmin(); + if(commonAdmins.size()>0){ + System.out.println(adminVOS.size()); + Integer count=adminVOS.size()%pageSize==0?adminVOS.size()/pageSize:adminVOS.size()/pageSize+1; + return Result.success(count.toString(),commonAdmins); + } + } + if(type.equals("hospital")){ + + } + return Result.error(ResponseCode.ERROR); + } + + } diff --git a/src/main/resources/static/js/mainHospitalView.js b/src/main/resources/static/js/mainHospitalView.js index 1e6a9e1..22d8d47 100644 --- a/src/main/resources/static/js/mainHospitalView.js +++ b/src/main/resources/static/js/mainHospitalView.js @@ -280,7 +280,7 @@ function updateTable(data) { <td class="tdOption"> <label id="edit" class="btn">Edit</label> <label id="delete" class="btn">Delete</label> - <label id="freeze" class="btn">Freeze</label> + <label id="freeze" class="btn">Change status</label> </td> </tr> `; diff --git a/src/main/resources/static/js/mainSupAdminView.js b/src/main/resources/static/js/mainSupAdminView.js index 8d4328f..2005f65 100644 --- a/src/main/resources/static/js/mainSupAdminView.js +++ b/src/main/resources/static/js/mainSupAdminView.js @@ -247,23 +247,36 @@ function updateTable(data) { <td class="tdOption"> <label id="edit" class="btn">Edit</label> <label id="delete" class="btn">Delete</label> - <label id="freeze" class="btn">Freeze</label> + <label id="freeze" class="btn">Change status</label> </td> </tr> `; tbody.append(tr); }); } -$(document).on("change","#page-size",function (){ - let pageSize=document.getElementById("page-size").value + +function pageSelect(pageSize,paginationDiv,pageNumber) { + $.ajax({ contentType: "application/json", - url: `/superAdmin/pageSelect?type=commonAdmin&pageSize=${pageSize}`, + url: `/superAdmin/pageSelect?type=commonAdmin&pageSize=${pageSize}&pageNumber=${pageNumber}`, type: "GET", dataType: "Json", success: function (data) { - console.log(data) + console.log(data) if (data.code != 0) { + console.log(data.code) + console.log(data.data) + paginationDiv.innerHTML = ""; //clear old button + for (let i = 1; i <= data.msg; i++) { + const button = document.createElement("button"); + button.textContent = i; + button.style.margin = "0 5px"; + button.style.padding = "5px 10px"; + button.style.cursor = "pointer"; + button.onclick = () => pageSelect(pageSize,paginationDiv,button.textContent); + paginationDiv.appendChild(button); + } updateTable(data.data) //location.reload() } else { @@ -271,5 +284,10 @@ $(document).on("change","#page-size",function (){ } }, }) +} +$(document).on("change","#page-size",function (){ + let pageSize=document.getElementById("page-size").value + let paginationDiv = document.getElementById("pagination"); + pageSelect(pageSize,paginationDiv,"1"); }) \ No newline at end of file diff --git a/src/main/resources/templates/mainHospitalView.html b/src/main/resources/templates/mainHospitalView.html index d53b851..8531c77 100644 --- a/src/main/resources/templates/mainHospitalView.html +++ b/src/main/resources/templates/mainHospitalView.html @@ -60,7 +60,7 @@ <td class="tdOption"> <label id="edit" class="btn">Edit</label> <label id="delete" class="btn">Delete</label> - <label id="freeze" class="btn">Freeze</label> + <label id="freeze" class="btn">Change status</label> </td> </tr> </tbody> diff --git a/src/main/resources/templates/mainSupAdminView.html b/src/main/resources/templates/mainSupAdminView.html index c0d52d8..d3d05a2 100644 --- a/src/main/resources/templates/mainSupAdminView.html +++ b/src/main/resources/templates/mainSupAdminView.html @@ -48,7 +48,7 @@ <td class="tdOption"> <label id="edit" class="btn">Edit</label> <label id="delete" class="btn">Delete</label> - <label id="freeze" class="btn">Freeze</label> + <label id="freeze" class="btn">Change status</label> </td> </tr> @@ -91,13 +91,22 @@ <button type="button" id="addAdmin" style="margin-right: 170px;margin-left: 20px">Submit</button> <button type="button" onclick="location.reload()">Cancel</button> </div> -<div> - <select id="page-size"> +<div style="display: flex; align-items: center; gap: 10px; justify-content: center;"> + <select id="page-size" style="background-color: #f9f9f9; + border: 1px solid #ccc; + border-radius: 4px; + padding: 8px 12px; + font-size: 14px; + color: #333; + cursor: pointer; + width: 150px; + transition: all 0.3s ease;"> <option value="">items per page</option> <option value="1">1</option> <option value="2">2</option> <option value="15">15</option> </select> + <div id="pagination" style="margin-top: 10px;"></div> </div> <script src="/js/mainSupAdminView.js"></script> </body> -- GitLab