"use client"; import { useState } from "react"; import { Users, Shuffle, Copy } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { Input } from "@/components/ui/input"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { toast } from "sonner"; export default function RandomGroupPage() { const [namesText, setNamesText] = useState(""); const [groupCount, setGroupCount] = useState(2); const [groups, setGroups] = useState([]); const handleShuffle = () => { const names = namesText .split(/[,\n,]+/) .map((n) => n.trim()) .filter((n) => n !== ""); if (names.length === 0) { toast.error("请输入成员名单"); return; } if (groupCount <= 0) { toast.error("分组数量必须大于 0"); return; } // Shuffle names const shuffled = [...names].sort(() => Math.random() - 0.5); // Create groups const newGroups: string[][] = Array.from({ length: groupCount }, () => []); shuffled.forEach((name, index) => { newGroups[index % groupCount].push(name); }); setGroups(newGroups.filter(g => g.length > 0)); toast.success("随机分组完成"); }; const copyToClipboard = async (text: string) => { try { await navigator.clipboard.writeText(text); toast.success("已复制到剪贴板"); } catch { toast.error("复制失败"); } }; const formatGroupsText = () => { return groups .map((group, index) => `小组 ${index + 1}: ${group.join(", ")}`) .join("\n\n"); }; return (

随机分组工具

输入成员名单,公平地进行随机分组

名单与配置