2024-08-07 17:07:14 +08:00
|
|
|
|
import { useState, useEffect } from 'react';
|
2024-09-25 14:25:10 +08:00
|
|
|
|
import { Card, message, Table, Popconfirm, Button, Tag, Modal, Form, Input, DatePicker } from 'antd';
|
2024-08-06 23:21:42 +08:00
|
|
|
|
import { getCommentListAPI } from '@/api/Comment';
|
2024-09-27 21:20:35 +08:00
|
|
|
|
import { delCommentDataAPI } from '@/api/Comment';
|
2024-08-07 17:07:14 +08:00
|
|
|
|
import { ColumnsType } from 'antd/es/table';
|
|
|
|
|
|
import { titleSty } from '@/styles/sty';
|
|
|
|
|
|
import Title from '@/components/Title';
|
2024-08-15 15:28:58 +08:00
|
|
|
|
import { Comment } from '@/types/app/comment'
|
2024-08-17 15:34:39 +08:00
|
|
|
|
import dayjs from 'dayjs';
|
2024-08-06 23:21:42 +08:00
|
|
|
|
|
2024-08-07 18:43:07 +08:00
|
|
|
|
const CommentPage = () => {
|
2024-08-07 17:07:14 +08:00
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
|
const [comment, setComment] = useState<Comment>();
|
|
|
|
|
|
const [list, setList] = useState<Comment[]>([]);
|
2024-08-06 23:21:42 +08:00
|
|
|
|
|
2024-08-07 18:43:07 +08:00
|
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
|
|
|
|
2024-08-07 17:07:14 +08:00
|
|
|
|
const getCommentList = async () => {
|
|
|
|
|
|
const { data } = await getCommentListAPI();
|
2024-09-02 16:58:20 +08:00
|
|
|
|
|
2024-08-14 13:16:14 +08:00
|
|
|
|
// 根据时间排序:最新时间在前
|
2024-09-02 16:58:20 +08:00
|
|
|
|
// const sortedData = (data as Comment[]).sort((a, b) => +b.createTime - +a.createTime);
|
|
|
|
|
|
setList(data)
|
2024-08-07 17:07:14 +08:00
|
|
|
|
setLoading(false)
|
|
|
|
|
|
}
|
2024-08-06 23:21:42 +08:00
|
|
|
|
|
2024-08-07 17:07:14 +08:00
|
|
|
|
const delCommentData = async (id: number) => {
|
|
|
|
|
|
setLoading(true)
|
|
|
|
|
|
await delCommentDataAPI(id);
|
2024-08-06 23:21:42 +08:00
|
|
|
|
getCommentList();
|
2024-08-07 17:07:14 +08:00
|
|
|
|
message.success('🎉 删除评论成功');
|
2024-08-06 23:21:42 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-08-07 17:07:14 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
setLoading(true)
|
|
|
|
|
|
getCommentList();
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
const columns: ColumnsType = [
|
|
|
|
|
|
{
|
|
|
|
|
|
title: 'ID',
|
|
|
|
|
|
dataIndex: 'id',
|
|
|
|
|
|
key: 'id',
|
|
|
|
|
|
align: "center"
|
|
|
|
|
|
},
|
2024-09-28 16:15:10 +08:00
|
|
|
|
// {
|
|
|
|
|
|
// title: '状态',
|
|
|
|
|
|
// dataIndex: 'auditStatus',
|
|
|
|
|
|
// key: 'auditStatus',
|
|
|
|
|
|
// fixed: 'left',
|
|
|
|
|
|
// render: (status: number) => status ?
|
|
|
|
|
|
// <Tag bordered={false} color="processing">通过</Tag>
|
|
|
|
|
|
// : <Tag bordered={false} color="error">待审核</Tag>
|
|
|
|
|
|
// },
|
2024-08-07 17:07:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '名称',
|
|
|
|
|
|
dataIndex: 'name',
|
|
|
|
|
|
key: 'name',
|
|
|
|
|
|
fixed: 'left',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '内容',
|
|
|
|
|
|
dataIndex: 'content',
|
|
|
|
|
|
key: 'content',
|
2024-09-02 16:58:20 +08:00
|
|
|
|
width: 400,
|
|
|
|
|
|
render: (text: string, record) => <span className="hover:text-primary cursor-pointer line-clamp-2" onClick={() => {
|
2024-08-07 18:43:07 +08:00
|
|
|
|
setComment(record)
|
|
|
|
|
|
setIsModalOpen(true)
|
|
|
|
|
|
}}>{text}</span>
|
2024-08-07 17:07:14 +08:00
|
|
|
|
},
|
2024-09-28 16:15:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '邮箱',
|
|
|
|
|
|
dataIndex: 'email',
|
|
|
|
|
|
key: 'email',
|
|
|
|
|
|
render: (text: string) => text ? text : '暂无邮箱',
|
|
|
|
|
|
},
|
2024-08-07 17:07:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '网站',
|
|
|
|
|
|
dataIndex: 'url',
|
|
|
|
|
|
key: 'url',
|
|
|
|
|
|
render: (url: string) => url ? <a href={url} className="hover:text-primary">{url}</a> : '无网站',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '所属文章',
|
|
|
|
|
|
dataIndex: 'articleTitle',
|
|
|
|
|
|
key: 'articleTitle',
|
2024-09-02 16:58:20 +08:00
|
|
|
|
render: (text: string) => (text ? text : '该评论暂未绑定文章'),
|
2024-08-07 17:07:14 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '评论时间',
|
|
|
|
|
|
dataIndex: 'createTime',
|
|
|
|
|
|
key: 'createTime',
|
2024-09-02 16:58:20 +08:00
|
|
|
|
render: (date: string) => dayjs(+date).format('YYYY-MM-DD HH:mm:ss'),
|
2024-08-07 17:07:14 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '操作',
|
|
|
|
|
|
key: 'action',
|
|
|
|
|
|
fixed: 'right',
|
|
|
|
|
|
align: 'center',
|
2024-08-07 18:43:07 +08:00
|
|
|
|
render: (text: string, record: Comment) => (
|
2024-08-07 23:30:01 +08:00
|
|
|
|
<div className='flex justify-center space-x-2'>
|
2024-09-27 21:20:35 +08:00
|
|
|
|
<Button onClick={() => {
|
|
|
|
|
|
setComment(record)
|
|
|
|
|
|
setIsModalOpen(true)
|
|
|
|
|
|
}}>查看</Button>
|
2024-08-07 18:43:07 +08:00
|
|
|
|
|
2024-08-07 17:07:14 +08:00
|
|
|
|
<Popconfirm title="警告" description="你确定要删除吗" okText="确定" cancelText="取消" onConfirm={() => delCommentData(record.id)}>
|
|
|
|
|
|
<Button type="primary" danger>删除</Button>
|
|
|
|
|
|
</Popconfirm>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2024-08-07 13:02:59 +08:00
|
|
|
|
|
2024-09-02 16:58:20 +08:00
|
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
|
|
|
|
|
|
|
|
const onSubmit = async (values: FilterForm) => {
|
|
|
|
|
|
const query: FilterData = {
|
2024-09-27 21:20:35 +08:00
|
|
|
|
key: values.title ? values.title : undefined,
|
|
|
|
|
|
content: values.content ? values.content : undefined,
|
|
|
|
|
|
startDate: values.createTime ? values.createTime[0].valueOf() + '' : undefined,
|
|
|
|
|
|
endDate: values.createTime ? values.createTime[1].valueOf() + '' : undefined,
|
2024-09-02 16:58:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const { data } = await getCommentListAPI({ query });
|
2024-09-27 21:20:35 +08:00
|
|
|
|
console.log(data);
|
|
|
|
|
|
setList(data)
|
2024-09-02 16:58:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-06 23:21:42 +08:00
|
|
|
|
return (
|
2024-08-07 17:07:14 +08:00
|
|
|
|
<>
|
|
|
|
|
|
<Title value='评论管理' />
|
|
|
|
|
|
|
2024-09-02 16:58:20 +08:00
|
|
|
|
<Card className='my-2 overflow-scroll'>
|
|
|
|
|
|
<Form layout="inline" onFinish={onSubmit} autoComplete="off" className='flex-nowrap'>
|
|
|
|
|
|
<Form.Item label="标题" name="title" className='w-2/12'>
|
2024-09-27 21:20:35 +08:00
|
|
|
|
<Input placeholder='请输入标题关键词' />
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
|
|
<Form.Item label="内容" name="content" className='w-2/12'>
|
|
|
|
|
|
<Input placeholder='请输入内容关键词' />
|
2024-09-02 16:58:20 +08:00
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
|
|
<Form.Item label="时间范围" name="createTime" className='w-3/12'>
|
|
|
|
|
|
<RangePicker placeholder={["选择起始时间", "选择结束时间"]} />
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
|
|
<Form.Item className='pr-6'>
|
|
|
|
|
|
<Button type="primary" htmlType="submit">查询</Button>
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Form>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
2024-08-07 17:07:14 +08:00
|
|
|
|
<Card className={`${titleSty} mt-2`}>
|
2024-09-02 16:58:20 +08:00
|
|
|
|
<Table
|
|
|
|
|
|
rowKey="id"
|
|
|
|
|
|
dataSource={list}
|
|
|
|
|
|
columns={columns}
|
|
|
|
|
|
loading={loading}
|
|
|
|
|
|
expandable={{ defaultExpandAllRows: true }}
|
|
|
|
|
|
scroll={{ x: 'max-content' }}
|
|
|
|
|
|
pagination={{
|
|
|
|
|
|
position: ['bottomCenter'],
|
|
|
|
|
|
defaultPageSize: 8,
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
2024-08-07 17:07:14 +08:00
|
|
|
|
</Card>
|
2024-08-07 18:43:07 +08:00
|
|
|
|
|
|
|
|
|
|
<Modal title='评论详情' open={isModalOpen} onCancel={() => setIsModalOpen(false)} footer={null}>
|
|
|
|
|
|
<div className='pt-2 space-y-2'>
|
|
|
|
|
|
<div><b>所属文章:</b> {comment?.articleTitle}</div>
|
|
|
|
|
|
<div><b>评论时间:</b> {dayjs(comment?.createTime).format("YYYY-MM-DD HH:mm:ss")}</div>
|
|
|
|
|
|
<div><b>评论用户:</b> {comment?.name}</div>
|
2024-09-27 21:20:35 +08:00
|
|
|
|
<div><b>邮箱:</b> {comment?.email ? comment?.email : "暂无邮箱"}</div>
|
2024-08-07 18:43:07 +08:00
|
|
|
|
<div><b>网站:</b> {comment?.url ? <a href={comment?.url} className="hover:text-primary">{comment?.url}</a> : '无网站'}</div>
|
|
|
|
|
|
<div><b>内容:</b> {comment?.content}</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Modal>
|
2024-08-07 17:07:14 +08:00
|
|
|
|
</>
|
2024-08-06 23:21:42 +08:00
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-08-07 18:43:07 +08:00
|
|
|
|
export default CommentPage;
|