|
|
|
@ -4,7 +4,7 @@ import { ElForm, ElFormItem, ElRow, ElCol } from 'element-plus'
|
|
|
|
import { COMPONENT_MAP } from './componentMap'
|
|
|
|
import { COMPONENT_MAP } from './componentMap'
|
|
|
|
import { propTypes } from '@/utils/propTypes'
|
|
|
|
import { propTypes } from '@/utils/propTypes'
|
|
|
|
import { getSlot } from '@/utils/tsxHelper'
|
|
|
|
import { getSlot } from '@/utils/tsxHelper'
|
|
|
|
import { setTextPlaceholder } from './helper'
|
|
|
|
import { setTextPlaceholder, setGridProp } from './helper'
|
|
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'VForm',
|
|
|
|
name: 'VForm',
|
|
|
|
@ -43,39 +43,53 @@ export default defineComponent({
|
|
|
|
// 渲染包裹标签,是否使用栅格布局
|
|
|
|
// 渲染包裹标签,是否使用栅格布局
|
|
|
|
function renderWrap() {
|
|
|
|
function renderWrap() {
|
|
|
|
const content = isCol ? (
|
|
|
|
const content = isCol ? (
|
|
|
|
<ElRow gutter={20}>
|
|
|
|
<ElRow gutter={20}>{renderFormItemWrap()}</ElRow>
|
|
|
|
<ElCol>{renderFormItem()}</ElCol>
|
|
|
|
|
|
|
|
</ElRow>
|
|
|
|
|
|
|
|
) : (
|
|
|
|
) : (
|
|
|
|
renderFormItem()
|
|
|
|
renderFormItemWrap()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
console.log(content)
|
|
|
|
|
|
|
|
return content
|
|
|
|
return content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 渲染formItem
|
|
|
|
// 是否要渲染el-col
|
|
|
|
function renderFormItem() {
|
|
|
|
function renderFormItemWrap() {
|
|
|
|
// hidden属性表示隐藏
|
|
|
|
// hidden属性表示隐藏,不做渲染
|
|
|
|
return schema
|
|
|
|
return schema
|
|
|
|
.filter((v) => !v.hidden)
|
|
|
|
.filter((v) => !v.hidden)
|
|
|
|
.map((item) => {
|
|
|
|
.map((item) => {
|
|
|
|
return (
|
|
|
|
// 如果是 Divider 组件,需要自己占用一行
|
|
|
|
<ElFormItem {...(item.formItemProps || {})} prop={item.field} label={item.label}>
|
|
|
|
const isDivider = item.component === 'Divider'
|
|
|
|
{() => {
|
|
|
|
const Com = COMPONENT_MAP['Divider'] as ReturnType<typeof defineComponent>
|
|
|
|
const Com = COMPONENT_MAP[item.component as string] as ReturnType<
|
|
|
|
return isDivider ? (
|
|
|
|
typeof defineComponent
|
|
|
|
<Com {...{ contentPosition: 'left', ...item.componentProps }}>
|
|
|
|
>
|
|
|
|
{item?.componentProps?.text}
|
|
|
|
return (
|
|
|
|
</Com>
|
|
|
|
<Com v-model={test.value} {...(autoSetPlaceholder && setTextPlaceholder(item))}>
|
|
|
|
) : isCol ? (
|
|
|
|
{item.options ? renderOptions() : null}
|
|
|
|
// 如果需要栅格,需要包裹 ElCol
|
|
|
|
</Com>
|
|
|
|
<ElCol {...setGridProp(item.colProps)}>{renderFormItem(item)}</ElCol>
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
}}
|
|
|
|
renderFormItem(item)
|
|
|
|
</ElFormItem>
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 渲染formItem
|
|
|
|
|
|
|
|
function renderFormItem(item: VFormSchema) {
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<ElFormItem {...(item.formItemProps || {})} prop={item.field} label={item.label}>
|
|
|
|
|
|
|
|
{() => {
|
|
|
|
|
|
|
|
const Com = COMPONENT_MAP[item.component as string] as ReturnType<
|
|
|
|
|
|
|
|
typeof defineComponent
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<Com vModel={test.value} {...(autoSetPlaceholder && setTextPlaceholder(item))}>
|
|
|
|
|
|
|
|
{item.options ? renderOptions() : null}
|
|
|
|
|
|
|
|
</Com>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
</ElFormItem>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 渲染options
|
|
|
|
// 渲染options
|
|
|
|
function renderOptions() {
|
|
|
|
function renderOptions() {
|
|
|
|
// const optionsMap = ['Radio', 'Checkbox', 'Select']
|
|
|
|
// const optionsMap = ['Radio', 'Checkbox', 'Select']
|
|
|
|
|