import { useState, useEffect } from 'react'; import { Table, Button, Tag, notification, Card, Popconfirm, Form } from 'antd'; import { titleSty } from '@/styles/sty' import Title from '@/components/Title'; import { Link } from 'react-router-dom'; import { delArticleDataAPI, getArticleListAPI } from '@/api/Article'; import type { Tag as ArticleTag } from '@/types/app/tag'; import type { Cate } from '@/types/app/cate'; import type { Article } from '@/types/app/article'; import { useWebStore } from '@/stores'; export default () => { const web = useWebStore(state => state.web) const [current, setCurrent] = useState(1); const [loading, setLoading] = useState(false); const [articleList, setArticleList] = useState([]); const [form] = Form.useForm(); const getArticleList = async () => { setLoading(true); const { data } = await getArticleListAPI({ query: { isDraft: 1 } }); setArticleList(data as Article[]); setLoading(false); }; useEffect(() => { getArticleList() }, []); const delArticleData = async (id: number) => { setLoading(true); await delArticleDataAPI(id); await getArticleList(); form.resetFields() setCurrent(1) notification.success({ message: '🎉 删除文章成功' }) setLoading(false); }; // 标签颜色 const colors = ['', '#2db7f5', '#87d068', '#f50', '#108ee9']; const columns = [ { title: 'ID', dataIndex: 'id', key: 'id', align: 'center', width: 100, }, { title: '标题', dataIndex: 'title', key: 'title', align: 'center', width: 300, render: (text: string, record: Article) => {text}, }, { title: '摘要', dataIndex: 'description', key: 'description', align: 'center', width: 350, render: (text: string) =>
{text ? text : '该文章暂未设置文章摘要'}
, }, { title: '分类', dataIndex: 'cateList', key: 'cateList', align: 'center', render: (cates: Cate[]) => cates.map((item, index) => {item.name}) }, { title: '标签', dataIndex: 'tagList', key: 'tagList', align: 'center', render: (tags: ArticleTag[]) => tags.map((item, index) => {item.name}) }, { title: '操作', key: 'action', fixed: 'right', align: 'center', render: (text: string, record: Article) => (
delArticleData(record.id!)}>
), }, ]; return ( <> <Card className={`${titleSty} mt-2 min-h-[calc(100vh-180px)]`}> <Table rowKey="id" dataSource={articleList} columns={columns as any} loading={loading} scroll={{ x: 'max-content' }} pagination={{ position: ['bottomCenter'], current, defaultPageSize: 8, onChange(current) { setCurrent(current) } }} /> </Card> </> ); };