123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <template>
- <el-dialog
- class="cur-material"
- :visible="dialogVisibleMaterial"
- width="900px"
- title="当前推送课件"
- @close="dialogMaterialClose"
- >
- <div class="material-name">{{ materialName }}</div>
- <template v-if="materialType === 'COURSEWARE'">
- <question :context="context" />
- </template>
- <template v-else>
- <template v-if="fileType === 'pdf'">
- <pdf v-for="i in numPages" :key="i" :src="pdfSrc" :page="i"></pdf>
- </template>
- <template v-else-if="isImage(fileType)">
- <el-image fit="contain" :src="file_url_https" />
- </template>
- <template v-if="fileType !== 'pdf'">
- <iframe
- :src="'https://view.officeapps.live.com/op/view.aspx?src=' + `${file_url_https}`"
- width="100%"
- height="490px"
- scrolling="no"
- >
- </iframe>
- </template>
- </template>
- <div slot="footer">
- <el-button type="primary" @click="finishMyMaterial">完成</el-button>
- </div>
- </el-dialog>
- </template>
- <script>
- import pdf from 'vue-pdf';
- import { GetCoursewareContent_View } from '@/api/course';
- import { GetFileStoreInfo } from '@/api/app';
- import { FinishMyMaterial } from '@/api/live';
- export default {
- components: {
- pdf
- },
- props: {
- dialogVisibleMaterial: {
- default: false,
- type: Boolean
- },
- taskId: {
- default: '',
- type: String
- },
- materialId: {
- default: '',
- type: String
- },
- materialName: {
- default: '',
- type: String
- },
- materialType: {
- default: '',
- type: String
- },
- materialPictureUrl: {
- default: '',
- type: String
- }
- },
- data() {
- return {
- context: null,
- file_relative_path: '',
- file_url_https: '',
- pdfSrc: '',
- numPages: 1
- };
- },
- computed: {
- fileType() {
- return this.file_url_https.slice(
- this.file_url_https.lastIndexOf('.') + 1,
- this.file_url_https.length
- );
- }
- },
- watch: {
- materialId() {
- if (this.materialType === 'COURSEWARE') {
- this.getCoursewareContent_View();
- } else {
- this.getFileStoreInfo();
- }
- }
- },
- methods: {
- dialogMaterialClose() {
- this.$emit('dialogMaterialClose');
- },
- getCoursewareContent_View() {
- GetCoursewareContent_View({ id: this.materialId }).then(res => {
- if (res.content) {
- this.context = {
- id: this.currentCourse,
- ui_type: JSON.parse(res.content).question.ui_type,
- sort_number: 1,
- content: JSON.parse(res.content)
- };
- } else {
- this.context = null;
- }
- });
- },
- getFileStoreInfo() {
- GetFileStoreInfo({ file_id: this.materialId }).then(
- ({ file_relative_path, file_url_https }) => {
- this.file_relative_path = file_relative_path;
- this.file_url_https = file_url_https;
- let fileType = file_url_https.slice(
- file_url_https.lastIndexOf('.') + 1,
- file_url_https.length
- );
- if (fileType === 'pdf') {
- this.getNumPages(file_url_https);
- }
- }
- );
- },
- getNumPages(url) {
- let loadingTask = pdf.createLoadingTask(url);
- loadingTask.promise
- .then(pdf => {
- this.pdfSrc = loadingTask;
- this.numPages = pdf.numPages;
- })
- .catch(err => {
- console.error('pdf加载失败', err);
- this.$message.error('pdf加载失败');
- });
- },
- finishMyMaterial() {
- FinishMyMaterial({
- task_id: this.taskId,
- material_id: this.materialId,
- material_type: this.materialType
- }).then(() => {
- this.$message.success('完成推送资料成功');
- this.$emit('dialogMaterialClose');
- });
- },
- isImage(type) {
- return ['jpeg', 'gif', 'jpg', 'png', 'bmp', 'pic', 'svg'].includes(type);
- }
- }
- };
- </script>
- <style lang="scss">
- @import '~@/styles/mixin.scss';
- .cur-material {
- @include dialog;
- .material-name {
- font-size: 16px;
- font-weight: 700;
- color: #000;
- margin-bottom: 16px;
- }
- }
- </style>
|