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.

141 lines
2.8 KiB

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