Skip to content

Let's use AI to Earn!

anquanjiance

bulaienaofutuojiesenzhang7182137eb07b
diff --git a/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx b/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx
index d98f8721..e458609d 100644
--- a/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx
+++ b/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx
@@ -26,7 +26,6 @@ import PubParmasTextareaUpload from "@/components/PublishDialog/compoents/PubPar
import { AccountPlatInfoMap, PlatType } from "@/app/config/platConfig";
import { PubType } from "@/app/config/publishConfig";
import { useTransClient } from "@/app/i18n/client";
-import { toolsApi } from "@/api/tools";
const { TextArea } = Input;
const { Dragger } = Upload;
@@ -86,9 +85,6 @@ const PubParmasTextarea = memo(
);
// 裁剪弹框
const [videoCoverSetingModal, setVideoCoverSetingModal] = useState(false);
- // 内容安全检测状态
- const [moderationLoading, setModerationLoading] = useState(false);
- const [moderationResult, setModerationResult] = useState<boolean | null>(null);
const textareaRef = useRef<TextAreaRef>(null);
const isFirst = useRef({
effect: true,
@@ -96,31 +92,6 @@ const PubParmasTextarea = memo(
});
const { t } = useTransClient("publish");
- // 内容安全检测函数
- const handleContentModeration = useCallback(async () => {
- if (!value.trim()) {
- message.warning("请先输入内容");
- return;
- }
-
- try {
- setModerationLoading(true);
- setModerationResult(null);
- const result = await toolsApi.textModeration(value);
- setModerationResult(result);
- if (result) {
- message.success(t("actions.contentSafe"));
- } else {
- message.warning(t("actions.contentUnsafe"));
- }
- } catch (error) {
- console.error("内容安全检测失败:", error);
- message.error("内容安全检测失败,请稍后重试");
- } finally {
- setModerationLoading(false);
- }
- }, [value, t]);
-
useEffect(() => {
if (isFirst.current.effect) {
isFirst.current.effect = false;
@@ -336,32 +307,6 @@ const PubParmasTextarea = memo(
}, 10);
}}
/>
- {value.trim() && (
- <div style={{ marginTop: 8, display: 'flex', alignItems: 'center', gap: 8 }}>
- <Button
- size="small"
- loading={moderationLoading}
- onClick={handleContentModeration}
- type={moderationResult === true ? "primary" : moderationResult === false ? "default" : "default"}
- style={{
- backgroundColor: moderationResult === true ? '#52c41a' : moderationResult === false ? '#ff4d4f' : undefined,
- borderColor: moderationResult === true ? '#52c41a' : moderationResult === false ? '#ff4d4f' : undefined,
- color: moderationResult === true || moderationResult === false ? '#fff' : undefined
- }}
- >
- {moderationLoading ? t("actions.checkingContent") : t("actions.contentModeration")}
- </Button>
- {moderationResult !== null && (
- <span style={{
- fontSize: 12,
- color: moderationResult ? '#52c41a' : '#ff4d4f',
- fontWeight: 500
- }}>
- {moderationResult ? t("actions.contentSafe") : t("actions.contentUnsafe")}
- </span>
- )}
- </div>
- )}
<ReactSortable
className="pubParmasTextarea-uploads"
list={imageFileList}
diff --git a/src/components/PublishDialog/index.tsx b/src/components/PublishDialog/index.tsx
index 4027a20b..dba3c14f 100644
--- a/src/components/PublishDialog/index.tsx
+++ b/src/components/PublishDialog/index.tsx
@@ -40,6 +40,7 @@ import { useTransClient } from "@/app/i18n/client";
import { apiGetMaterialGroupList, apiGetMaterialList } from "@/api/material";
import { getMediaGroupList, getMediaList } from "@/api/media";
import { getOssUrl } from "@/utils/oss";
+import { toolsApi } from "@/api/tools";
export interface IPublishDialogRef {
// 设置发布时间
@@ -109,8 +110,70 @@ const PublishDialog = memo(
);
const { errParamsMap } = usePubParamsVerify(pubListChoosed);
const [createLoading, setCreateLoading] = useState(false);
+ // 内容安全检测状态
+ const [moderationLoading, setModerationLoading] = useState(false);
+ const [moderationResult, setModerationResult] = useState<boolean | null>(null);
const { t } = useTransClient("publish");
+ // 内容安全检测函数
+ const handleContentModeration = useCallback(async () => {
+ // 获取当前描述内容
+ let contentToCheck = "";
+ if (step === 0 && pubListChoosed.length >= 2) {
+ contentToCheck = commonPubParams.des || "";
+ } else if (step === 1 && expandedPubItem) {
+ contentToCheck = expandedPubItem.params.des || "";
+ } else if (pubListChoosed.length === 1) {
+ contentToCheck = pubListChoosed[0].params.des || "";
+ }
+
+ if (!contentToCheck.trim()) {
+ message.warning("请先输入内容");
+ return;
+ }
+
+ try {
+ setModerationLoading(true);
+ setModerationResult(null);
+ const result = await toolsApi.textModeration(contentToCheck);
+ setModerationResult(!!result);
+ if (result) {
+ message.success("内容安全");
+ } else {
+ message.warning("内容不安全");
+ }
+ } catch (error) {
+ console.error("内容安全检测失败:", error);
+ message.error("内容安全检测失败,请稍后重试");
+ } finally {
+ setModerationLoading(false);
+ }
+ }, [step, pubListChoosed, commonPubParams, expandedPubItem, t]);
+
+ // 检查是否有描述内容
+ const hasDescription = useMemo(() => {
+ if (step === 0 && pubListChoosed.length >= 2) {
+ return !!(commonPubParams.des && commonPubParams.des.trim());
+ } else if (step === 1 && expandedPubItem) {
+ return !!(expandedPubItem.params.des && expandedPubItem.params.des.trim());
+ } else if (pubListChoosed.length === 1) {
+ return !!(pubListChoosed[0].params.des && pubListChoosed[0].params.des.trim());
+ }
+ return false;
+ }, [step, pubListChoosed, commonPubParams, expandedPubItem]);
+
+ // 监听内容变化,重置内容安全检测状态
+ useEffect(() => {
+ setModerationResult(null);
+ }, [commonPubParams.des, expandedPubItem?.params.des, pubListChoosed.map(item => item.params.des).join(',')]);
+
+ // 当内容被清空时,也重置检测状态
+ useEffect(() => {
+ if (!hasDescription) {
+ setModerationResult(null);
+ }
+ }, [hasDescription]);
+
// 草稿选择弹窗/数据
const [draftModalOpen, setDraftModalOpen] = useState(false);
const [groupLoading, setGroupLoading] = useState(false);
@@ -607,7 +670,7 @@ const PublishDialog = memo(
>
<PublishDialogDataPicker />
- <div className="publishDialog-footer-btns">
+ <div className="publishDialog-footer-btns" style={{ display: 'flex', flexDirection: 'row', gap: 12 }}>
{step === 0 && pubListChoosed.length >= 2 ? (
<Button
size="large"
@@ -621,31 +684,62 @@ const PublishDialog = memo(
</Button>
) : (
<>
- <Button size="large" onClick={closeDialog}>
- {t("buttons.cancelPublish")}
- </Button>
- <Button
- size="large"
- type="primary"
- loading={createLoading}
- onClick={() => {
- for (const [key, errVideoItem] of errParamsMap) {
- if (errVideoItem) {
- const pubItem = pubListChoosed.find(
- (v) => v.account.id === key,
- )!;
- if (step === 1) {
- setExpandedPubItem(pubItem);
+ <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
+ {moderationResult !== null && (
+ <span style={{
+ fontSize: 14,
+ color: moderationResult ? '#52c41a' : '#ff4d4f',
+ fontWeight: 500,
+ width: 100,
+ }}>
+ {moderationResult ? "内容安全" : "内容不安全"}
+ </span>
+ )}
+
+ {hasDescription && (
+ <Button
+ size="large"
+ loading={moderationLoading}
+ onClick={handleContentModeration}
+ type={moderationResult === true ? "primary" : moderationResult === false ? "default" : "default"}
+ style={{
+ backgroundColor: moderationResult === true ? '#52c41a' : moderationResult === false ? '#ff4d4f' : undefined,
+ borderColor: moderationResult === true ? '#52c41a' : moderationResult === false ? '#ff4d4f' : undefined,
+ color: moderationResult === true || moderationResult === false ? '#fff' : undefined
+ }}
+ >
+ {moderationLoading ? "检测中..." : "内容安全检测"}
+ </Button>
+ )}
+
+ </div>
+ <div style={{ display: 'flex', gap: 12 }}>
+ <Button size="large" onClick={closeDialog}>
+ {t("buttons.cancelPublish")}
+ </Button>
+ <Button
+ size="large"
+ type="primary"
+ loading={createLoading}
+ onClick={() => {
+ for (const [key, errVideoItem] of errParamsMap) {
+ if (errVideoItem) {
+ const pubItem = pubListChoosed.find(
+ (v) => v.account.id === key,
+ )!;
+ if (step === 1) {
+ setExpandedPubItem(pubItem);
+ }
+ message.warning(errVideoItem.parErrMsg);
+ return;
}
- message.warning(errVideoItem.parErrMsg);
- return;
}
- }
- pubClick();
- }}
- >
- {t("buttons.schedulePublish")}
- </Button>
+ pubClick();
+ }}
+ >
+ {t("buttons.schedulePublish")}
+ </Button>
+ </div>
</>
)}
</div>