175 lines
4.7 KiB
Vue
175 lines
4.7 KiB
Vue
<template>
|
|
<el-form :model="formData" ref="applyForm" label-width="auto" :rules="rules">
|
|
<el-row>
|
|
<el-col :span="24">
|
|
<el-form-item :label="label" prop="attachment">
|
|
<template v-if="preview">
|
|
<el-button type="primary" link @click="handleDownload(singleFile)" style="font-size: 18px">{{ singleFile?.originalFileName }}</el-button>
|
|
</template>
|
|
<template v-else>
|
|
<file-upload @getFile="getAttachment" :showFileList="showFileList" :maxSize="0" @delete="deleteAttachment"/>
|
|
</template>
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="24">
|
|
<el-form-item label="其他文件">
|
|
<el-card style="width: 100%">
|
|
<file-upload @getFile="getOtherFile"/>
|
|
<fvTable style="width: 100%;max-height: 250px;height: 250px" v-if="showTable" :tableConfig="tableConfig"
|
|
:data="allFileList" :isSettingCol="false" :pagination="false">
|
|
<template #empty>
|
|
<el-empty :image-size="90" description="暂无数据" style="padding: 0"/>
|
|
</template>
|
|
</fvTable>
|
|
</el-card>
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-row>
|
|
</el-form>
|
|
</template>
|
|
|
|
<script setup lang="jsx">
|
|
import FileUpload from '@/components/FileUpload.vue'
|
|
import {deleteFile, downloadFile} from "../api/project-demand";
|
|
import {ElMessage, ElMessageBox} from "element-plus";
|
|
|
|
const emit = defineEmits(["getAttachment", "getOtherFile"])
|
|
const formData = ref({})
|
|
const tableConfig = reactive({
|
|
columns: [
|
|
{
|
|
prop: 'index',
|
|
type: 'index',
|
|
label: '序号',
|
|
align: 'center',
|
|
width: '80',
|
|
},
|
|
{
|
|
prop: 'originalFileName',
|
|
label: '文件名',
|
|
align: 'center',
|
|
},
|
|
{
|
|
prop: 'tag',
|
|
label: '标签',
|
|
align: 'center'
|
|
},
|
|
{
|
|
prop: 'size',
|
|
label: '文件大小',
|
|
align: 'center',
|
|
currentRender: ({row, index}) => (parseInt(row.size / 1024) + 'KB')
|
|
},
|
|
// {
|
|
// prop: 'oper',
|
|
// label: '操作',
|
|
// align: 'center',
|
|
// showOverflowTooltip: false,
|
|
// currentRender: ({row, index}) => {
|
|
// return (
|
|
// <div>
|
|
// <el-button type="primary" link onClick={() => handleDownload(row)}>下载</el-button>
|
|
// <el-button type="primary" size="large" link onClick={() => deleteOtherFile(row)}>删除</el-button>
|
|
// </div>
|
|
// )
|
|
// }
|
|
// }
|
|
]
|
|
})
|
|
const rules = reactive({
|
|
attachment: [{required: true, message: '请上传附件', trigger: ['blur','change']}],
|
|
})
|
|
const applyForm=ref()
|
|
const singleFile=ref()
|
|
const allFileList=ref([])
|
|
const props = defineProps({
|
|
showFileList: {
|
|
type: Boolean,
|
|
default: false
|
|
}, label: {
|
|
type: String,
|
|
default: '项目附件'
|
|
}, showTable: {
|
|
type: Boolean,
|
|
default: true
|
|
}, preview: {
|
|
type: Boolean,
|
|
default: false
|
|
},otherFileList: {
|
|
type: Array,
|
|
default: []
|
|
},formData: {
|
|
type: Array,
|
|
default: []
|
|
}
|
|
})
|
|
watch(() => props.showTable, (newVal) => {
|
|
props.showTable = newVal
|
|
}, {deep: true})
|
|
watch(() => props.otherFileList, (newVal) => {
|
|
newVal.forEach(item=>{
|
|
allFileList.value.push(item)
|
|
})
|
|
}, {deep: true})
|
|
watch(() => props.formData.fileList, (newVal) => {
|
|
newVal.forEach(item=>{
|
|
allFileList.value.push(item)
|
|
})
|
|
}, {deep: true})
|
|
watch(() => props.formData.singleFile, (newVal) => {
|
|
singleFile.value = newVal
|
|
}, {deep: true})
|
|
const getAttachment = (val) => {
|
|
emit('getAttachment', val)
|
|
}
|
|
const getOtherFile = (val) => {
|
|
emit('getOtherFile', val)
|
|
}
|
|
const deleteAttachment = (val) => {
|
|
deleteFile(val).then(res => {
|
|
if (res.code === 1000) {
|
|
ElMessage.success("删除成功");
|
|
}
|
|
});
|
|
}
|
|
const deleteOtherFile = (row) => {
|
|
ElMessageBox.confirm(`确认删除名称为${row.originalFileName}的表格吗?`, '系统提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
}).then(() => {
|
|
deleteFile(row.fileId).then(res => {
|
|
if (res.code === 1000) {
|
|
ElMessage.success("删除成功");
|
|
props.otherFileList.splice(props.otherFileList.findIndex((item) => item.id === row.fileId), 1);
|
|
}
|
|
});
|
|
}).catch(() => {
|
|
ElMessage.warning("用户取消删除! ");
|
|
})
|
|
}
|
|
const handleDownload = (row) => {
|
|
downloadFile(row.fileId).then(res => {
|
|
const blob = new Blob([res])
|
|
let a = document.createElement('a')
|
|
a.href = URL.createObjectURL(blob)
|
|
a.download = row.originalFileName
|
|
a.click()
|
|
})
|
|
}
|
|
defineExpose({
|
|
validate(){
|
|
return applyForm.value.validate()
|
|
},
|
|
clearValidate(){
|
|
return applyForm.value.clearValidate()
|
|
},
|
|
allFileList,
|
|
singleFile
|
|
})
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
</style>
|