From 5eda5444b7204c6695cd7031e4a666000bce8fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BE=E8=82=83?= <15833576927@163.com> Date: Wed, 29 May 2024 11:18:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E5=9B=A0=E5=9E=8B=E5=88=86=E7=89=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E3=80=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/upload.js | 4 +-- src/components/fileUploader/index.vue | 12 ++++++--- src/utils/ruoyi.js | 28 +++++++++++++++++++++ src/views/genoTypeData/genoManage/index.vue | 15 ++++++----- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/api/upload.js b/src/api/upload.js index aa1315e..af27c00 100644 --- a/src/api/upload.js +++ b/src/api/upload.js @@ -22,8 +22,8 @@ http.interceptors.response.use(response => { * @param identifier 文件md5 * @returns {Promise>} */ -const taskInfo = (identifier) => { - return http.get(`/sys_upload_task/taskInfo/${identifier}`) +const taskInfo = (identifier,data) => { + return http.post(`/sys_upload_task/taskInfo/${identifier}`,data) } /** diff --git a/src/components/fileUploader/index.vue b/src/components/fileUploader/index.vue index ccd153d..008a4f0 100644 --- a/src/components/fileUploader/index.vue +++ b/src/components/fileUploader/index.vue @@ -24,10 +24,10 @@ const mergeParams = ref({}) /** * 获取一个上传任务,没有则初始化一个 */ -const getTaskInfo = async (file) => { +const getTaskInfo = async (file,params) => { let task; const identifier = await md5(file) - const {code, data, msg} = await taskInfo(identifier) + const {code, data, msg} = await taskInfo(identifier,params) if (code === 200) { task = data if (!task) { @@ -162,7 +162,13 @@ const handleUpload = (file, taskRecord, options) => { const handleHttpRequest = async (options) => { const file = options.file options.indeterminate = true - const task = await getTaskInfo(file) + let params = { + fileName:file.name, + fileSize:file.size, + fileMemo:options.fileMemo, + ...mergeParams.value + } + const task = await getTaskInfo(file,params) options.indeterminate = false if (task) { const {finished, path, taskRecord} = task diff --git a/src/utils/ruoyi.js b/src/utils/ruoyi.js index a16f978..667c1b1 100644 --- a/src/utils/ruoyi.js +++ b/src/utils/ruoyi.js @@ -413,4 +413,32 @@ export function processDot(num, precision) { export function formatNumber(num) { const result = processDot(num, 2); return result.replace(/\d(?=(\d{3})+\.)/g, "$&,"); +} +/** + * 上传文件将对象转换为FormData + * @param values + */ +export function toFormData(values) { + const formData = new FormData() + return getFormData(values, formData) +} + +export function getFormData(values, formData) { + if (values) { + Object.keys(values).forEach(key => { + const value = values[key] + if (value !== undefined && value !== null) { + if (Array.isArray(value)) { + formData.delete(key) + formData.append(key, JSON.stringify(values[key])) + } else if (Object.prototype.toString.call(value) === '[object Object]') { + getFormData(value, formData) + } else { + formData.delete(key) + formData.append(key, values[key]) + } + } + }) + } + return formData } \ No newline at end of file diff --git a/src/views/genoTypeData/genoManage/index.vue b/src/views/genoTypeData/genoManage/index.vue index 4faf68d..b4d184f 100644 --- a/src/views/genoTypeData/genoManage/index.vue +++ b/src/views/genoTypeData/genoManage/index.vue @@ -184,7 +184,7 @@ import TitleDivider from "@/components/titleDivider/index.vue"; import useSettingsStore from "@/store/modules/settings.js"; import UploadGeno from "@/views/genoTypeData/genoManage/uploadGeno.vue"; -import {fileToBlobURL, handleTree} from "@/utils/ruoyi.js"; +import {fileToBlobURL, handleTree, toFormData} from "@/utils/ruoyi.js"; import { addGeno, delGeno, editGeno, selClassInfo, @@ -341,12 +341,15 @@ const saveGeno = () => { const params = { ...formData.value, genus: undefined, - tFiles:formData.value.tFiles.filter(item => !!item.id) + tFiles:undefined, + } + if (formData.value.id){ + params.tFilesString = formData.value.tFiles.filter(item => !!item.id) } formRef.value.validate(valid => { if (valid) { submitLoading.value = true - api(params).then(res => { + api(toFormData(params)).then(res => { uploadGenoRef.value.uploadFile(res.data) // proxy.$modal.msgSuccess('保存成功'); // getList() @@ -445,10 +448,10 @@ const handleUpdate = (row) => { showGenoForm.value = true } const delFileGeno = (item) => { - if (isArray(formData.value.delFileIds)){ - formData.value.delFileIds.push(item.id) + if (isArray(formData.value.delFile)){ + formData.value.delFile.push(item.id) }else{ - formData.value.delFileIds = [item.id] + formData.value.delFile = [item.id] } }