paging.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <div class="layer" v-if="max>=1">
  3. <div class="number">
  4. <span :class="{disablehandle:current==1}" @click="current = current - 1">
  5. <i class="iconfont iconedit_pre"></i>
  6. </span>
  7. <template v-if="currMin > min">
  8. <span @click="current = min">{{ min }}</span>
  9. <span v-if="currMin - 1 > min">…</span>
  10. </template>
  11. <span
  12. v-for="index in numbers"
  13. :key="index"
  14. :class="{ active: index === current }"
  15. @click="current = index"
  16. >
  17. {{ index }}
  18. </span>
  19. <template v-if="currMax < max">
  20. <span v-if="currMax + 1 < max">…</span>
  21. <span @click="current = max">{{ max }}</span>
  22. </template>
  23. <span :class="{disablehandle:current >= max}" @click="current = current + 1">
  24. <i class="iconfont iconedit_next"></i>
  25. </span>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. export default {
  31. props: ["paging"],
  32. data() {
  33. return {
  34. ...this.paging,
  35. };
  36. },
  37. computed: {
  38. min() {
  39. return 1;
  40. },
  41. max() {
  42. return Math.ceil(this.total / this.pageSize);
  43. },
  44. routineMin() {
  45. return this.current - Math.ceil(this.showSize / 2);
  46. },
  47. routineMax() {
  48. return this.current + Math.floor(this.showSize / 2);
  49. },
  50. currMin() {
  51. let c = this.max - this.routineMax;
  52. if (this.routineMin <= this.min) {
  53. return this.min;
  54. } else if (c >= 0) {
  55. return this.routineMin;
  56. } else if (this.routineMin + c <= this.min) {
  57. return this.min;
  58. } else {
  59. return this.routineMin + c;
  60. }
  61. },
  62. currMax() {
  63. let c = this.min - this.routineMin;
  64. if (this.routineMax >= this.max) {
  65. return this.max;
  66. } else if (c <= 0) {
  67. return this.routineMax;
  68. } else if (this.routineMax + c >= this.max) {
  69. return this.max;
  70. } else {
  71. return this.routineMax + c;
  72. }
  73. },
  74. numbers() {
  75. let total = this.currMax - this.currMin;
  76. let numbers = [];
  77. if (total === 0) {
  78. numbers.push(1);
  79. } else {
  80. for (let i = 0; i <= total; i++) {
  81. numbers.push(this.currMin + i);
  82. }
  83. }
  84. return numbers;
  85. },
  86. },
  87. watch: {
  88. current(val, old) {
  89. if (isNaN(this.current)) {
  90. return (this.current = old);
  91. } else if (this.current < this.min) {
  92. return (this.current = this.min);
  93. } else if (this.current > this.max) {
  94. return (this.current = this.max);
  95. }
  96. this.$emit("changeCurrent", this.current);
  97. },
  98. paging() {
  99. Object.keys(this.paging).forEach((k) => (this[k] = this.paging[k]));
  100. },
  101. "paging.total": function() {
  102. Object.keys(this.paging).forEach((k) => (this[k] = this.paging[k]));
  103. },
  104. },
  105. };
  106. </script>
  107. <style lang="less" scoped>
  108. @wh:32px;
  109. @color:#1983F6;
  110. .layer {
  111. span {
  112. font-size: 16px;
  113. display: inline-block;
  114. vertical-align: middle;
  115. margin: 0 10px;
  116. color: #202020;
  117. font-weight: bold;
  118. width: @wh;
  119. height: @wh;
  120. text-align: center;
  121. border-radius: 2px;
  122. background: #fff;
  123. line-height: @wh;
  124. &.active {
  125. color: #fff;
  126. background: @color;
  127. }
  128. }
  129. .number span {
  130. margin: 0 5px;
  131. cursor: pointer;
  132. &:first-of-type{
  133. margin-left: 0;
  134. }
  135. }
  136. div {
  137. display: inline-block;
  138. }
  139. div input {
  140. background: none;
  141. border: 1px solid rgba(85, 85, 85, 1);
  142. width: 46px;
  143. height: 28px;
  144. border-radius: 2px;
  145. vertical-align: middle;
  146. text-align: center;
  147. color: #fff;
  148. }
  149. .disablehandle {
  150. color: #C0C4CC;
  151. pointer-events: none;
  152. }
  153. .layout .next-page-item:after {
  154. width: 0;
  155. height: 0;
  156. border-color: transparent transparent transparent #011111;
  157. border-style: solid;
  158. border-width: 5px 0 5px 8px;
  159. }
  160. }
  161. </style>