Jelajahi Sumber

垃圾富文本校验

shaogen1995 11 bulan lalu
induk
melakukan
1b83ea90f7
1 mengubah file dengan 13 tambahan dan 21 penghapusan
  1. 13 21
      src/components/ZRichTexts/index.tsx

+ 13 - 21
src/components/ZRichTexts/index.tsx

@@ -64,23 +64,18 @@ function ZRichTexts(
 
     // 不是按章节发布,检查第一个富文本
     if (!isSection) {
-      const txt = sectionArr[0].txt.toHTML()
-
-      const txtRes = txt.replaceAll(' ', '').replaceAll('</p><p>', '')
-
-      if (txtRes === '') flag = true
-
-      if (txtRes.split('></p>').length - 1 === 1 && !txtRes.includes('class="media-')) flag = true
+      const txt = sectionArr[0].txt.toText()
+      const txtHtml = sectionArr[0].txt.toHTML()
+      const txtRes = txt.replaceAll('\n', '').replaceAll(' ', '')
+      if (!txtRes && !txtHtml.includes('class="media-wrap')) flag = true
     } else {
       // 按章节发布  检查 所有的 标题 和富文本
-      sectionArr.forEach((v, i) => {
+      sectionArr.forEach(v => {
         if (!v.name) flag = true
-        const txt: string = v.txt.toHTML()
-
-        const txtRes = txt.replaceAll(' ', '').replaceAll('</p><p>', '')
-        if (txtRes === '') flag = true
-
-        if (txtRes.split('></p>').length - 1 === 1 && !txtRes.includes('class="media-')) flag = true
+        const txt = v.txt.toText()
+        const txtHtml = sectionArr[0].txt.toHTML()
+        const txtRes = txt.replaceAll('\n', '').replaceAll(' ', '')
+        if (!txtRes && !txtHtml.includes('class="media-wrap')) flag = true
       })
     }
 
@@ -255,13 +250,10 @@ function ZRichTexts(
     (name: string, txt: any) => {
       let flag = false
       if (!name && isSection) flag = true
-      const txtRes: string = txt.toHTML()
-      const txtRes2 = txtRes.replaceAll(' ', '').replaceAll('</p><p>', '')
-
-      if (txtRes2 === '') flag = true
-
-      if (txtRes2.split('></p>').length - 1 === 1 && !txtRes2.includes('class="media-')) flag = true
-
+      const txt2 = txt.toText()
+      const txtHtml = txt.toHTML()
+      const txtRes = txt2.replaceAll('\n', '').replaceAll(' ', '')
+      if (!txtRes && !txtHtml.includes('class="media-wrap')) flag = true
       return flag
     },
     [isSection]