This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Button, Form, Input, Upload, App, Modal, Progress, Space } from 'antd';
|
import { Button, Form, Input, Upload, App, Modal, Progress, Space } from 'antd';
|
||||||
import { CloudUploadOutlined, LinkOutlined, FileTextOutlined, DownloadOutlined, FilePdfOutlined, FilePptOutlined, VideoCameraOutlined, PictureOutlined } from '@ant-design/icons';
|
import { CloudUploadOutlined, LinkOutlined, FileTextOutlined, DownloadOutlined, FilePdfOutlined, FilePptOutlined, VideoCameraOutlined, PictureOutlined } from '@ant-design/icons';
|
||||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import { createProject, updateProject, submitProject, uploadProjectFile, getProjects } from '../../api';
|
import { createProject, updateProject, submitProject, uploadProjectFile, getProjects } from '../../api';
|
||||||
|
|
||||||
const { TextArea } = Input;
|
const { TextArea } = Input;
|
||||||
@@ -22,10 +22,6 @@ const getFileIcon = (fileType) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFileUrl = (file) => {
|
|
||||||
return file.file_url_display || file.file_url || (file.file ? URL.createObjectURL(file.file) : null);
|
|
||||||
};
|
|
||||||
|
|
||||||
const ProjectSubmission = ({ competitionId, initialValues, onCancel, onSuccess }) => {
|
const ProjectSubmission = ({ competitionId, initialValues, onCancel, onSuccess }) => {
|
||||||
const { message, modal } = App.useApp();
|
const { message, modal } = App.useApp();
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
@@ -167,6 +163,12 @@ const ProjectSubmission = ({ competitionId, initialValues, onCancel, onSuccess }
|
|||||||
|
|
||||||
const onFinish = async (values) => {
|
const onFinish = async (values) => {
|
||||||
setIsCreatingProject(true);
|
setIsCreatingProject(true);
|
||||||
|
|
||||||
|
console.log('onFinish values:', values);
|
||||||
|
console.log('competitionId:', competitionId);
|
||||||
|
|
||||||
|
const hasFiles = pendingAttachments.length > 0 || pendingCoverImage;
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
...values,
|
...values,
|
||||||
competition: competitionId,
|
competition: competitionId,
|
||||||
@@ -182,18 +184,25 @@ const ProjectSubmission = ({ competitionId, initialValues, onCancel, onSuccess }
|
|||||||
onSuccess();
|
onSuccess();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const res = await createProject(data);
|
let projectId;
|
||||||
const projectId = res.data.id;
|
|
||||||
|
|
||||||
if (pendingAttachments.length > 0 || pendingCoverImage) {
|
if (hasFiles) {
|
||||||
|
const res = await createProject(data);
|
||||||
|
projectId = res.data.id;
|
||||||
await uploadPendingFiles(projectId);
|
await uploadPendingFiles(projectId);
|
||||||
|
message.success('项目创建成功,文件上传完成');
|
||||||
|
} else {
|
||||||
|
const res = await createProject(data);
|
||||||
|
projectId = res.data.id;
|
||||||
|
message.success('项目创建成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
message.success('项目创建成功');
|
|
||||||
queryClient.invalidateQueries(['projects']);
|
queryClient.invalidateQueries(['projects']);
|
||||||
onSuccess();
|
onSuccess();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error(`创建失败: ${error.response?.data?.detail || error.message}`);
|
console.error('创建项目失败:', error);
|
||||||
|
const errorMsg = error.response?.data?.detail || error.response?.data?.message || JSON.stringify(error.response?.data) || error.message;
|
||||||
|
message.error(`创建失败: ${errorMsg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setIsCreatingProject(false);
|
setIsCreatingProject(false);
|
||||||
@@ -375,7 +384,7 @@ const ProjectSubmission = ({ competitionId, initialValues, onCancel, onSuccess }
|
|||||||
maxCount={5}
|
maxCount={5}
|
||||||
accept=".ppt,.pptx,.pdf,.mp4,.mov,.avi,.webm,.jpg,.jpeg,.png,.gif,.webp,.doc,.docx"
|
accept=".ppt,.pptx,.pdf,.mp4,.mov,.avi,.webm,.jpg,.jpeg,.png,.gif,.webp,.doc,.docx"
|
||||||
beforeUpload={(file) => {
|
beforeUpload={(file) => {
|
||||||
console.log('beforeUpload triggered for:', file.name);
|
console.log('beforeUpload triggered for:', file.name, 'initialValues:', initialValues);
|
||||||
const allowedExtensions = ['ppt', 'pptx', 'pdf', 'mp4', 'mov', 'avi', 'webm', 'jpg', 'jpeg', 'png', 'gif', 'webp', 'doc', 'docx'];
|
const allowedExtensions = ['ppt', 'pptx', 'pdf', 'mp4', 'mov', 'avi', 'webm', 'jpg', 'jpeg', 'png', 'gif', 'webp', 'doc', 'docx'];
|
||||||
const fileExt = file.name.split('.').pop()?.toLowerCase();
|
const fileExt = file.name.split('.').pop()?.toLowerCase();
|
||||||
|
|
||||||
@@ -390,7 +399,10 @@ const ProjectSubmission = ({ competitionId, initialValues, onCancel, onSuccess }
|
|||||||
return Upload.LIST_IGNORE;
|
return Upload.LIST_IGNORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialValues?.id) {
|
const hasProjectId = initialValues?.id;
|
||||||
|
console.log('hasProjectId:', hasProjectId);
|
||||||
|
|
||||||
|
if (hasProjectId) {
|
||||||
console.log('beforeUpload passed, manually calling handleUpload');
|
console.log('beforeUpload passed, manually calling handleUpload');
|
||||||
handleUpload({ file, onSuccess: () => {}, onError: () => {} });
|
handleUpload({ file, onSuccess: () => {}, onError: () => {} });
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user