import {PropType} from '@peryl/react-compose'; export type iIsMatchParam = { option: any; value: any }; export type iIsMatch = (param: iIsMatchParam) => boolean; export const IsMatchPropsOption = { isMatch: { type: Function as PropType } /*判断值是否相等*/ } as const; export const createIsMatch = (props: { isMatch?: iIsMatch }): iIsMatch => props.isMatch || isObjectCommonMatch; /** * 判断两个对象是否相等,如果两个都是对象,仅判断公共的key的值是否都相等 * @author 韦胜健 * @date 2022/8/30 17:03 */ export const isObjectCommonMatch: iIsMatch = ({ option, value }) => { if (option != null && value !== null && typeof option === 'object' && typeof value === 'object') { const commonKeys = Object.keys(option).filter((key) => key in value); return commonKeys.length > 0 && commonKeys.every((key) => option[key] == value[key]); } else { return option == value; } };