From c6944d9c479c15ee4f3eda661ee65c63bfbb7393 Mon Sep 17 00:00:00 2001 From: kun <1422840143@qq.com> Date: Fri, 15 Sep 2023 18:02:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20BUG=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/newNotification/index.vue | 229 +++++++++++------- 1 file changed, 148 insertions(+), 81 deletions(-) diff --git a/src/views/goverment/notice/newNotification/index.vue b/src/views/goverment/notice/newNotification/index.vue index d15c56a..70125db 100644 --- a/src/views/goverment/notice/newNotification/index.vue +++ b/src/views/goverment/notice/newNotification/index.vue @@ -44,15 +44,15 @@ size="small" > - + - @@ -107,7 +108,7 @@ import { ref, reactive, onMounted, watch, computed, onUnmounted, toRaw } from "v import { ElMessage, FormRules, FormInstance } from "element-plus"; import { GlobalStore } from "@/stores"; import { useRoute, useRouter } from "vue-router"; -import FileUpload from "@/components/FilesUpload/FilesUpload.vue"; +import FilesUploadPlus from "@/components/FilesUploadPlus/FilesUpload.vue"; import type { UploadFile } from "@/components/FilesUpload/FilesUpload.vue"; import { getDicList } from "@/api/modules/jxjview"; import { getgovNamelist, getentNamelist, getproNamelist } from "@/api/modules/goverment"; @@ -131,6 +132,7 @@ interface searchFormType { const current = ref({} as AnnexFilesOptions); const route = useRoute(); +const documentDataIndex = ref(0); const editorRef = ref(); const store = GlobalStore(); const radio = ref(0); @@ -153,7 +155,7 @@ const typeList = ref([ { label: "邮件", value: 1 }, { label: "材料推送", value: 2 } ]); -const annexFileList = ref([]); +const annexFileList: any = ref([]); const tags = ref([]); const value = ref([]); const govList = ref([]); @@ -187,14 +189,6 @@ const handleClose = (row: acceptNameList) => { const getMsg = val => { leftForm.value.content = val; }; -const handlechange = e => { - console.log(e); - current.value.files = e.map(item => { - item.label = current.value.dictLabel; - return item; - }); - console.log(annexFileList.value); -}; // 通讯录过滤寻找匹配合适项 let nameList = computed(val => { return (radio.value === 2 ? govList.value : radio.value === 3 ? entList.value : proList.value).filter(val => { @@ -261,7 +255,8 @@ const onChange = (row: any) => { const onAddData = () => { annexFileList.value?.push({ - fileName: "" + label: "", + fileList: [] }); }; @@ -269,38 +264,142 @@ const deleteRow = row => { const i = annexFileList.value?.indexOf(row); i != null && annexFileList.value?.splice(i, 1); }; - +const handlechange = e => { + console.log(e); + current.value.files = e.map(item => { + item.label = current.value.dictLabel; + return item; + }); + console.log(current.value.files); + annexFileList.value[documentDataIndex.value].fileList = current.value.files; + console.log(annexFileList.value); +}; // 上传附件按钮 -const onUpload = async row => { +const onUpload = async (row: any, index: any) => { + console.log(row); showFilesUpload.value = true; - current.value = row; + documentDataIndex.value = index; + if (row.fileList.length > 0) { + let arr: any = []; + row.fileList.map(item => { + if (item.response && item.response.originalFilename) { + arr.push({ + response: { ...item.response, url: item.response.url }, + name: item.response.originalFilename, + url: item.response.url, + size: +item.response.size, + type: item.response.contentType + }); + } else if (item.response) { + arr.push({ + response: { ...item.response, url: item.response.fileUrl }, + name: item.response.fileName, + url: item.response.fileUrl, + size: +item.response.fileSize, + type: item.response.contentType + }); + } else { + arr.push({ + response: { ...item, url: item.fileUrl }, + name: item.fileName, + url: item.fileUrl, + size: +item.fileSize, + type: item.contentType + }); + } + }); + current.value.files = arr; + console.log(current.value.files); + } else { + current.value.files = []; + } }; // 点击发送按钮 const handleSubmit = async (formEl: FormInstance | undefined) => { if (!formEl) return; await formEl.validate(async (valid, fields) => { if (valid) { - const fileList: AnnexFile[] = []; - annexFileList.value.forEach(item => { - const files = item.files; - - files?.forEach(file => { - const curr: AnnexFile = {}; - curr.createTime = file.response?.createTime; - curr.extendName = file.response?.ext; - // TODO: 上传文件后, 后端返回两个 name 字段, 一个后端存储的 filename, 一个文件本身的 originalFilename - curr.fileName = file.response?.originalFilename; - // curr.fileName = file.response?.filename; - // curr.fileId = file.response && +file.response.id; - curr.fileSize = `${file.response?.size || ""}`; - curr.fileUrl = file.response?.url; - - curr.label = file.label; - - fileList.push(curr); - }); - - item.files = files; + let requestData = { + accepts: [], + content: leftForm.value.content, + title: leftForm.value.title, + type: searchForm.value.type, + annexFileDtoList: annexFileList.value + }; + let annexPass = true; + console.log(annexFileList.value); + requestData.annexFileDtoList.map(item => { + if (!item.label) { + annexPass = false; + } + if (item.files && item.files.length > 0) { + annexPass = true; + } else if (item.fileList && item.fileList.length > 0) { + annexPass = true; + } else { + annexPass = false; + } + }); + if (!annexPass) { + ElMessage.error("请上传附件资料"); + return; + } + requestData.annexFileDtoList.map(item => { + if (item.files && item.files.length > 0) { + item.files.map(item2 => { + item.annexFileList.push({ + createTime: item2.response.createTime, + extendName: item2.response.ext, + fileId: item2.response.id, + fileName: item2.response.originalFilename, + fileSize: item2.response.size, + fileUrl: item2.response.url, + contentType: item2.response.contentType + }); + }); + delete item.files; + } else if (item.fileList && item.fileList.length > 0) { + let updateArr = [] as any; + item.fileList.map(item2 => { + if (item2.fileId) { + delete item2.fileId; + } + if (item2.response && item2.response.originalFilename) { + updateArr.push({ + createTime: item2.response.createTime, + extendName: item2.response.ext, + fileId: item2.response.id, + fileName: item2.response.originalFilename, + fileSize: item2.response.size, + fileUrl: item2.response.url, + contentType: item2.response.contentType + }); + } else if (item2.response) { + updateArr.push({ + createTime: item2.response.createTime, + extendName: item2.response.extendName, + fileId: item2.response.fileId, + fileName: item2.response.fileName, + fileSize: item2.response.fileSize, + fileUrl: item2.response.fileUrl, + contentType: item2.response.contentType + }); + } else { + updateArr.push({ + createTime: item2.createTime, + extendName: item2.extendName, + fileId: item2.fileId, + fileName: item2.fileName, + fileSize: item2.fileSize, + fileUrl: item2.fileUrl, + contentType: item2.contentType + }); + } + }); + item.annexFileList = updateArr; + delete item.fileList; + } + delete item.id; }); const acceptsList: acceptNameList[] = []; console.log(tags); @@ -319,33 +418,14 @@ const handleSubmit = async (formEl: FormInstance | undefined) => { console.log(curr); acceptsList.push(curr); }); - + requestData.accepts = acceptsList; if (store.Message) { - const editFiles = []; - annexFileList.value.forEach(item => { - let files = item.files; - files?.forEach(j => { - editFiles.push(j.response); - }); - }); - await noticeeditmyPost({ - accepts: acceptsList, - annexFileList: editFiles, - content: leftForm.value.content, - title: leftForm.value.title, - type: searchForm.value.type, - noticeId: route.query.noticeId - }); + requestData.noticeId = route.query.noticeId; + await noticeeditmyPost(requestData); ElMessage.success("编辑成功"); delete store.Message; } else { - await addNotice({ - accepts: acceptsList, - annexFileList: fileList, - content: leftForm.value.content, - title: leftForm.value.title, - type: searchForm.value.type - }); + await addNotice(requestData); ElMessage.success("发送成功"); } reset(); @@ -395,25 +475,12 @@ onMounted(async () => { console.log(searchForm.value.type); leftForm.value = store.Message; - annexFileList.value.forEach(item => { - const currFiles = store.Message.annexFileList.filter(j => { - return j.label == item.fileName; + let editAnnexFileList = store.Message.annexFileList; + editAnnexFileList.forEach(item => { + annexFileList.value.push({ + label: item.label, + fileList: item.annexFileList }); - const files = []; - - currFiles.forEach(curr => { - annexFileList.value.fileName = curr.fileName; - files.push({ - id: curr.fileId, - name: curr.fileName, - size: +curr.fileSize, - type: "image/png", - response: { ...curr, contentType: "image/png" } - }); - }); - - item.files = files; - // item.fileName = store.Message?.title; }); console.log(annexFileList.value); tags.value = store.Message.acceptList;