fix : 修复需求上报文件上传/删除问题

This commit is contained in:
2024-06-07 16:46:44 +08:00
parent 9655c41492
commit 42fea1853d
4 changed files with 98 additions and 98 deletions

View File

@@ -37,6 +37,32 @@ import FileUpload from '@/components/FileUpload.vue'
import {deleteFile, downloadFile} from "@/api/project-demand";
import {ElMessage, ElMessageBox, ElNotification} from "element-plus";
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: []
}
})
const emit = defineEmits(["getAttachment", "getOtherFile"])
const formData = ref({})
const tableConfig = reactive({
@@ -72,9 +98,9 @@ const tableConfig = reactive({
currentRender: ({row, index}) => {
let btn = []
btn.push({label: '下载', func: () => handleDownload(row), type: 'primary'})
if (row.newFile){
btn.push({label: '删除', func: () => handleDelete(row), type: 'primary'})
}
// if (row.newFile){
// btn.push({label: '删除', func: () => handleDelete(row), type: 'primary'})
// }
return (
<div style={{width: '100%'}}>
{
@@ -88,6 +114,12 @@ const tableConfig = reactive({
</el-button>
))
}
{
row.newFile||props.preview ? <popover-delete name={row.originalFileName} type={'文件'} btnType={'danger'}
perm={['mosr:requirement:del']}
onDelete={() => handleDelete(row)}/>
: ''
}
</div>
)
}
@@ -101,39 +133,13 @@ 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.length===0) {
if (props.formData.fileList===null||props.formData.fileList.length===0) {
allFileList.value = newVal
} else {
newVal?.forEach(item => {
@@ -156,6 +162,21 @@ watch(() => props.formData.singleFile, (newVal) => {
console.log('singleFile', newVal)
singleFile.value = newVal
}, {deep: true})
watch(() => isSingleFile.value, (newVal) => {
isSingleFile.value = newVal
}, {deep: true})
const handleDelete = (row) => {
deleteFile(row.fileId).then(res => {
ElNotification({
title: '提示',
message: res.msg,
type: res.code === 1000 ? 'success' : 'error'
})
if (res.code === 1000) {
allFileList.value.splice(allFileList.value.findIndex((item) => item.id === row.fileId), 1);
}
});
}
const getAttachment = (val) => {
isSingleFile.value = true
emit('getAttachment', val)
@@ -172,6 +193,7 @@ const deleteAttachment = (val) => {
type: 'success'
})
isSingleFile.value = false
singleFile.value={}
}
});
}
@@ -221,7 +243,8 @@ defineExpose({
return applyForm.value.clearValidate()
},
allFileList,
singleFile
singleFile,
isSingleFile
})
</script>

View File

@@ -12,7 +12,7 @@
<script setup lang="jsx">
import {downloadFile, deleteFile} from "@/api/project-demand";
import {ElMessageBox, ElNotification} from "element-plus";
import {ElNotification} from "element-plus";
const props = defineProps({
title: {
@@ -70,9 +70,9 @@ const tableConfig = reactive({
currentRender: ({row, index}) => {
let btn = []
btn.push({label: '下载', func: () => handleDownload(row), type: 'primary'})
if (row.newFile) {
btn.push({label: '删除', func: () => handleDelete(row), type: 'primary'})
}
// if (row.newFile) {
// btn.push({label: '删除', func: () => handleDelete(row), type: 'primary'})
// }
return (
<div style={{width: '100%'}}>
{
@@ -85,6 +85,12 @@ const tableConfig = reactive({
</el-button>
))
}
{
row.newFile ? <popover-delete name={row.originalFileName} type={'文件'} btnType={'danger'}
perm={['mosr:requirement:del']}
onDelete={() => handleDelete(row)}/>
: ''
}
</div>
)
}
@@ -132,28 +138,16 @@ const handleDownload = (row) => {
})
}
const handleDelete = (row) => {
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) {
_value.value.splice(_value.value.findIndex((item) => item.id === row.fileId), 1);
}
});
}).catch(() => {
deleteFile(row.fileId).then(res => {
ElNotification({
title: '提示',
message: '用户取消删除! ',
type: 'warning'
message: res.msg,
type: res.code === 1000 ? 'success' : 'error'
})
})
if (res.code === 1000) {
_value.value.splice(_value.value.findIndex((item) => item.id === row.fileId), 1);
}
});
}
watch(() => props.processViewer, (newVal) => {