index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div class="layout">
  3. <a @click="clickHandle(index - 1)" ></a>
  4. <a @click="clickHandle(1)" :class="{active: index === 1}" >1</a><a class="more" @click="clickHandle(current - 3)" v-if="current>5" >...</a><a
  5. v-if="page!==maxPage && page!==1"
  6. v-for="page in pages"
  7. :key="page"
  8. @click="clickHandle(page)"
  9. :class="{active: index === page}"
  10. >{{page}}</a><a class="more" @click="clickHandle(pages[pages.length-1] + 2)" v-if="pages[pages.length-1]+2<=maxPage" >...</a><a @click="clickHandle(maxPage)" v-if="maxPage!==1" :class="{active: index === maxPage}" >{{maxPage}}</a>
  11. <i class="iconfont icon-youjiantou" @click="clickHandle(index + 1)" ></i>
  12. </div>
  13. </template>
  14. <script>
  15. /**
  16. * 取得页码数组
  17. * @param showPageMaxCount 允许显示的页码最大数量
  18. * @param pageNow 当前页码
  19. * @param pageCount 总页数
  20. * @return 页码数组(整数数组)
  21. */
  22. function getPageNumArr (showPageMaxCount, pageNow, pageCount) {
  23. let pageNumArr = []
  24. let pageNumBegin, pageNumEnd
  25. if (pageCount <= showPageMaxCount) {
  26. pageNumBegin = 1
  27. pageNumEnd = pageCount
  28. } else {
  29. if (pageNow <= Math.floor(showPageMaxCount / 2)) {
  30. pageNumBegin = 1
  31. pageNumEnd = showPageMaxCount
  32. } else if (pageCount - pageNow <= Math.floor(showPageMaxCount / 2)) {
  33. pageNumBegin = pageCount - showPageMaxCount
  34. pageNumEnd = pageCount
  35. pageNumEnd - pageNumBegin >= showPageMaxCount && pageNumBegin++
  36. } else {
  37. pageNumBegin = Math.ceil(pageNow - showPageMaxCount / 2)
  38. pageNumEnd = Math.floor(pageNow + showPageMaxCount / 2)
  39. pageNumEnd - pageNumBegin >= showPageMaxCount && pageNumBegin++
  40. }
  41. }
  42. for (let i = pageNumBegin; i <= pageNumEnd; i++) {
  43. pageNumArr.push(i)
  44. }
  45. return pageNumArr
  46. }
  47. export default {
  48. props: {
  49. current: {
  50. default: 1
  51. },
  52. reindex: {
  53. default: 1
  54. },
  55. total: {
  56. default: 10
  57. },
  58. equable: {
  59. default: 10
  60. },
  61. length: {
  62. default: 5
  63. },
  64. value: {
  65. default: 1
  66. },
  67. color: {
  68. default: '#2d2d2d'
  69. }
  70. },
  71. data () {
  72. return { index: this.value }
  73. },
  74. mounted () {
  75. this.$emit('maxPage', this.maxPage)
  76. },
  77. computed: {
  78. maxPage () {
  79. let val = Math.ceil(this.total / this.equable)
  80. this.$emit('maxPage', val)
  81. return val
  82. },
  83. pages () {
  84. let temp = getPageNumArr(this.length, this.index, this.maxPage)
  85. return temp
  86. }
  87. },
  88. methods: {
  89. clickHandle (index) {
  90. if (index > 0 && index <= this.maxPage) {
  91. this.index = index
  92. }
  93. this.$emit('clickHandle', this.index)
  94. }
  95. },
  96. watch: {
  97. index (newVal) {
  98. this.$bus.$emit('input', newVal)
  99. },
  100. current (newVal) {
  101. this.index = newVal
  102. }
  103. }
  104. }
  105. </script>
  106. <style scoped>
  107. .layout .more:hover::after{
  108. transform: scaleX(0)!important;
  109. }
  110. .layout a:last-child:hover::before{
  111. transform: scaleX(2);
  112. }
  113. .layout a:last-child:hover::after{
  114. transform: translateX(5px);
  115. }
  116. .layout a:last-child::before{
  117. background-color: #111;
  118. height: 2px;
  119. width: 8px;
  120. transform-origin: 0 0;
  121. }
  122. .layout a:last-child::after{
  123. width: 0;
  124. height: 0;
  125. border-style: solid;
  126. border-width: 5px 0 5px 8px;
  127. border-color: transparent transparent transparent #011111;
  128. }
  129. /* .layout {
  130. text-align: center;
  131. }
  132. .layout a {
  133. margin: 10px;
  134. font-size: 18px;
  135. display: inline-block;
  136. cursor: pointer;
  137. user-select: none;
  138. color: #2d2d2d;
  139. }
  140. .layout a.active,
  141. .layout a:hover {
  142. color: #111111;
  143. border-bottom: 2px solid #111;
  144. } */
  145. </style>