index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="pag-block no-sizes">
  3. <el-pagination
  4. layout="total, prev, pager, next"
  5. @current-change="(data: number) => emit('current-change', data)"
  6. :current-page="currentPage"
  7. :page-size="currSize"
  8. background
  9. :total="total"
  10. >
  11. </el-pagination>
  12. <div
  13. class="sizes-down"
  14. :style="{ left: 40 + total.toString().length * 10 + 'px' }"
  15. v-if="!hideSizes"
  16. >
  17. <span class="el-dropdown-link" @click.stop="show = !show">
  18. {{ currSize }} 条/页
  19. <i :class="show ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i>
  20. </span>
  21. <ul @click.stop v-if="show">
  22. <li
  23. v-for="num in csizes"
  24. :key="num"
  25. :class="{ selected: num === currSize }"
  26. @click="clickHandle(num)"
  27. >
  28. {{ num }}条/页
  29. </li>
  30. </ul>
  31. </div>
  32. </div>
  33. </template>
  34. <script setup lang="ts">
  35. import { onActivated, onUnmounted, ref, watch, watchEffect } from "vue";
  36. const props = withDefaults(
  37. defineProps<{
  38. currentPage: number;
  39. size?: number;
  40. total: number;
  41. hideSizes?: boolean;
  42. csizes?: number[];
  43. }>(),
  44. {
  45. hideSizes: true,
  46. csizes: () => [12, 24],
  47. }
  48. );
  49. const emit = defineEmits<{
  50. (e: "size-change", size: number): void;
  51. (e: "current-change", size: number): void;
  52. }>();
  53. const currSize = ref(props.size || props.csizes[0]);
  54. const show = ref(false);
  55. watchEffect(() => {
  56. if (currSize.value != props.size) {
  57. emit("size-change", currSize.value);
  58. }
  59. });
  60. const clickHandle = (num: number) => {
  61. currSize.value = num;
  62. show.value = false;
  63. };
  64. const docClick = () => (show.value = false);
  65. onActivated(() => {
  66. document.documentElement.addEventListener("click", docClick, false);
  67. });
  68. onUnmounted(() => {
  69. document.documentElement.removeEventListener("click", docClick, false);
  70. });
  71. </script>
  72. <style lang="scss" scope>
  73. .pag-block {
  74. position: relative;
  75. z-index: 88;
  76. .sizes-down {
  77. position: absolute;
  78. top: 50%;
  79. transform: translateY(-50%);
  80. span {
  81. box-sizing: border-box;
  82. font-size: 13px;
  83. appearance: none;
  84. color: rgb(96, 98, 102);
  85. display: inline-block;
  86. height: 30px;
  87. line-height: 30px;
  88. min-width: 100px;
  89. border: 1px solid rgb(220, 223, 230);
  90. border-radius: 4px;
  91. outline: none;
  92. padding: 0px 35px 0 15px;
  93. cursor: pointer;
  94. i {
  95. position: absolute;
  96. right: 15px;
  97. top: 50%;
  98. transform: translateY(-50%);
  99. color: inherit;
  100. }
  101. }
  102. ul {
  103. width: 100%;
  104. bottom: 100%;
  105. position: absolute;
  106. z-index: 1001;
  107. border: solid 1px #e4e7ed;
  108. border-radius: 4px;
  109. background-color: #ffffff;
  110. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  111. box-sizing: border-box;
  112. margin: 5px 0;
  113. list-style: none;
  114. padding: 6px 0;
  115. margin: 0;
  116. box-sizing: border-box;
  117. li {
  118. font-size: 14px;
  119. padding: 0 20px;
  120. position: relative;
  121. white-space: nowrap;
  122. overflow: hidden;
  123. text-overflow: ellipsis;
  124. color: #606266;
  125. height: 34px;
  126. line-height: 34px;
  127. box-sizing: border-box;
  128. cursor: pointer;
  129. &:hover {
  130. background-color: #f5f7fa;
  131. }
  132. &.selected {
  133. color: #d6000f;
  134. font-weight: bold;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. </style>