vhb-table
Version:
一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
93 lines (91 loc) • 2.57 kB
JavaScript
import { getFuncText } from '../../tools/utils'
import GlobalConfig from '../../v-h-b-table/src/conf'
export default {
name: 'VhbRadioButton',
props: {
value: [String, Number, Boolean],
label: [String, Number, Boolean],
title: [String, Number],
content: [String, Number],
disabled: Boolean,
strict: { type: Boolean, default: () => GlobalConfig.radioButton.strict },
size: { type: String, default: () => GlobalConfig.radioButton.size || GlobalConfig.size }
},
inject: {
$xeradiogroup: {
default: null
}
},
computed: {
vSize () {
return this.size || this.$parent.size || this.$parent.vSize
},
isDisabled () {
const { $xeradiogroup } = this
return this.disabled || ($xeradiogroup && $xeradiogroup.disabled)
},
isStrict () {
const { $xeradiogroup } = this
return $xeradiogroup ? $xeradiogroup.strict : this.strict
}
},
render (h) {
const { $scopedSlots, $xeradiogroup, isDisabled, title, vSize, value, label, content } = this
const attrs = {}
if (title) {
attrs.title = title
}
return h('label', {
class: ['vhb-radio', 'vhb-radio-button', {
[`size--${vSize}`]: vSize,
'is--disabled': isDisabled
}],
attrs
}, [
h('input', {
class: 'vhb-radio--input',
attrs: {
type: 'radio',
name: $xeradiogroup ? $xeradiogroup.name : null,
disabled: isDisabled
},
domProps: {
checked: $xeradiogroup ? $xeradiogroup.value === label : value === label
},
on: {
change: this.changeEvent,
click: this.clickEvent
}
}),
h('span', {
class: 'vhb-radio--label'
}, $scopedSlots.default ? $scopedSlots.default.call(this, {}) : [getFuncText(content)])
])
},
methods: {
handleValue (label, evnt) {
const { $xeradiogroup } = this
const params = { label, $event: evnt }
if ($xeradiogroup) {
$xeradiogroup.handleChecked(params)
} else {
this.$emit('input', label)
this.$emit('change', params)
}
},
changeEvent (evnt) {
const { isDisabled } = this
if (!isDisabled) {
this.handleValue(this.label, evnt)
}
},
clickEvent (evnt) {
const { $xeradiogroup, isDisabled, isStrict } = this
if (!isDisabled && !isStrict) {
if (this.label === ($xeradiogroup ? $xeradiogroup.value : this.value)) {
this.handleValue(null, evnt)
}
}
}
}
}