|
@@ -96,7 +96,7 @@
|
|
|
width="180px"
|
|
|
/>
|
|
|
|
|
|
- <el-table-column label="操作" align="center" width="150px">
|
|
|
+ <el-table-column label="操作" align="center" width="200px">
|
|
|
<template slot-scope="scope">
|
|
|
<el-link
|
|
|
type="primary"
|
|
@@ -105,6 +105,13 @@
|
|
|
@click="handlePreview(scope.row)"
|
|
|
>在线预览</el-link
|
|
|
>
|
|
|
+ <el-link
|
|
|
+ type="primary"
|
|
|
+ icon="el-icon-download"
|
|
|
+ style="margin-left: 10px"
|
|
|
+ @click="handleDownload(scope.row)"
|
|
|
+ >课件下载</el-link
|
|
|
+ >
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</template>
|
|
@@ -224,6 +231,8 @@ import DetailLink from "@/components/DetailLink";
|
|
|
import VideoPlayer from "@/components/VideoPlayer";
|
|
|
import PdfReader from "@/components/PdfReader";
|
|
|
import SecFormat from "@/components/SecFormat";
|
|
|
+import axios from 'axios'
|
|
|
+axios.defaults.withCredentials = true
|
|
|
|
|
|
export default {
|
|
|
name: "CourseFileList",
|
|
@@ -395,6 +404,38 @@ export default {
|
|
|
this.previewData.viewUrl = data.viewUrl;
|
|
|
this.previewData.fileUrl = data.fileUrl;
|
|
|
},
|
|
|
+ handleDownload(data){
|
|
|
+ if(data.fileUrl.includes('pdf') || data.fileUrl.includes('mp4')){
|
|
|
+ this.handlePdfLink(data.fileUrl, data.fileUrl.substring(data.fileUrl.lastIndexOf('/')+1))
|
|
|
+ }else{
|
|
|
+ const a = document.createElement('a')
|
|
|
+ a.target="_blank"
|
|
|
+ a.href = data.fileUrl
|
|
|
+ a.download = ''
|
|
|
+ a.click()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handlePdfLink(url, filename){
|
|
|
+ axios.get(url, {
|
|
|
+ responseType: 'blob',
|
|
|
+ })
|
|
|
+ .then((res) => {
|
|
|
+ // 生成 Blob 对象,设置 type 等信息
|
|
|
+ const e = new Blob([res.data], {
|
|
|
+ type: 'application/octet-stream',
|
|
|
+ 'Content-Disposition':'attachment'
|
|
|
+ })
|
|
|
+ // 将 Blob 对象转为 url
|
|
|
+ const link = window.URL.createObjectURL(e)
|
|
|
+ const a = document.createElement('a')
|
|
|
+ a.target="_blank"
|
|
|
+ a.href = link
|
|
|
+ a.download = filename
|
|
|
+ a.click()
|
|
|
+ }).catch(err => {
|
|
|
+ console.error(err)
|
|
|
+ })
|
|
|
+ },
|
|
|
|
|
|
closePreview() {
|
|
|
this.previewData = {};
|