'use client'; import { useEffect } from 'react'; import { useFlowmeChannelStore } from '../store/channel'; import { useForm } from 'react-hook-form'; import { pick } from 'es-toolkit'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table'; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Plus, Pencil, Trash2 } from 'lucide-react'; const TableList = () => { const { list, setShowEdit, setFormData, deleteData } = useFlowmeChannelStore(); return (
标题 描述 标签 颜色 操作 {list.map((item) => ( {item.title} {item.description} {item.tags?.join(', ')}
{item.color}
))}
); }; const FormModal = () => { const { showEdit, setShowEdit, formData, updateData } = useFlowmeChannelStore(); const { handleSubmit, reset, control, } = useForm(); useEffect(() => { if (!showEdit) return; if (formData?.id) { reset(formData); } else { reset({ title: '', description: '', color: '#007bff', }); } }, [formData, showEdit, reset]); const onSubmit = async (data: any) => { const _formData: any = pick(data, ['title', 'description', 'tags', 'link', 'data', 'color']); if (formData.id) { _formData.id = formData.id; } const res = await updateData(_formData); if (res.code === 200) { setShowEdit(false); } }; return ( {formData?.id ? '编辑' : '添加'}
); }; export const List = () => { const { getList, setShowEdit, setFormData } = useFlowmeChannelStore(); useEffect(() => { getList(); }, [getList]); return (
); }; export default List