Merge pull request 'fix : 修复需求上报文件上传/删除问题' (#298) from dj into master

Reviewed-on: http://git.feashow.cn/clay/mosr-web/pulls/298
This commit is contained in:
2024-06-07 08:46:59 +00:00
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 {deleteFile, downloadFile} from "@/api/project-demand";
import {ElMessage, ElMessageBox, ElNotification} from "element-plus"; 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 emit = defineEmits(["getAttachment", "getOtherFile"])
const formData = ref({}) const formData = ref({})
const tableConfig = reactive({ const tableConfig = reactive({
@@ -72,9 +98,9 @@ const tableConfig = reactive({
currentRender: ({row, index}) => { currentRender: ({row, index}) => {
let btn = [] let btn = []
btn.push({label: '下载', func: () => handleDownload(row), type: 'primary'}) btn.push({label: '下载', func: () => handleDownload(row), type: 'primary'})
if (row.newFile){ // if (row.newFile){
btn.push({label: '删除', func: () => handleDelete(row), type: 'primary'}) // btn.push({label: '删除', func: () => handleDelete(row), type: 'primary'})
} // }
return ( return (
<div style={{width: '100%'}}> <div style={{width: '100%'}}>
{ {
@@ -88,6 +114,12 @@ const tableConfig = reactive({
</el-button> </el-button>
)) ))
} }
{
row.newFile||props.preview ? <popover-delete name={row.originalFileName} type={'文件'} btnType={'danger'}
perm={['mosr:requirement:del']}
onDelete={() => handleDelete(row)}/>
: ''
}
</div> </div>
) )
} }
@@ -101,39 +133,13 @@ const applyForm = ref()
const singleFile = ref() const singleFile = ref()
const isSingleFile = ref(false) const isSingleFile = ref(false)
const allFileList = 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) => { watch(() => props.showTable, (newVal) => {
props.showTable = newVal props.showTable = newVal
}, {deep: true}) }, {deep: true})
watch(() => props.otherFileList, (newVal) => { watch(() => props.otherFileList, (newVal) => {
console.log('newotherFileList', newVal) console.log('newotherFileList', newVal)
if (props.preview) { if (props.preview) {
if (props.formData.fileList.length===0) { if (props.formData.fileList===null||props.formData.fileList.length===0) {
allFileList.value = newVal allFileList.value = newVal
} else { } else {
newVal?.forEach(item => { newVal?.forEach(item => {
@@ -156,6 +162,21 @@ watch(() => props.formData.singleFile, (newVal) => {
console.log('singleFile', newVal) console.log('singleFile', newVal)
singleFile.value = newVal singleFile.value = newVal
}, {deep: true}) }, {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) => { const getAttachment = (val) => {
isSingleFile.value = true isSingleFile.value = true
emit('getAttachment', val) emit('getAttachment', val)
@@ -172,6 +193,7 @@ const deleteAttachment = (val) => {
type: 'success' type: 'success'
}) })
isSingleFile.value = false isSingleFile.value = false
singleFile.value={}
} }
}); });
} }
@@ -221,7 +243,8 @@ defineExpose({
return applyForm.value.clearValidate() return applyForm.value.clearValidate()
}, },
allFileList, allFileList,
singleFile singleFile,
isSingleFile
}) })
</script> </script>

View File

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

View File

@@ -16,8 +16,8 @@
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="6" v-if="route.query.id&&formData.specialFund"> <el-col :span="6">
<el-form-item label="专项资金" prop="specialFundId" > <el-form-item label="专项资金" prop="specialFundId" v-if="route.query.id&&formData.specialFund">
<span>{{ formData.specialFund }}</span> <span>{{ formData.specialFund }}</span>
</el-form-item> </el-form-item>
</el-col> </el-col>
@@ -214,10 +214,12 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="其中申请公司总部科技创新专项资金(元)" prop="specialFundAmount" v-if="!route.query.id&&formData.isSpecialFund"> <el-form-item label="其中申请公司总部科技创新专项资金(元)" prop="specialFundAmount"
v-if="!route.query.id&&formData.isSpecialFund">
<el-input-number v-model="formData.specialFundAmount" placeholder="请输入专项资金" :controls="false"/> <el-input-number v-model="formData.specialFundAmount" placeholder="请输入专项资金" :controls="false"/>
</el-form-item> </el-form-item>
<el-form-item label="其中申请公司总部科技创新专项资金(元)" prop="specialFundAmount" v-if="route.query.id&&formData.specialFundAmount"> <el-form-item label="其中申请公司总部科技创新专项资金(元)" prop="specialFundAmount"
v-if="route.query.id&&formData.specialFundAmount">
<el-input-number v-model="formData.specialFundAmount" placeholder="请输入专项资金" :controls="false"/> <el-input-number v-model="formData.specialFundAmount" placeholder="请输入专项资金" :controls="false"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
@@ -278,7 +280,6 @@ const deploymentId = ref()
const specialFundOption = ref([]) const specialFundOption = ref([])
const showTable = ref(true) const showTable = ref(true)
const otherFileList = ref([]) const otherFileList = ref([])
const file = ref({})
const formData = ref({ const formData = ref({
isSpecialFund: false, isSpecialFund: false,
industryUniversityResearch: '0', industryUniversityResearch: '0',
@@ -357,7 +358,6 @@ const compositeParam = (item, type) => {
const getAttachment = (val) => { const getAttachment = (val) => {
console.log('上传文件getAttachment', val) console.log('上传文件getAttachment', val)
file.value = compositeParam(val)
formData.value.singleFile = compositeParam(val) formData.value.singleFile = compositeParam(val)
} }
const getOtherFile = (val) => { const getOtherFile = (val) => {
@@ -370,6 +370,8 @@ const getOtherFile = (val) => {
}) })
} }
const getFileParam = (item) => { const getFileParam = (item) => {
console.log('item', item)
if (item === undefined) return;
return { return {
fileId: item.fileId, fileId: item.fileId,
tag: item.tag tag: item.tag
@@ -385,26 +387,21 @@ const handleSubmit = debounce(async (instance) => {
type: 'error' type: 'error'
}) })
} }
let singleFile = {}
if (file.value.fileId !== undefined) {
singleFile = {
fileId: file.value.fileId
}
}
let otherFiles = [] let otherFiles = []
otherFileList.value.forEach(item => { otherFileList.value.forEach(item => {
otherFiles.push(getFileParam(item)) otherFiles.push(getFileParam(item))
}) })
if (formData.value.singleFile !== undefined) {
formData.value.singleFile = getFileParam(formData.value.singleFile)
}
let params = { let params = {
...formData.value, ...formData.value,
// isSpecialFund: formData.value.isSpecialFund ? formData.value.isSpecialFund : false,
deploymentId: deploymentId.value, deploymentId: deploymentId.value,
fileList: otherFiles, fileList: otherFiles,
singleFile: singleFile,
requirementId: route.query.id ? route.query.id : '-1' requirementId: route.query.id ? route.query.id : '-1'
} }
console.log('params', params, formData.value) console.log('params', params)
if (JSON.stringify(singleFile) === "{}") { if (!attachment.value.isSingleFile) {
attachment.value.validate() attachment.value.validate()
ElNotification({ ElNotification({
title: '提示', title: '提示',
@@ -415,52 +412,37 @@ const handleSubmit = debounce(async (instance) => {
} else { } else {
attachment.value.clearValidate() attachment.value.clearValidate()
} }
// let res = await requirementReported(params) let res = await requirementReported(params)
// ElNotification({ ElNotification({
// title: '提示', title: '提示',
// message: res.msg, message: res.msg,
// type: res.code === 1000 ? 'success' : 'error' type: res.code === 1000 ? 'success' : 'error'
// }) })
// if (res.code === 1000) { if (res.code === 1000) {
// tagsViewStore.delVisitedViews(router.currentRoute.value.path) tagsViewStore.delVisitedViews(router.currentRoute.value.path)
// await router.push({ await router.push({
// name: 'Summary' name: 'Summary'
// }) })
// } }
}) })
}) })
const handleResubmit = debounce(() => { const handleResubmit = debounce(() => {
let singleFile = {}
let otherFiles = [] let otherFiles = []
let fileArray let fileArray
if (name.value === 'Summary/edit') { if (name.value === 'Summary/edit') {
singleFile = {
fileId: attachment.value.singleFile?.fileId
}
fileArray = attachment.value.allFileList fileArray = attachment.value.allFileList
} else {
if (file.value.fileId !== undefined) {
singleFile = {
fileId: file.value.fileId
}
}
fileArray = otherFileList.value
} }
fileArray.forEach(item => { fileArray.forEach(item => {
otherFiles.push(getFileParam(item)) otherFiles.push(getFileParam(item))
}) })
//todo requirementId
let params = { let params = {
...formData.value, ...formData.value,
// isSpecialFund: formData.value.isSpecialFund ? formData.value.isSpecialFund : false,
deploymentId: deploymentId.value, deploymentId: deploymentId.value,
fileList: otherFiles, fileList: otherFiles,
singleFile: singleFile,
requirementId: route.query.id ? route.query.id : '-1' requirementId: route.query.id ? route.query.id : '-1'
} }
console.log('重新提交params', params, formData.value) console.log('重新提交params', params, formData.value)
if (JSON.stringify(singleFile) === "{}") { if (!attachment.value.isSingleFile) {
attachment.value.validate() attachment.value.validate()
ElNotification({ ElNotification({
title: '提示', title: '提示',

View File

@@ -156,6 +156,7 @@ const tableConfig = reactive({
prop: 'oper', prop: 'oper',
label: '操作', label: '操作',
align: 'center', align: 'center',
fixed:'right',
showOverflowTooltip: false, showOverflowTooltip: false,
currentRender: ({row, index}) => { currentRender: ({row, index}) => {
let btn = [] let btn = []