|
@@ -76,34 +76,12 @@
|
|
|
</template>
|
|
|
|
|
|
<template v-else>
|
|
|
- <template v-if="fileType === 'pdf'">
|
|
|
- <pdf v-for="i in numPages" :key="i" :src="pdfSrc" :page="i" />
|
|
|
- </template>
|
|
|
-
|
|
|
- <template v-else-if="isImage(fileType)">
|
|
|
- <el-image fit="contain" :src="file_url_https" />
|
|
|
- </template>
|
|
|
-
|
|
|
- <div v-else-if="fileType === 'mp3'" class="audio-file">
|
|
|
- <audio :src="file_url_https" controls />
|
|
|
- </div>
|
|
|
-
|
|
|
- <div v-else-if="fileType === 'mp4'" class="video-file">
|
|
|
- <video :src="file_url_https" controls />
|
|
|
- </div>
|
|
|
-
|
|
|
- <div v-else-if="fileType === 'txt'" class="text-file">
|
|
|
- <el-input v-model="text" type="textarea" :readonly="true" resize="none" />
|
|
|
- </div>
|
|
|
-
|
|
|
- <template v-else>
|
|
|
- <iframe
|
|
|
- :src="'https://view.officeapps.live.com/op/view.aspx?src=' + `${file_url_https}`"
|
|
|
- width="100%"
|
|
|
- height="490px"
|
|
|
- scrolling="no"
|
|
|
- />
|
|
|
- </template>
|
|
|
+ <iframe
|
|
|
+ v-if="fileUrl.length > 0"
|
|
|
+ :src="`https://docpreview.utschool.cn/onlinePreview?url=${fileUrl}`"
|
|
|
+ width="100%"
|
|
|
+ height="540px"
|
|
|
+ />
|
|
|
</template>
|
|
|
|
|
|
<div slot="footer">
|
|
@@ -123,17 +101,14 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import pdf from 'vue-pdf';
|
|
|
import { GetCoursewareContent_View, GetMaterialInfo } from '@/api/course';
|
|
|
import { GetFileStoreInfo, getContentFile } from '@/api/app';
|
|
|
import { FinishMyMaterial, GetCurMaterialSent, GetStudentExamAnswer_FinishMaterial } from '@/api/live';
|
|
|
import { getToken } from '@/utils/auth';
|
|
|
+import { encode } from 'js-base64';
|
|
|
|
|
|
export default {
|
|
|
name: 'CurMaterial',
|
|
|
- components: {
|
|
|
- pdf
|
|
|
- },
|
|
|
props: {
|
|
|
taskId: {
|
|
|
default: '',
|
|
@@ -163,7 +138,7 @@ export default {
|
|
|
exam_answer: '',
|
|
|
ui_type: '',
|
|
|
category: '',
|
|
|
- file_relative_path: '',
|
|
|
+ fileUrl: '',
|
|
|
file_url_https: '',
|
|
|
pdfNum: 0,
|
|
|
pdfSrc: '',
|
|
@@ -201,7 +176,7 @@ export default {
|
|
|
if (!newVal) {
|
|
|
this.context = null;
|
|
|
this.exam_answer = '';
|
|
|
- this.file_relative_path = '';
|
|
|
+ this.fileUrl = '';
|
|
|
this.file_url_https = '';
|
|
|
this.pdfSrc = '';
|
|
|
this.numPages = 1;
|
|
@@ -324,21 +299,10 @@ export default {
|
|
|
},
|
|
|
|
|
|
getFileStoreInfo() {
|
|
|
- GetFileStoreInfo({ file_id: this.material_id }).then(({ file_relative_path, file_url_https }) => {
|
|
|
+ GetFileStoreInfo({ file_id: this.material_id }).then(({ file_url_https }) => {
|
|
|
this.category = 'file';
|
|
|
- this.file_relative_path = file_relative_path;
|
|
|
this.file_url_https = file_url_https;
|
|
|
- const fileType = file_url_https.slice(file_url_https.lastIndexOf('.') + 1, file_url_https.length);
|
|
|
- if (fileType === 'pdf') {
|
|
|
- this.getNumPages(file_relative_path);
|
|
|
- }
|
|
|
-
|
|
|
- if (fileType === 'txt') {
|
|
|
- fetch(`${process.env.VUE_APP_PDF}${file_relative_path}`).then(async res => {
|
|
|
- if (!res.ok) return;
|
|
|
- this.text = await res.text();
|
|
|
- });
|
|
|
- }
|
|
|
+ this.fileUrl = encodeURIComponent(encode(file_url_https));
|
|
|
});
|
|
|
},
|
|
|
|
|
@@ -362,36 +326,6 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- getNumPages(url) {
|
|
|
- const loading = this.$loading({ text: 'pdf 加载中...' });
|
|
|
- const loadingTask = pdf.createLoadingTask(`${process.env.VUE_APP_PDF}${url}`, {
|
|
|
- onProgress: ({ loaded, total }) => {
|
|
|
- const progress = loaded / total;
|
|
|
- if (progress < 1) return;
|
|
|
- if (Number.isInteger(loaded / 1024) && progress >= 1) {
|
|
|
- if (this.pdfNum === 0) {
|
|
|
- this.pdfNum += 1;
|
|
|
- }
|
|
|
- if (this.pdfNum === 1) {
|
|
|
- this.pdfNum = 0;
|
|
|
- loading.close();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- loadingTask.promise
|
|
|
- .then(pdf => {
|
|
|
- this.pdfSrc = loadingTask;
|
|
|
- this.numPages = pdf.numPages;
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.error('pdf加载失败', err);
|
|
|
- this.$message.error(this.$i18n.t('Key323'));
|
|
|
- this.pdfNum = 0;
|
|
|
- loading.close();
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
handleBookUserAnswer(data) {
|
|
|
this.exam_answer = data;
|
|
|
},
|
|
@@ -439,10 +373,6 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- isImage(type) {
|
|
|
- return ['jpeg', 'gif', 'jpg', 'png', 'bmp', 'pic', 'svg'].includes(type);
|
|
|
- },
|
|
|
-
|
|
|
/**
|
|
|
* 课件方法
|
|
|
*/
|