jichoi / calendar star
박정하 박정하 07-01
250701 박정하 (공통) 페이지네이션 컴포넌트 수정
@97fb27bd4f72e9c754c686e94918ddbd8e923ba9
client/views/component/Pagenation.vue
--- client/views/component/Pagenation.vue
+++ client/views/component/Pagenation.vue
@@ -1,66 +1,71 @@
 <template>
-  <div class="datatable-bottom">
-      <div class="datatable-info">
-        Showing {{ startIndex + 1 }} to {{ endIndex }} of {{ filteredRows.length }} entries
-      </div>
-      <nav class="datatable-pagination">
-        <ul class="datatable-pagination-list">
-          <li :class="{'datatable-disabled': currentPage === 1}" @click="changePage(currentPage - 1)">
-            <button class="datatable-pagination-list-item-link">‹</button>
-          </li>
-          <li v-for="page in totalPages" 
-              :key="page"
-              :class="{'datatable-active': currentPage === page}">
-            <button class="datatable-pagination-list-item-link" @click="changePage(page)">
-              {{ page }}
-            </button>
-          </li>
-          <li :class="{'datatable-disabled': currentPage === totalPages}" @click="changePage(currentPage + 1)">
-            <button class="datatable-pagination-list-item-link">›</button>
-          </li>
-        </ul>
-      </nav>
-    </div>
+  <div class="pagination">
+    <ul>
+      <li class="arrow" :class="{ disabled: currentPage <= 1 }" @click="changePage(currentPage - 1)">&lt;</li>
+      <template v-for="pageNum in displayedPageNumbers" :key="pageNum">
+        <li :class="{ active: currentPage === pageNum, disabled: currentPage === pageNum }" @click="changePage(pageNum)">{{ pageNum }}</li>
+      </template>
+      <li class="arrow" :class="{ disabled: currentPage >= totalPages }" @click="changePage(currentPage + 1)">&gt;</li>
+    </ul>
+  </div>
 </template>
-
 <script>
 export default {
-  data() {
-    return {
-      currentPage: 1
-    };
-  },
-  computed: {
-    filteredRows() {
-      if (!this.searchQuery) return this.rows;
-      return this.rows.filter(row =>
-        Object.values(row).some(val =>
-          String(val).toLowerCase().includes(this.searchQuery.toLowerCase())
-        )
-      );
-    },
-    totalPages() {
-      return Math.ceil(this.filteredRows.length / this.perPage);
-    },
-    startIndex() {
-      return (this.currentPage - 1) * this.perPage;
-    },
-    endIndex() {
-      return Math.min(this.currentPage * this.perPage, this.filteredRows.length);
-    },
-    paginatedRows() {
-      return this.filteredRows.slice(this.startIndex, this.endIndex);
+  props: {
+    search: {
+      type: Object,
+      required: true,
+      default: () => ({}),
     }
   },
+
+  computed: {
+    // 현재 페이지
+    currentPage() {
+      return this.search.currentPage;
+    },
+
+    // 총 페이지 수
+    totalPages() {
+      return this.search.totalPageCount > 0 ? this.search.totalPageCount : 1;
+    },
+
+    // 표시할 페이지 번호 목록
+    displayedPageNumbers() {
+      const currentPage = this.currentPage;
+      const totalPages = this.totalPages;
+
+      const visiblePages = this.search.pageSize > 0 ? this.search.pageSize : 10;
+
+      // 표시할 페이지 범위 계산
+      let startPageNum = Math.max(1, currentPage - Math.floor(visiblePages / 2));
+      let endPageNum = Math.min(totalPages, startPageNum + visiblePages - 1);
+
+      // endPage가 최대 페이지 수보다 작을 경우, startPage를 조정
+      if (endPageNum - startPageNum + 1 < visiblePages) {
+        startPageNum = Math.max(1, endPageNum - visiblePages + 1);
+      }
+
+      // 페이지 번호 배열 생성
+      const pageNumbers = [];
+      for (let i = startPageNum; i <= endPageNum; i++) {
+        pageNumbers.push(i);
+      }
+
+      return pageNumbers;
+    }
+  },
+
   methods: {
-    changePage(page) {
-      if (page < 1 || page > this.totalPages) return;
-      this.currentPage = page;
+    // 페이지 변경 처리
+    changePage(pageNum) {
+      if (pageNum < 1) pageNum = 1;
+      if (pageNum > this.totalPages) pageNum = this.totalPages;
+
+      if (pageNum !== this.currentPage) {
+        this.$emit('onChange', pageNum);
+      }
     }
   }
 };
-</script>
-
-<style scoped>
-/* Add your styles here */
-</style>
+</script>
(파일 끝에 줄바꿈 문자 없음)
Add a comment
List