import React, { useState } from "react"; import { Form, Input, Button, Tabs, Modal, Alert, Upload, message } from "antd"; import { PlusOutlined, CloseOutlined, UploadOutlined, ClockCircleOutlined, MessageOutlined, PictureOutlined, VideoCameraOutlined, FileOutlined, AppstoreOutlined, LinkOutlined, TeamOutlined, } from "@ant-design/icons"; import Layout from "@/components/Layout/Layout"; interface MessageContent { id: string; type: "text" | "image" | "video" | "file" | "miniprogram" | "link" | "group"; content: string; sendInterval?: number; intervalUnit?: "seconds" | "minutes"; scheduledTime?: { hour: number; minute: number; second: number; }; title?: string; description?: string; address?: string; coverImage?: string; groupId?: string; linkUrl?: string; } interface DayPlan { day: number; messages: MessageContent[]; } interface MessageSettingsProps { formData: any; onChange: (data: any) => void; onNext: () => void; onPrev: () => void; } // 消息类型配置 const messageTypes = [ { id: "text", icon: MessageOutlined, label: "文本" }, { id: "image", icon: PictureOutlined, label: "图片" }, { id: "video", icon: VideoCameraOutlined, label: "视频" }, { id: "file", icon: FileOutlined, label: "文件" }, { id: "miniprogram", icon: AppstoreOutlined, label: "小程序" }, { id: "link", icon: LinkOutlined, label: "链接" }, { id: "group", icon: TeamOutlined, label: "邀请入群" }, ]; // 模拟群组数据 const mockGroups = [ { id: "1", name: "产品交流群1", memberCount: 156 }, { id: "2", name: "产品交流群2", memberCount: 234 }, { id: "3", name: "产品交流群3", memberCount: 89 }, ]; const MessageSettings: React.FC = ({ formData, onChange, onNext, onPrev, }) => { const [dayPlans, setDayPlans] = useState([ { day: 0, messages: [ { id: "1", type: "text", content: "", sendInterval: 5, intervalUnit: "seconds", }, ], }, ]); const [isAddDayPlanOpen, setIsAddDayPlanOpen] = useState(false); const [isGroupSelectOpen, setIsGroupSelectOpen] = useState(false); const [selectedGroupId, setSelectedGroupId] = useState(""); // 添加新消息 const handleAddMessage = (dayIndex: number, type = "text") => { const updatedPlans = [...dayPlans]; const newMessage: MessageContent = { id: Date.now().toString(), type: type as MessageContent["type"], content: "", }; if (dayPlans[dayIndex].day === 0) { newMessage.sendInterval = 5; newMessage.intervalUnit = "seconds"; } else { newMessage.scheduledTime = { hour: 9, minute: 0, second: 0, }; } updatedPlans[dayIndex].messages.push(newMessage); setDayPlans(updatedPlans); onChange({ ...formData, messagePlans: updatedPlans }); }; // 更新消息内容 const handleUpdateMessage = ( dayIndex: number, messageIndex: number, updates: Partial ) => { const updatedPlans = [...dayPlans]; updatedPlans[dayIndex].messages[messageIndex] = { ...updatedPlans[dayIndex].messages[messageIndex], ...updates, }; setDayPlans(updatedPlans); onChange({ ...formData, messagePlans: updatedPlans }); }; // 删除消息 const handleRemoveMessage = (dayIndex: number, messageIndex: number) => { const updatedPlans = [...dayPlans]; updatedPlans[dayIndex].messages.splice(messageIndex, 1); setDayPlans(updatedPlans); onChange({ ...formData, messagePlans: updatedPlans }); }; // 切换时间单位 const toggleIntervalUnit = (dayIndex: number, messageIndex: number) => { const message = dayPlans[dayIndex].messages[messageIndex]; const newUnit = message.intervalUnit === "minutes" ? "seconds" : "minutes"; handleUpdateMessage(dayIndex, messageIndex, { intervalUnit: newUnit }); }; // 添加新的天数计划 const handleAddDayPlan = () => { const newDay = dayPlans.length; setDayPlans([ ...dayPlans, { day: newDay, messages: [ { id: Date.now().toString(), type: "text", content: "", scheduledTime: { hour: 9, minute: 0, second: 0, }, }, ], }, ]); setIsAddDayPlanOpen(false); message.success(`已添加第${newDay}天的消息计划`); }; // 选择群组 const handleSelectGroup = (groupId: string) => { setSelectedGroupId(groupId); setIsGroupSelectOpen(false); message.success( `已选择群组:${mockGroups.find((g) => g.id === groupId)?.name}` ); }; // 处理文件上传 const handleFileUpload = ( dayIndex: number, messageIndex: number, type: "image" | "video" | "file" ) => { message.success( `${ type === "image" ? "图片" : type === "video" ? "视频" : "文件" }上传成功` ); }; const items = dayPlans.map((plan, dayIndex) => ({ key: plan.day.toString(), label: plan.day === 0 ? "即时消息" : `第${plan.day}天`, children: (
{plan.messages.map((message, messageIndex) => (
{plan.day === 0 ? ( <>
间隔
handleUpdateMessage(dayIndex, messageIndex, { sendInterval: Number(e.target.value), }) } />
) : ( <>
发送时间
handleUpdateMessage(dayIndex, messageIndex, { scheduledTime: { ...(message.scheduledTime || { hour: 0, minute: 0, second: 0, }), hour: Number(e.target.value), }, }) } className="w-16" /> : handleUpdateMessage(dayIndex, messageIndex, { scheduledTime: { ...(message.scheduledTime || { hour: 0, minute: 0, second: 0, }), minute: Number(e.target.value), }, }) } className="w-16" /> : handleUpdateMessage(dayIndex, messageIndex, { scheduledTime: { ...(message.scheduledTime || { hour: 0, minute: 0, second: 0, }), second: Number(e.target.value), }, }) } className="w-16" />
)}
{messageTypes.map((type) => ( ))}
{message.type === "text" && ( handleUpdateMessage(dayIndex, messageIndex, { content: e.target.value, }) } placeholder="请输入消息内容" className="min-h-[100px]" /> )} {message.type === "miniprogram" && (
标题*
handleUpdateMessage(dayIndex, messageIndex, { title: e.target.value, }) } placeholder="请输入小程序标题" />
描述
handleUpdateMessage(dayIndex, messageIndex, { description: e.target.value, }) } placeholder="请输入小程序描述" />
链接*
handleUpdateMessage(dayIndex, messageIndex, { address: e.target.value, }) } placeholder="请输入小程序路径" />
封面*
{message.coverImage ? (
封面
) : ( )}
)} {message.type === "link" && (
标题*
handleUpdateMessage(dayIndex, messageIndex, { title: e.target.value, }) } placeholder="请输入链接标题" />
描述
handleUpdateMessage(dayIndex, messageIndex, { description: e.target.value, }) } placeholder="请输入链接描述" />
链接*
handleUpdateMessage(dayIndex, messageIndex, { linkUrl: e.target.value, }) } placeholder="请输入链接地址" />
封面*
{message.coverImage ? (
封面
) : ( )}
)} {message.type === "group" && (
选择群聊*
)} {(message.type === "image" || message.type === "video" || message.type === "file") && (
)}
))}
), })); return ( <>
} >

消息设置

{/* 添加天数计划弹窗 */} setIsAddDayPlanOpen(false)} onOk={() => { handleAddDayPlan(); setIsAddDayPlanOpen(false); }} >

选择要添加的消息计划类型

{/* 选择群聊弹窗 */} setIsGroupSelectOpen(false)} onOk={() => { handleSelectGroup(selectedGroupId); setIsGroupSelectOpen(false); }} >
{mockGroups.map((group) => (
handleSelectGroup(group.id)} >
{group.name}
成员数:{group.memberCount}
))}
); }; export default MessageSettings;