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.

127 lines
2.8 KiB

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="changePage"
  7. >
  8. <span>{{ page }} of {{ total }}</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. text
  30. :disabled="page===1"
  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. text
  47. :disabled="page===total"
  48. fab
  49. small
  50. v-on="on"
  51. @shortkey="nextPage(total)"
  52. @click="nextPage(total)"
  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. import Vue from 'vue'
  63. import { mapState, mapActions, mapMutations, mapGetters } from 'vuex'
  64. Vue.use(require('vue-shortkey'))
  65. export default {
  66. data() {
  67. return {
  68. editedPage: null,
  69. rules: [
  70. value => (value && parseInt(value, 10) > 0 && parseInt(value, 10) <= this.total) || 'Invalid page number!'
  71. ]
  72. }
  73. },
  74. computed: {
  75. ...mapState('documents', ['items', 'total']),
  76. ...mapGetters('pagination', ['current', 'limit', 'offset', 'page']),
  77. newPage: {
  78. get: function () {
  79. return this.page
  80. },
  81. set: function (newValue) {
  82. const value = parseInt(newValue, 10)
  83. this.editedPage = value
  84. }
  85. }
  86. },
  87. watch: {
  88. offset() {
  89. this.updateSearchOptions({
  90. limit: this.limit,
  91. offset: this.offset
  92. })
  93. this.getDocumentList({
  94. projectId: this.$route.params.id
  95. })
  96. },
  97. current() {
  98. this.setCurrent(this.current)
  99. }
  100. },
  101. created() {
  102. this.initPage({
  103. projectId: this.$route.params.id
  104. })
  105. this.getDocumentList({
  106. projectId: this.$route.params.id
  107. })
  108. },
  109. methods: {
  110. ...mapActions('documents', ['getDocumentList']),
  111. ...mapActions('pagination', ['prevPage', 'nextPage', 'initPage', 'movePage']),
  112. ...mapMutations('documents', ['setCurrent', 'updateSearchOptions']),
  113. changePage() {
  114. if (!this.editedPage || this.editedPage < 0 || this.editedPage > this.total) {
  115. return
  116. }
  117. this.movePage(this.editedPage)
  118. }
  119. }
  120. }
  121. </script>