UNPKG

tass-ui

Version:

A high quality UI Toolkit built on Vue.js3+.

40 lines (39 loc) 1.09 kB
import { getCurrentInstance, computed, watch } from "vue"; const useCheck = (props, state) => { const { emit } = getCurrentInstance(); const labelProps = computed(() => props.props.props.label); const keyProps = computed(() => props.props.props.key); const disabledProps = computed(() => props.props.props.disabled); const checkDisabled = computed(() => { return props.data.filter((item) => !item[disabledProps.value]); }); const handlerChange = (val) => { state.allCheck = val; state.checked = val ? checkDisabled.value.map((item) => { return item[keyProps.value]; }) : []; }; watch( () => state.checked, () => { const checkkeys = checkDisabled.value.map((item) => item[keyProps.value]); state.allCheck = checkkeys.length > 0 && checkkeys.every((key) => state.checked.includes(key)); emit("checkChange", state.checked); } ); watch( () => props.data, () => { state.allCheck = false; } ); return { labelProps, keyProps, disabledProps, handlerChange }; }; export { useCheck };