CourseWarePage.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <el-row id="manage-page-body">
  3. <el-col :span="3">
  4. <el-menu background-color="#f8f9fb" default-active="1" style="position: fixed;"
  5. @select="handleSelect">
  6. <el-menu-item index="0">
  7. <el-icon>
  8. <Back/>
  9. </el-icon>
  10. <span style="padding-left: 20px">返回首页</span>
  11. </el-menu-item>
  12. <el-menu-item index="1">
  13. <el-icon>
  14. <Document/>
  15. </el-icon>
  16. <span style="padding-left: 20px">全部课程</span>
  17. </el-menu-item>
  18. </el-menu>
  19. </el-col>
  20. <el-col :span="1"/>
  21. <el-col :span="18">
  22. <div class="pdf-reader">
  23. <pdf-viewer></pdf-viewer>
  24. <pointer-canvas ref="pointerCanvas" :no-pointer="!pointer" :no-box="!box"></pointer-canvas>
  25. <div class="pointer-actions">
  26. <c-button text :theme="pointer ? 'red' : ''" @click="pointer = !pointer">
  27. <i class="el-icon-edit"/> 指针</c-button>
  28. <c-button text :left="8" :theme="box ? 'blue' : ''" @click="box = !box">
  29. <i class="el-icon-crop"/> 框选</c-button>
  30. <c-button text :left="8" theme="orange" @click="cleanCanvas">
  31. <i class="el-icon-refresh-left"/> 清除</c-button>
  32. </div>
  33. </div>
  34. </el-col>
  35. </el-row>
  36. </template>
  37. <script>
  38. import PdfViewer from "@/components/PDF/PdfViewer";
  39. import { mapState } from "vuex";
  40. import {
  41. FOCUS_ON_INPUT,
  42. NEXT_PAGE,
  43. PREVIOUS_PAGE,
  44. RESET, SET_CURRENT_PAGE,
  45. SET_SRC,
  46. TOGGLE_SHOW_DISCUSSION,
  47. USE_FOCUS
  48. } from "@/store/types/pdf-types";
  49. import PointerCanvas from "@/components/PDF/PointerCanvas";
  50. import CButton from "@/components/Basic/CButton";
  51. export default {
  52. components: {CButton, PointerCanvas, PdfViewer},
  53. computed: {
  54. ...mapState({
  55. src: state => state.pdf.src,
  56. focus: state => state.pdf.focus
  57. })
  58. },
  59. data () {
  60. return {
  61. pointer: false,
  62. box: false,
  63. slide: {}
  64. };
  65. },
  66. mounted () {
  67. console.log("coursewarepage");
  68. this.$store.commit(RESET);
  69. let { page } = this.$route.params;
  70. if (page) {
  71. this.$store.commit(SET_CURRENT_PAGE, { currentPage: parseInt(page) });
  72. }
  73. const _slideId = this.$route.params.slideId;
  74. this.$apis.getSlideInfo({ slideId: _slideId }).then(res => {
  75. this.slide = res;
  76. }).catch(err => {
  77. //this.$setErrorMessage(err.response.data.msg)
  78. });
  79. this.$apis.getSlideUrl({ slideId: _slideId }).then(res => {
  80. console.log(this.$apis.getSlideUrl({ slideId: _slideId }));
  81. this.$store.commit(SET_SRC, { src: res });
  82. }).catch(err => {
  83. //this.$setErrorMessage('获取课件链接的过程中:' + err.response.data.msg)
  84. });
  85. window.addEventListener("keydown", this.handleKey);
  86. },
  87. beforeUnmount () {
  88. window.removeEventListener("keydown", this.handleKey);
  89. },
  90. methods: {
  91. handleSelect(index) {
  92. if (index === "0") {
  93. this.$router.push("portal");
  94. }
  95. if (index === "1") {
  96. document.getElementById("app").scrollIntoView({behavior: "smooth"});
  97. }
  98. },
  99. handleKey (e) {
  100. if (e.key === "Enter") {
  101. !this.showDiscussion && this.$store.commit(TOGGLE_SHOW_DISCUSSION);
  102. !this.focus && this.$store.commit(FOCUS_ON_INPUT);
  103. return;
  104. }
  105. if (e.key === "Escape") {
  106. if (this.focus) {
  107. this.$store.commit(USE_FOCUS);
  108. } else {
  109. this.$store.commit(TOGGLE_SHOW_DISCUSSION);
  110. }
  111. return;
  112. }
  113. if (!this.showDiscussion || !this.focus) {
  114. switch (e.key) {
  115. case "ArrowDown":
  116. case "ArrowRight":
  117. case "s":
  118. case "d":
  119. case " ":
  120. this.$store.commit(NEXT_PAGE);
  121. break;
  122. case "ArrowUp":
  123. case "ArrowLeft":
  124. case "w":
  125. case "a":
  126. this.$store.commit(PREVIOUS_PAGE);
  127. break;
  128. case "c":
  129. this.cleanCanvas();
  130. break;
  131. case "q":
  132. case "z":
  133. this.$refs.pointerCanvas.undo();
  134. break;
  135. case "e":
  136. case "y":
  137. this.$refs.pointerCanvas.redo();
  138. break;
  139. case "[":
  140. case "b":
  141. this.box = !this.box;
  142. break;
  143. case "p":
  144. case "v":
  145. this.pointer = !this.pointer;
  146. break;
  147. }
  148. }
  149. },
  150. cleanCanvas () {
  151. this.$refs.pointerCanvas.cleanCanvas();
  152. }
  153. },
  154. };
  155. </script>
  156. <style lang="scss" scoped>
  157. .pdf-reader {
  158. display: flex;
  159. align-items: center;
  160. justify-content: center;
  161. min-height: 100vh;
  162. }
  163. .icon-button {
  164. z-index: 2;
  165. position: absolute;
  166. left: 16px;
  167. top: 16px;
  168. background-color: rgba(218, 234, 250, 0.4);
  169. backdrop-filter: saturate(150%) blur(20px);
  170. &:hover {
  171. background-color: rgba(218, 234, 250, 0.67);
  172. }
  173. }
  174. .show-discussion, .hide-discussion {
  175. transition: .2s;
  176. }
  177. .hide-discussion {
  178. transform: translateY(100%);
  179. opacity: 0;
  180. }
  181. .pointer-actions {
  182. position: fixed;
  183. left: 6px;
  184. bottom: 8px;
  185. .c-button {
  186. background-color: white;
  187. }
  188. }
  189. </style>