Procházet zdrojové kódy

fix: 附件-分页增加边界判断

lanjianrong před 4 roky
rodič
revize
21c713c80d
1 změnil soubory, kde provedl 11 přidání a 5 odebrání
  1. 11 5
      app/public/js/material_file.js

+ 11 - 5
app/public/js/material_file.js

@@ -37,7 +37,7 @@ $(document).ready(function () {
                     if (!$('#file-list tr').length) {
                         getAllList();
                     } else {
-                        const curPageNo = $('#file-pagination > li[class="page-item active"] > a').text()
+                        const curPageNo = $('#file-pagination > li[class="page-item active"] > a').text() || 1
                         getAllList(parseInt(curPageNo));
                     }
                 });
@@ -56,10 +56,11 @@ $(document).ready(function () {
         postData('/tender/measure/material/file/delete', data, function () {
             const idx = fileData.findIndex(file => file.id === parseInt(attid))
             idx !== -1 && fileData.splice(idx, 1)
-            const curPageNo = parseInt($('#file-pagination > li[class="page-item active"] > a').text())
+            const curPageNo = parseInt($('#file-pagination > li[class="page-item active"] > a').text()) || 1
             if ($('#file-list tr').length === 1) {
                 getAllList(curPageNo - 1);
             } else {
+
                 getAllList(curPageNo);
             }
             // self.parents('tr').remove();
@@ -74,7 +75,7 @@ $(document).ready(function () {
     // 切换页数
     $('#file-pagination').on('click', '.page-item a', function () {
         // 找到当前的pageNo
-        const curPageNo = $('#file-pagination > li[class="page-item active"] > a').text()
+        const curPageNo = $('#file-pagination > li[class="page-item active"] > a').text() || 1
         const btnType = $(this).attr('aria-label')
         const total = calcCount();
         // btnType存在,说明点击的是前一个/后一个
@@ -107,7 +108,9 @@ $(document).ready(function () {
         // 总页数
         const pageNum = Math.ceil(total/pageCount);
         // 当前页附件内容
-        const currPageAttData = fileData && $('#file-checkbox').is(':checked') ? fileData.slice((currPageNum-1)*pageCount, currPageNum*pageCount) : filterFileData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
+        const currPageAttData = fileData && $('#file-checkbox').is(':checked') ? fileData.slice((currPageNum-1)*pageCount, currPageNum*pageCount) : filterFileData.map((v, index) => {
+            return {...v, index }
+        }).slice((currPageNum-1)*pageCount, currPageNum*pageCount);
 
         renderHtml(currPageAttData)
         // 渲染分页器
@@ -117,6 +120,7 @@ $(document).ready(function () {
 
     function renderPagination(pageNo, pageSize) {
         $('#file-pagination').empty()
+        if (pageSize < 2) return
         const btnHtml = `
         <li class="page-item page-begin">
             <a class="page-link" href="#" aria-label="Start">
@@ -144,7 +148,9 @@ $(document).ready(function () {
         // console.log('pageNo',pageNo, 'pageSize', pageSize)
         if (pageNo - 2 <= 0 || pageNo + 2 >= pageSize)  {
             if (pageNo < 3) {
-                for (let i = 0; i < 5; i++) {
+                console.log('pageSize', pageSize)
+                const max = pageSize > 5 ? 5 : pageSize
+                for (let i = 0; i < max; i++) {
                     html += pageNo === i + 1 ?
                         `<li class="page-item active"><a class="page-link" href="#">${i+1}</a></li>` :
                         `<li class="page-item"><a class="page-link" href="#">${i+1}</a></li>`