<template>
|
<div>
|
<div style="margin-bottom: 10px">
|
<el-upload ref='upload' :action="fileAction" :auto-upload="true" :before-upload="fileBeforeUpload"
|
:data="{ id: currentId }" :headers="uploadHeader" :on-error="onError" :on-success="handleSuccessUp"
|
:show-file-list="false" accept='.jpg,.jpeg,.png,.gif,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.zip,.rar'
|
style="width: 80px !important;">
|
<el-button size="small" style="height: 38px" type="primary">附件上传</el-button>
|
</el-upload>
|
</div>
|
<lims-table :tableData="tableDataFile" :column="columnFile" height="500px" key="tableDataFile"
|
:tableLoading="tableLoadingFile"></lims-table>
|
<el-dialog title="查看附件" :visible.sync="lookDialogVisible" width="800px" top="5vh" fullscreen append-to-body>
|
<filePreview v-if="lookDialogVisible" :fileUrl="javaApi + '/word/' + currentInfo.fileUrl" :currentFile="{}"
|
style="max-height: 90vh;overflow-y: auto;" />
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import limsTable from "@/components/Table/lims-table.vue";
|
import { fileList, delFile } from "@/api/structural/workshop.js"
|
import filePreview from "@/components/Preview/filePreview.vue";
|
export default {
|
components: {
|
limsTable,
|
filePreview,
|
},
|
props: ['currentId'],
|
computed: {
|
fileAction() {
|
return this.javaApi + '/workShop/uploadFile'
|
},
|
},
|
data() {
|
return {
|
columnFile: [
|
{
|
dataType: 'tag',
|
label: '类型',
|
prop: 'type',
|
formatData: (params) => {
|
if (params == 1) {
|
return '图片'
|
} else if (params == 2) {
|
return '文件'
|
} else {
|
return ''
|
}
|
},
|
formatType: (params) => {
|
if (params == 1) {
|
return 'success'
|
} else if (params == 2) {
|
return 'warning'
|
} else {
|
return ''
|
}
|
}
|
},
|
{ label: '附件名称', prop: 'fileName' },
|
{ label: '上传人', prop: 'name' },
|
{ label: '上传时间', prop: 'createTime' },
|
{
|
dataType: 'action',
|
fixed: 'right',
|
label: '操作',
|
width: '170px',
|
operation: [
|
{
|
name: '下载',
|
type: 'text',
|
clickFun: (row) => {
|
this.handleDown(row);
|
}
|
},
|
{
|
name: '删除',
|
type: 'text',
|
clickFun: (row) => {
|
this.delete(row);
|
}
|
},
|
{
|
name: '预览',
|
type: 'text',
|
clickFun: (row) => {
|
this.currentInfo = row
|
this.lookDialogVisible = true
|
}
|
},
|
]
|
}
|
],
|
tableDataFile: [],
|
tableLoadingFile: false,
|
lookDialogVisible: false,
|
currentInfo: {},
|
}
|
},
|
mounted() {
|
this.getFileList()
|
},
|
methods: {
|
// 查询附件查看列表回调
|
getFileList() {
|
this.tableLoadingFile = true
|
fileList({ id: this.currentId }).then(res => {
|
this.tableLoadingFile = false
|
if (res.code === 200) {
|
this.tableDataFile = res.data
|
}
|
}).catch(err => {
|
this.tableLoadingFile = false
|
})
|
},
|
fileBeforeUpload(file) {
|
let flag = true
|
console.log('file----', file)
|
if (file.size > 1024 * 1024 * 10) {
|
this.$message.error('上传文件不超过10M');
|
this.$refs.upload.clearFiles()
|
flag = false
|
}
|
if (!flag) {
|
return Promise.reject(flag); //正确的终止
|
}
|
},
|
handleSuccessUp(response,) {
|
this.upLoading = false;
|
if (response.code == 200) {
|
this.$message.success('上传成功');
|
this.getFileList()
|
}
|
},
|
// 下载附件的文件
|
handleDown(row) {
|
this.$download.saveAs(row.fileUrl, row.fileName);
|
},
|
// 删除附件文件
|
delete(row) {
|
this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning'
|
}).then(() => {
|
this.tableLoadingFile = true
|
delFile({ id: row.id }).then(res => {
|
this.tableLoadingFile = false
|
this.$message.success('删除成功')
|
this.getFileList()
|
}).catch(err => {
|
this.tableLoadingFile = false
|
console.log('err---', err);
|
})
|
}).catch(() => {
|
this.$message({
|
type: 'info',
|
message: '已取消删除'
|
});
|
})
|
},
|
onError(err, file, fileList, type) {
|
this.$message.error('上传失败')
|
this.$refs.upload.clearFiles()
|
},
|
}
|
}
|
</script>
|
|
<style scoped></style>
|