diff --git a/config/unplugin/auto-import.ts b/config/unplugin/auto-import.ts index e80028b..91f9266 100644 --- a/config/unplugin/auto-import.ts +++ b/config/unplugin/auto-import.ts @@ -29,6 +29,7 @@ export function configAutoImport() { 'merge', 'debounce', 'isEqual', + 'isString' ], '@/hooks': ['useModal'], }, diff --git a/src/views/creative-generation-workshop/manuscript-writer/check/components/content-card/constants.ts b/src/views/creative-generation-workshop/manuscript-writer/check/components/content-card/constants.ts index 447141f..791942f 100644 --- a/src/views/creative-generation-workshop/manuscript-writer/check/components/content-card/constants.ts +++ b/src/views/creative-generation-workshop/manuscript-writer/check/components/content-card/constants.ts @@ -1,3 +1,7 @@ +export const escapeRegExp = (str: string) => { + return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +}; + export const FORM_RULES = { title: [{ required: true, message: '请输入标题' }], }; diff --git a/src/views/creative-generation-workshop/manuscript-writer/check/components/content-card/highlight-textarea.vue b/src/views/creative-generation-workshop/manuscript-writer/check/components/content-card/highlight-textarea.vue new file mode 100644 index 0000000..6d4535a --- /dev/null +++ b/src/views/creative-generation-workshop/manuscript-writer/check/components/content-card/highlight-textarea.vue @@ -0,0 +1,179 @@ + + + + + diff --git a/src/views/creative-generation-workshop/manuscript-writer/check/components/content-card/index.vue b/src/views/creative-generation-workshop/manuscript-writer/check/components/content-card/index.vue index 38326ed..7737510 100644 --- a/src/views/creative-generation-workshop/manuscript-writer/check/components/content-card/index.vue +++ b/src/views/creative-generation-workshop/manuscript-writer/check/components/content-card/index.vue @@ -20,7 +20,7 @@ import TextOverTips from '@/components/text-over-tips'; import 'swiper/css'; import 'swiper/css/navigation'; import { Navigation } from 'swiper/modules'; -import { FORM_RULES, enumTab, TAB_LIST, RESULT_LIST, LEVEL_MAP } from './constants'; +import { FORM_RULES, enumTab, TAB_LIST, RESULT_LIST, LEVEL_MAP, escapeRegExp } from './constants'; import { getImagePreSignedUrl } from '@/api/all/common'; import { EnumManuscriptType } from '@/views/creative-generation-workshop/manuscript/list/constants'; @@ -48,21 +48,36 @@ export default { emits: ['update:modelValue', 'filesChange', 'selectImage', 'againCheck', 'startCheck'], setup(props, { emit, expose }) { const activeTab = ref(enumTab.TEXT); - const aiCheckLoading = ref(false); + const aiReplaceLoading = ref(false); const formRef = ref(null); const uploadRef = ref(null); const modules = [Navigation]; const isTextTab = computed(() => activeTab.value === enumTab.TEXT); const aiReview = computed(() => props.modelValue.ai_review); + const isDisabled = computed(() => props.checkLoading || aiReplaceLoading.value); const onAiReplace = () => { - if (aiCheckLoading.value) return; + if (aiReplaceLoading.value) return; - aiCheckLoading.value = true; + aiReplaceLoading.value = true; setTimeout(() => { - aiCheckLoading.value = false; - }, 2000); + const content = props.modelValue.content; + const rules = aiReview.value?.violation_items ?? []; + const sortedRules = [...rules].sort((a, b) => b.word.length - a.word.length); + + const replacedContent = sortedRules.reduce((result, rule) => { + if (!rule.word || !rule.replace_word) return result; + + const escapedWord = escapeRegExp(rule.word); + const regex = new RegExp(escapedWord, 'g'); + + return result.replace(regex, rule.replace_word); + }, content); + + props.modelValue.content = replacedContent; + aiReplaceLoading.value = false; + }, 500); }; const onAgainCheck = () => { @@ -92,7 +107,7 @@ export default { const reset = () => { formRef.value?.resetFields?.(); formRef.value?.clearValidate?.(); - aiCheckLoading.value = false; + aiReplaceLoading.value = false; }; const getFileExtension = (filename) => { const match = filename.match(/\.([^.]+)$/); @@ -170,12 +185,12 @@ export default { const renderFooterRow = () => { return ( <> - {isTextTab.value ? ( -