|
<!--
* @Author: Devin
* @Date: 2023-02-17 15:37:24
* @LastEditors: Devin
* @LastEditTime: 2023-02-22 14:51:51
* @Description: 复杂表单:
1. 支持slot组件嵌入;
2. 支持动态组件插入;
3. 支持表单元素联动;
-->
<template>
<el-form label-width="auto" :inline="true">
<el-row :gutter="20">
<template v-for="(formItem, index) in complexForms" :key="index">
<!-- 判断是否存在联动隐藏表单元素 -->
<template v-if="formItem?.['childForms']">
<!-- 联动当前表单元素 -->
<el-col :span="formItem?.['span'] || 12">
<common-complex-form-item
:form-item="formItem"
:form-values="formValues"
>
<template v-if="formItem.slotName" #[formItem.slotName]="scope">
<slot :name="formItem.slotName" :row="scope['row']"></slot>
</template>
</common-complex-form-item>
</el-col>
<!-- 通过条件显示的表单元素 -->
<template v-if="formValues[formItem.name]">
<el-col
v-for="(child, childIdx) in formItem?.['childForms']?.[
formValues[formItem.name]
]"
:key="childIdx"
:span="child?.['span'] || 12"
>
<common-complex-form-item
:form-item="child"
:form-values="formValues"
>
<template v-if="formItem.slotName" #[formItem.slotName]="scope">
<slot :name="formItem.slotName" :row="scope['row']"></slot>
</template>
</common-complex-form-item>
</el-col>
</template>
</template>
<!-- 不存在联动表单元素时 -->
<template v-else>
<el-col :span="formItem?.['span'] || 12">
<common-complex-form-item
:form-item="formItem"
:form-values="formValues"
>
<template v-if="formItem.slotName" #[formItem.slotName]="scope">
<slot :name="formItem.slotName" :row="scope['row']"></slot>
</template>
</common-complex-form-item>
</el-col>
</template>
</template>
</el-row>
</el-form>
</template>
<script setup lang="ts">
import { defineProps } from 'vue';
import CommonComplexFormItem from './CommonComplexFormItem.vue';
defineProps({
complexForms: {
type: Array<any>,
default: () => []
},
formValues: {
type: Object,
default: () => {}
}
});
</script>
<script lang="ts">
export default {
name: 'CommonComplexForm'
};
</script>
<style scoped lang="scss"></style>
|