diff --git a/src/factory/feedback/FeedbackModal.jsx b/src/factory/feedback/FeedbackModal.jsx index 5456ca99..2cc7e3a3 100644 --- a/src/factory/feedback/FeedbackModal.jsx +++ b/src/factory/feedback/FeedbackModal.jsx @@ -1,7 +1,7 @@ import React, { useState, useCallback } from 'react'; import './FeedbackModal.scss'; import { createMemo } from '../../forums/api'; -import { message, Upload } from 'antd'; +import { message, Upload, Icon } from 'antd'; import { httpUrl } from '../../forums/fetch'; // 导入图片资源 @@ -20,9 +20,9 @@ function FeedbackModal({ visible, onClose, onSuccess }) { title: '', description: '', }); - const [fileList, setFileList] = useState([]); const [errors, setErrors] = useState({}); const [isSubmitting, setIsSubmitting] = useState(false); + const [fileList, setFileList] = useState([]); // 处理输入变化 const handleInputChange = useCallback((field, value) => { @@ -40,21 +40,18 @@ function FeedbackModal({ visible, onClose, onSuccess }) { }, [errors]); // 文件上传前校验 - const beforeUpload = useCallback((file) => { + const beforeUpload = (file) => { const isLt100M = file.size / 1024 / 1024 < 100; if (!isLt100M) { message.error('文件大小必须小于100MB!'); } return isLt100M; - }, []); + }; - // 文件列表变化处理 - const handleFileChange = useCallback((info) => { - if (info.file.status === 'uploading' || info.file.status === 'done' || info.file.status === 'removed') { - const newFileList = info.fileList || []; - setFileList(newFileList); - } - }, []); + // 文件列表变化 + const handleFileChange = ({ fileList: newFileList }) => { + setFileList(newFileList); + }; // 验证表单 const validateForm = useCallback(() => { @@ -75,17 +72,16 @@ function FeedbackModal({ visible, onClose, onSuccess }) { setIsSubmitting(true); try { - // 获取附件ID数组 - const attachmentIdArray = fileList.map(item => { - // 优先使用 response.id(新上传的文件),其次是 item.id(已存在的文件) - return item.response && item.response.id ? item.response.id : item.id; - }).filter(id => id); // 过滤掉undefined/null + // 构建附件ID数组,参考forums/edit的实现 + const attachmentIdArray = fileList.map(item => + item.response && item.response.id ? item.response.id : item.id ? item.id : item + ); // 构建接口参数,主题板块默认填11 const params = { forum_id: 11, children_forum_id: '0', - attachments: attachmentIdArray.length > 0 ? attachmentIdArray : undefined, + attachments: attachmentIdArray, memo: { subject: formData.title, content: formData.description, @@ -111,13 +107,13 @@ function FeedbackModal({ visible, onClose, onSuccess }) { } finally { setIsSubmitting(false); } - }, [formData, fileList, validateForm, onClose, onSuccess]); + }, [formData, validateForm, fileList, onClose, onSuccess]); // 处理取消 const handleCancel = useCallback(() => { setFormData({ title: '', description: '' }); - setFileList([]); setErrors({}); + setFileList([]); onClose?.(); }, [onClose]); @@ -190,28 +186,23 @@ function FeedbackModal({ visible, onClose, onSuccess }) { {errors.description && {errors.description}} - {/* 附件上传 */} + {/* 附件上传 - 参考forums/edit配置 */}
-
+
点击或拖拽文件到此区域上传
-文件大小不超过 100MB
+点击或拖拽文件到此区域上传,文件大小不超过 100MB