"use client" import { useState, useEffect } from "react" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group" import { Slider } from "@/components/ui/slider" import { format } from "date-fns" import { Search, Users } from "lucide-react" import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog" import { api } from "@/lib/api" interface BasicInfoStepProps { onNext: (data: any) => void initialData?: { name?: string distributeType?: string | number maxPerDay?: number timeType?: string | number startTime?: string endTime?: string accounts?: string[] account?: string[] } } export default function BasicInfoStep({ onNext, initialData = {} }: BasicInfoStepProps) { const [formData, setFormData] = useState({ name: initialData.name ?? `流量分发 ${format(new Date(), "yyyyMMdd HHmm")}`, distributeType: String(initialData.distributeType ?? "1"), maxPerDay: initialData.maxPerDay ?? 200, timeType: String(initialData.timeType ?? "2"), startTime: initialData.startTime ?? "09:00", endTime: initialData.endTime ?? "18:00", }) // 账号选择相关状态 const [accountDialogOpen, setAccountDialogOpen] = useState(false) const [accountList, setAccountList] = useState([]) const [selectedAccountIds, setSelectedAccountIds] = useState( (initialData.account || initialData.accounts || []).map(String) ) const [accountPage, setAccountPage] = useState(1) const [accountTotal, setAccountTotal] = useState(0) const [accountLoading, setAccountLoading] = useState(false) // 拉取账号列表 useEffect(() => { setAccountLoading(true) api.get(`/v1/workbench/account-list?page=${accountPage}&size=10`).then((res: any) => { setAccountList(res.data?.list || []) setAccountTotal(res.data?.total || 0) }).finally(() => setAccountLoading(false)) }, [accountPage]) const handleChange = (field: string, value: any) => { setFormData((prev) => ({ ...prev, [field]: value })) } const handleSubmit = () => { onNext({ name: formData.name, distributeType: Number(formData.distributeType), maxPerDay: formData.maxPerDay, timeType: Number(formData.timeType), startTime: formData.timeType == "2" ? formData.startTime : "09:00", endTime: formData.timeType == "2" ? formData.endTime : "21:00", account: selectedAccountIds, accounts: selectedAccountIds, }) } // 账号弹窗确认 const handleAccountDialogConfirm = () => { setAccountDialogOpen(false) } return (

基本信息

handleChange("name", e.target.value)} placeholder="请输入计划名称" required />
handleChange("distributeType", value)} className="space-y-2" >
每日最大分配量 {formData.maxPerDay} 人/天
handleChange("maxPerDay", value[0])} className="py-4" />

限制每天最多分配的流量数量(1-1000)

handleChange("timeType", value)} className="space-y-4" >
{formData.timeType == "2" && (
handleChange("startTime", e.target.value)} />
handleChange("endTime", e.target.value)} />
)}
{/* 账号选择 */}
0 ? `已选择${selectedAccountIds.length}个账号` : ''} readOnly className="pl-10 cursor-pointer" onClick={() => setAccountDialogOpen(true)} />
已选账号: {selectedAccountIds.length === 0 ? ( 未选择 ) : ( {selectedAccountIds.length} 个 )}
{/* 账号选择弹窗 */} 选择账号
{/* 账号列表 */}
{accountLoading ? (
加载中...
) : accountList.length === 0 ? (
暂无账号
) : ( accountList.map(account => ( )) )}
{/* 确认按钮 */}
) }