UNPKG

birdpaper-ui

Version:

一个通用的 vue3 UI组件库。A common vue3 UI component library.

59 lines (58 loc) 1.78 kB
"use strict"; const vue = require("vue"); const birdpaperIcon = require("birdpaper-icon"); const _sfc_main = vue.defineComponent({ name: "Checkbox", props: { /** 绑定值 Binding value */ modelValue: { type: [Boolean, Array], default: false }, /** 是否禁用 Disabled or not */ disabled: { type: Boolean, default: false }, /** 复选框的值 */ value: { type: [String, Number] }, /** 是否为不确定状态 */ indeterminate: { type: Boolean, default: false } }, components: { IconCheckLine: birdpaperIcon.IconCheckLine, IconSubtractLine: birdpaperIcon.IconSubtractLine }, emits: ["update:modelValue", "change"], setup(props, { emit }) { const name = "bp-checkbox"; const cls = vue.computed(() => { let clsName = [name]; if (props.disabled) { clsName.push(`${name}-disabled`); } return clsName; }); const isCheck = vue.computed(() => { if (Array.isArray(props.modelValue)) { if (!props.value) return false; return props.modelValue.includes(props.value); } return props.modelValue; }); const handleClick = () => { if (props.disabled) return; if (Array.isArray(props.modelValue)) { if (!props.value) return false; let arr = JSON.parse(JSON.stringify(props.modelValue)); const index = arr.indexOf(props.value); index === -1 ? arr.push(props.value) : arr.splice(index, 1); emit("update:modelValue", arr); return emit("change", arr); } emit("update:modelValue", !props.modelValue); return emit("change", !props.modelValue); }; return { cls, name, isCheck, handleClick }; } }); module.exports = _sfc_main;