|
@@ -1,17 +1,23 @@
|
|
|
|
|
+<!-- eslint-disable vue/no-mutating-props -->
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
import type { PropType } from 'vue'
|
|
import type { PropType } from 'vue'
|
|
|
-import type { BasicForm, BasicFormItem, AdvancedForm, AdvancedFormItem } from '@/types/form'
|
|
|
|
|
|
|
+import type { BasicFormItem } from '@/types/form'
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
|
|
|
+ modelValue: {
|
|
|
|
|
+ required: true
|
|
|
|
|
+ },
|
|
|
item: {
|
|
item: {
|
|
|
required: true,
|
|
required: true,
|
|
|
type: Object as PropType<BasicFormItem>
|
|
type: Object as PropType<BasicFormItem>
|
|
|
- },
|
|
|
|
|
- formData: {
|
|
|
|
|
- required: true,
|
|
|
|
|
- type: Object
|
|
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
+const emits = defineEmits(['update:modelValue'])
|
|
|
|
|
+
|
|
|
|
|
+const modelValue = computed({
|
|
|
|
|
+ get: () => props.modelValue,
|
|
|
|
|
+ set: value => emits('update:modelValue', value)
|
|
|
|
|
+})
|
|
|
|
|
|
|
|
const placeholder = (item: BasicFormItem) => {
|
|
const placeholder = (item: BasicFormItem) => {
|
|
|
if (['select'].includes(item.type)) {
|
|
if (['select'].includes(item.type)) {
|
|
@@ -25,17 +31,17 @@ const placeholder = (item: BasicFormItem) => {
|
|
|
<template>
|
|
<template>
|
|
|
<component
|
|
<component
|
|
|
:is="'el-' + item.type"
|
|
:is="'el-' + item.type"
|
|
|
- v-model="formData[item.name]"
|
|
|
|
|
|
|
+ v-model="modelValue"
|
|
|
v-bind="item.props"
|
|
v-bind="item.props"
|
|
|
:placeholder="item.placeholder || placeholder(item)"
|
|
:placeholder="item.placeholder || placeholder(item)"
|
|
|
>
|
|
>
|
|
|
<template v-if="item.type === 'radio-group'">
|
|
<template v-if="item.type === 'radio-group'">
|
|
|
- <el-radio :label="option.label" v-for="option in item.options" v-bind="option.props">
|
|
|
|
|
|
|
+ <el-radio :label="option.label" v-for="(option, index) in item.options" :key="index" v-bind="option.props">
|
|
|
{{ option.value }}
|
|
{{ option.value }}
|
|
|
</el-radio>
|
|
</el-radio>
|
|
|
</template>
|
|
</template>
|
|
|
<template v-if="item.type === 'checkbox-group'">
|
|
<template v-if="item.type === 'checkbox-group'">
|
|
|
- <el-checkbox :label="option.label" v-for="option in item.options" v-bind="option.props">
|
|
|
|
|
|
|
+ <el-checkbox :label="option.label" v-for="(option, index) in item.options" :key="index" v-bind="option.props">
|
|
|
{{ option.value }}
|
|
{{ option.value }}
|
|
|
</el-checkbox>
|
|
</el-checkbox>
|
|
|
</template>
|
|
</template>
|
|
@@ -43,7 +49,8 @@ const placeholder = (item: BasicFormItem) => {
|
|
|
<el-option
|
|
<el-option
|
|
|
:label="option.label"
|
|
:label="option.label"
|
|
|
:value="option.value"
|
|
:value="option.value"
|
|
|
- v-for="option in item.options"
|
|
|
|
|
|
|
+ v-for="(option, index) in item.options"
|
|
|
|
|
+ :key="index"
|
|
|
v-bind="option.props"
|
|
v-bind="option.props"
|
|
|
></el-option>
|
|
></el-option>
|
|
|
</template>
|
|
</template>
|