浏览代码

富文本校验太麻烦了

shaogen1995 1 年之前
父节点
当前提交
b94ba71d9f
共有 2 个文件被更改,包括 13 次插入5 次删除
  1. 12 4
      src/components/ZRichTexts/index.tsx
  2. 1 1
      src/pages/A1event/A1add/index.tsx

+ 12 - 4
src/components/ZRichTexts/index.tsx

@@ -68,7 +68,9 @@ function ZRichTexts(
 
       const txtRes = txt.replaceAll(' ', '').replaceAll('</p><p>', '')
 
-      if (txtRes.split('></p>').length - 1 === 1 || txtRes === '') flag = true
+      if (txtRes === '') flag = true
+
+      if (txtRes.split('></p>').length - 1 === 1 && !txtRes.includes('class="media-')) flag = true
     } else {
       // 按章节发布  检查 所有的 标题 和富文本
       sectionArr.forEach((v, i) => {
@@ -76,7 +78,9 @@ function ZRichTexts(
         const txt: string = v.txt.toHTML()
 
         const txtRes = txt.replaceAll(' ', '').replaceAll('</p><p>', '')
-        if (txtRes.split('></p>').length - 1 === 1 || txtRes === '') flag = true
+        if (txtRes === '') flag = true
+
+        if (txtRes.split('></p>').length - 1 === 1 && !txtRes.includes('class="media-')) flag = true
       })
     }
 
@@ -252,8 +256,12 @@ function ZRichTexts(
       let flag = false
       if (!name && isSection) flag = true
       const txtRes: string = txt.toHTML()
-      if (txtRes.replaceAll('<p>', '').replaceAll('</p>', '').replaceAll(' ', '') === '')
-        flag = true
+      const txtRes2 = txtRes.replaceAll(' ', '').replaceAll('</p><p>', '')
+
+      if (txtRes2 === '') flag = true
+
+      if (txtRes2.split('></p>').length - 1 === 1 && !txtRes2.includes('class="media-')) flag = true
+
       return flag
     },
     [isSection]

+ 1 - 1
src/pages/A1event/A1add/index.tsx

@@ -146,7 +146,7 @@ function A1add({ editInfo, closeFu, editTableFu, addTableFu }: Props) {
       const rtf = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }
 
       // if (1 + 1 === 2) {
-      //   console.log('------', rtf)
+      //   console.log('------222', rtf)
       //   return
       // }