Kaynağa Gözat

fix: 级联在表单模式下校验触发时机异常

lanjianrong 4 yıl önce
ebeveyn
işleme
9007270bb2

+ 3 - 1
src/components/EditableForm/src/editableFormItem.jsx

@@ -131,7 +131,8 @@ const EditableFormItem = ({
     }
   }
   const save = async e => {
-    const { value, local = '' } = e.currentTarget
+    console.log('1111', e)
+    const { value = null, local = '' } = e.currentTarget || {}
     // console.log(value)
     if (value === record || isNull(value)) {
       toggleEdit()
@@ -163,6 +164,7 @@ const EditableFormItem = ({
             popupVisible={true}
             showFooter={true}
             onBlur={save}
+            isEditFormItem
           />
         )
         break

+ 9 - 1
src/components/LazyCascader/LazyCascader.jsx

@@ -1,5 +1,6 @@
 import { getAuthCache } from '@/utils/auth'
 import { CASCADER_HISTORY_KEY } from '@/utils/cache/cacheEnum'
+import { isUnDef } from '@/utils/is'
 import { Cascader, Divider, Tag } from 'antd'
 import React, { forwardRef, useEffect, useState, useLayoutEffect } from 'react'
 import { connect } from 'umi'
@@ -18,6 +19,7 @@ const CLazyCascader = props => {
     showFooter = false,
     defaultValue,
     onBlur,
+    isEditFormItem,
     ...resetProps
   } = props
   const [visible, setVisible] = useState(popupVisible)
@@ -139,11 +141,17 @@ const CLazyCascader = props => {
 
   const handleOnPopupVisibleChange = e => {
     setVisible(e)
+    if (isUnDef(isEditFormItem)) {
+      return
+    }
     // 检测value是为了防止在Form里面的自定义级联组件失效
     // TODO: 自定义FormItem组件需要接受value以及onChange事件
-    if (value && !e && cValue === defaultValue) {
+    if ((!cValue && !e) || cValue === defaultValue) {
       triggerChange(null)
     }
+    // if (value && !e && cValue === defaultValue) {
+    //   triggerChange(null)
+    // }
   }
   return (
     <div className={[styles.cascader, 'Cascader-Body'].join(' ')}>