Skip to content

Commit

Permalink
支增加表单设计器控件
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Jun 24, 2024
1 parent 9b36a02 commit 6fd9f1e
Show file tree
Hide file tree
Showing 25 changed files with 2,530 additions and 35 deletions.
10 changes: 6 additions & 4 deletions plugin-render-antd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ VxeUI.use(VxeUIPluginRenderAntd)
| optionGroups | 只对 name=ASelect 有效,下拉组件分组选项列表 | Array || [] |
| optionGroupProps | 只对 name=ASelect 有效,下拉组件分组选项属性参数配置 | Object || { options: 'options', label: 'label' } |
| events | 渲染组件附加事件,参数为 ( {row,rowIndex,column,columnIndex}, ...Component arguments ) | Object |||
| nativeEvents | 渲染组件附加事件,参数为 ( {row,rowIndex,column,columnIndex}, ...Component arguments ) | Object |||

### edit-render 可编辑渲染器配置项说明

Expand All @@ -52,7 +51,6 @@ VxeUI.use(VxeUIPluginRenderAntd)
| optionGroups | 只对 name=ASelect 有效,下拉组件分组选项列表 | Array || [] |
| optionGroupProps | 只对 name=ASelect 有效,下拉组件分组选项属性参数配置 | Object || { options: 'options', label: 'label' } |
| events | 渲染组件附加事件,参数为 ( {row,rowIndex,column,columnIndex}, ...Component arguments ) | Object |||
| nativeEvents | 渲染组件附加事件,参数为 ( {row,rowIndex,column,columnIndex}, ...Component arguments ) | Object |||

### filter-render 筛选渲染器配置项说明

Expand All @@ -65,7 +63,6 @@ VxeUI.use(VxeUIPluginRenderAntd)
| optionGroups | 只对 name=ASelect 有效,下拉组件分组选项列表 | Array || [] |
| optionGroupProps | 只对 name=ASelect 有效,下拉组件分组选项属性参数配置 | Object || { options: 'options', label: 'label' } |
| events | 渲染组件附加事件,参数为 ( {}, ...Component arguments ) | Object |||
| nativeEvents | 渲染组件附加事件,参数为 ( {}, ...Component arguments ) | Object |||

### item-render 表单-项选渲染器配置项说明

Expand All @@ -78,7 +75,12 @@ VxeUI.use(VxeUIPluginRenderAntd)
| optionGroups | 只对 name=ASelect 有效,下拉组件分组选项列表 | Array || [] |
| optionGroupProps | 只对 name=ASelect 有效,下拉组件分组选项属性参数配置 | Object || { options: 'options', label: 'label' } |
| events | 渲染组件附加事件,参数为 ( {}, ...Component arguments ) | Object |||
| nativeEvents | 渲染组件附加事件,参数为 ( {}, ...Component arguments ) | Object |||

### 表单设计器配置项

| 描述 |
|------|
| 'AInputWidget', 'ATextareaWidget', 'ANumberInputWidget', 'ADatePickerWidget', 'ASelectWidget', 'ARadioWidget', 'ACheckboxWidget', 'ASwitchWidget' |

## Cell demo

