Commit bd2440c7 by qiyeqing

会话下载文件

1 parent 2069bb0f
...@@ -98,8 +98,8 @@ ...@@ -98,8 +98,8 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="action" label="操作"> <el-table-column prop="action" label="操作">
<template > <template slot-scope="scope">
<el-button type="text" size="small">下载</el-button> <el-button type="text" size="small" @click="downloadFile(scope.row)">下载</el-button>
<el-button type="text" size="small">查看</el-button> <el-button type="text" size="small">查看</el-button>
</template> </template>
</el-table-column> </el-table-column>
...@@ -150,7 +150,7 @@ ...@@ -150,7 +150,7 @@
content content
} from '@/api/content.js' } from '@/api/content.js'
import { import {
yearMouthDay yearMouthDay,download
} from '@/utils/common.js' } from '@/utils/common.js'
export default { export default {
components: { components: {
...@@ -197,6 +197,16 @@ ...@@ -197,6 +197,16 @@
this.getTree() this.getTree()
}, },
methods: { methods: {
downloadFile(e){
const url = window.URL.createObjectURL(new Blob([e.file.attachment],{type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'}))
const link = document.createElement('a')
link.href = url
link.setAttribute('download',e.file.filename) // 下载文件的名称及文件类型后缀
document.body.appendChild(link)
link.click()
document.body.removeChild(link); // 下载完成移除元素
window.URL.revokeObjectURL(url); // 释放掉blob对象
},
filterSize(size) { filterSize(size) {
if (!size) return ''; if (!size) return '';
if (size < this.pow1024(1)) return size + ' B'; if (size < this.pow1024(1)) return size + ' B';
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!