PdfController.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="pdf-controller">
  3. <div class="actions" :class="hide ? 'hide-actions' : ''" style="margin-top: 30px">
  4. <el-button title="下载" size="small" style="margin-right: 5px" v-if="canDownload"
  5. @click="handleDownloadPdfFile"><el-icon><Download /></el-icon></el-button>
  6. <el-button @click="handlePrevious" title="上一页" size="small"><el-icon><ArrowLeftBold /></el-icon></el-button>
  7. <label class="page">
  8. {{currentPage}} / {{totalPages}}
  9. </label>
  10. <label class="to-page-action">
  11. <el-input placeholder="to" ref="input" type="number" v-model="toPage" @input="handleToPage"/>
  12. </label>
  13. <el-button @click="handleNext" title="下一页" size="small"><el-icon><ArrowRightBold /></el-icon></el-button>
  14. </div>
  15. <el-button @click="hide = !hide" :title="hide ? '展开' : '收起'" class="show-button" :class="hide ? 'show-button-hide' : 'show-button-show'" circle>
  16. <el-icon><ArrowUpBold /></el-icon>
  17. </el-button>
  18. </div>
  19. </template>
  20. <script>
  21. import { NEXT_PAGE, PREVIOUS_PAGE, SET_CURRENT_PAGE} from "../../../store/types/pdf-types";
  22. import { mapState } from "vuex";
  23. export default {
  24. data () {
  25. return {
  26. pageMarked: false,
  27. toPage: 1,
  28. hide: false,
  29. canDownload: false,
  30. //currentPage: 1
  31. };
  32. },
  33. mounted() {
  34. this.handleCanDownload();
  35. //this.$router.replace({ path:"/empty/" + this.$route.params.courseWareId});
  36. },
  37. computed: {
  38. ...mapState({
  39. src: state => state.pdf.src,
  40. totalPages: state => state.pdf.totalPages,
  41. currentPage: state => state.pdf.currentPage
  42. })
  43. },
  44. methods: {
  45. handlePrevious () {
  46. this.$store.commit(PREVIOUS_PAGE);
  47. },
  48. handleNext () {
  49. this.$store.commit(NEXT_PAGE);
  50. },
  51. handleToPage (value) {
  52. if (value === "" || value === 0) {
  53. return;
  54. }
  55. value = typeof value === typeof "" ? parseInt(value) : value;
  56. if (value > this.totalPages) {
  57. this.$store.commit(SET_CURRENT_PAGE, { currentPage: this.totalPages });
  58. } else if (value <= 0) {
  59. this.$store.commit(SET_CURRENT_PAGE, { currentPage: 1 });
  60. } else {
  61. this.$store.commit(SET_CURRENT_PAGE, { currentPage: value });
  62. }
  63. },
  64. handleCanDownload () {
  65. this.$apis.getCanDownloadById(this.$route.params.courseWareId).then(res => {
  66. this.canDownload = res.data.data;
  67. });
  68. },
  69. handleDownloadPdfFile() {
  70. this.$apis.getCourseWareById(this.$route.params.courseWareId).then(res => {
  71. window.open(res.data.data.fileUrl, "_blank");
  72. });
  73. }
  74. }
  75. };
  76. </script>
  77. <style>
  78. .pdf-controller {
  79. position: fixed;
  80. right: 12px;
  81. top: 25px;
  82. display: flex;
  83. align-items: center;
  84. justify-content: center;
  85. z-index: 2;
  86. transition: .2s ease-out;
  87. color: #619dc9;
  88. }
  89. .actions {
  90. display: flex;
  91. align-items: center;
  92. justify-content: center;
  93. padding: 4px 12px;
  94. margin-right: 12px;
  95. border-radius: 12px;
  96. background-color: rgba(218, 234, 250, 0.4);
  97. backdrop-filter: saturate(150%) blur(20px);
  98. transition: .2s ease-out;
  99. }
  100. .hide-actions {
  101. transform: translateY(-80px);
  102. }
  103. .page {
  104. color: #7a8a9a;
  105. padding: 0 6px;
  106. font-size: 14px;
  107. }
  108. .to-page-action {
  109. color: #7a8a9a;
  110. padding: 0 6px;
  111. font-size: 14px;
  112. width: 100px;
  113. }
  114. .show-button {
  115. transition: .2s ease-out;
  116. margin-top: 30px;
  117. }
  118. .show-button-hide {
  119. transform: scale(-1);
  120. }
  121. .show-button-show {
  122. transform: scale(1);
  123. }
  124. @media (max-width: 500px) {
  125. .show-button {
  126. display: none;
  127. }
  128. .hide-actions {
  129. transform: translateY(0);
  130. }
  131. }
  132. </style>