Expand Down
6 changes: 3 additions & 3 deletions plugin-render-antd/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vxe-ui/plugin-render-antd",
"version": "4.0.3",
"version": "4.0.4",
"description": "Vxe UI plug-in for compatibility with the ant-design-vue component.",
"scripts": {
"lib": "gulp build"
Expand Down Expand Up @@ -51,8 +51,8 @@
"typescript": "^4.6.4",
"vinyl-source-stream": "^2.0.0",
"vue": "^3.4.27",
"vxe-pc-ui": "^4.0.24",
"vxe-table": "^4.7.25"
"vxe-pc-ui": "^4.0.30",
"vxe-table": "^4.7.32"
},
"repository": {
"type": "git",
Expand Down
164 changes: 164 additions & 0 deletions plugin-render-antd/src/form-design/checkbox-widget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import { defineComponent, h, PropType, resolveComponent, ComponentOptions, computed } from 'vue'
import { useWidgetPropDataSource, WidgetDataSourceOptionObjVO } from './use'
import XEUtils from 'xe-utils'

import type { VxeUIExport, VxeGlobalRendererHandles, VxeFormComponent, VxeFormItemComponent, VxeSwitchComponent, VxeInputComponent } from 'vxe-pc-ui'

interface WidgetACheckboxFormObjVO {
options: WidgetDataSourceOptionObjVO[]
}

export function createWidgetACheckbox (VxeUI: VxeUIExport) {
const getWidgetACheckboxConfig = (params: VxeGlobalRendererHandles.CreateFormDesignWidgetConfigParams): VxeGlobalRendererHandles.CreateFormDesignWidgetConfigObj<WidgetACheckboxFormObjVO> => {
return {
title: '复选框',
icon: 'vxe-icon-checkbox-checked',
options: {
options: XEUtils.range(0, 3).map((v, i) => {
return {
value: VxeUI.getI18n('vxe.formDesign.widgetProp.dataSource.defValue', [i + 1])
}
})
}
}
}

const WidgetACheckboxFormComponent = defineComponent({
props: {
renderOpts: {
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewOptions>,
default: () => ({})
},
renderParams: {
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewParams<WidgetACheckboxFormObjVO>>,
default: () => ({})
}
},
emits: [],
setup (props) {
const VxeUIFormComponent = VxeUI.getComponent<VxeFormComponent>('VxeForm')
const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')
const VxeUISwitchComponent = VxeUI.getComponent<VxeSwitchComponent>('VxeSwitch')
const VxeUIInputComponent = VxeUI.getComponent<VxeInputComponent>('VxeInput')

const { renderDataSourceFormItem } = useWidgetPropDataSource(VxeUI, props, false)

return () => {
const { renderParams } = props
const { widget } = renderParams

return h(VxeUIFormComponent, {
class: 'vxe-form-design--widget-render-form-wrapper',
vertical: true,
span: 24,
titleBold: true,
titleOverflow: true,
data: widget.options
}, {
default () {
return [
h(VxeUIFormItemComponent, {
title: VxeUI.getI18n('vxe.formDesign.widgetProp.name')
}, {
default () {
return h(VxeUIInputComponent, {
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
}
})
}
}),
renderDataSourceFormItem()
]
}
})
}
}
})

const WidgetACheckboxViewComponent = defineComponent({
props: {
renderOpts: {
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewOptions>,
default: () => ({})
},
renderParams: {
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewParams<WidgetACheckboxFormObjVO>>,
default: () => ({})
}
},
emits: [],
setup (props) {
const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')

const checkboxOptions = computed(() => {
const { renderParams } = props
const { widget } = renderParams
const { options } = widget
return options.options.map(item => {
return {
label: item.value,
value: item.value
}
})
})

const changeEvent = () => {
const { renderParams } = props
const { widget, $formView } = renderParams
if ($formView) {
const itemValue = $formView ? $formView.getItemValue(widget) : null
$formView.updateItemStatus(widget, itemValue)
}
}

return () => {
const { renderParams } = props
const { widget, $formView } = renderParams

return h(VxeUIFormItemComponent, {
class: ['vxe-form-design--widget-render-form-item'],
field: widget.field,
title: widget.title
}, {
default () {
return h(resolveComponent('a-checkbox-group') as ComponentOptions, {
value: $formView ? $formView.getItemValue(widget) : null,
options: checkboxOptions.value,
onChange: changeEvent,
'onUpdate:value' (val: any) {
if ($formView) {
$formView.setItemValue(widget, val)
}
}
})
}
})
}
}
})

return {
getWidgetACheckboxConfig,
WidgetACheckboxFormComponent,
WidgetACheckboxViewComponent
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineComponent, h, PropType, resolveComponent, ComponentOptions } from 'vue'

import type { VxeUIExport, VxeGlobalRendererHandles, VxeFormComponent, VxeFormItemComponent, VxeSwitchComponent } from 'vxe-pc-ui'
import type { VxeUIExport, VxeGlobalRendererHandles, VxeFormComponent, VxeFormItemComponent, VxeSwitchComponent, VxeInputComponent } from 'vxe-pc-ui'

interface WidgetADatePickerFormObjVO {
placeholder: string
Expand Down Expand Up @@ -33,6 +33,7 @@ export function createWidgetADatePicker (VxeUI: VxeUIExport) {
const VxeUIFormComponent = VxeUI.getComponent<VxeFormComponent>('VxeForm')
const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')
const VxeUISwitchComponent = VxeUI.getComponent<VxeSwitchComponent>('VxeSwitch')
const VxeUIInputComponent = VxeUI.getComponent<VxeInputComponent>('VxeInput')

return () => {
const { renderParams } = props
Expand All @@ -52,7 +53,7 @@ export function createWidgetADatePicker (VxeUI: VxeUIExport) {
title: VxeUI.getI18n('vxe.formDesign.widgetProp.name')
}, {
default () {
return h(resolveComponent('a-date-picker') as ComponentOptions, {
return h(VxeUIInputComponent, {
modelValue: widget.title,
'onUpdate:modelValue' (val: any) {
widget.title = val
Expand Down Expand Up @@ -120,10 +121,10 @@ export function createWidgetADatePicker (VxeUI: VxeUIExport) {
}, {
default () {
return h(resolveComponent('a-date-picker') as ComponentOptions, {
modelValue: $formView ? $formView.getItemValue(widget) : null,
value: $formView ? $formView.getItemValue(widget) : null,
placeholder: options.placeholder,
onChange: changeEvent,
'onUpdate:modelValue' (val: any) {
'onUpdate:value' (val: any) {
if ($formView) {
$formView.setItemValue(widget, val)
}
Expand Down
75 changes: 71 additions & 4 deletions plugin-render-antd/src/form-design/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { h } from 'vue'
import { createWidgetAInput } from './a-input'
import { createWidgetADatePicker } from './a-date-picker'
import { createWidgetAInput } from './input-widget'
import { createWidgetATextarea } from './textarea-widget'
import { createWidgetAInputNumber } from './number-input-widget'
import { createWidgetADatePicker } from './date-picker-widget'
import { createWidgetASelect } from './select-widget'
import { createWidgetARadio } from './radio-widget'
import { createWidgetACheckbox } from './checkbox-widget'
import { createWidgetASwitch } from './switch-widget'

import type { VxeUIExport } from 'vxe-pc-ui'

Expand All @@ -9,10 +15,16 @@ import type { VxeUIExport } from 'vxe-pc-ui'
*/
export function defineFormDesignRender (VxeUI: VxeUIExport) {
const { getWidgetAInputConfig, WidgetAInputViewComponent, WidgetAInputFormComponent } = createWidgetAInput(VxeUI)
const { getWidgetATextareaConfig, WidgetATextareaViewComponent, WidgetATextareaFormComponent } = createWidgetATextarea(VxeUI)
const { getWidgetAInputNumberConfig, WidgetAInputNumberViewComponent, WidgetAInputNumberFormComponent } = createWidgetAInputNumber(VxeUI)
const { getWidgetADatePickerConfig, WidgetADatePickerViewComponent, WidgetADatePickerFormComponent } = createWidgetADatePicker(VxeUI)
const { getWidgetASelectConfig, WidgetASelectViewComponent, WidgetASelectFormComponent } = createWidgetASelect(VxeUI)
const { getWidgetARadioConfig, WidgetARadioViewComponent, WidgetARadioFormComponent } = createWidgetARadio(VxeUI)
const { getWidgetACheckboxConfig, WidgetACheckboxViewComponent, WidgetACheckboxFormComponent } = createWidgetACheckbox(VxeUI)
const { getWidgetASwitchConfig, WidgetASwitchViewComponent, WidgetASwitchFormComponent } = createWidgetASwitch(VxeUI)

VxeUI.renderer.mixin({
AInput: {
AInputWidget: {
createFormDesignWidgetConfig: getWidgetAInputConfig,
renderFormDesignWidgetView (renderOpts, renderParams) {
return h(WidgetAInputViewComponent, { renderOpts, renderParams })
Expand All @@ -21,14 +33,69 @@ export function defineFormDesignRender (VxeUI: VxeUIExport) {
return h(WidgetAInputFormComponent, { renderOpts, renderParams })
}
},
ADatePicker: {
ATextareaWidget: {
createFormDesignWidgetConfig: getWidgetATextareaConfig,
renderFormDesignWidgetView (renderOpts, renderParams) {
return h(WidgetATextareaViewComponent, { renderOpts, renderParams })
},
renderFormDesignWidgetFormView (renderOpts, renderParams) {
return h(WidgetATextareaFormComponent, { renderOpts, renderParams })
}
},
ANumberInputWidget: {
createFormDesignWidgetConfig: getWidgetAInputNumberConfig,
renderFormDesignWidgetView (renderOpts, renderParams) {
return h(WidgetAInputNumberViewComponent, { renderOpts, renderParams })
},
renderFormDesignWidgetFormView (renderOpts, renderParams) {
return h(WidgetAInputNumberFormComponent, { renderOpts, renderParams })
}
},
ADatePickerWidget: {
createFormDesignWidgetConfig: getWidgetADatePickerConfig,
renderFormDesignWidgetView (renderOpts, renderParams) {
return h(WidgetADatePickerViewComponent, { renderOpts, renderParams })
},
renderFormDesignWidgetFormView (renderOpts, renderParams) {
return h(WidgetADatePickerFormComponent, { renderOpts, renderParams })
}
},
ASelectWidget: {
createFormDesignWidgetConfig: getWidgetASelectConfig,
renderFormDesignWidgetView (renderOpts, renderParams) {
return h(WidgetASelectViewComponent, { renderOpts, renderParams })
},
renderFormDesignWidgetFormView (renderOpts, renderParams) {
return h(WidgetASelectFormComponent, { renderOpts, renderParams })
}
},
ARadioWidget: {
createFormDesignWidgetConfig: getWidgetARadioConfig,
renderFormDesignWidgetView (renderOpts, renderParams) {
return h(WidgetARadioViewComponent, { renderOpts, renderParams })
},
renderFormDesignWidgetFormView (renderOpts, renderParams) {
return h(WidgetARadioFormComponent, { renderOpts, renderParams })
}
},
ACheckboxWidget: {
createFormDesignWidgetConfig: getWidgetACheckboxConfig,
createFormDesignWidgetFieldValue: () => [],
renderFormDesignWidgetView (renderOpts: any, renderParams: any) {
return h(WidgetACheckboxViewComponent, { renderOpts, renderParams })
},
renderFormDesignWidgetFormView (renderOpts: any, renderParams: any) {
return h(WidgetACheckboxFormComponent, { renderOpts, renderParams })
}
},
ASwitchWidget: {
createFormDesignWidgetConfig: getWidgetASwitchConfig,
renderFormDesignWidgetView (renderOpts, renderParams) {
return h(WidgetASwitchViewComponent, { renderOpts, renderParams })
},
renderFormDesignWidgetFormView (renderOpts, renderParams) {
return h(WidgetASwitchFormComponent, { renderOpts, renderParams })
}
}
})
}
Loading

0 comments on commit 6fd9f1e

Please sign in to comment.