import React, { useState } from 'react' import { Label } from '@/components/ui/label' import { Input } from '@/components/ui/input' import { Button } from '@/components/ui/button' import { Switch } from '@/components/ui/switch' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { X } from 'lucide-react' import type { DreamConfig } from '../types' interface DreamSectionProps { config: DreamConfig onChange: (config: DreamConfig) => void } interface TimeRange { startTime: string endTime: string } export const DreamSection = React.memo(function DreamSection({ config, onChange }: DreamSectionProps) { // 解析 dream_send 为 platform 和 userId const parseDreamSend = (dreamSend: string): { platform: string; userId: string } => { if (!dreamSend || !dreamSend.includes(':')) { return { platform: 'qq', userId: '' } } const [platform, userId] = dreamSend.split(':') return { platform, userId } } const { platform: initialPlatform, userId: initialUserId } = parseDreamSend(config.dream_send) const [platform, setPlatform] = useState(initialPlatform) const [userId, setUserId] = useState(initialUserId) // 解析时间段字符串为开始和结束时间 const parseTimeRange = (range: string): TimeRange => { const [start, end] = range.split('-') return { startTime: start || '09:00', endTime: end || '22:00' } } // 更新 dream_send const updateDreamSend = (newPlatform: string, newUserId: string) => { const dreamSend = newUserId ? `${newPlatform}:${newUserId}` : '' onChange({ ...config, dream_send: dreamSend }) } const handlePlatformChange = (value: string) => { setPlatform(value) updateDreamSend(value, userId) } const handleUserIdChange = (value: string) => { setUserId(value) updateDreamSend(platform, value) } const handleAddTimeRange = () => { onChange({ ...config, dream_time_ranges: [...config.dream_time_ranges, '09:00-22:00'] }) } const handleRemoveTimeRange = (index: number) => { onChange({ ...config, dream_time_ranges: config.dream_time_ranges.filter((_, i) => i !== index) }) } const handleTimeRangeChange = (index: number, field: 'startTime' | 'endTime', value: string) => { const newRanges = [...config.dream_time_ranges] const currentRange = parseTimeRange(newRanges[index]) if (field === 'startTime') { currentRange.startTime = value } else { currentRange.endTime = value } newRanges[index] = `${currentRange.startTime}-${currentRange.endTime}` onChange({ ...config, dream_time_ranges: newRanges }) } return (
默认30分钟
默认20轮
程序启动后首次做梦前的延迟时间,默认60秒
选择平台并输入用户ID,做梦结束后将梦境发送给该用户。用户ID为空则不推送
设置允许做梦的时间段,支持跨夜区间(如 23:00 到次日 02:00)。列表为空则全天允许做梦
当前配置为全天允许做梦
)}开启后,梦境发送给配置的用户后,也会存储到聊天上下文中,在后续对话中可见