做了很多事

This commit is contained in:
宇阳
2024-09-02 16:58:20 +08:00
parent 303e14b7a8
commit b01cdf9b8a
4 changed files with 63 additions and 30 deletions

View File

@@ -17,12 +17,14 @@ export const editArticleDataAPI = (data: Article) =>
export const getArticleDataAPI = (id?: number) => Request<Article>("GET", `/article/${id}`) export const getArticleDataAPI = (id?: number) => Request<Article>("GET", `/article/${id}`)
// 获取文章列表 // 获取文章列表
export const getArticleListAPI = (data?: QueryData) => Request<Article[]>("POST", `/article/list`, { export const getArticleListAPI = (data?: QueryData) => {
data: { ...data?.query }, return Request<Article[]>("POST", `/article/list`, {
params: { data: { ...data?.query },
sort: data?.sort, params: {
} sort: data?.sort,
}) }
})
}
// 分页获取文章列表 // 分页获取文章列表
export const getArticlePagingAPI = (data?: QueryData) => Request<Paginate<Article[]>>("POST", `/article/paging`, { export const getArticlePagingAPI = (data?: QueryData) => Request<Paginate<Article[]>>("POST", `/article/paging`, {

View File

@@ -1,10 +1,10 @@
import { FileDir } from '@/types/app/file'; import { useRef, useState } from 'react';
import { InboxOutlined } from '@ant-design/icons'; import { InboxOutlined } from '@ant-design/icons';
import { message, Modal, Radio, Select, Spin } from 'antd'; import { message, Modal, Radio, Select, Spin } from 'antd';
import { useUserStore } from '@/stores'; import { useUserStore } from '@/stores';
import { FileDir } from '@/types/app/file';
import { baseURL } from '@/utils/request'; import { baseURL } from '@/utils/request';
import Compressor from 'compressorjs'; import Compressor from 'compressorjs';
import { useRef, useState } from 'react';
interface UploadFileProps { interface UploadFileProps {
dir: FileDir, dir: FileDir,

View File

@@ -59,15 +59,16 @@ const ArticlePage = () => {
dataIndex: 'title', dataIndex: 'title',
key: 'title', key: 'title',
align: 'center', align: 'center',
width: 250, width: 300,
render: (text: string) => <div className='line-clamp-1'>{text}</div>,
}, },
{ {
title: '摘要', title: '摘要',
dataIndex: 'description', dataIndex: 'description',
key: 'description', key: 'description',
align: 'center', align: 'center',
width: 400, width: 350,
render: (text: string) => (text ? text : '该文章暂未设置文章摘要'), render: (text: string) => <div className='line-clamp-2'>{text ? text : '该文章暂未设置文章摘要'}</div>,
}, },
{ {
title: '分类', title: '分类',
@@ -201,7 +202,7 @@ const ArticlePage = () => {
scroll={{ x: 'max-content' }} scroll={{ x: 'max-content' }}
pagination={{ pagination={{
position: ['bottomCenter'], position: ['bottomCenter'],
pageSize: 8 defaultPageSize: 8,
}} }}
/> />
</Card> </Card>

View File

@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { Spin, Card, message, Table, Popconfirm, Button, Tag, Modal } from 'antd'; import { Spin, Card, message, Table, Popconfirm, Button, Tag, Modal, Form, Input, DatePicker } from 'antd';
import { getCommentListAPI } from '@/api/Comment'; import { getCommentListAPI } from '@/api/Comment';
import { auditCommentDataAPI, delCommentDataAPI } from '@/api/Comment'; import { auditCommentDataAPI, delCommentDataAPI } from '@/api/Comment';
import { ColumnsType } from 'antd/es/table'; import { ColumnsType } from 'antd/es/table';
@@ -17,9 +17,10 @@ const CommentPage = () => {
const getCommentList = async () => { const getCommentList = async () => {
const { data } = await getCommentListAPI(); const { data } = await getCommentListAPI();
// 根据时间排序:最新时间在前 // 根据时间排序:最新时间在前
const sortedData = (data as Comment[]).sort((a, b) => +b.createTime - +a.createTime); // const sortedData = (data as Comment[]).sort((a, b) => +b.createTime - +a.createTime);
setList(sortedData as Comment[]) setList(data)
setLoading(false) setLoading(false)
} }
@@ -74,7 +75,8 @@ const CommentPage = () => {
title: '内容', title: '内容',
dataIndex: 'content', dataIndex: 'content',
key: 'content', key: 'content',
render: (text: string, record) => <span className="hover:text-primary cursor-pointer" onClick={() => { width: 400,
render: (text: string, record) => <span className="hover:text-primary cursor-pointer line-clamp-2" onClick={() => {
setComment(record) setComment(record)
setIsModalOpen(true) setIsModalOpen(true)
}}>{text}</span> }}>{text}</span>
@@ -89,12 +91,13 @@ const CommentPage = () => {
title: '所属文章', title: '所属文章',
dataIndex: 'articleTitle', dataIndex: 'articleTitle',
key: 'articleTitle', key: 'articleTitle',
render: (text: string) => (text ? text : '该评论暂未绑定文章'),
}, },
{ {
title: '评论时间', title: '评论时间',
dataIndex: 'createTime', dataIndex: 'createTime',
key: 'createTime', key: 'createTime',
render: (date: string) => dayjs(date).format('YYYY-MM-DD HH:mm:ss'), render: (date: string) => dayjs(+date).format('YYYY-MM-DD HH:mm:ss'),
}, },
{ {
title: '操作', title: '操作',
@@ -123,24 +126,51 @@ const CommentPage = () => {
}, },
]; ];
const { RangePicker } = DatePicker;
const onSubmit = async (values: FilterForm) => {
const query: FilterData = {
key: values.title ? values.title : null,
startDate: values.createTime ? values.createTime[0].valueOf() + '' : null,
endDate: values.createTime ? values.createTime[1].valueOf() + '' : null,
}
const { data } = await getCommentListAPI({ query });
}
return ( return (
<> <>
<Title value='评论管理' /> <Title value='评论管理' />
<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'>
<Input placeholder='请输入关键词' />
</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>
<Card className={`${titleSty} mt-2`}> <Card className={`${titleSty} mt-2`}>
<Spin spinning={loading} indicator={<svg />}> <Table
{list.length && <Table rowKey="id"
rowKey="id" dataSource={list}
dataSource={list} columns={columns}
columns={columns} loading={loading}
expandable={{ defaultExpandAllRows: true }} expandable={{ defaultExpandAllRows: true }}
scroll={{ x: 'max-content' }} scroll={{ x: 'max-content' }}
pagination={{ pagination={{
position: ['bottomCenter'], position: ['bottomCenter'],
pageSize: 8 defaultPageSize: 8,
}} }}
/>} />
</Spin>
</Card> </Card>
<Modal title='评论详情' open={isModalOpen} onCancel={() => setIsModalOpen(false)} footer={null}> <Modal title='评论详情' open={isModalOpen} onCancel={() => setIsModalOpen(false)} footer={null}>