diff --git a/src/App.tsx b/src/App.tsx index 87e2f33..a709e54 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,6 +7,7 @@ import ECommerce from './pages/Dashboard/ECommerce'; import Create from './pages/Create'; import Cate from './pages/Cate'; import Article from './pages/Article'; +import Comment from './pages/Comment'; import Login from './pages/Login'; import DefaultLayout from './layout/DefaultLayout'; @@ -96,6 +97,16 @@ function App() { } /> + + + + + + } + /> )} diff --git a/src/components/Sidebar/index.tsx b/src/components/Sidebar/index.tsx index 9633e87..e265c80 100644 --- a/src/components/Sidebar/index.tsx +++ b/src/components/Sidebar/index.tsx @@ -191,13 +191,13 @@ const Sidebar = ({ sidebarOpen, setSidebarOpen }: SidebarProps) => {
  • 'group relative flex items-center gap-2.5 rounded-md px-4 font-medium text-bodydark2 duration-300 ease-in-out hover:text-white ' + (isActive && '!text-white') } > - Form Layout + 评论管理
  • diff --git a/src/pages/Article/index.tsx b/src/pages/Article/index.tsx index ab4969e..d461d14 100644 --- a/src/pages/Article/index.tsx +++ b/src/pages/Article/index.tsx @@ -1,12 +1,11 @@ -// ArticleManagement.tsx import React, { useState, useEffect } from 'react'; import { Table, Tag, Button, notification, Card, Popconfirm } from 'antd'; import { delArticleDataAPI, getArticleListAPI } from '@/api/Article'; import dayjs from 'dayjs'; -import { Article } from '@/types/article'; +import type { Article } from '@/types/article'; import Breadcrumb from '@/components/Breadcrumbs' -const ArticleManagement: React.FC = () => { +const Article: React.FC = () => { const [loading, setLoading] = useState(false); const [articleList, setArticleList] = useState([]); @@ -42,6 +41,7 @@ const ArticleManagement: React.FC = () => { dataIndex: 'id', key: 'id', align: 'center', + width: 100, }, { title: '标题', @@ -63,7 +63,6 @@ const ArticleManagement: React.FC = () => { dataIndex: 'cate', key: 'cate', align: 'center', - // render: (cate: { name: string }[]) => {cate[0].name}, render: () => 测试分类, }, { @@ -130,7 +129,7 @@ const ArticleManagement: React.FC = () => { dataSource={articleList} columns={columns as any} loading={loading} - scroll={{ x: '1850px' }} + scroll={{ x: 'max-content' }} pagination={{ position: ['bottomCenter'], pageSize: 8 @@ -140,4 +139,4 @@ const ArticleManagement: React.FC = () => { ); }; -export default ArticleManagement; \ No newline at end of file +export default Article; \ No newline at end of file diff --git a/src/pages/Cate/index.tsx b/src/pages/Cate/index.tsx index 7b3f048..f5f4239 100644 --- a/src/pages/Cate/index.tsx +++ b/src/pages/Cate/index.tsx @@ -124,7 +124,7 @@ const CateManager: React.FC = () => { }, [cate, model]); return ( - } className='border-stroke dark:border-strokedark [&>.ant-card-head]:border-stroke [&>.ant-card-head]:dark:border-strokedark dark:bg-boxdark [&>.ant-card-body]:pt-2'> + } className='border-stroke dark:border-strokedark [&>.ant-card-head]:border-stroke [&>.ant-card-head]:dark:border-strokedark dark:bg-boxdark [&>.ant-card-body]:pt-2'>
    diff --git a/src/pages/Comment/components/List/index.tsx b/src/pages/Comment/components/List/index.tsx new file mode 100644 index 0000000..c2a117c --- /dev/null +++ b/src/pages/Comment/components/List/index.tsx @@ -0,0 +1,111 @@ +import React from 'react'; +import { Table, Button, Pagination, Spin, message, Modal, Popconfirm } from 'antd'; +import { ColumnsType } from 'antd/es/table'; +import dayjs from 'dayjs'; +import { auditCommentDataAPI, delCommentDataAPI } from '@/api/Comment'; + +interface ListProps { + data: Info; + getCommentList: (page?: Page) => void; +} + +const List: React.FC = ({ data, getCommentList }) => { + const auditComment = async (id: number) => { + await auditCommentDataAPI(id); + getCommentList(); + message.success('🎉 审核评论成功'); + }; + + const delComment = async (id: number) => { + await delCommentDataAPI(id); + getCommentList(); + message.success('🎉 删除评论成功'); + }; + + const columns: ColumnsType = [ + { + title: 'ID', + dataIndex: 'id', + key: 'id', + width: 100, + fixed: 'left', + }, + { + title: '名称', + dataIndex: 'name', + key: 'name', + width: 170, + fixed: 'left', + }, + { + title: '邮箱', + dataIndex: 'email', + key: 'email', + width: 230, + }, + { + title: '内容', + dataIndex: 'content', + key: 'content', + width: 270, + }, + { + title: '网站', + dataIndex: 'url', + key: 'url', + width: 250, + render: (url: string) => url ? {url} : '无网站', + }, + { + title: '所属文章', + dataIndex: 'article', + key: 'article', + width: 300, + }, + { + title: '评论时间', + dataIndex: 'date', + key: 'date', + width: 230, + render: (date: string) => dayjs(date).format('YYYY-MM-DD HH:mm:ss'), + }, + { + title: '操作', + key: 'action', + width: data.tab === 'audit' ? 120 : 80, + fixed: 'right', + align: 'center', + render: (_: any, record: any) => ( + <> + {data.tab === 'audit' && ( + + )} + + delComment(record.id)}> + + + + + ), + }, + ]; + + return ( +
    + }> + + + + ); +}; + +export default List; diff --git a/src/pages/Comment/index.tsx b/src/pages/Comment/index.tsx new file mode 100644 index 0000000..7ec0485 --- /dev/null +++ b/src/pages/Comment/index.tsx @@ -0,0 +1,53 @@ +import React, { useState, useEffect, useCallback } from 'react'; +import { Tabs, Spin, Card } from 'antd'; +import { TabsProps } from 'antd'; +import { getCommentListAPI } from '@/api/Comment'; +import List from './components/List'; +import Breadcrumb from '@/components/Breadcrumbs'; + +const { TabPane } = Tabs; + +const CommentManager: React.FC = () => { + const [info, setInfo] = useState({ + tab: 'list', + loading: false, + list: [], + paginate: { size: 0, page: 0, total: 0 } + }); + + const getCommentList = useCallback(async (page?: Page) => { + setInfo(prev => ({ ...prev, loading: true })); + + const { data } = await getCommentListAPI(page); + + setInfo(prev => ({ + list: data.result.filter(item => (prev.tab === 'list' ? item.audit === 1 : item.audit === 0)), + loading: false + })); + }, [info.tab]); + + useEffect(() => { + getCommentList(); + }, [getCommentList]); + + const handleTabChange = (key: string) => { + setInfo(prev => ({ ...prev, tab: key })); + getCommentList(); + }; + + return ( + } className='border-stroke dark:border-strokedark [&>.ant-card-head]:border-stroke [&>.ant-card-head]:dark:border-strokedark dark:bg-boxdark [&>.ant-card-body]:pt-2'> + + + {info.loading ? : } + + + + {info.loading ? : } + + + + ); +}; + +export default CommentManager;