PreviewCourse.vue 4.7 KB

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