element teble嵌套表单

呈现效果
以下代码是组件代码 并不是上图的代码 ,只是大致功能是一样的,emm 主要是table列表里面嵌套form表单 并有添加校验, 其余功能代码是组件传参 或其他逻辑使用的未用到可不用

<template>
    <div>
        <el-form :rules="rules" ref="tableForm" :model='tableDataForm'>
            <el-table class="area-info" border :data="tableDataForm.tableData" style="width: 100%">
                <el-table-column fixed prop="targetType" label="指标类型" width="130" show-overflow-tooltip>
                    <template #default="scope">
                        <el-form-item label=" " :prop="'tableData.' + scope.$index + '.targetType'" :rules="rules.targetType">
                            <el-select v-model="scope.row.targetType" placeholder="请选择">
                                <el-option v-for="(v,i) in index_typeList" :key="i" :label="v.label" :value="v.value" />
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column fixed prop="targetName" label="指标名称" width="200" show-overflow-tooltip>
                    <template #default="scope">
                        <el-form-item label=" " :prop="'tableData.' + scope.$index + '.targetName'" :rules="rules.targetName">
                            <el-input v-model="scope.row.targetName"  show-word-limit maxlength="50"/>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column fixed prop="targetCode" label="指标编码" width="120">
                    <template #default="scope">
                        <el-form-item label=" " :prop="'tableData.' + scope.$index + '.targetCode'" :rules="rules.targetCode">
                            <el-input v-model="scope.row.targetCode" />
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="unit" label="计量单位" width="120" show-overflow-tooltip>
                    <template #default="scope">
                        <el-form-item>
                            <el-select v-model="scope.row.unit" placeholder="请选择">
                                <el-option v-for="(v,i) in measuring_unit" :key="i" :label="v.label" :value="v.value" />
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="thresholdUp" label="一级阈值上限" width="120" show-overflow-tooltip>
                    <template #default="scope">
                        <el-form-item label=" " :prop="'tableData.' + scope.$index + '.thresholdUp'" :rules="rules.thresholdUp">
                            <el-input v-model="scope.row.thresholdUp" />
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="thresholdUp2" label="二级阈值上限" width="120" show-overflow-tooltip>
                    <template #default="scope">
                        <el-form-item label=" " :prop="'tableData.' + scope.$index + '.thresholdUp2'" :rules="rules.thresholdUp2">
                            <el-input v-model="scope.row.thresholdUp2" />
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="thresholdDown" label="一级阈值下限" width="120" show-overflow-tooltip>
                    <template #default="scope">
                        <el-form-item label=" " :prop="'tableData.' + scope.$index + '.thresholdDown'" :rules="rules.thresholdDown">
                            <el-input v-model="scope.row.thresholdDown" />
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="thresholdDown2" label="二级阈值下限" width="120" show-overflow-tooltip>
                    <template #default="scope">
                        <el-form-item label=" " :prop="'tableData.' + scope.$index + '.thresholdDown2'" :rules="rules.thresholdDown2">
                            <el-input v-model="scope.row.thresholdDown2" />
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="rangeUp" label="量程上限" width="120" show-overflow-tooltip>
                    <template #default="scope">
                        <el-form-item label=" " :prop="'tableData.' + scope.$index + '.rangeUp'" :rules="rules.rangeUp">
                            <el-input v-model="scope.row.rangeUp" />
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="rangeDown" label="量程下限" width="120" show-overflow-tooltip>
                    <template #default="scope">
                        <el-form-item label=" " :prop="'tableData.' + scope.$index + '.rangeDown'" :rules="rules.rangeDown">
                            <el-input v-model="scope.row.rangeDown" />
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="parameterDesc" label="指标描述" width="160" show-overflow-tooltip>
                    <template #default="scope">
                        <el-form-item>
                            <el-input v-model="scope.row.parameterDesc"  show-word-limit maxlength="100"/>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column fixed="right" prop="useArea" label="操作" width="70">
                    <template #default="scope">
                        <div>
                            <a @click="handleDel(scope.row,scope.$index)" class="operation delete">删除</a>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
        </el-form>
    </div>
