|
|
@@ -1,92 +0,0 @@
|
|
|
-<script setup lang="ts">
|
|
|
-import type { AdvancedForm, FormSlot } from '@/types/form'
|
|
|
-import { containerTypes } from '@/utils/constants'
|
|
|
-import { buildFormSlots } from '@/utils/utils'
|
|
|
-
|
|
|
-interface Props {
|
|
|
- formConfig: AdvancedForm
|
|
|
- formData: any
|
|
|
- formSlots?: Array<FormSlot>
|
|
|
-}
|
|
|
-const props = defineProps<Props>()
|
|
|
-
|
|
|
-const formData = computed(() => {
|
|
|
- if (props.formData.id) {
|
|
|
- return props.formData
|
|
|
- } else {
|
|
|
- const res = props.formData
|
|
|
- props.formConfig?.formItems.forEach(item => {
|
|
|
- item.group.forEach(element => {
|
|
|
- if (containerTypes.includes(element.type)) {
|
|
|
- element.children?.forEach(tab => {
|
|
|
- tab.children?.forEach(child => {
|
|
|
- if (!child.notFormItem) {
|
|
|
- res[child.name] =
|
|
|
- res[child.name] !== undefined && child.value !== undefined ? res[child.name] : child.value
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- } else {
|
|
|
- if (!element.notFormItem) {
|
|
|
- // 避免修改当前表单项value重置其他表单项的value
|
|
|
- res[element.name] =
|
|
|
- res[element.name] !== undefined && element.value !== undefined ? res[element.name] : element.value
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- return res
|
|
|
- }
|
|
|
-})
|
|
|
-</script>
|
|
|
-
|
|
|
-<template>
|
|
|
- <el-card
|
|
|
- v-for="(item, index) in formConfig.formItems"
|
|
|
- :key="index"
|
|
|
- :header="item.label"
|
|
|
- class="mb-16px"
|
|
|
- shadow="never"
|
|
|
- >
|
|
|
- <el-row :gutter="20">
|
|
|
- <el-col :span="sub.span || formConfig.span || 12" v-for="(sub, key) in item.group" :key="key">
|
|
|
- <component
|
|
|
- :is="'el-' + sub.type"
|
|
|
- v-if="containerTypes.includes(sub.type)"
|
|
|
- v-model="sub.value"
|
|
|
- v-bind="sub.props"
|
|
|
- :children="sub.children"
|
|
|
- :formData="formData"
|
|
|
- :formConfig="formConfig"
|
|
|
- v-on="sub.events || {}"
|
|
|
- >
|
|
|
- <template #[slot.alias]="slotProps" v-for="slot in sub.slots" :key="slot.alias">
|
|
|
- <slot :name="slot.alias" v-bind="slotProps"></slot>
|
|
|
- </template>
|
|
|
- </component>
|
|
|
- <template v-else>
|
|
|
- <el-form-item :label="sub.label" :rules="sub.rules" :prop="sub.name" v-show="!sub.hidden">
|
|
|
- <form-comp :item="sub" v-model="formData[sub.name]">
|
|
|
- <template #[slot.alias]="slotProps" v-for="slot in sub.slots" :key="slot.alias">
|
|
|
- <slot :name="slot.alias" v-bind="slotProps"></slot>
|
|
|
- </template>
|
|
|
- </form-comp>
|
|
|
- </el-form-item>
|
|
|
- </template>
|
|
|
- <!-- <el-form-item :label="sub.label" :rules="sub.rules" :prop="sub.name">
|
|
|
- <form-comp :item="sub" v-model="formData[sub.name]">
|
|
|
- <template #[slot.alias]="slotProps" v-for="slot in sub.slots" :key="slot.alias">
|
|
|
- <slot :name="slot.alias" v-bind="slotProps"></slot>
|
|
|
- </template>
|
|
|
- </form-comp>
|
|
|
- </el-form-item> -->
|
|
|
- </el-col>
|
|
|
- </el-row>
|
|
|
- </el-card>
|
|
|
-</template>
|
|
|
-
|
|
|
-<style lang="scss" scoped>
|
|
|
-:deep(.el-select) {
|
|
|
- width: 100%;
|
|
|
-}
|
|
|
-</style>
|