diff --git a/Touchkebao/src/pages/pc/ckbox/powerCenter/message-push-assistant/create-push-task/components/StepSendMessage/index.module.scss b/Touchkebao/src/pages/pc/ckbox/powerCenter/message-push-assistant/create-push-task/components/StepSendMessage/index.module.scss index 12ee6679..2fe9b07f 100644 --- a/Touchkebao/src/pages/pc/ckbox/powerCenter/message-push-assistant/create-push-task/components/StepSendMessage/index.module.scss +++ b/Touchkebao/src/pages/pc/ckbox/powerCenter/message-push-assistant/create-push-task/components/StepSendMessage/index.module.scss @@ -273,6 +273,16 @@ .aiRewriteInput { max-width: 240px; } + + .aiRewriteActions { + display: flex; + align-items: center; + gap: 8px; + } + + .aiRewriteButton { + min-width: 96px; + } } } diff --git a/Touchkebao/src/pages/pc/ckbox/powerCenter/message-push-assistant/create-push-task/components/StepSendMessage/index.tsx b/Touchkebao/src/pages/pc/ckbox/powerCenter/message-push-assistant/create-push-task/components/StepSendMessage/index.tsx index 8a19ad74..991f3a2a 100644 --- a/Touchkebao/src/pages/pc/ckbox/powerCenter/message-push-assistant/create-push-task/components/StepSendMessage/index.tsx +++ b/Touchkebao/src/pages/pc/ckbox/powerCenter/message-push-assistant/create-push-task/components/StepSendMessage/index.tsx @@ -10,7 +10,12 @@ import { Switch, message as antdMessage, } from "antd"; -import { CopyOutlined, DeleteOutlined, PlusOutlined } from "@ant-design/icons"; +import { + CopyOutlined, + DeleteOutlined, + PlusOutlined, + ReloadOutlined, +} from "@ant-design/icons"; import type { CheckboxChangeEvent } from "antd/es/checkbox"; import styles from "./index.module.scss"; @@ -21,6 +26,7 @@ import type { ContentItem } from "@/components/ContentSelection/data"; import { createContentLibrary, deleteContentLibrary, + aiEditContent, type CreateContentLibraryParams, } from "./api"; @@ -80,6 +86,7 @@ const StepSendMessage: React.FC = ({ onSelectedContentLibrariesChange, }) => { const [savingScriptGroup, setSavingScriptGroup] = useState(false); + const [aiRewriting, setAiRewriting] = useState(false); const [deletingGroupIds, setDeletingGroupIds] = useState([]); const handleAddMessage = useCallback( @@ -172,6 +179,99 @@ const StepSendMessage: React.FC = ({ savingScriptGroup, ]); + const handleAiRewrite = useCallback(async () => { + if (!aiRewriteEnabled) { + antdMessage.warning("请先开启AI智能话术改写"); + return; + } + const trimmedPrompt = aiPrompt.trim(); + const originalContent = messageContent; + const trimmedContent = originalContent.trim(); + if (!trimmedPrompt) { + antdMessage.warning("请输入改写提示词"); + return; + } + if (!trimmedContent) { + antdMessage.warning("请输入需要改写的内容"); + return; + } + if (aiRewriting) { + return; + } + let hideLoading: ReturnType | undefined; + try { + setAiRewriting(true); + hideLoading = antdMessage.loading("AI正在改写话术...", 0); + const response = await aiEditContent({ + aiPrompt: trimmedPrompt, + content: originalContent, + }); + hideLoading?.(); + const normalizedResponse = response as { + content?: string; + contentAfter?: string; + contentFront?: string; + data?: + | string + | { + content?: string; + contentAfter?: string; + contentFront?: string; + }; + result?: string; + }; + const dataField = normalizedResponse?.data; + const dataContent = + typeof dataField === "string" + ? dataField + : (dataField?.content ?? undefined); + const dataContentAfter = + typeof dataField === "string" ? undefined : dataField?.contentAfter; + const dataContentFront = + typeof dataField === "string" ? undefined : dataField?.contentFront; + + const primaryAfter = + normalizedResponse?.contentAfter ?? dataContentAfter ?? undefined; + const primaryFront = + normalizedResponse?.contentFront ?? dataContentFront ?? undefined; + + let rewrittenContent = ""; + if (typeof response === "string") { + rewrittenContent = response; + } else if (primaryAfter) { + rewrittenContent = primaryFront + ? `${primaryFront}\n${primaryAfter}` + : primaryAfter; + } else if (typeof normalizedResponse?.content === "string") { + rewrittenContent = normalizedResponse.content; + } else if (typeof dataContent === "string") { + rewrittenContent = dataContent; + } else if (typeof normalizedResponse?.result === "string") { + rewrittenContent = normalizedResponse.result; + } else if (primaryFront) { + rewrittenContent = primaryFront; + } + if (!rewrittenContent || typeof rewrittenContent !== "string") { + antdMessage.error("AI改写失败,请稍后重试"); + return; + } + onMessageContentChange(rewrittenContent.trim()); + antdMessage.success("AI改写完成,请确认内容"); + } catch (error) { + hideLoading?.(); + console.error("AI改写失败:", error); + antdMessage.error("AI改写失败,请稍后重试"); + } finally { + setAiRewriting(false); + } + }, [ + aiPrompt, + aiRewriting, + aiRewriteEnabled, + messageContent, + onMessageContentChange, + ]); + const handleApplyGroup = useCallback( (group: ScriptGroup) => { onCurrentScriptMessagesChange(group.messages); @@ -389,13 +489,24 @@ const StepSendMessage: React.FC = ({ - +
+ + +