</template>

<script setup>
    import { onBeforeMount, reactive, ref, getCurrentInstance, watch, nextTick, onMounted } from "vue";
    import { useRouter } from 'vue-router';
    const router = useRouter();
    const { proxy } = getCurrentInstance();
    const validation = proxy.validation;
    const props = defineProps({
        listData: [],
    });
    const tableDataForm = reactive({
        tableData: [],
    })
    const measuring_unit = ref([])
    const index_typeList=ref([])
    const rules = {
        targetType: [{ required: true, message: '请选择', trigger: ['blur', 'change'], }, ],
        targetName: [{ required: true, message: '请输入', trigger: ['blur', 'change'], },
            { validator: validation, check: ['empty', 'blank'] }
        ],
        targetCode: [{ required: true, message: '请输入', trigger: ['blur', 'change'], },
            { validator: validation, check: ['empty', 'blank'] }
        ],
        thresholdUp:[{ validator: validation, check: [ 'number-decimals'] }],
        thresholdUp2:[{ validator: validation, check: [ 'number-decimals'] }],
        thresholdDown:[{ validator: validation, check: [ 'number-decimals'] }],
        thresholdDown2:[{ validator: validation, check: [ 'number-decimals'] }],
        rangeUp:[{ validator: validation, check: [ 'number-decimals'] }],
        rangeDown:[{ validator: validation, check: [ 'number-decimals'] }],

    }

    watch(()=>props.listData,(n,o)=> {
        if(n && n.length && n.length!=0){
           tableDataForm.tableData=JSON.parse(JSON.stringify(n)) 
       
        }
    } ,{ immediate: true })
    const handleDel = (item, index) => {
        tableDataForm.tableData.splice(index, 1)
    }
    onMounted(()=>{
        getdictionariesList();
    })
    defineExpose({
        addList,
        saveForm
    });
    
    async function getdictionariesList() {
        await proxy.api.apiSelectDictMap({ key: 'index_type,measuring_unit' }).then((res) => {
            if (res.success) {
                index_typeList.value = res.data.index_type;
                measuring_unit.value=res.data.measuring_unit;
            }
        })
    }
    function addList() {
        tableDataForm.tableData.push({})
    }

    function saveForm() {
        proxy.$refs.tableForm.validate((valid, fields) => {
            if (valid) {
                // 业务逻辑操作代码...
                proxy.$emit('completed', tableDataForm.tableData, )
            }
        })
    }
</script>
<style  lang="less"  scoped>
:deep(.el-form-item__label){
    padding: 0 !important; 
}
:deep(.el-form-item){
    display: inline-flex !important;
}
</style>
  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
element表格是一种常见的用于展示和组织数据的形式,而嵌套表单则是在element表格中嵌入的一种特殊形式的表单嵌套表单是指在element表格的某一行或某一列中,以表单的形式进一步展示具体的数据或提供数据录入的功能。例如,在一个员工信息表格中,可以为每个员工提供一个嵌套表单,以展示或编辑他们的联系信息、薪资等详细数据。 使用element表格嵌套表单的好处包括: 1. 数据展示更加清晰:通过嵌套表单的方式,可以将详细的数据信息以表单的形式展示在表格的某一行或某一列中,使得数据的结构更加清晰,便于用户浏览和理解。 2. 方便数据编辑:通过嵌套表单,用户可以直接在表格中进行数据的编辑和更新,无需跳转到其他页面或打开弹窗,提高了数据的操作效率。 3. 紧凑的布局:嵌套表单可以将更多的数据信息以表单的形式收纳在表格中,不会占用额外的页面空间,使得整体布局更加紧凑,提升了页面的可用性和美观性。 4. 数据关联性强:通过嵌套表单,可以将不同表格中的相关数据进行关联,使得数据之间的联系更加明确和直观,方便用户进行跨表格的操作和分析。 总之,element表格嵌套表单是一种有效的数据展示和操作方式,可以提高用户对数据的理解和操作效率。它在各种管理系统、数据展示系统等场景中都有广泛的应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值