CurMaterial.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <el-dialog
  3. :class="['cur-material', { 'align-left': !isAlignCenter }]"
  4. :visible="dialogVisibleMaterial"
  5. :modal="false"
  6. width="900px"
  7. @close="dialogMaterialClose"
  8. >
  9. <div slot="title" class="dialog-header">
  10. <span class="dialog-header-title">当前推送资料</span>
  11. <span @click="isAlignCenter = !isAlignCenter">
  12. <svg-icon :icon-class="isAlignCenter ? 'align-left' : 'align-center'" />
  13. </span>
  14. </div>
  15. <div class="material-name">{{ materialName }}</div>
  16. <template v-if="materialType === 'COURSEWARE'">
  17. <bookquestion
  18. ref="courseware"
  19. :context="context"
  20. @handleBookUserAnswer="handleBookUserAnswer"
  21. />
  22. </template>
  23. <template v-else>
  24. <template v-if="fileType === 'pdf'">
  25. <pdf v-for="i in numPages" :key="i" :src="pdfSrc" :page="i" />
  26. </template>
  27. <template v-else-if="isImage(fileType)">
  28. <el-image fit="contain" :src="file_url_https" />
  29. </template>
  30. <template v-else>
  31. <iframe
  32. :src="'https://view.officeapps.live.com/op/view.aspx?src=' + `${file_url_https}`"
  33. width="100%"
  34. height="490px"
  35. scrolling="no"
  36. />
  37. </template>
  38. </template>
  39. <div slot="footer">
  40. <el-button type="primary" @click="finishMyMaterial">完成</el-button>
  41. </div>
  42. </el-dialog>
  43. </template>
  44. <script>
  45. import pdf from 'vue-pdf';
  46. import { GetCoursewareContent_View } from '@/api/course';
  47. import { GetFileStoreInfo, getContentFile } from '@/api/app';
  48. import { FinishMyMaterial } from '@/api/live';
  49. import { getToken } from '@/utils/auth';
  50. export default {
  51. components: {
  52. pdf
  53. },
  54. props: {
  55. dialogVisibleMaterial: {
  56. default: false,
  57. type: Boolean
  58. },
  59. taskId: {
  60. default: '',
  61. type: String
  62. },
  63. materialId: {
  64. default: '',
  65. type: String
  66. },
  67. materialName: {
  68. default: '',
  69. type: String
  70. },
  71. materialType: {
  72. default: '',
  73. type: String
  74. },
  75. materialPictureUrl: {
  76. default: '',
  77. type: String
  78. }
  79. },
  80. data() {
  81. return {
  82. context: null,
  83. exam_answer: '',
  84. file_relative_path: '',
  85. file_url_https: '',
  86. pdfSrc: '',
  87. numPages: 1,
  88. isAlignCenter: true
  89. };
  90. },
  91. computed: {
  92. fileType() {
  93. return this.file_url_https.slice(
  94. this.file_url_https.lastIndexOf('.') + 1,
  95. this.file_url_https.length
  96. );
  97. }
  98. },
  99. watch: {
  100. dialogVisibleMaterial(newVal) {
  101. if (!newVal) {
  102. this.context = null;
  103. this.exam_answer = '';
  104. this.file_relative_path = '';
  105. this.file_url_https = '';
  106. this.pdfSrc = '';
  107. this.numPages = 1;
  108. }
  109. },
  110. materialId() {
  111. if (this.materialType === 'COURSEWARE') {
  112. this.getCoursewareContent_View();
  113. } else {
  114. this.getFileStoreInfo();
  115. }
  116. }
  117. },
  118. created() {
  119. this.uploadBookWriteParent();
  120. },
  121. methods: {
  122. dialogMaterialClose() {
  123. this.$emit('dialogMaterialClose');
  124. },
  125. getCoursewareContent_View() {
  126. GetCoursewareContent_View({ id: this.materialId }).then(({ content }) => {
  127. if (content) {
  128. this.context = {
  129. id: this.materialId,
  130. ui_type: JSON.parse(content).question.ui_type,
  131. content: JSON.parse(content)
  132. };
  133. this.$nextTick(() => {
  134. this.$refs.courseware.handleAnswerTimeStart();
  135. });
  136. } else {
  137. this.context = null;
  138. }
  139. });
  140. },
  141. getFileStoreInfo() {
  142. GetFileStoreInfo({ file_id: this.materialId }).then(
  143. ({ file_relative_path, file_url_https }) => {
  144. this.file_relative_path = file_relative_path;
  145. this.file_url_https = file_url_https;
  146. let fileType = file_url_https.slice(
  147. file_url_https.lastIndexOf('.') + 1,
  148. file_url_https.length
  149. );
  150. if (fileType === 'pdf') {
  151. this.getNumPages(file_url_https);
  152. }
  153. }
  154. );
  155. },
  156. getNumPages(url) {
  157. let loadingTask = pdf.createLoadingTask(url);
  158. loadingTask.promise
  159. .then(pdf => {
  160. this.pdfSrc = loadingTask;
  161. this.numPages = pdf.numPages;
  162. })
  163. .catch(err => {
  164. console.error('pdf加载失败', err);
  165. this.$message.error('pdf加载失败');
  166. });
  167. },
  168. handleBookUserAnswer(data) {
  169. this.exam_answer = data;
  170. },
  171. finishMyMaterial() {
  172. if (this.materialType === 'COURSEWARE' && this.exam_answer.length === 0) {
  173. this.$message.warning('请完成课件');
  174. return;
  175. }
  176. const loading = this.$loading();
  177. FinishMyMaterial({
  178. task_id: this.taskId,
  179. material_id: this.materialId,
  180. material_type: this.materialType,
  181. exam_answer: this.exam_answer
  182. })
  183. .then(() => {
  184. this.$message.success('完成推送资料成功');
  185. this.$emit('dialogMaterialClose');
  186. })
  187. .finally(() => {
  188. loading.close();
  189. this.exam_answer = '';
  190. });
  191. },
  192. isImage(type) {
  193. return ['jpeg', 'gif', 'jpg', 'png', 'bmp', 'pic', 'svg'].includes(type);
  194. },
  195. /**
  196. * 课件方法
  197. */
  198. // 上传文件
  199. uploadBookWriteParent() {
  200. const { token, isHas } = getToken();
  201. let UserCode = isHas ? token.user_code : '';
  202. let UserType = isHas ? token.user_type : '';
  203. let SessionID = isHas ? token.session_id : '';
  204. this.bookuploadUrl = `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&SecurityLevel=Mid`;
  205. },
  206. // 下载文件zip
  207. downloadBookWriteParent(idList) {
  208. let MethodName = 'file_store_manager-StartCreateFileCompressPack';
  209. let data = {
  210. file_id_list: JSON.parse(idList)
  211. };
  212. getContentFile(MethodName, data).then(res => {
  213. let id = res.file_compress_task_id;
  214. this.bookDownTimer = setInterval(() => {
  215. this.checkTaskProgress(id);
  216. }, 2000);
  217. });
  218. },
  219. // 成功后调用打包进度
  220. checkTaskProgress(taskId) {
  221. const { token, isHas } = getToken();
  222. let UserCode = isHas ? token.user_code : '';
  223. let UserType = isHas ? token.user_type : '';
  224. let SessionID = isHas ? token.session_id : '';
  225. let MethodName = 'file_store_manager-GetFileCompressTaskProgress';
  226. let data = {
  227. file_compress_task_id: taskId
  228. };
  229. getContentFile(MethodName, data).then(res => {
  230. if (res.is_finish === 'true') {
  231. clearInterval(this.bookDownTimer);
  232. window.open(
  233. `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileDownload?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&FileID=${res.compress_pack_file_id}`
  234. );
  235. }
  236. });
  237. }
  238. }
  239. };
  240. </script>
  241. <style lang="scss">
  242. @import '~@/styles/mixin.scss';
  243. .cur-material {
  244. @include dialog;
  245. &.align-left {
  246. .el-dialog {
  247. margin-left: 20px;
  248. }
  249. }
  250. .el-dialog__header {
  251. .dialog-header {
  252. display: flex;
  253. justify-content: space-between;
  254. padding-right: 24px;
  255. &-title {
  256. font-weight: bold;
  257. font-size: 18px;
  258. line-height: 24px;
  259. }
  260. .svg-icon {
  261. cursor: pointer;
  262. }
  263. }
  264. }
  265. .material-name {
  266. font-size: 16px;
  267. font-weight: 700;
  268. color: #000;
  269. margin-bottom: 16px;
  270. }
  271. }
  272. </style>