mirror of
https://github.com/fugary/simple-element-plus-template.git
synced 2025-11-12 14:27:49 +00:00
优化表单配置
This commit is contained in:
@@ -78,6 +78,23 @@ const modelValue = computed({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const childTypeMapping = { // 自动映射子元素类型,配置的时候可以不写type
|
||||||
|
'checkbox-group': 'checkbox',
|
||||||
|
'radio-group': 'radio',
|
||||||
|
select: 'option'
|
||||||
|
}
|
||||||
|
|
||||||
|
const children = computed(() => {
|
||||||
|
const option = props.option
|
||||||
|
const result = option.children || [] // 初始化一些默认值
|
||||||
|
result.forEach(childItem => {
|
||||||
|
if (!childItem.type) {
|
||||||
|
childItem.type = childTypeMapping[option.type]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -94,9 +111,9 @@ const modelValue = computed({
|
|||||||
:readonly="option.readonly"
|
:readonly="option.readonly"
|
||||||
@change="option.change"
|
@change="option.change"
|
||||||
>
|
>
|
||||||
<template v-if="option.children&&option.children.length">
|
<template v-if="children&&children.length">
|
||||||
<control-child
|
<control-child
|
||||||
v-for="(childItem, index) in option.children"
|
v-for="(childItem, index) in children"
|
||||||
:key="index"
|
:key="index"
|
||||||
:option="childItem"
|
:option="childItem"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { GlobalLayoutMode, GlobalLocales } from '@/consts/GlobalConstants'
|
import { GlobalLocales } from '@/consts/GlobalConstants'
|
||||||
import { useGlobalConfigStore } from '@/stores/GlobalConfigStore'
|
import { useGlobalConfigStore } from '@/stores/GlobalConfigStore'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { $i18nBundle } from '@/messages'
|
import { $i18nBundle } from '@/messages'
|
||||||
|
|||||||
@@ -28,12 +28,10 @@ const options = [
|
|||||||
},
|
},
|
||||||
children: [{
|
children: [{
|
||||||
labelKey: 'common.label.langCn',
|
labelKey: 'common.label.langCn',
|
||||||
value: GlobalLocales.CN,
|
value: GlobalLocales.CN
|
||||||
type: 'option'
|
|
||||||
}, {
|
}, {
|
||||||
labelKey: 'common.label.langEn',
|
labelKey: 'common.label.langEn',
|
||||||
value: GlobalLocales.EN,
|
value: GlobalLocales.EN
|
||||||
type: 'option'
|
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -46,12 +44,10 @@ const options = [
|
|||||||
},
|
},
|
||||||
children: [{
|
children: [{
|
||||||
labelKey: 'common.label.layoutLeft',
|
labelKey: 'common.label.layoutLeft',
|
||||||
value: GlobalLayoutMode.LEFT,
|
value: GlobalLayoutMode.LEFT
|
||||||
type: 'option'
|
|
||||||
}, {
|
}, {
|
||||||
labelKey: 'common.label.layoutTop',
|
labelKey: 'common.label.layoutTop',
|
||||||
value: GlobalLayoutMode.TOP,
|
value: GlobalLayoutMode.TOP
|
||||||
type: 'option'
|
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,6 +35,46 @@ const formOptions = [{
|
|||||||
value: '',
|
value: '',
|
||||||
placeholder: '选择出生日期',
|
placeholder: '选择出生日期',
|
||||||
required: true
|
required: true
|
||||||
|
}, {
|
||||||
|
label: '兴趣爱好',
|
||||||
|
type: 'checkbox-group',
|
||||||
|
prop: 'hobby',
|
||||||
|
value: '',
|
||||||
|
required: true,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
label: '编程',
|
||||||
|
value: 'program'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '吃饭',
|
||||||
|
value: 'eat'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '睡觉',
|
||||||
|
value: 'sleep'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
label: '性别',
|
||||||
|
type: 'radio-group',
|
||||||
|
prop: 'gender',
|
||||||
|
value: '',
|
||||||
|
required: true,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
label: '男',
|
||||||
|
value: 'male'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '女',
|
||||||
|
value: 'female'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '保密',
|
||||||
|
value: 'unknown'
|
||||||
|
}
|
||||||
|
]
|
||||||
}]
|
}]
|
||||||
const userDto = ref({
|
const userDto = ref({
|
||||||
userName: '',
|
userName: '',
|
||||||
|
|||||||
Reference in New Issue
Block a user