From 5df49e6baea005c46099d41d7221abd2f5fa16bc Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Tue, 28 Jul 2026 09:14:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor(upload-voice-modal):=20=E4=B8=89?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=E9=87=8D=E6=9E=84=20UploadVoiceModal?= =?UTF-8?q?=EF=BC=88329=E2=86=9287=E8=A1=8C,=20-74%=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 1: 抽 types/constants - types.ts — UploadVoiceModalProps, GENDER_OPTIONS, UPLOAD_CONFIG Phase 2: 拆 5 个 UI 组件 - FileUploadZone — 拖拽上传区 - FileInfoCard — 已选文件信息卡 - UploadProgress — 上传进度条 - FormFields — 名称/性别/描述表单 - ActionButtons — 取消/上传操作按钮 Phase 3: 主组件瘦身 - 仅保留 Modal 框架 + 子组件组装 - 内联样式变量化,labelStyle/inputStyle 复用 --- .../voices/components/UploadVoiceModal.tsx | 316 ++---------------- .../upload-voice-modal/ActionButtons.tsx | 68 ++++ .../upload-voice-modal/FileInfoCard.tsx | 42 +++ .../upload-voice-modal/FileUploadZone.tsx | 56 ++++ .../upload-voice-modal/FormFields.tsx | 106 ++++++ .../upload-voice-modal/UploadProgress.tsx | 45 +++ .../components/upload-voice-modal/index.ts | 6 + .../components/upload-voice-modal/types.ts | 30 ++ 8 files changed, 390 insertions(+), 279 deletions(-) create mode 100755 apps/web/src/pages/voices/components/upload-voice-modal/ActionButtons.tsx create mode 100755 apps/web/src/pages/voices/components/upload-voice-modal/FileInfoCard.tsx create mode 100755 apps/web/src/pages/voices/components/upload-voice-modal/FileUploadZone.tsx create mode 100755 apps/web/src/pages/voices/components/upload-voice-modal/FormFields.tsx create mode 100755 apps/web/src/pages/voices/components/upload-voice-modal/UploadProgress.tsx create mode 100755 apps/web/src/pages/voices/components/upload-voice-modal/index.ts create mode 100755 apps/web/src/pages/voices/components/upload-voice-modal/types.ts diff --git a/apps/web/src/pages/voices/components/UploadVoiceModal.tsx b/apps/web/src/pages/voices/components/UploadVoiceModal.tsx index 75aaff541..56928dbb7 100755 --- a/apps/web/src/pages/voices/components/UploadVoiceModal.tsx +++ b/apps/web/src/pages/voices/components/UploadVoiceModal.tsx @@ -1,24 +1,13 @@ import React from "react" -import { UploadOutlined, SoundOutlined } from "@ant-design/icons" -import { Modal, Upload, message } from "antd" -import { type VoiceGender } from "@/pages/voices/types" -import { formatFileSize } from "@/pages/voices/utils/format" - -export interface UploadVoiceModalProps { - open: boolean - uploadFile: File | null - uploadName: string - uploadGender: VoiceGender - uploadDesc: string - uploadProgress: number | null - onClose: () => void - onFileSelect: (file: File) => void - onFileRemove: () => void - onNameChange: (name: string) => void - onGenderChange: (gender: VoiceGender) => void - onDescChange: (desc: string) => void - onUpload: () => void -} +import { Modal } from "antd" +import { + FileUploadZone, + FileInfoCard, + UploadProgress, + FormFields, + ActionButtons, +} from "./upload-voice-modal" +import type { UploadVoiceModalProps } from "./upload-voice-modal" /** 上传音频弹窗 */ const UploadVoiceModal: React.FC = ({ @@ -36,17 +25,20 @@ const UploadVoiceModal: React.FC = ({ onDescChange, onUpload, }) => { + const uploading = uploadProgress !== null + const canUpload = !!uploadFile && !!uploadName.trim() + return ( { - if (uploadProgress !== null) return // 上传中不可关闭 + if (uploading) return // 上传中不可关闭 onClose() }} footer={null} width={520} - maskClosable={uploadProgress === null} + maskClosable={!uploading} >
= ({ }} > {/* 拖拽上传区 */} - { - onFileSelect(file) - return false - }} - onRemove={() => { - onFileRemove() - }} - showUploadList={false} - disabled={uploadProgress !== null} - > -

- -

-

- 点击或拖拽音频文件到此处 -

-

- 支持 MP3、WAV、AAC、FLAC 等格式,最大 200MB -

-
+ {/* 已选文件信息 */} - {uploadFile && ( -
- -
-
- {uploadFile.name} -
-
- {formatFileSize(uploadFile.size)} -
-
-
- )} + {uploadFile && } {/* 上传进度 */} - {uploadProgress !== null && ( -
-
- {uploadProgress}% -
-
- {uploadProgress < 100 ? "上传中..." : "处理中..."} -
-
-
-
-
- )} + {uploadProgress !== null && } - {/* 名称 */} -
-
- 素材名称 -
- onNameChange(e.target.value)} - placeholder="输入素材名称" - maxLength={100} - disabled={uploadProgress !== null} - style={{ - width: "100%", - padding: "8px 12px", - border: "1px solid var(--border-color)", - borderRadius: 8, - fontSize: 13, - background: "var(--bg-primary)", - color: "var(--text-primary)", - outline: "none", - }} - /> -
- - {/* 性别选择 */} -
-
- 音色性别 -
-
- {(["female", "male", "child"] as VoiceGender[]).map((g) => ( - - ))} -
-
- - {/* 描述 */} -
-
- 音色描述(可选) -
-