From a4f4a7958c58de61cc3c480e259ed7e68f4dfd78 Mon Sep 17 00:00:00 2001 From: cumt-robin <1148121254@qq.com> Date: Thu, 14 Nov 2024 18:02:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20cra-react18=E9=A1=B9=E7=9B=AE=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AE=A1=E6=A0=B8=E8=AF=84=E8=AE=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #149 --- .changeset/small-cherries-teach.md | 7 + app/cra-react18/src/router/index.tsx | 4 + .../src/views/Backend/Comment/All.tsx | 4 +- .../src/views/Backend/Comment/Review.tsx | 161 ++++++++++++++++++ app/express-server/src/controllers/comment.js | 18 +- 5 files changed, 183 insertions(+), 11 deletions(-) create mode 100644 .changeset/small-cherries-teach.md create mode 100644 app/cra-react18/src/views/Backend/Comment/Review.tsx diff --git a/.changeset/small-cherries-teach.md b/.changeset/small-cherries-teach.md new file mode 100644 index 0000000..a6c4165 --- /dev/null +++ b/.changeset/small-cherries-teach.md @@ -0,0 +1,7 @@ +--- +"cra-react18": minor +"express-server": patch +--- + +feat: cra-react18项目增加审核评论功能 +fix: 后端审核评论参数approved校验错误 diff --git a/app/cra-react18/src/router/index.tsx b/app/cra-react18/src/router/index.tsx index b7444fe..afd439f 100644 --- a/app/cra-react18/src/router/index.tsx +++ b/app/cra-react18/src/router/index.tsx @@ -96,6 +96,10 @@ const routes: RouteObject[] = [ path: "all-comment", lazy: () => import("../views/Backend/Comment/All"), }, + { + path: "review-comment", + lazy: () => import("../views/Backend/Comment/Review"), + }, ], }, ]; diff --git a/app/cra-react18/src/views/Backend/Comment/All.tsx b/app/cra-react18/src/views/Backend/Comment/All.tsx index aa31594..fbef81f 100644 --- a/app/cra-react18/src/views/Backend/Comment/All.tsx +++ b/app/cra-react18/src/views/Backend/Comment/All.tsx @@ -36,7 +36,7 @@ export const Component = () => { }, }); - const handleGetArticleList = async () => { + const handleGetCommentList = async () => { const res = await commentService.pageAdmin({ pageNo: pagination.current as number, pageSize: pagination.pageSize as number, @@ -46,7 +46,7 @@ export const Component = () => { setPagination({ ...pagination, total: res.total }); }; - const { loading, trigger: search } = useAsyncLoading(handleGetArticleList, [pagination.current, pagination.pageSize], { + const { loading, trigger: search } = useAsyncLoading(handleGetCommentList, [pagination.current, pagination.pageSize], { initialLoading: true, }); diff --git a/app/cra-react18/src/views/Backend/Comment/Review.tsx b/app/cra-react18/src/views/Backend/Comment/Review.tsx new file mode 100644 index 0000000..4020bdf --- /dev/null +++ b/app/cra-react18/src/views/Backend/Comment/Review.tsx @@ -0,0 +1,161 @@ +import { Image, Space, Table, Button, message, Modal } from "antd"; +import { ColumnType, TablePaginationConfig } from "antd/es/table"; +import { useEffect, useState } from "react"; +import styled from "styled-components"; +import { NavLink } from "react-router-dom"; +import { useAsyncLoading } from "@/hooks/async"; +import { CommentDTO } from "@/bean/dto"; +import CommentAvatarFallback from "@/assets/img/comment-avatar.svg"; +import { format } from "@/utils/date-utils"; +import { commentService } from "@/services/comment"; +import { approvedFormatter } from "@/utils/formatter"; + +const Wrapper = styled.section` + padding: 20px; + background-color: #fff; +`; + +const Avatar = styled(Image)` + && { + width: 40px; + height: 40px; + border-radius: 100%; + } +`; + +export const Component = () => { + const [messageList, setMessageList] = useState([]); + + const [pagination, setPagination] = useState({ + current: 1, + pageSize: 10, + total: 0, + showTotal: (total) => `共计${total}条`, + onChange: (page, pageSize) => { + setPagination({ ...pagination, current: page, pageSize }); + }, + }); + + const handleGetCommentList = async () => { + const res = await commentService.pageNotApproved({ + pageNo: pagination.current as number, + pageSize: pagination.pageSize as number, + type: 1, // 1代表是文章评论 + }); + setMessageList(res.data); + setPagination({ ...pagination, total: res.total }); + }; + + const { loading, trigger: search } = useAsyncLoading(handleGetCommentList, [pagination.current, pagination.pageSize], { + initialLoading: true, + }); + + useEffect(() => { + search(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [pagination.current, pagination.pageSize]); + + const onCommitReview = async (record: CommentDTO, approved: 1 | 2) => { + Modal.confirm({ + title: `确认要执行${approved === 1 ? "通过" : "不通过"}操作吗?`, + onOk: async () => { + await commentService.review({ + id: record.id, + approved, + email: record.email, + content: record.content, + jump_url: record.jump_url, + }); + message.success("操作成功"); + search(); + }, + }); + }; + + const columns: ColumnType[] = [ + { + title: "昵称", + width: "120px", + dataIndex: "nick_name", + }, + { + title: "头像", + dataIndex: "avatar", + width: "132px", + render: (_, record) => { + return ; + }, + }, + { + title: "评论内容", + dataIndex: "content", + width: "180px", + }, + { + title: "评论的文章", + dataIndex: "article_name", + width: "180px", + render: (_, record) => { + return {record.article_name}; + }, + }, + { + title: "审核状态", + dataIndex: "approved", + width: "120px", + render: (_, record) => { + return approvedFormatter(record.approved ?? 0); + }, + }, + { + title: "邮箱", + dataIndex: "email", + width: "140px", + }, + { + title: "个人网站", + dataIndex: "site_url", + width: "160px", + }, + { + title: "创建时间", + dataIndex: "create_time", + width: "160px", + render: (value) => { + return format(value); + }, + }, + { + title: "操作", + width: "180px", + key: "action", + fixed: "right", + render: (_, record, index) => { + return ( + + + + + + ); + }, + }, + ]; + + return ( + +
+
+ ); +}; diff --git a/app/express-server/src/controllers/comment.js b/app/express-server/src/controllers/comment.js index 015860d..4f94fcb 100644 --- a/app/express-server/src/controllers/comment.js +++ b/app/express-server/src/controllers/comment.js @@ -55,7 +55,7 @@ router.get( code: "012001", data: [], }); - } + }, ); } res.send({ @@ -67,7 +67,7 @@ router.get( connection.release(); }); }); - } + }, ); /** @@ -106,7 +106,7 @@ router.post( }, (error) => { console.log("通知邮件发送失败", error); - } + }, ); res.send({ code: "0", @@ -120,9 +120,9 @@ router.post( code: "013001", msg: `${wd}失败`, }); - } + }, ); - } + }, ); /** @@ -200,7 +200,7 @@ router.get( }); } }); - } + }, ); /** @@ -210,7 +210,7 @@ router.put( "/review", [ body("id").isInt(), - body("approved").isIn([0, 1]).withMessage("must be 0 or 1"), + body("approved").isIn([1, 2]).withMessage("must be 1 or 2"), body("email").optional().isString(), body("jump_url").optional().isString(), body("email").optional().isString(), @@ -237,7 +237,7 @@ router.put( }); } }); - } + }, ); /** @@ -291,7 +291,7 @@ router.get( }); } }); - } + }, ); /**