From 41467de512438090d2b94d7071a3ae007fe173a2 Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Thu, 28 Jan 2021 09:48:16 +0800 Subject: [PATCH] . --- src/layouts/navbar/index.vue | 2 +- src/libs/util.js | 14 +++++++++ src/main.js | 3 ++ src/mixins/file/index.js | 30 ++++++++++++------- src/pages/achievement/assessment/index.vue | 9 +++--- .../achievement/list/practiceResults.vue | 6 ++-- src/pages/achievement/practice/index.vue | 7 ++--- src/pages/exam/do/index.vue | 6 ++-- src/pages/index/list/index.vue | 12 ++++++-- src/pages/practice/list/myPractice.vue | 6 ++-- src/plugins/filters/index.js | 12 ++++++++ src/styles/pages/testPaperDetail.scss | 3 ++ 12 files changed, 80 insertions(+), 30 deletions(-) create mode 100644 src/plugins/filters/index.js diff --git a/src/layouts/navbar/index.vue b/src/layouts/navbar/index.vue index a73b53b..c0869dc 100644 --- a/src/layouts/navbar/index.vue +++ b/src/layouts/navbar/index.vue @@ -35,7 +35,7 @@ export default { { icon: 'el-icon-lx-copy', index: '/wrongBook/list', - title: '我的错题本' + title: '错题练习' }, { icon: 'el-icon-chat-dot-round', diff --git a/src/libs/util.js b/src/libs/util.js index 2943822..32458d7 100644 --- a/src/libs/util.js +++ b/src/libs/util.js @@ -89,6 +89,20 @@ const util = { getFileExt(fileName) { return fileName.substring(fileName.lastIndexOf('.') + 1) }, + // 传入文件名和路径,下载图片视频,支持跨域,a标签加download不支持跨域 + downloadFile(fileName,url) { + var x = new XMLHttpRequest() + x.open("GET", url, true) + x.responseType = 'blob' + x.onload=function(e) { + var url = window.URL.createObjectURL(x.response) + var a = document.createElement('a') + a.href = url + a.download = fileName + a.click() + } + x.send() + }, } export default util \ No newline at end of file diff --git a/src/main.js b/src/main.js index 8a5e331..5a63a36 100644 --- a/src/main.js +++ b/src/main.js @@ -16,9 +16,12 @@ import permission from '@/router/permission'; // 插件 import plugins from '@/plugins'; +import filters from '@/plugins/filters' Vue.use(plugins); +Object.keys(filters).forEach(item => Vue.filter(item,filters[item])) + Vue.prototype.api = api; Vue.prototype.$get = get; Vue.prototype.$post = post; diff --git a/src/mixins/file/index.js b/src/mixins/file/index.js index 29ff8f0..6132920 100644 --- a/src/mixins/file/index.js +++ b/src/mixins/file/index.js @@ -1,4 +1,5 @@ import util from '@/libs/util' +import { Loading } from 'element-ui' export default { data() { return { @@ -7,15 +8,16 @@ export default { iframeSrc: '', pdfVisible: false, pdfSrc: '', - imgName: '', - imgSrc: '' + isDownload: 0, + loadIns: null, } }, mounted() { this.insertScript() }, methods: { - preview(url,isVideo){ + preview(url,isVideo,isDownload){ + this.isDownload = isDownload let ext = util.getFileExt(url) if(isVideo){ this.$get(`${this.api.getPlayAuth}/${url}`).then(res => { @@ -63,14 +65,22 @@ export default { this.playAuth = '' this.player.pause() }, - download(fileName,url){ - let ext = util.getFileExt(url) - if(util.isImg(ext)){ - this.imgName = fileName - this.imgSrc = url - this.$refs.picLink.click() + download(fileName,url,isVideo){ + if(isVideo){ + this.loadIns = Loading.service() + this.preview(url,isVideo,1) + setTimeout(() => { + util.downloadFile(fileName,document.querySelector('#player video').src) + this.loadIns.close() + this.playAuth = '' + },1000) }else{ - window.open(url) + let ext = util.getFileExt(url) + if(util.isImg(ext)){ + util.downloadFile(fileName,url) + }else{ + window.open(url) + } } } } diff --git a/src/pages/achievement/assessment/index.vue b/src/pages/achievement/assessment/index.vue index 017518f..fe4deac 100644 --- a/src/pages/achievement/assessment/index.vue +++ b/src/pages/achievement/assessment/index.vue @@ -64,13 +64,13 @@ @@ -82,13 +82,14 @@ -
+
- 下载图片 + 下载 + 下载