From d395a4d1c2d20ddbb255fa10dc34e6c4c694ad45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E9=98=B3?= <3311118881@qq.com> Date: Tue, 6 Aug 2024 21:02:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 15 +++- src/api/Article.ts | 9 +- src/api/Cate.ts | 9 +- src/api/Comment.ts | 9 +- src/api/File.ts | 7 +- src/api/Link.ts | 9 +- src/api/Swiper.ts | 9 +- src/api/Tag.ts | 9 +- src/components/Sidebar/index.tsx | 5 +- src/pages/Article/index.tsx | 148 +++++++++++++++++++++++++++++++ src/pages/Cate/index.tsx | 33 ++++--- 11 files changed, 217 insertions(+), 45 deletions(-) create mode 100644 src/pages/Article/index.tsx diff --git a/src/App.tsx b/src/App.tsx index 0d4838b..87e2f33 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,8 +6,9 @@ import PageTitle from './components/PageTitle'; import ECommerce from './pages/Dashboard/ECommerce'; import Create from './pages/Create'; import Cate from './pages/Cate'; -import DefaultLayout from './layout/DefaultLayout'; +import Article from './pages/Article'; import Login from './pages/Login'; +import DefaultLayout from './layout/DefaultLayout'; import useAuthRedirect from '@/hooks/useAuthRedirect'; @@ -15,7 +16,7 @@ import { ConfigProvider } from 'antd'; function App() { useAuthRedirect() - + const [loading, setLoading] = useState(true); const { pathname } = useLocation(); @@ -85,6 +86,16 @@ function App() { } /> + + + +
+ + } + /> )} diff --git a/src/api/Article.ts b/src/api/Article.ts index 6637c90..8cf5e55 100644 --- a/src/api/Article.ts +++ b/src/api/Article.ts @@ -17,10 +17,11 @@ export const editArticleDataAPI = (data: Article) => export const getArticleDataAPI = (id?: number) => Request
("GET", `/article/${id}`) // 获取文章列表 -export const getArticleListAPI = (page?: Page) => { - if (page) { - return Request>("GET", `/article?page=${page.page}&size=${page.size}`); +export const getArticleListAPI = (pagination?: Page) => { + if (pagination) { + const { page, size } = pagination + return Request>("GET", `/article?page=${page}&size=${size}`); } else { - return Request("GET", `/article`); + return Request("GET", `/article/all`); } }; diff --git a/src/api/Cate.ts b/src/api/Cate.ts index 6a880b8..3a03e2c 100644 --- a/src/api/Cate.ts +++ b/src/api/Cate.ts @@ -14,10 +14,11 @@ export const editCateDataAPI = (data: Cate) => Request("PATCH", "/cate", d export const getCateDataAPI = (id?: number) => Request("GET", `/cate/${id}`) // 获取分类列表 -export const getCateListAPI = (page?: Page) => { - if (page) { - return Request>("GET", `/cate?page=${page.page}&size=${page.size}`); +export const getCateListAPI = (pagination?: Page) => { + if (pagination) { + const { page, size } = pagination + return Request>("GET", `/cate?page=${page}&size=${size}`); } else { - return Request("GET", `/cate`); + return Request("GET", `/cate/all`); } }; diff --git a/src/api/Comment.ts b/src/api/Comment.ts index 9633798..707c107 100644 --- a/src/api/Comment.ts +++ b/src/api/Comment.ts @@ -16,10 +16,11 @@ export const editCommentDataAPI = (data: Comment) => Request("PATCH", " export const getCommentDataAPI = (id?: number) => Request>("GET", `/comment/${id}`) // 获取评论列表 -export const getCommentListAPI = (page?: Page) => { - if (page) { - return Request>("GET", `/comment?page=${page.page}&size=${page.size}`); +export const getCommentListAPI = (pagination?: Page) => { + if (pagination) { + const { page, size } = pagination + return Request>("GET", `/comment?page=${page}&size=${size}`); } else { - return Request("GET", `/comment`); + return Request("GET", `/comment/all`); } }; diff --git a/src/api/File.ts b/src/api/File.ts index 5f69d66..bc48925 100644 --- a/src/api/File.ts +++ b/src/api/File.ts @@ -10,9 +10,10 @@ export const editFileDataAPI = (data: File) => Request("PATCH", "/file", d export const getFileDataAPI = (id?: number) => Request>("GET", `/file/${id}`) // 获取文件列表 -export const getFileListAPI = (page?: Page) => { - if (page) { - return Request("GET", `/file?page=${page.page}&size=${page.size}`); +export const getFileListAPI = (pagination?: Page) => { + if (pagination) { + const { page, size } = pagination + return Request("GET", `/file?page=${page}&size=${size}`); } else { return Request("GET", `/file`); } diff --git a/src/api/Link.ts b/src/api/Link.ts index 9e21e6f..29146d9 100644 --- a/src/api/Link.ts +++ b/src/api/Link.ts @@ -14,10 +14,11 @@ export const editLinkDataAPI = (data: Link) => Request("PATCH", "/link", d export const getLinkDataAPI = (id?: number) => Request("GET", `/link/${id}`) // 获取网站列表 -export const getLinkListAPI = (page?: Page) => { - if (page) { - return Request>("GET", `/link?page=${page.page}&size=${page.size}`); +export const getLinkListAPI = (pagination?: Page) => { + if (pagination) { + const { page, size } = pagination + return Request>("GET", `/link?page=${page}&size=${size}`); } else { - return Request("GET", `/link`); + return Request("GET", `/link/all`); } }; diff --git a/src/api/Swiper.ts b/src/api/Swiper.ts index 26dc0ff..b72d468 100644 --- a/src/api/Swiper.ts +++ b/src/api/Swiper.ts @@ -14,10 +14,11 @@ export const editSwiperDataAPI = (data: Swiper) => Request("PATCH", "/sw export const getSwiperDataAPI = (id?: number) => Request("GET", `/swiper/${id}`) // 获取轮播图列表 -export const getSwiperListAPI = (page?: Page) => { - if (page) { - return Request>("GET", `/swiper?page=${page.page}&size=${page.size}`); +export const getSwiperListAPI = (pagination?: Page) => { + if (pagination) { + const { page, size } = pagination + return Request>("GET", `/swiper?page=${page}&size=${size}`); } else { - return Request("GET", `/swiper`); + return Request("GET", `/swiper/all`); } }; diff --git a/src/api/Tag.ts b/src/api/Tag.ts index e7809e2..f47f4a1 100644 --- a/src/api/Tag.ts +++ b/src/api/Tag.ts @@ -14,10 +14,11 @@ export const editTagDataAPI = (data: Tag) => Request("PATCH", "/tag", data) export const getTagDataAPI = (id?: number) => Request("GET", `/tag/${id}`) // 获取标签列表 -export const getTagListAPI = (page?: Page) => { - if (page) { - return Request>("GET", `/tag?page=${page.page}&size=${page.size}`); +export const getTagListAPI = (pagination?: Page) => { + if (pagination) { + const { page, size } = pagination + return Request>("GET", `/tag?page=${page}&size=${size}`); } else { - return Request("GET", `/tag`); + return Request("GET", `/tag/all`); } }; diff --git a/src/components/Sidebar/index.tsx b/src/components/Sidebar/index.tsx index a670d9a..9633e87 100644 --- a/src/components/Sidebar/index.tsx +++ b/src/components/Sidebar/index.tsx @@ -179,15 +179,16 @@ 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 Elements + 文章管理
  • +
  • { + const [loading, setLoading] = useState(false); + const [paginate, setPaginate] = useState>(); + + const getArticleList = async (pagination?: { page: number; size: number }) => { + setLoading(true); + const result = await getArticleListAPI(pagination); + console.log(result,888); + + // setPaginate(data as Paginate); + setLoading(false); + }; + + useEffect(() => { + getArticleList(); + }, []); + + const delArticleData = async (id: number) => { + setLoading(true); + + await delArticleDataAPI(id); + notification.success({ + message: '成功', + description: '🎉 删除文章成功', + }); + getArticleList({ page: paginate?.page!, size: paginate?.size! }); + + setLoading(false); + }; + + const colors = ['info', '', 'success', 'danger', 'warning']; + + const columns = [ + { + title: 'ID', + dataIndex: 'id', + key: 'id', + align: 'center' as const, + }, + { + title: '标题', + dataIndex: 'title', + key: 'title', + align: 'center' as const, + }, + { + title: '摘要', + dataIndex: 'description', + key: 'description', + align: 'center' as const, + render: (text: string) => (text ? text : '该文章暂未设置文章摘要'), + }, + { + title: '分类', + dataIndex: 'cate', + key: 'cate', + align: 'center' as const, + render: (cate: { name: string }[]) => {cate[0].name}, + }, + { + title: '标签', + dataIndex: 'tag', + key: 'tag', + align: 'center' as const, + render: (tag: string) => ( +
    + {tag + ? tag.split(',').map((item, index) => ( + + {item} + + )) + : 暂无标签} +
    + ), + }, + { + title: '浏览量', + dataIndex: 'view', + key: 'view', + align: 'center' as const, + }, + { + title: '评论数量', + dataIndex: 'comment', + key: 'comment', + align: 'center' as const, + }, + { + title: '发布时间', + dataIndex: 'createtime', + key: 'create_time', + align: 'center' as const, + render: (text: string) => dayjs(text).format('YYYY-MM-DD HH:mm:ss'), + }, + { + title: '操作', + key: 'action', + fixed: 'right' as const, + align: 'center' as const, + render: (text: string, record: Article) => ( +
    + + + {/* */} + + ( + delArticleData(record.id!)}> + + + ) +
    + ), + }, + ]; + + useEffect(() => { + getArticleList({ page: 1, size: 5 }) + }, []) + + 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'> + + + ); +}; + +export default ArticleManagement; \ No newline at end of file diff --git a/src/pages/Cate/index.tsx b/src/pages/Cate/index.tsx index 787a6c5..a538d1b 100644 --- a/src/pages/Cate/index.tsx +++ b/src/pages/Cate/index.tsx @@ -1,9 +1,12 @@ import React, { useState, useEffect, useRef } from 'react'; -import { Form, Input, Button, Tree, Modal, notification, Spin, Dropdown, Card, MenuProps } from 'antd'; -import { DownOutlined } from '@ant-design/icons'; -import { addCateDataAPI, delCateDataAPI, editCateDataAPI, getCateDataAPI, getCateListAPI } from '@/api/Cate'; -import Breadcrumb from '@/components/Breadcrumbs'; import { Cate } from '@/types/cate'; +import { addCateDataAPI, delCateDataAPI, editCateDataAPI, getCateDataAPI, getCateListAPI } from '@/api/Cate'; + +import Breadcrumb from '@/components/Breadcrumbs'; +import { DownOutlined } from '@ant-design/icons'; +import { MdOutlineKeyboardArrowDown, MdOutlineKeyboardArrowUp } from "react-icons/md"; +import { Form, Input, Button, Tree, Modal, notification, Spin, Dropdown, Card, MenuProps, Popconfirm } from 'antd'; + import "./index.scss" const CateManager: React.FC = () => { @@ -59,15 +62,13 @@ const CateManager: React.FC = () => { }); }; - const delCateData = (id: number) => { - // whetherToDelete(async () => { - // await delCateDataAPI(id); - // notification.success({ message: '🎉 删除分类成功' }); - // getCateList(); - // }, '分类'); + const delCateData = async (id: number) => { + await delCateDataAPI(id); + notification.success({ message: '🎉 删除分类成功' }); + getCateList(); }; - const close = () => { + const closeModel = () => { setModel(false); formRef.current.resetFields(); }; @@ -86,7 +87,11 @@ const CateManager: React.FC = () => { }, { key: '3', - label: delCateData(item.id!)}>删除, + label: ( + delCateData(item.id!)}> + 删除 + + ), }, ]; @@ -128,7 +133,7 @@ const CateManager: React.FC = () => { - +
    @@ -147,7 +152,7 @@ const CateManager: React.FC = () => { - +