vxe-pc-ui
Version:
A vue based PC component library
53 lines (52 loc) • 1.94 kB
JavaScript
import { defineComponent, h, inject } from 'vue';
import { useWidgetName } from '../../form-design/src/use';
import VxeFormItemComponent from '../../form/src/form-item';
import VxeSwitchComponent from '../../switch/src/switch';
export const WidgetVxeSwitchViewComponent = defineComponent({
props: {
renderOpts: {
type: Object,
default: () => ({})
},
renderParams: {
type: Object,
default: () => ({})
}
},
emits: [],
setup(props) {
const $xeFormView = inject('$xeFormView', null);
const { computeKebabCaseName } = useWidgetName(props);
const changeEvent = () => {
const { renderParams } = props;
const { widget } = renderParams;
if ($xeFormView) {
const itemValue = $xeFormView ? $xeFormView.getItemValue(widget) : null;
$xeFormView.updateWidgetStatus(widget, itemValue);
}
};
return () => {
const { renderParams } = props;
const { widget } = renderParams;
const kebabCaseName = computeKebabCaseName.value;
return h(VxeFormItemComponent, {
class: ['vxe-form-design--widget-render-form-item', `widget-${kebabCaseName}`],
field: widget.field,
title: widget.title,
itemRender: {}
}, {
default() {
return h(VxeSwitchComponent, {
modelValue: $xeFormView ? $xeFormView.getItemValue(widget) : null,
onChange: changeEvent,
'onUpdate:modelValue'(val) {
if ($xeFormView) {
$xeFormView.setItemValue(widget, val);
}
}
});
}
});
};
}
});