jialh
2024-12-11 cb5ecb1d5e80fe0b510e5dc229c02bd25a89153b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<template>
    <div class="pagination">
      <button :disabled="currentPage === 1" @click="prevPage">上一页</button>
      <!-- <span>第 {{ currentPage }} 页 / 共 {{ totalPages }} 页</span> -->
      <view class="page">
        <span> {{ currentPage }}  </span> / {{ totalPages }}
      </view>
      <button :disabled="currentPage === totalPages" @click="nextPage">下一页</button>
    </div>
  </template>
  
  <script>
  export default {
    props: {
      totalItems: {
        type: Number,
        required: true
      },
      itemsPerPage: {
        type: Number,
        default: 10
      },
      currentPage: {
        type: Number,
        default: 1
      }
    },
    computed: {
      totalPages() {
        return Math.ceil(this.totalItems / this.itemsPerPage);
      }
    },
    methods: {
      prevPage() {
        if (this.currentPage > 1) {
          this.$emit('page-change', this.currentPage - 1);
        }
      },
      nextPage() {
        if (this.currentPage < this.totalPages) {
          this.$emit('page-change', this.currentPage + 1);
        }
      }
    }
  };
  </script>
  
  <style scoped>
  .pagination {
    display: flex;
    align-items: center;
    justify-content: space-around;
    margin: 20px 0;
  }
  
  .pagination button {
    appearance: none; /* 移除浏览器默认样式 */
    padding: 0 15px;
    margin: 0 5px;
    cursor: pointer;
    background: #3D9AFF;
    color: #FFFFFF;
  }
  
  .pagination button[disabled]{
    cursor: not-allowed; /* 禁用鼠标样式 */
    background: white !important; /* 强制覆盖背景颜色 */
    color: #666666 !important; /* 强制覆盖文字颜色 */
  }
  
  .pagination .page {
    margin: 0 10px;
  }
  .pagination .page span {
   color: #3D9AFF;
  }
  </style>