PreviewCourse.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <el-dialog class="preview-course" :visible="visible" :title="$t('Key144')" width="1100px" @close="dialogClose">
  3. <template v-if="fileType === 'courseware'">
  4. <template v-if="category === 'NPC'">
  5. <booknpc
  6. v-if="context"
  7. ref="booknpc"
  8. task-model=""
  9. :is-show-save="false"
  10. :context="context"
  11. :theme-color="themeColor"
  12. :preview-type="previewType"
  13. :preview-group-id="previewGroupId"
  14. />
  15. </template>
  16. <template v-if="category === 'NNPE'">
  17. <booknnpe
  18. v-if="context"
  19. :context="context"
  20. :theme-color="themeColor"
  21. task-model=""
  22. :is-show-save="false"
  23. :is-show-title="true"
  24. :preview-type="previewType"
  25. :preview-group-id="previewGroupId"
  26. />
  27. </template>
  28. <template v-if="category === 'RLC'">
  29. <bookrlc v-if="context" :context="context" :theme-color="themeColor" :book-font-size="bookFontSize" />
  30. </template>
  31. </template>
  32. <template v-else-if="fileType === 'file'">
  33. <div v-loading="loading">
  34. <iframe
  35. v-if="fileUrl.length > 0"
  36. id="iframe"
  37. :src="`${$store.state.app.config.doc_preview_service_address}/onlinePreview?url=${fileUrl}`"
  38. width="100%"
  39. height="540px"
  40. ></iframe>
  41. </div>
  42. </template>
  43. <div slot="footer">
  44. <el-button @click="dialogClose">
  45. {{ $t('Key246') }}
  46. </el-button>
  47. </div>
  48. </el-dialog>
  49. </template>
  50. <script>
  51. export default {
  52. name: 'PreviewCourse'
  53. };
  54. </script>
  55. <script setup>
  56. import { ref, watch, nextTick } from 'vue';
  57. import { GetFileStoreInfo } from '@/api/app';
  58. import { GetCoursewareContent_View } from '@/api/course';
  59. import { encode } from 'js-base64';
  60. import { Message } from 'element-ui';
  61. const props = defineProps({
  62. visible: {
  63. type: Boolean
  64. },
  65. fileType: {
  66. type: String,
  67. default: ''
  68. },
  69. fileId: {
  70. type: String,
  71. default: ''
  72. },
  73. previewGroupId: {
  74. default: '[]',
  75. type: String
  76. }
  77. });
  78. const emits = defineEmits(['dialogClose']);
  79. watch(
  80. () => props.fileType,
  81. (newVal) => {
  82. if (newVal.length === 0) return;
  83. if (newVal === 'courseware') {
  84. getCoursewareContent_View();
  85. } else {
  86. getFileStoreInfo();
  87. }
  88. }
  89. );
  90. watch(
  91. () => props.visible,
  92. (newVal) => {
  93. if (!newVal) {
  94. category.value = '';
  95. context.value = null;
  96. themeColor.value = '';
  97. fileUrl.value = '';
  98. loading.value = false;
  99. }
  100. }
  101. );
  102. const previewType = 'previewCheckShow';
  103. let category = ref('');
  104. let context = ref(null);
  105. let themeColor = ref('');
  106. let bookFontSize = ref('');
  107. function getCoursewareContent_View() {
  108. GetCoursewareContent_View({ id: props.fileId }).then(
  109. ({ content, category: cate, book_theme_color, book_font_size }) => {
  110. if (!content) {
  111. context.value = null;
  112. return;
  113. }
  114. category.value = cate;
  115. if (category.value === 'OC' || category.value.length === 0 || category.value === 'AILP') {
  116. return Message.warning('该课件类型已被废弃');
  117. }
  118. if (category.value === 'NPC') {
  119. themeColor.value = book_theme_color;
  120. context.value = JSON.parse(content);
  121. return;
  122. }
  123. if (category.value === 'NNPE') {
  124. themeColor.value = book_theme_color;
  125. context.value = JSON.parse(content);
  126. return;
  127. }
  128. if (category.value === 'RLC') {
  129. themeColor.value = book_theme_color;
  130. bookFontSize.value = book_font_size;
  131. context.value = JSON.parse(content);
  132. return;
  133. }
  134. }
  135. );
  136. }
  137. let fileUrl = ref('');
  138. let loading = ref(false);
  139. function getFileStoreInfo() {
  140. GetFileStoreInfo({ file_id: props.fileId }).then(({ file_url_https }) => {
  141. loading.value = true;
  142. fileUrl.value = encodeURIComponent(encode(file_url_https));
  143. nextTick(() => {
  144. document.getElementById('iframe').onload = () => {
  145. loading.value = false;
  146. };
  147. });
  148. });
  149. }
  150. function dialogClose() {
  151. emits('dialogClose');
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. @import '~@/styles/mixin';
  156. .preview-course {
  157. @include dialog;
  158. :deep .el-dialog__header {
  159. font-weight: bold;
  160. }
  161. :deep .el-dialog__body {
  162. min-height: 300px;
  163. }
  164. }
  165. </style>