You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
2.7 KiB

2 years ago
3 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="v-data-footer">
  3. <v-edit-dialog large persistent @save="changePageNumber">
  4. <span>{{ value }} of {{ total }}</span>
  5. <template #input>
  6. <div class="mt-4 title">Move Page</div>
  7. <v-text-field
  8. v-model="editedPage"
  9. :rules="rules"
  10. :label="$t('generic.edit')"
  11. single-line
  12. counter
  13. autofocus
  14. />
  15. </template>
  16. </v-edit-dialog>
  17. <v-btn
  18. v-shortkey.once="['shift', 'arrowleft']"
  19. :disabled="isFirstPage"
  20. text
  21. fab
  22. small
  23. @shortkey="firstPage"
  24. @click="firstPage"
  25. >
  26. <v-icon>{{ mdiPageFirst }}</v-icon>
  27. </v-btn>
  28. <v-btn
  29. v-shortkey.once="['arrowleft']"
  30. :disabled="isFirstPage"
  31. text
  32. fab
  33. small
  34. @shortkey="prevPage"
  35. @click="prevPage"
  36. >
  37. <v-icon>{{ mdiChevronLeft }}</v-icon>
  38. </v-btn>
  39. <v-btn
  40. v-shortkey.once="['arrowright']"
  41. :disabled="isLastPage"
  42. text
  43. fab
  44. small
  45. @shortkey="nextPage"
  46. @click="nextPage"
  47. >
  48. <v-icon>{{ mdiChevronRight }}</v-icon>
  49. </v-btn>
  50. <v-btn
  51. v-shortkey.once="['shift', 'arrowright']"
  52. :disabled="isLastPage"
  53. text
  54. fab
  55. small
  56. @shortkey="lastPage"
  57. @click="lastPage"
  58. >
  59. <v-icon>{{ mdiPageLast }}</v-icon>
  60. </v-btn>
  61. </div>
  62. </template>
  63. <script lang="ts">
  64. import Vue from 'vue'
  65. import { mdiPageFirst, mdiPageLast, mdiChevronLeft, mdiChevronRight } from '@mdi/js'
  66. export default Vue.extend({
  67. props: {
  68. value: {
  69. type: Number,
  70. default: 1,
  71. required: true
  72. },
  73. total: {
  74. type: Number,
  75. default: 1,
  76. required: true
  77. }
  78. },
  79. data() {
  80. return {
  81. editedPage: '1',
  82. rules: [
  83. (v: string) =>
  84. (v && parseInt(v, 10) > 0 && parseInt(v, 10) <= this.total) || 'Invalid page number!'
  85. ],
  86. mdiPageFirst,
  87. mdiPageLast,
  88. mdiChevronLeft,
  89. mdiChevronRight
  90. }
  91. },
  92. computed: {
  93. isFirstPage(): boolean {
  94. return this.value === 1
  95. },
  96. isLastPage(): boolean {
  97. return this.value === this.total || this.total === 0
  98. }
  99. },
  100. methods: {
  101. changePageNumber() {
  102. if (!this.editedPage) {
  103. return
  104. }
  105. const page = parseInt(this.editedPage, 10)
  106. if (page < 0 || page > this.total) {
  107. return
  108. }
  109. this.$emit('click:jump', page)
  110. },
  111. prevPage() {
  112. if (this.value === 1) {
  113. return
  114. }
  115. this.$emit('click:prev')
  116. },
  117. nextPage() {
  118. if (this.value === this.total) {
  119. return
  120. }
  121. this.$emit('click:next')
  122. },
  123. firstPage() {
  124. this.$emit('click:first')
  125. },
  126. lastPage() {
  127. this.$emit('click:last')
  128. }
  129. }
  130. })
  131. </script>