UNPKG

yuang-framework-ui-pc

Version:

yuang-framework-ui-pc Library

44 lines (43 loc) 1.15 kB
import { inject } from "vue"; import { formItemContextKey } from "element-plus"; import { debugWarn } from "element-plus/es/utils/error"; function isEmptyValue(value, multiple) { const isNull = value == null || value === ""; return isNull || multiple && !value.length; } function valueIsChanged(value1, value2, multiple) { const isNull1 = isEmptyValue(value1); const isNull2 = isEmptyValue(value2); if (isNull1 && isNull2) { return false; } if (!multiple) { return isNull1 !== isNull2 || value1 !== value2; } const isEmpty1 = isNull1 || !value1.length; const isEmpty2 = isNull2 || !value2.length; if (isEmpty1 && isEmpty2) { return false; } if (isEmpty1 !== isEmpty2) { return true; } if (value1.length !== value2.length) { return true; } return value1.some((v) => !value2.includes(v)); } function useFormValidate() { const formItem = inject(formItemContextKey, null); const validateChange = () => { if (formItem != null) { formItem.validate("change").catch((e) => debugWarn(e)); } }; return { validateChange }; } export { isEmptyValue, useFormValidate, valueIsChanged };