vxe-pc-ui
Version:
A vue based PC component library
63 lines (56 loc) • 2.17 kB
text/typescript
import { PropType, defineComponent, h, inject } from 'vue'
import { WidgetVxeInputFormObjVO } from './vxe-input-data'
import { useWidgetName } from '../../form-design/src/use'
import VxeFormItemComponent from '../../form/src/form-item'
import VxeInputComponent from '../../input/src/input'
import type { VxeGlobalRendererHandles, VxeFormViewConstructor, VxeFormViewPrivateMethods } from '../../../types'
export const WidgetVxeInputViewComponent = defineComponent({
props: {
renderOpts: {
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewOptions>,
default: () => ({})
},
renderParams: {
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewParams<WidgetVxeInputFormObjVO>>,
default: () => ({})
}
},
emits: [],
setup (props) {
const $xeFormView = inject<(VxeFormViewConstructor & VxeFormViewPrivateMethods) | null>('$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 { options } = widget
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(VxeInputComponent, {
modelValue: $xeFormView ? $xeFormView.getItemValue(widget) : null,
placeholder: options.placeholder,
onChange: changeEvent,
'onUpdate:modelValue' (val) {
if ($xeFormView) {
$xeFormView.setItemValue(widget, val)
}
}
})
}
})
}
}
})