Merge pull request 'feat : 文件下载组件删除功能' (#195) from dj into master

Reviewed-on: http://git.feashow.cn/clay/mosr-web/pulls/195
This commit is contained in:
2024-05-18 11:56:52 +00:00
3 changed files with 44 additions and 35 deletions

View File

@@ -11,13 +11,15 @@
:before-upload="beforeUpload" :before-upload="beforeUpload"
:on-success="handleUploadSuccess" :on-success="handleUploadSuccess"
:on-error="uploadError" :on-error="uploadError"
:before-remove="beforeRemove"
:on-remove="handleRemove"
> >
<el-button color="#DED0B2" :loading="loading">上传文件</el-button> <el-button color="#DED0B2" :loading="loading">上传文件</el-button>
</el-upload> </el-upload>
</template> </template>
<script setup> <script setup>
import {ElMessage} from "element-plus"; import {ElMessage,ElMessageBox} from "element-plus";
import {getToken} from '@/utils/auth' import {getToken} from '@/utils/auth'
const baseURL = import.meta.env.VITE_BASE_URL const baseURL = import.meta.env.VITE_BASE_URL
const uploadFileUrl = ref(baseURL + "/workflow/process/file/upload") const uploadFileUrl = ref(baseURL + "/workflow/process/file/upload")
@@ -45,7 +47,7 @@ const props = defineProps({
} }
}) })
const emit = defineEmits(["input", "getFile"]) const emit = defineEmits(["input", "getFile","delete"])
const fileList = ref([]) const fileList = ref([])
const _value = computed({ const _value = computed({
get() { get() {
@@ -55,7 +57,17 @@ const _value = computed({
emit("input", val); emit("input", val);
} }
}) })
const beforeRemove = (file, fileList) => {
return ElMessageBox.confirm(`确认删除名称为${file.name}的文件吗?`, '系统提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => true)
}
const handleRemove = (file, fileList) => {
emit("delete",file.response.data.id)
}
const beforeUpload = (file) => { const beforeUpload = (file) => {
// const FileExt = file.name.replace(/.+\./, ""); // const FileExt = file.name.replace(/.+\./, "");
// if (['zip', 'rar', 'pdf', 'doc', 'docx', 'xlsx'].indexOf(FileExt.toLowerCase()) === -1) { // if (['zip', 'rar', 'pdf', 'doc', 'docx', 'xlsx'].indexOf(FileExt.toLowerCase()) === -1) {
@@ -94,4 +106,7 @@ a {
font-size: 14px; font-size: 14px;
color: #2a99ff; color: #2a99ff;
} }
:deep(.el-upload-list) {
width: 400px;
}
</style> </style>

View File

@@ -36,7 +36,7 @@
<Tinymce image-url="/notice/file" file-url="/notice/file" v-model:value="formData.collectExplain" height="300" <Tinymce image-url="/notice/file" file-url="/notice/file" v-model:value="formData.collectExplain" height="300"
v-if="showTinymce"/> v-if="showTinymce"/>
<baseTitle title="申请文件"></baseTitle> <baseTitle title="申请文件"></baseTitle>
<file-upload ref="uploadFile" @getFile="getFile"/> <file-upload @getFile="getFile"/>
<fvTable style="width: 100%;max-height: 200px" v-if="showTable" :tableConfig="tableConfig" :data="formData.fileList" <fvTable style="width: 100%;max-height: 200px" v-if="showTable" :tableConfig="tableConfig" :data="formData.fileList"
:isSettingCol="false" :pagination="false"> :isSettingCol="false" :pagination="false">
<template #empty> <template #empty>
@@ -199,15 +199,15 @@ const init = async () => {
}) })
}) })
} }
const submitParam=()=>{ const submitParam=(item)=>{
return { return {
collectExplain: formData.value.collectExplain, collectExplain: item.collectExplain,
collectType: formData.value.collectType, collectType: item.collectType,
companyIds: formData.value.companyIds, companyIds: item.companyIds,
deadline: formData.value.deadline, deadline: item.deadline,
requirementId: formData.value.requirementId?formData.value.requirementId:0, requirementId: item.requirementId?item.requirementId:0,
requirementName: formData.value.requirementName, requirementName: item.requirementName,
files: formData.value.fileList, files: item.fileList,
deploymentId: processInstanceData.value.deploymentId deploymentId: processInstanceData.value.deploymentId
} }
} }
@@ -215,7 +215,7 @@ const handleSubmit = async (instance) => {
if (!instance) return if (!instance) return
instance.validate(async (valid) => { instance.validate(async (valid) => {
if (!valid) return if (!valid) return
let res = await addRequirement(submitParam()) let res = await addRequirement(submitParam(formData.value))
if (res.code === 1000) { if (res.code === 1000) {
ElMessage.success(res.msg) ElMessage.success(res.msg)
tagsViewStore.delVisitedViews(router.currentRoute.value.path) tagsViewStore.delVisitedViews(router.currentRoute.value.path)

View File

@@ -10,13 +10,13 @@
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="项目验收附件" prop="attachment"> <el-form-item label="项目验收附件" prop="attachment">
<file-upload @getFile="getAttachment" :showFileList="true"/> <file-upload @getFile="getAttachment" :showFileList="true" @delete="handleDelete"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="其他文件"> <el-form-item label="其他文件">
<el-card style="width: 100%"> <el-card style="width: 100%">
<file-upload @getFile="getOtherFile" :showFileList="true"/> <file-upload @getFile="getOtherFile" :showFileList="false" />
<fvTable style="width: 100%;max-height: 250px" v-if="showTable" :tableConfig="tableConfig" <fvTable style="width: 100%;max-height: 250px" v-if="showTable" :tableConfig="tableConfig"
:data="otherFileList" :isSettingCol="false" :pagination="false"> :data="otherFileList" :isSettingCol="false" :pagination="false">
<template #empty> <template #empty>
@@ -36,6 +36,8 @@
<script setup lang="jsx"> <script setup lang="jsx">
import FileUpload from "@/components/FileUpload.vue"; import FileUpload from "@/components/FileUpload.vue";
import {ElMessage} from "element-plus";
import {deleteFile} from "@/api/project-demand";
const formData = ref({}) const formData = ref({})
const rules = reactive({ const rules = reactive({
@@ -99,30 +101,22 @@ const compositeParam = (item) => {
} }
const getAttachment = (val) => { const getAttachment = (val) => {
console.log('上传文件', val) console.log('上传文件', val)
showTable.value = false // showTable.value = false
nextTick(() => { // let fileObj = compositeParam(val)
showTable.value = true // formData.value.fileList.push(fileObj)
}) // nextTick(() => {
let fileObj = {} // showTable.value = true
let newFileArray = [] // })
if (route.query.isAdd === undefined) {
val.forEach(item => {
fileObj = compositeParam(item)
newFileArray.push(fileObj)
formData.value.fileList.push(fileObj)
})
fileList.value = formData.value.fileList
} else {
val.forEach(item => {
fileObj = compositeParam(item)
newFileArray.push(fileObj)
})
formData.value.fileList = newFileArray
fileList.value = newFileArray
}
} }
const getOtherFile = () => { const getOtherFile = () => {
}
const handleDelete=(val)=>{
deleteFile(val).then(res => {
if (res.code === 1000) {
ElMessage.success("删除成功");
}
});
} }
const handleSubmit = (instance) => { const handleSubmit = (instance) => {
if (!instance) return if (!instance) return