添加内容过滤功能

This commit is contained in:
张成
2026-02-14 13:56:54 +08:00
parent 64f0267457
commit baa60bbfcb
6 changed files with 171 additions and 147 deletions

View File

@@ -11,7 +11,7 @@ import dayjs from "dayjs";
import classnames from "classnames";
import CommentServices from "@/services/commentServices";
import messageService from "@/services/messageService";
import { delay } from "@/utils";
import { delay, getBackendErrorMsg } from "@/utils";
import type {
BaseComment,
Comment,
@@ -459,36 +459,48 @@ export default forwardRef(function Comments(
}
async function createComment(val: string) {
const res = await CommentServices.createComment({ game_id, content: val });
if (res.code === 0) {
setComments((prev) => {
commentCountUpdateRef.current?.(prev.length + 1);
return [{ ...res.data, replies: [] }, ...prev];
});
toast("发布成功");
try {
const res = await CommentServices.createComment({ game_id, content: val });
if (res.code === 0) {
setComments((prev) => {
commentCountUpdateRef.current?.(prev.length + 1);
return [{ ...res.data, replies: [] }, ...prev];
});
toast("发布成功");
} else {
toast(getBackendErrorMsg(res, "评论失败"));
}
} catch (error) {
toast(getBackendErrorMsg(error, "评论失败"));
}
}
async function replyComment({ parent_id, reply_to_user_id, content }) {
const res = await CommentServices.replyComment({
parent_id,
reply_to_user_id,
content,
});
if (res.code === 0) {
setComments((prev) => {
return prev.map((item) => {
if (item.id === parent_id) {
return {
...item,
replies: [res.data, ...item.replies],
reply_count: item.reply_count + 1,
};
}
return item;
});
try {
const res = await CommentServices.replyComment({
parent_id,
reply_to_user_id,
content,
});
toast("回复成功");
if (res.code === 0) {
setComments((prev) => {
return prev.map((item) => {
if (item.id === parent_id) {
return {
...item,
replies: [res.data, ...item.replies],
reply_count: item.reply_count + 1,
};
}
return item;
});
});
toast("回复成功");
} else {
toast(getBackendErrorMsg(res, "回复失败"));
}
} catch (error) {
toast(getBackendErrorMsg(error, "回复失败"));
}
}

View File

@@ -18,7 +18,7 @@ import {
useProfessions,
useNtrpLevels,
} from "@/store/pickerOptionsStore";
import { formatNtrpDisplay } from "@/utils/helper";
import { formatNtrpDisplay, getBackendErrorMsg } from "@/utils/helper";
import { useGlobalState } from "@/store/global";
// 用户信息接口
@@ -252,8 +252,8 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
} catch (error) {
console.warn("保存失败:", error);
Taro.showToast({
title: "保存失败",
icon: "error",
title: getBackendErrorMsg(error, "保存失败"),
icon: "none",
});
}
};
@@ -295,8 +295,8 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
} catch (error) {
console.warn("保存失败:", error);
Taro.showToast({
title: "保存失败",
icon: "error",
title: getBackendErrorMsg(error, "保存失败"),
icon: "none",
});
}
};