Browse Source

底部空行过滤

tianyunperfect 4 năm trước cách đây
mục cha
commit
3f64629962
1 tập tin đã thay đổi với 14 bổ sung2 xóa
  1. 14 2
      src/pages/Memory/components/UpdateForm.tsx

+ 14 - 2
src/pages/Memory/components/UpdateForm.tsx

@@ -86,16 +86,21 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
     back: '',
     front: '',
     id: undefined,
-    period: 0,
+    period: 0, onlyText: "",
     remindTime: new Date(),
     tag: '',
     updateTime: '',
     userId: 0,
-    ...props.values,
+    ...props.values
   });
 
   const {onCancel: hideModal, modalVisible} = props;
 
+  // 移除底部空白行
+  const removeEmptyLine = (text: string) => {
+    return text.replace(/(<p><br><\/p>)*$/g, '');
+  }
+
   const addHandle = async () => {
     /**
      * 判断
@@ -111,6 +116,13 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
     }
     setBtnDisable(true); // 禁用按钮
     let res;
+    // 移除底部空白行
+    setFormValues({
+      'front': removeEmptyLine(formValues.front),
+      'back': removeEmptyLine(formValues.back)
+    });
+
+    // 新增或者更新
     if (formValues.id !== undefined) {
       res = await service.update(formValues);
     } else {