214 lines
5.7 KiB
Vue
214 lines
5.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&&JSON.stringify(singleFile) !== '{}'&&JSON.stringify(singleFile)!=='null'">
|
|
<el-button type="primary" link @click="handleDownload(singleFile)" style="font-size: 18px">
|
|
{{ singleFile?.originalFileName }}
|
|
</el-button>
|
|
<el-button type="danger" link @click="deleteOtherFile(singleFile,1)">删除</el-button>
|
|
</template>
|
|
<template v-else-if="!preview||JSON.stringify(singleFile) === '{}'||singleFile==null">
|
|
<file-upload @getFile="getAttachment" :showFileList="showFileList" :multiple="false" :maxSize="1" :disabled="isSingleFile" @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: 300px;" 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, ElNotification} 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>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
// <el-button type="primary" size="large" link onClick={() => deleteOtherFile(row)}>删除</el-button>
|
|
]
|
|
})
|
|
const rules = reactive({
|
|
attachment: [{required: true, message: '请上传附件', trigger: ['blur', 'change']}],
|
|
})
|
|
const applyForm = ref()
|
|
const singleFile = ref()
|
|
const isSingleFile = ref(false)
|
|
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) => {
|
|
console.log('newotherFileList',newVal)
|
|
if (props.preview) {
|
|
if(props.formData.fileList==null){
|
|
allFileList.value=newVal
|
|
}else {
|
|
newVal?.forEach(item => {
|
|
allFileList.value.push(item)
|
|
})
|
|
}
|
|
|
|
}else {
|
|
allFileList.value=newVal
|
|
}
|
|
}, {deep: true})
|
|
watch(() => props.formData.fileList, (newVal) => {
|
|
console.log('newVal-fileList',newVal)
|
|
if (props.preview) {
|
|
newVal?.forEach(item => {
|
|
allFileList.value.push(item)
|
|
})
|
|
}
|
|
}, {deep: true})
|
|
watch(() => props.formData.singleFile, (newVal) => {
|
|
console.log('singleFile',newVal)
|
|
singleFile.value = newVal
|
|
}, {deep: true})
|
|
const getAttachment = (val) => {
|
|
isSingleFile.value=true
|
|
emit('getAttachment', val)
|
|
}
|
|
const getOtherFile = (val) => {
|
|
emit('getOtherFile', val)
|
|
}
|
|
const deleteAttachment = (val) => {
|
|
deleteFile(val).then(res => {
|
|
if (res.code === 1000) {
|
|
ElNotification({
|
|
title: '提示',
|
|
message:"删除成功",
|
|
type:'success'
|
|
})
|
|
isSingleFile.value=false
|
|
}
|
|
});
|
|
}
|
|
const deleteOtherFile = (row, type) => {
|
|
ElMessageBox.confirm(`确认删除名称为${row.originalFileName}的表格吗?`, '系统提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
}).then(() => {
|
|
deleteFile(row.fileId).then(res => {
|
|
ElNotification({
|
|
title: '提示',
|
|
message: res.msg,
|
|
type: res.code === 1000 ? 'success' : 'error'
|
|
})
|
|
if (res.code === 1000) {
|
|
if (type === 1) {
|
|
singleFile.value = {}
|
|
} else {
|
|
props.otherFileList.splice(props.otherFileList.findIndex((item) => item.id === row.fileId), 1);
|
|
}
|
|
}
|
|
});
|
|
}).catch(() => {
|
|
ElNotification({
|
|
title: '提示',
|
|
message: "用户取消删除! ",
|
|
type: '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>
|
|
:deep(.el-table--fit ){
|
|
height: 300px!important;
|
|
}
|
|
</style>
|