/* eslint-disable @typescript-eslint/no-explicit-any */ import { mergeWith } from 'lodash'; export function separatePropsByDestruct>( props: T, componentDefaultProps?: Record, formItemDefaultProps?: Record ) { const { // FormItem 专有属性 name, control, rules, customError, showToast, label, labelStyle, checkboxLabel, labelWrapperStyle, labelContainerStyle, requiredMark, layout, message, messageWrapperStyle, showQuestionIcon, onClickQuestionIcon, triggerValidationOnChange, hideInternalMessage, fallbackValue, tooltip, notice, confirmButtonText, selectConfirmButtonText, style, // 其余属性作为组件属性 ...componentProps } = props; return { formItemProps: mergeWith( {}, formItemDefaultProps, { name, control, rules, customError, showToast, label, tooltip, labelStyle, labelWrapperStyle, labelContainerStyle, requiredMark, layout, message, messageWrapperStyle, showQuestionIcon, onClickQuestionIcon, triggerValidationOnChange, hideInternalMessage, fallbackValue, confirmButtonText, notice, style: { // 兼容 bingding 逻辑 backgroundColor: '#fff', ...style, }, }, (a, b) => { // 如果 b 是 undefined,则返回 a,否则返回 b return b === undefined ? a : b; } ), componentProps: { label: checkboxLabel, confirmButtonText: selectConfirmButtonText, ...(componentDefaultProps || {}), ...componentProps, }, }; }