CurMaterial.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <el-dialog
  3. class="cur-material"
  4. :visible="dialogVisibleMaterial"
  5. width="900px"
  6. title="当前推送课件"
  7. @close="dialogMaterialClose"
  8. >
  9. <div class="material-name">{{ materialName }}</div>
  10. <template v-if="materialType === 'COURSEWARE'">
  11. <question :context="context" />
  12. </template>
  13. <template v-else>
  14. <template v-if="fileType === 'pdf'">
  15. <pdf v-for="i in numPages" :key="i" :src="pdfSrc" :page="i"></pdf>
  16. </template>
  17. <template v-else-if="isImage(fileType)">
  18. <el-image fit="contain" :src="file_url_https" />
  19. </template>
  20. <template v-if="fileType !== 'pdf'">
  21. <iframe
  22. :src="'https://view.officeapps.live.com/op/view.aspx?src=' + `${file_url_https}`"
  23. width="100%"
  24. height="490px"
  25. scrolling="no"
  26. >
  27. </iframe>
  28. </template>
  29. </template>
  30. <div slot="footer">
  31. <el-button type="primary" @click="finishMyMaterial">完成</el-button>
  32. </div>
  33. </el-dialog>
  34. </template>
  35. <script>
  36. import pdf from 'vue-pdf';
  37. import { GetCoursewareContent_View } from '@/api/course';
  38. import { GetFileStoreInfo } from '@/api/app';
  39. import { FinishMyMaterial } from '@/api/live';
  40. export default {
  41. components: {
  42. pdf
  43. },
  44. props: {
  45. dialogVisibleMaterial: {
  46. default: false,
  47. type: Boolean
  48. },
  49. taskId: {
  50. default: '',
  51. type: String
  52. },
  53. materialId: {
  54. default: '',
  55. type: String
  56. },
  57. materialName: {
  58. default: '',
  59. type: String
  60. },
  61. materialType: {
  62. default: '',
  63. type: String
  64. },
  65. materialPictureUrl: {
  66. default: '',
  67. type: String
  68. }
  69. },
  70. data() {
  71. return {
  72. context: null,
  73. file_relative_path: '',
  74. file_url_https: '',
  75. pdfSrc: '',
  76. numPages: 1
  77. };
  78. },
  79. computed: {
  80. fileType() {
  81. return this.file_url_https.slice(
  82. this.file_url_https.lastIndexOf('.') + 1,
  83. this.file_url_https.length
  84. );
  85. }
  86. },
  87. watch: {
  88. materialId() {
  89. if (this.materialType === 'COURSEWARE') {
  90. this.getCoursewareContent_View();
  91. } else {
  92. this.getFileStoreInfo();
  93. }
  94. }
  95. },
  96. methods: {
  97. dialogMaterialClose() {
  98. this.$emit('dialogMaterialClose');
  99. },
  100. getCoursewareContent_View() {
  101. GetCoursewareContent_View({ id: this.materialId }).then(res => {
  102. if (res.content) {
  103. this.context = {
  104. id: this.currentCourse,
  105. ui_type: JSON.parse(res.content).question.ui_type,
  106. sort_number: 1,
  107. content: JSON.parse(res.content)
  108. };
  109. } else {
  110. this.context = null;
  111. }
  112. });
  113. },
  114. getFileStoreInfo() {
  115. GetFileStoreInfo({ file_id: this.materialId }).then(
  116. ({ file_relative_path, file_url_https }) => {
  117. this.file_relative_path = file_relative_path;
  118. this.file_url_https = file_url_https;
  119. let fileType = file_url_https.slice(
  120. file_url_https.lastIndexOf('.') + 1,
  121. file_url_https.length
  122. );
  123. if (fileType === 'pdf') {
  124. this.getNumPages(file_url_https);
  125. }
  126. }
  127. );
  128. },
  129. getNumPages(url) {
  130. let loadingTask = pdf.createLoadingTask(url);
  131. loadingTask.promise
  132. .then(pdf => {
  133. this.pdfSrc = loadingTask;
  134. this.numPages = pdf.numPages;
  135. })
  136. .catch(err => {
  137. console.error('pdf加载失败', err);
  138. this.$message.error('pdf加载失败');
  139. });
  140. },
  141. finishMyMaterial() {
  142. FinishMyMaterial({
  143. task_id: this.taskId,
  144. material_id: this.materialId,
  145. material_type: this.materialType
  146. }).then(() => {
  147. this.$message.success('完成推送资料成功');
  148. this.$emit('dialogMaterialClose');
  149. });
  150. },
  151. isImage(type) {
  152. return ['jpeg', 'gif', 'jpg', 'png', 'bmp', 'pic', 'svg'].includes(type);
  153. }
  154. }
  155. };
  156. </script>
  157. <style lang="scss">
  158. @import '~@/styles/mixin.scss';
  159. .cur-material {
  160. @include dialog;
  161. .material-name {
  162. font-size: 16px;
  163. font-weight: 700;
  164. color: #000;
  165. margin-bottom: 16px;
  166. }
  167. }
  168. </style>