"use client" import { useState, useEffect } from "react" import Link from "next/link" import { useRouter } from "next/navigation" import { Button } from "@/components/ui/button" import { Card } from "@/components/ui/card" import { Switch } from "@/components/ui/switch" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" import { PlusCircle, MoreVertical, Edit, Trash2, ArrowLeft, Clock, Search, Filter, RefreshCw } from "lucide-react" import { Input } from "@/components/ui/input" import { Badge } from "@/components/ui/badge" import { api } from "@/lib/api" import { showToast } from "@/lib/toast" interface GroupPushTask { id: string name: string status: number config: { maxPerDay: number pushOrder: number isLoop: number groups: any[] contentLibraries: any[] lastPushTime: string createTime: string } } export default function GroupPushPage() { const router = useRouter() const [tasks, setTasks] = useState([]) const [searchTerm, setSearchTerm] = useState("") const [deleteDialogOpen, setDeleteDialogOpen] = useState(false) const [taskToDelete, setTaskToDelete] = useState(null) const [loading, setLoading] = useState(false) const [currentPage, setCurrentPage] = useState(1) const [total, setTotal] = useState(0) const pageSize = 10 // 拉取数据 const fetchTasks = async (page = 1, search = "") => { setLoading(true) const loadingToast = showToast("正在加载...", "loading", true) try { const params = new URLSearchParams({ type: "3", page: page.toString(), limit: pageSize.toString(), }) if (search) params.append("keyword", search) const res = await api.get(`/v1/workbench/list?${params.toString()}`) as any loadingToast.remove() if (res.code === 200) { setTasks(res.data.list) setTotal(res.data.total) } else { showToast(res.msg || "获取失败", "error") } } catch (e) { loadingToast.remove() showToast((e as any)?.message || "网络错误", "error") } finally { setLoading(false) } } useEffect(() => { fetchTasks(currentPage, searchTerm) // eslint-disable-next-line }, [currentPage]) const handleDelete = (id: string) => { setTaskToDelete(id) setDeleteDialogOpen(true) } const confirmDelete = async () => { if (taskToDelete) { const loadingToast = showToast("正在删除...", "loading", true) try { const res = await api.delete(`/v1/workbench/delete?id=${taskToDelete}`) as any loadingToast.remove() if (res.code === 200) { showToast("删除成功", "success") fetchTasks(currentPage, searchTerm) } else { showToast(res.msg || "删除失败", "error") } } catch (e) { loadingToast.remove() showToast((e as any)?.message || "网络错误", "error") } setTaskToDelete(null) } setDeleteDialogOpen(false) } const handleToggleStatus = async (id: string, enabled: boolean) => { const loadingToast = showToast("正在更新状态...", "loading", true) try { const res = await api.post('/v1/workbench/update-status', { id, status: enabled ? 1 : 0 }) as any loadingToast.remove() if (res.code === 200) { showToast("状态已更新", "success") fetchTasks(currentPage, searchTerm) } else { showToast(res.msg || "操作失败", "error") } } catch (e) { loadingToast.remove() showToast((e as any)?.message || "网络错误", "error") } } const handleSearch = () => { setCurrentPage(1) fetchTasks(1, searchTerm) } const handleRefresh = () => { fetchTasks(currentPage, searchTerm) } return (
{/* 顶部导航栏 */}

社群推送

{/* 搜索栏 */}
setSearchTerm(e.target.value)} onKeyDown={e => e.key === 'Enter' && handleSearch()} />
{/* 任务列表 */} {loading ? (
{[...Array(3)].map((_, index) => (
))}
) : tasks.length === 0 ? (

暂无社群推送任务

点击"新建任务"按钮创建您的第一个社群推送任务

) : (
{tasks.map((task) => (

{task.name}

{task.status === 1 ? "进行中" : "已暂停"}
handleToggleStatus(task.id, checked)} /> 查看 编辑 handleDelete(task.id)}> 删除
推送群数:{task.config.groups?.length || 0} 个
内容库:{task.config.contentLibraries?.length || 0} 个
每日推送:{task.config.maxPerDay} 条
推送顺序:{task.config.pushOrder === 2 ? "按最新" : "按最早"}
循环推送:{task.config.isLoop === 1 ? "是" : "否"}
上次推送:{task.config.lastPushTime || "--"}
创建时间:{task.config.createTime || "--"}
))}
)} {/* 分页 */} {!loading && total > pageSize && (
第 {currentPage} 页 共 {Math.ceil(total / pageSize)} 页
)}
确认删除 您确定要删除这个社群推送任务吗?此操作无法撤销。
) }