import { defineComponent, h, PropType, ComponentOptions } from 'vue' import { getCurrComponent } from '../util/comp' import type { VxeUIExport, VxeGlobalRendererHandles } from 'vxe-pc-ui' interface WidgetElInputFormObjVO { placeholder: string } export function createWidgetElInput (VxeUI: VxeUIExport) { const getWidgetElInputConfig = (params: VxeGlobalRendererHandles.CreateFormDesignWidgetConfigParams): VxeGlobalRendererHandles.CreateFormDesignWidgetConfigObj => { return { title: '输入框', icon: 'vxe-icon-input', options: { placeholder: '请输入' } } } const WidgetElInputFormComponent = defineComponent({ props: { renderOpts: { type: Object as PropType, default: () => ({}) }, renderParams: { type: Object as PropType>, default: () => ({}) } }, emits: [], setup (props) { const VxeUIFormComponent = VxeUI.getComponent('VxeForm') const VxeUIFormItemComponent = VxeUI.getComponent('VxeFormItem') const VxeUISwitchComponent = VxeUI.getComponent('VxeSwitch') return () => { const { renderParams } = props const { widget } = renderParams const { options } = widget return h(VxeUIFormComponent, { class: 'vxe-form-design--widget-render-form-wrapper', vertical: true, span: 24, titleBold: true, titleOverflow: true, data: options }, { default () { return [ h(VxeUIFormItemComponent, { title: VxeUI.getI18n('vxe.formDesign.widgetProp.name') }, { default () { return h(getCurrComponent('el-input') as ComponentOptions, { modelValue: widget.title, 'onUpdate:modelValue' (val: any) { widget.title = val } }) } }), h(VxeUIFormItemComponent, { title: VxeUI.getI18n('vxe.formDesign.widgetProp.placeholder'), field: 'placeholder', itemRender: { name: 'ElInput' } }), h(VxeUIFormItemComponent, { title: VxeUI.getI18n('vxe.formDesign.widgetProp.required') }, { default () { return h(VxeUISwitchComponent, { modelValue: widget.required, 'onUpdate:modelValue' (val: any) { widget.required = val } }) } }) ] } }) } } }) const WidgetElInputViewComponent = defineComponent({ props: { renderOpts: { type: Object as PropType, default: () => ({}) }, renderParams: { type: Object as PropType>, default: () => ({}) } }, emits: [], setup (props) { const VxeUIFormItemComponent = VxeUI.getComponent('VxeFormItem') const changeEvent = () => { const { renderParams } = props const { widget, $formView } = renderParams if ($formView) { const itemValue = $formView ? $formView.getItemValue(widget) : null $formView.updateWidgetStatus(widget, itemValue) } } return () => { const { renderParams } = props const { widget, $formView } = renderParams const { options } = widget return h(VxeUIFormItemComponent, { class: ['vxe-form-design--widget-render-form-item'], field: widget.field, title: widget.title }, { default () { return h(getCurrComponent('el-input') as ComponentOptions, { modelValue: $formView ? $formView.getItemValue(widget) : null, placeholder: options.placeholder, onChange: changeEvent, 'onUpdate:modelValue' (val: any) { if ($formView) { $formView.setItemValue(widget, val) } } }) } }) } } }) return { getWidgetElInputConfig, WidgetElInputFormComponent, WidgetElInputViewComponent } }