tass-ui
Version:
A high quality UI Toolkit built on Vue.js3+.
40 lines (39 loc) • 1.18 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const useCheck = (props, state) => {
const { emit } = vue.getCurrentInstance();
const labelProps = vue.computed(() => props.props.props.label);
const keyProps = vue.computed(() => props.props.props.key);
const disabledProps = vue.computed(() => props.props.props.disabled);
const checkDisabled = vue.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];
}) : [];
};
vue.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);
}
);
vue.watch(
() => props.data,
() => {
state.allCheck = false;
}
);
return {
labelProps,
keyProps,
disabledProps,
handlerChange
};
};
exports.useCheck = useCheck;