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