Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. <template lang="html">
  2.  
  3. <div class="">
  4.  
  5. <nav class="pagination">
  6. <a class="button" @click="setPage(currentPage - 1)" :disabled="defPrevButton()"><i class="fa fa-arrow-circle-o-left"></i> Voltar</a>
  7. <a class="button" @click="setPage(currentPage + 1)" :disabled="defNextButton()"><i class="fa fa-arrow-circle-o-right"></i> Avançar</a>
  8. <ul>
  9. <li v-show="defFirstAndLastPageButtons()">
  10. <a :disabled="isCurrentPageInLoop(currentPage, 1)" :class="setCSSActiveButton(currentPage, 1)" @click="setPage(1)">1</a>
  11. </li>
  12. <li v-show="defFirstAndLastPageButtons()">
  13. <span>...</span>
  14. </li>
  15. <li v-for="pag in pages">
  16. <a :disabled="isCurrentPageInLoop(currentPage, pag)" :class="setCSSActiveButton(currentPage, pag)" @click="setPage(pag)">{{ pag }}</a>
  17. </li>
  18. <li v-show="defFirstAndLastPageButtons()">
  19. <span>...</span>
  20. </li>
  21. <li v-show="defFirstAndLastPageButtons()">
  22. <a :disabled="isCurrentPageInLoop(currentPage, lastPageNumber)" :class="setCSSActiveButton(currentPage, lastPageNumber)" @click="setPage(lastPageNumber)">{{ lastPageNumber }}</a>
  23. </li>
  24. </ul>
  25. </nav>
  26. </div>
  27.  
  28. </template>
  29.  
  30. <script>
  31. import _ from 'lodash'
  32.  
  33. const CENTRAL_PAGE_BUTTONS = 5 // informar um inteiro impar
  34. const TOTAL_PAGE_BUTTONS = CENTRAL_PAGE_BUTTONS + 2 // nao alterar essa constante
  35.  
  36. export default {
  37. data () {
  38. return {
  39. }
  40. },
  41. computed: {
  42. pages () {
  43. const totalPages = _.toInteger(this.total / this.pageLimite) + 1
  44. console.log('total, pagelimite, totalPages', this.total, this.pageLimite, totalPages)
  45. let _array = []
  46.  
  47. if (totalPages <= TOTAL_PAGE_BUTTONS) {
  48. _array = _.range(1, totalPages + 1)
  49. } else if (this.currentPage <= CENTRAL_PAGE_BUTTONS) {
  50. _array = _.range(2, CENTRAL_PAGE_BUTTONS + 2)
  51. } else if ((this.currentPage + (_.toInteger(CENTRAL_PAGE_BUTTONS / 2))) >= totalPages) {
  52. _array = _.range(totalPages - CENTRAL_PAGE_BUTTONS, totalPages)
  53. } else {
  54. _array = _.range(this.currentPage - 2, this.currentPage + (CENTRAL_PAGE_BUTTONS - 2))
  55. }
  56. return _array
  57. },
  58. lastPageNumber () {
  59. return _.toInteger(this.total / this.pageLimite) + 1
  60. }
  61. },
  62. ready () {
  63. },
  64. methods: {
  65. setCSSActiveButton (currentPage, pag) {
  66. console.log('currentPage, pag (loop)', currentPage, pag)
  67. if (this.isCurrentPageInLoop(currentPage, pag)) {
  68. return 'button is-primary'
  69. }
  70. return 'button'
  71. },
  72. isCurrentPageInLoop (currentPage, pag) {
  73. if (currentPage === pag) {
  74. return true
  75. }
  76. return false
  77. },
  78. setPage (pag) {
  79. this.$emit('set-current-page', pag)
  80. },
  81. defPrevButton () {
  82. return this.currentPage < 2
  83. },
  84. defNextButton () {
  85. return (this.currentPage * this.pageLimite) > this.total
  86. },
  87. defFirstAndLastPageButtons () {
  88. return ((this.total / this.pageLimite) >= TOTAL_PAGE_BUTTONS)
  89. }
  90. },
  91. props: [ 'total', 'currentPage', 'pageLimite' ],
  92. components: {}
  93. }
  94. </script>
  95.  
  96. <style lang="css">
  97. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement