song-ui-u
Version:
vue3 + js的PC前端组件库
40 lines (37 loc) • 1.23 kB
JavaScript
import { getCurrentInstance, computed } from 'vue';
import { types } from '../../../../utils/types.mjs';
import 'song-ui-pro-icon';
function useCheckboxEvent({ props, model, checkboxGroupKey, isDisabled, isGroup, isLoading }) {
const { emit } = getCurrentInstance();
const changeEvent = (e) => {
emit("change", e.target.checked, e);
};
const beforeChange = computed(() => isGroup ? checkboxGroupKey?.beforeChange?.value : props.beforeChange);
const isBeforeChange = computed(() => types().isFunction(beforeChange.value));
const clickEvent = (e) => {
if (isBeforeChange.value || isDisabled.value || isLoading.value) {
const ev = e || window.event;
ev.preventDefault();
if (isBeforeChange.value && !isDisabled.value && !isLoading.value) {
isLoading.value = true;
beforeChange.value().then(() => {
updateData();
isLoading.value = false;
}).catch(() => {
isLoading.value = false;
});
}
return;
}
updateData();
};
const updateData = () => {
model.value = props.value;
};
return {
changeEvent,
clickEvent
};
}
export { useCheckboxEvent };
//# sourceMappingURL=use-checkbox-event.mjs.map