2024-09-28 16:15:10 +08:00
|
|
|
|
import { useState, useEffect } from 'react';
|
|
|
|
|
|
import { Card, message, Table, Popconfirm, Button, Tag, Modal, Form, Input, DatePicker, Select } from 'antd';
|
|
|
|
|
|
import { ColumnsType } from 'antd/es/table';
|
2024-09-28 16:40:04 +08:00
|
|
|
|
import { getWallListAPI, delWallDataAPI, getWallCateListAPI } from '@/api/Wall';
|
2024-09-28 16:15:10 +08:00
|
|
|
|
import { titleSty } from '@/styles/sty';
|
|
|
|
|
|
import Title from '@/components/Title';
|
2024-10-12 14:29:38 +08:00
|
|
|
|
import type { Cate, Wall, FilterForm, FilterWall } from '@/types/app/wall';
|
2024-09-28 16:15:10 +08:00
|
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
|
|
|
|
|
|
|
const WallPage = () => {
|
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
|
const [wall, setWall] = useState<Wall>();
|
|
|
|
|
|
const [list, setList] = useState<Wall[]>([]);
|
|
|
|
|
|
|
|
|
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
const getWallList = async () => {
|
|
|
|
|
|
const { data } = await getWallListAPI();
|
|
|
|
|
|
|
|
|
|
|
|
setList(data)
|
|
|
|
|
|
setLoading(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const delWallData = async (id: number) => {
|
|
|
|
|
|
setLoading(true)
|
|
|
|
|
|
await delWallDataAPI(id);
|
|
|
|
|
|
getWallList();
|
|
|
|
|
|
message.success('🎉 删除留言成功');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 获取留言的分类列表
|
|
|
|
|
|
const [cateList, setCateList] = useState<Cate[]>([])
|
|
|
|
|
|
const getCateList = async () => {
|
|
|
|
|
|
const { data } = await getWallCateListAPI()
|
|
|
|
|
|
setCateList((data as Cate[]).filter(item => item.id !== 1))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
setLoading(true)
|
|
|
|
|
|
getWallList();
|
|
|
|
|
|
getCateList()
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
const columns: ColumnsType = [
|
|
|
|
|
|
{
|
|
|
|
|
|
title: 'ID',
|
|
|
|
|
|
dataIndex: 'id',
|
|
|
|
|
|
key: 'id',
|
|
|
|
|
|
align: "center"
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '分类',
|
|
|
|
|
|
dataIndex: 'cate',
|
|
|
|
|
|
key: 'cate',
|
|
|
|
|
|
render: ({ name }, { color }) => <Tag bordered={false} color={color} className='!text-[#565656]'>{name}</Tag>,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '名称',
|
|
|
|
|
|
dataIndex: 'name',
|
2024-11-11 14:41:15 +08:00
|
|
|
|
key: 'name'
|
2024-09-28 16:15:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '内容',
|
|
|
|
|
|
dataIndex: 'content',
|
|
|
|
|
|
key: 'content',
|
|
|
|
|
|
width: 400,
|
|
|
|
|
|
render: (text: string, record) => <span className="hover:text-primary cursor-pointer line-clamp-2" onClick={() => {
|
|
|
|
|
|
setWall(record)
|
|
|
|
|
|
setIsModalOpen(true)
|
|
|
|
|
|
}}>{text}</span>
|
|
|
|
|
|
},
|
2024-10-18 15:14:58 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '邮箱',
|
|
|
|
|
|
dataIndex: 'email',
|
|
|
|
|
|
key: 'email',
|
|
|
|
|
|
render: (text: string) => text ? text : '暂无邮箱',
|
|
|
|
|
|
},
|
2024-09-28 16:15:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
title: '留言时间',
|
|
|
|
|
|
dataIndex: 'createTime',
|
|
|
|
|
|
key: 'createTime',
|
|
|
|
|
|
render: (date: string) => dayjs(+date).format('YYYY-MM-DD HH:mm:ss'),
|
2024-11-11 14:26:04 +08:00
|
|
|
|
sorter: (a: Wall, b: Wall) => +a.createTime! - +b.createTime!
|
2024-09-28 16:15:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '操作',
|
|
|
|
|
|
key: 'action',
|
|
|
|
|
|
fixed: 'right',
|
|
|
|
|
|
align: 'center',
|
|
|
|
|
|
render: (text: string, record: Wall) => (
|
|
|
|
|
|
<div className='flex justify-center space-x-2'>
|
|
|
|
|
|
<Button onClick={() => {
|
|
|
|
|
|
setWall(record)
|
|
|
|
|
|
setIsModalOpen(true)
|
|
|
|
|
|
}}>查看</Button>
|
|
|
|
|
|
|
|
|
|
|
|
<Popconfirm title="警告" description="你确定要删除吗" okText="确定" cancelText="取消" onConfirm={() => delWallData(record.id)}>
|
|
|
|
|
|
<Button type="primary" danger>删除</Button>
|
|
|
|
|
|
</Popconfirm>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
|
|
|
|
|
|
|
|
const onSubmit = async (values: FilterForm) => {
|
2024-09-28 16:40:04 +08:00
|
|
|
|
const query: FilterWall = {
|
|
|
|
|
|
key: values.content,
|
|
|
|
|
|
cateId: values.cateId,
|
2024-10-12 14:29:38 +08:00
|
|
|
|
startDate: values.createTime && values.createTime[0].valueOf() + '',
|
|
|
|
|
|
endDate: values.createTime && values.createTime[1].valueOf() + ''
|
2024-09-28 16:15:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const { data } = await getWallListAPI({ query });
|
|
|
|
|
|
setList(data)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Title value='留言管理' />
|
|
|
|
|
|
|
|
|
|
|
|
<Card className='my-2 overflow-scroll'>
|
|
|
|
|
|
<Form layout="inline" onFinish={onSubmit} autoComplete="off" className='flex-nowrap'>
|
2024-11-11 14:10:37 +08:00
|
|
|
|
<Form.Item label="内容" name="content" className='min-w-[200px]'>
|
2024-09-28 16:15:10 +08:00
|
|
|
|
<Input placeholder='请输入内容关键词' />
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
2024-11-11 14:10:37 +08:00
|
|
|
|
<Form.Item label="分类" name="cateId" className='min-w-[200px]'>
|
2024-09-28 16:15:10 +08:00
|
|
|
|
<Select
|
|
|
|
|
|
allowClear
|
|
|
|
|
|
options={cateList}
|
|
|
|
|
|
fieldNames={{ label: 'name', value: 'id' }}
|
|
|
|
|
|
placeholder="请选择分类"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
2024-11-11 14:10:37 +08:00
|
|
|
|
<Form.Item label="时间范围" name="createTime" className='min-w-[250px]'>
|
2024-09-28 16:15:10 +08:00
|
|
|
|
<RangePicker placeholder={["选择起始时间", "选择结束时间"]} />
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
|
|
<Form.Item className='pr-6'>
|
|
|
|
|
|
<Button type="primary" htmlType="submit">查询</Button>
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Form>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
2024-11-12 19:55:24 +08:00
|
|
|
|
<Card className={`${titleSty} mt-2 min-h-[calc(100vh-180px)]`}>
|
2024-09-28 16:15:10 +08:00
|
|
|
|
<Table
|
|
|
|
|
|
rowKey="id"
|
|
|
|
|
|
dataSource={list}
|
|
|
|
|
|
columns={columns}
|
|
|
|
|
|
loading={loading}
|
|
|
|
|
|
expandable={{ defaultExpandAllRows: true }}
|
|
|
|
|
|
scroll={{ x: 'max-content' }}
|
|
|
|
|
|
pagination={{
|
|
|
|
|
|
position: ['bottomCenter'],
|
|
|
|
|
|
defaultPageSize: 8,
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
|
|
<Modal title='留言详情' open={isModalOpen} onCancel={() => setIsModalOpen(false)} footer={null}>
|
|
|
|
|
|
<div className='pt-2 space-y-2'>
|
2024-10-19 19:58:09 +08:00
|
|
|
|
<div><b>留言时间:</b> {dayjs(+wall?.createTime!).format("YYYY-MM-DD HH:mm:ss")}</div>
|
2024-09-28 16:15:10 +08:00
|
|
|
|
<div><b>留言用户:</b> {wall?.name}</div>
|
|
|
|
|
|
<div><b>内容:</b> {wall?.content}</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Modal>
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default WallPage;
|