|
|
|
|
@ -25,8 +25,10 @@ |
|
|
|
|
<span>{{ formatISOTime(scope.row.uploadTime) }}</span> |
|
|
|
|
</template> |
|
|
|
|
</el-table-column> |
|
|
|
|
<el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width"> |
|
|
|
|
<el-table-column label="操作" align="center" width="240" class-name="small-padding fixed-width"> |
|
|
|
|
<template slot-scope="scope" v-if="scope.row.id !== 1"> |
|
|
|
|
<el-button size="mini" type="text" icon="el-icon-view" @click="previewFile(scope.row)" v-hasPermi="['QandA:knowledge:preview']">预览</el-button> |
|
|
|
|
<el-button size="mini" type="text" icon="el-icon-download" @click="downloadFile(scope.row)" v-hasPermi="['QandA:knowledge:filedownload']">下载</el-button> |
|
|
|
|
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['QandA:knowledge:update']">修改</el-button> |
|
|
|
|
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['QandA:knowledge:del']">删除</el-button> |
|
|
|
|
</template> |
|
|
|
|
@ -80,7 +82,7 @@ |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
import { list, del, add, update, permanentKnowledgeList, uploadedFilesList } from "@/api/QandA/knowledge" |
|
|
|
|
import { list, del, add, update, permanentKnowledgeList, uploadedFilesList, downloadFile } from "@/api/QandA/knowledge" |
|
|
|
|
import { getToken } from "@/utils/auth" |
|
|
|
|
import Treeselect from "@riophae/vue-treeselect" |
|
|
|
|
import "@riophae/vue-treeselect/dist/vue-treeselect.css" |
|
|
|
|
@ -378,6 +380,62 @@ export default { |
|
|
|
|
// 提交上传文件 |
|
|
|
|
submitFileForm() { |
|
|
|
|
this.$refs.upload.submit() |
|
|
|
|
}, |
|
|
|
|
// 预览文件 |
|
|
|
|
previewFile(row) { |
|
|
|
|
// 构建完整的文件路径 |
|
|
|
|
const filePath = this.appBase + row.filePath; |
|
|
|
|
|
|
|
|
|
// 根据文件格式进行不同处理 |
|
|
|
|
if (row.format === 'txt') { |
|
|
|
|
// 对于txt文件,可以通过新窗口打开直接预览 |
|
|
|
|
window.open(filePath, '_blank'); |
|
|
|
|
} else if (row.format === 'docx') { |
|
|
|
|
// 对于docx文件,可以使用在线预览服务或通过新窗口打开 |
|
|
|
|
// 这里使用新窗口打开的方式 |
|
|
|
|
window.open(filePath, '_blank'); |
|
|
|
|
// 也可以使用在线预览服务,例如: |
|
|
|
|
// const previewUrl = `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(filePath)}`; |
|
|
|
|
// window.open(previewUrl, '_blank'); |
|
|
|
|
} else { |
|
|
|
|
// 其他文件格式的处理 |
|
|
|
|
this.$message.info('暂不支持此文件格式的预览'); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 下载文件 |
|
|
|
|
downloadFile(row) { |
|
|
|
|
// 使用导入的API函数进行文件下载 |
|
|
|
|
downloadFile(row.id).then(response => { |
|
|
|
|
// 获取文件名,如果响应头中没有则使用row.source |
|
|
|
|
let fileName = row.source; |
|
|
|
|
const contentDisposition = response.headers['content-disposition']; |
|
|
|
|
if (contentDisposition && contentDisposition.indexOf('filename=') !== -1) { |
|
|
|
|
fileName = decodeURIComponent(contentDisposition.split('filename=')[1]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 创建Blob对象 |
|
|
|
|
const blob = new Blob([response.data]); |
|
|
|
|
|
|
|
|
|
// 创建下载链接 |
|
|
|
|
const link = document.createElement('a'); |
|
|
|
|
link.href = URL.createObjectURL(blob); |
|
|
|
|
link.download = fileName; |
|
|
|
|
link.style.display = 'none'; |
|
|
|
|
|
|
|
|
|
// 添加到DOM并触发下载 |
|
|
|
|
document.body.appendChild(link); |
|
|
|
|
link.click(); |
|
|
|
|
|
|
|
|
|
// 清理 |
|
|
|
|
document.body.removeChild(link); |
|
|
|
|
URL.revokeObjectURL(link.href); // 释放URL对象 |
|
|
|
|
|
|
|
|
|
// 显示下载成功提示 |
|
|
|
|
this.$message.success('文件下载成功'); |
|
|
|
|
}).catch(error => { |
|
|
|
|
console.error('文件下载失败:', error); |
|
|
|
|
this.$message.error('文件下载失败,请重试'); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|