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.

114 lines
2.3 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 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 {{ length }}</span>
  9. <template v-slot:input>
  10. <div class="mt-4 title">
  11. Move Page
  12. </div>
  13. </template>
  14. <template v-slot:input>
  15. <v-text-field
  16. v-model="newPage"
  17. :rules="rules"
  18. label="Edit"
  19. single-line
  20. counter
  21. autofocus
  22. />
  23. </template>
  24. </v-edit-dialog>
  25. <v-tooltip bottom>
  26. <template v-slot:activator="{ on }">
  27. <v-btn
  28. v-shortkey.once="['arrowleft']"
  29. :disabled="value===1"
  30. text
  31. fab
  32. small
  33. v-on="on"
  34. @shortkey="prevPage"
  35. @click="prevPage"
  36. >
  37. <v-icon>mdi-chevron-left</v-icon>
  38. </v-btn>
  39. </template>
  40. <span></span>
  41. </v-tooltip>
  42. <v-tooltip bottom>
  43. <template v-slot:activator="{ on }">
  44. <v-btn
  45. v-shortkey.once="['arrowright']"
  46. :disabled="value===length || length===0"
  47. text
  48. fab
  49. small
  50. v-on="on"
  51. @shortkey="nextPage"
  52. @click="nextPage"
  53. >
  54. <v-icon>mdi-chevron-right</v-icon>
  55. </v-btn>
  56. </template>
  57. <span></span>
  58. </v-tooltip>
  59. </div>
  60. </template>
  61. <script>
  62. export default {
  63. props: {
  64. value: {
  65. type: Number,
  66. default: 1,
  67. required: true
  68. },
  69. length: {
  70. type: Number,
  71. default: 1,
  72. required: true
  73. }
  74. },
  75. data() {
  76. return {
  77. editedPage: null,
  78. rules: [
  79. v => (v && parseInt(v, 10) > 0 && parseInt(v, 10) <= this.length) || 'Invalid page number!'
  80. ]
  81. }
  82. },
  83. computed: {
  84. newPage: {
  85. get() {
  86. return this.value
  87. },
  88. set(newValue) {
  89. const value = parseInt(newValue, 10)
  90. this.editedPage = value
  91. }
  92. }
  93. },
  94. methods: {
  95. changePageNumber() {
  96. if (!this.editedPage || this.editedPage < 0 || this.editedPage > this.length) {
  97. return
  98. }
  99. this.$emit('input', this.editedPage)
  100. },
  101. prevPage() {
  102. const page = Math.max(this.value - 1, 1)
  103. this.$emit('input', page)
  104. },
  105. nextPage() {
  106. const page = Math.min(this.value + 1, this.length)
  107. this.$emit('input', page)
  108. }
  109. }
  110. }
  111. </script>