vxe-table
Version:
一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、模态窗口、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
82 lines (80 loc) • 2.16 kB
JavaScript
import { UtilTools } from '../../tools'
import XEUtils from 'xe-utils/ctor'
import GlobalConfig from '../../conf'
import vSize from '../../mixins/size'
export default {
name: 'VxeCheckbox',
mixins: [vSize],
props: {
value: Boolean,
label: [String, Number],
indeterminate: Boolean,
title: [String, Number],
content: [String, Number],
disabled: Boolean,
size: { type: String, default: () => GlobalConfig.checkbox.size || GlobalConfig.size }
},
inject: {
$xecheckboxgroup: {
default: null
}
},
computed: {
isGroup () {
return this.$xecheckboxgroup
},
isDisabled () {
return this.disabled || (this.isGroup && this.$xecheckboxgroup.disabled)
}
},
render (h) {
const { $slots, $xecheckboxgroup, isGroup, isDisabled, title, vSize, indeterminate, value, label, content } = this
const attrs = {}
if (title) {
attrs.title = title
}
return h('label', {
class: ['vxe-checkbox', {
[`size--${vSize}`]: vSize,
'is--indeterminate': indeterminate,
'is--disabled': isDisabled
}],
attrs
}, [
h('input', {
class: 'vxe-checkbox--input',
attrs: {
type: 'checkbox',
disabled: isDisabled
},
domProps: {
checked: isGroup ? XEUtils.includes($xecheckboxgroup.value, label) : value
},
on: {
change: this.changeEvent
}
}),
h('span', {
class: 'vxe-checkbox--icon'
}),
h('span', {
class: 'vxe-checkbox--label'
}, $slots.default || [UtilTools.getFuncText(content)])
])
},
methods: {
changeEvent (evnt) {
const { $xecheckboxgroup, isGroup, isDisabled, label } = this
if (!isDisabled) {
const checked = evnt.target.checked
const params = { checked, label, $event: evnt }
if (isGroup) {
$xecheckboxgroup.handleChecked(params)
} else {
this.$emit('input', checked)
this.$emit('change', params)
}
}
}
}
}