123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- <template>
- <el-dialog
- :class="['cur-material', { 'align-left': !isAlignCenter }]"
- :visible="dialogVisibleMaterial"
- :modal="false"
- width="900px"
- @close="dialogMaterialClose"
- >
- <div slot="title" class="dialog-header">
- <span class="dialog-header-title">当前推送资料</span>
- <span @click="isAlignCenter = !isAlignCenter">
- <svg-icon :icon-class="isAlignCenter ? 'align-left' : 'align-center'" />
- </span>
- </div>
- <div class="material-name">{{ materialName }}</div>
- <template v-if="materialType === 'COURSEWARE'">
- <bookquestion
- ref="courseware"
- :context="context"
- @handleBookUserAnswer="handleBookUserAnswer"
- />
- </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>
- <template v-else>
- <iframe
- :src="'https://view.officeapps.live.com/op/view.aspx?src=' + `${file_url_https}`"
- width="100%"
- height="490px"
- scrolling="no"
- />
- </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, getContentFile } from '@/api/app';
- import { FinishMyMaterial } from '@/api/live';
- import { getToken } from '@/utils/auth';
- 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,
- exam_answer: '',
- file_relative_path: '',
- file_url_https: '',
- pdfSrc: '',
- numPages: 1,
- isAlignCenter: true
- };
- },
- computed: {
- fileType() {
- return this.file_url_https.slice(
- this.file_url_https.lastIndexOf('.') + 1,
- this.file_url_https.length
- );
- }
- },
- watch: {
- dialogVisibleMaterial(newVal) {
- if (!newVal) {
- this.context = null;
- this.exam_answer = '';
- this.file_relative_path = '';
- this.file_url_https = '';
- this.pdfSrc = '';
- this.numPages = 1;
- }
- },
- materialId() {
- if (this.materialType === 'COURSEWARE') {
- this.getCoursewareContent_View();
- } else {
- this.getFileStoreInfo();
- }
- }
- },
- created() {
- this.uploadBookWriteParent();
- },
- methods: {
- dialogMaterialClose() {
- this.$emit('dialogMaterialClose');
- },
- getCoursewareContent_View() {
- GetCoursewareContent_View({ id: this.materialId }).then(({ content }) => {
- if (content) {
- this.context = {
- id: this.materialId,
- ui_type: JSON.parse(content).question.ui_type,
- content: JSON.parse(content)
- };
- this.$nextTick(() => {
- this.$refs.courseware.handleAnswerTimeStart();
- });
- } 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加载失败');
- });
- },
- handleBookUserAnswer(data) {
- this.exam_answer = data;
- },
- finishMyMaterial() {
- if (this.materialType === 'COURSEWARE' && this.exam_answer.length === 0) {
- this.$message.warning('请完成课件');
- return;
- }
- const loading = this.$loading();
- FinishMyMaterial({
- task_id: this.taskId,
- material_id: this.materialId,
- material_type: this.materialType,
- exam_answer: this.exam_answer
- })
- .then(() => {
- this.$message.success('完成推送资料成功');
- this.$emit('dialogMaterialClose');
- })
- .finally(() => {
- loading.close();
- this.exam_answer = '';
- });
- },
- isImage(type) {
- return ['jpeg', 'gif', 'jpg', 'png', 'bmp', 'pic', 'svg'].includes(type);
- },
- /**
- * 课件方法
- */
- // 上传文件
- uploadBookWriteParent() {
- const { token, isHas } = getToken();
- let UserCode = isHas ? token.user_code : '';
- let UserType = isHas ? token.user_type : '';
- let SessionID = isHas ? token.session_id : '';
- this.bookuploadUrl = `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&SecurityLevel=Mid`;
- },
- // 下载文件zip
- downloadBookWriteParent(idList) {
- let MethodName = 'file_store_manager-StartCreateFileCompressPack';
- let data = {
- file_id_list: JSON.parse(idList)
- };
- getContentFile(MethodName, data).then(res => {
- let id = res.file_compress_task_id;
- this.bookDownTimer = setInterval(() => {
- this.checkTaskProgress(id);
- }, 2000);
- });
- },
- // 成功后调用打包进度
- checkTaskProgress(taskId) {
- const { token, isHas } = getToken();
- let UserCode = isHas ? token.user_code : '';
- let UserType = isHas ? token.user_type : '';
- let SessionID = isHas ? token.session_id : '';
- let MethodName = 'file_store_manager-GetFileCompressTaskProgress';
- let data = {
- file_compress_task_id: taskId
- };
- getContentFile(MethodName, data).then(res => {
- if (res.is_finish === 'true') {
- clearInterval(this.bookDownTimer);
- window.open(
- `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileDownload?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&FileID=${res.compress_pack_file_id}`
- );
- }
- });
- }
- }
- };
- </script>
- <style lang="scss">
- @import '~@/styles/mixin.scss';
- .cur-material {
- @include dialog;
- &.align-left {
- .el-dialog {
- margin-left: 20px;
- }
- }
- .el-dialog__header {
- .dialog-header {
- display: flex;
- justify-content: space-between;
- padding-right: 24px;
- &-title {
- font-weight: bold;
- font-size: 18px;
- line-height: 24px;
- }
- .svg-icon {
- cursor: pointer;
- }
- }
- }
- .material-name {
- font-size: 16px;
- font-weight: 700;
- color: #000;
- margin-bottom: 16px;
- }
- }
- </style>
|