From 40cd7ae74d4e2b911b5109824dfed63ebfb85dc2 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Tue, 28 Jul 2026 09:52:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor(voices):=20=E6=8B=86=E5=88=86=20TtsMod?= =?UTF-8?q?al=20=E4=B8=BA=E5=AD=90=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 三阶段重构: - Phase 1: 提取类型与常量到 tts-modal/types.ts - Phase 2: 拆分为 6 个 UI 子组件 - TextInputSection: 文本输入区 - VoiceSelector: 音色选择下拉 - SpeedControl: 语速调节滑块 - SynthesizeButton: 合成按钮 - ErrorAlert: 错误提示 - ResultPanel: 合成结果展示 - Phase 3: 主文件 258→53 行(-79%) 保持导入路径向后兼容,主文件仍在原位置 --- .../src/pages/voices/components/TtsModal.tsx | 237 ++---------------- .../components/tts-modal/ErrorAlert.tsx | 24 ++ .../components/tts-modal/ResultPanel.tsx | 51 ++++ .../components/tts-modal/SpeedControl.tsx | 47 ++++ .../components/tts-modal/SynthesizeButton.tsx | 51 ++++ .../components/tts-modal/TextInputSection.tsx | 56 +++++ .../components/tts-modal/VoiceSelector.tsx | 49 ++++ .../voices/components/tts-modal/index.ts | 8 + .../voices/components/tts-modal/types.ts | 29 +++ apps/web/src/test/pages/voices/smoke.test.tsx | 7 + 10 files changed, 338 insertions(+), 221 deletions(-) create mode 100755 apps/web/src/pages/voices/components/tts-modal/ErrorAlert.tsx create mode 100755 apps/web/src/pages/voices/components/tts-modal/ResultPanel.tsx create mode 100755 apps/web/src/pages/voices/components/tts-modal/SpeedControl.tsx create mode 100755 apps/web/src/pages/voices/components/tts-modal/SynthesizeButton.tsx create mode 100755 apps/web/src/pages/voices/components/tts-modal/TextInputSection.tsx create mode 100755 apps/web/src/pages/voices/components/tts-modal/VoiceSelector.tsx create mode 100755 apps/web/src/pages/voices/components/tts-modal/index.ts create mode 100755 apps/web/src/pages/voices/components/tts-modal/types.ts diff --git a/apps/web/src/pages/voices/components/TtsModal.tsx b/apps/web/src/pages/voices/components/TtsModal.tsx index 0bfbab43e..1859489b3 100755 --- a/apps/web/src/pages/voices/components/TtsModal.tsx +++ b/apps/web/src/pages/voices/components/TtsModal.tsx @@ -1,27 +1,12 @@ import React from "react" -import { RobotOutlined } from "@ant-design/icons" -import { Modal, message } from "antd" -import { type PresetVoiceDisplay } from "@/pages/voices/types" -import { genderLabel } from "@/pages/voices/utils/format" - -export type TtsStatus = "idle" | "synthesizing" | "done" | "error" - -export interface TtsModalProps { - open: boolean - ttsText: string - ttsVoiceId: string - ttsSpeed: number - ttsStatus: TtsStatus - ttsAudioUrl: string | null - ttsError: string | null - presetVoices: PresetVoiceDisplay[] - onClose: () => void - onTextChange: (text: string) => void - onVoiceChange: (voiceId: string) => void - onSpeedChange: (speed: number) => void - onSynthesize: () => void - onSave: () => void -} +import { Modal } from "antd" +import { type TtsModalProps, type TtsStatus } from "./tts-modal/types" +import TextInputSection from "./tts-modal/TextInputSection" +import VoiceSelector from "./tts-modal/VoiceSelector" +import SpeedControl from "./tts-modal/SpeedControl" +import SynthesizeButton from "./tts-modal/SynthesizeButton" +import ErrorAlert from "./tts-modal/ErrorAlert" +import ResultPanel from "./tts-modal/ResultPanel" /** AI 配音弹窗 */ const TtsModal: React.FC = ({ @@ -50,205 +35,13 @@ const TtsModal: React.FC = ({ padding: "8px 0", }} > - {/* 文本输入 */} -
-
- 输入文本 -
-