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.

135 lines
2.6 KiB

  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 v-slot: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>mdi-page-first</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>mdi-chevron-left</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>mdi-chevron-right</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>mdi-page-last</v-icon>
  66. </v-btn>
  67. </div>
  68. </template>
  69. <script lang="ts">
  70. import Vue from 'vue'
  71. export default Vue.extend({
  72. props: {
  73. value: {
  74. type: Number,
  75. default: 1,
  76. required: true
  77. },
  78. total: {
  79. type: Number,
  80. default: 1,
  81. required: true
  82. }
  83. },
  84. data() {
  85. return {
  86. editedPage: '1',
  87. rules: [
  88. (v: string) => (v && parseInt(v, 10) > 0 && parseInt(v, 10) <= this.total) || 'Invalid page number!'
  89. ]
  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>