首页 > 其他分享 >elementUI 多层结构动态生成el-form及校验

elementUI 多层结构动态生成el-form及校验

时间:2023-05-09 10:34:09浏览次数:32  
标签:el 频控 form title elementUI key 数据结构

如题,当整个el-form 都是通过多层数据结构循环渲染出来的表单,

那么每个el-form-item的prop和el-input、el-select等的v-model也是动态变量填充,

怎么样才能内嵌rules校验呢?

如下数据结构:

// form通过initData数据结构进行渲染
const initData = [
  {
    channel: 'sms',
    title: '短信频控',
    ref: 'smsFormRef',
    model: 'smsFreqObj',
    icon: 'el-icon-message',
    state: true, 
    lists: [
      {
        title: '全局频控',
        titTip: '',
        options: [
          {
            type: 'select',
            title: '频控分组',
            key: 'freqGroup',
            defaultVal: '0',
            placeholder: '请选择频控分组',
            options: [
              { code: '0', name: '默认频控' },
              { code: '1', name: '特殊策略' },
            ]
          },
          {
            type: 'input',
            key: 'freqConfig',
            defaultVal: [
              ['1', ''],
              ['7', '']
            ]
          }
        ]
      }
    ]
  }
]

// 表单数据收集
data(){
    return {
        freqObj: {
            smsFreqObj: {
                freqGroup: '',
                freqConfig: [
                  ["1", ""],
                  ['7', '']
                ],
            }
        }
    }
}
<template>
  <div class="frequency-list overflow-page">
    <el-card class="search-wrap el-card-8">
       // 折叠面板控件
      <el-collapse v-model="activeNames">
         // 从这里开始进入initData多层循环
        <el-collapse-item v-for="init in initData" :title="init.title" :name="init.channel">
           // 循环多个表单
          <el-form :inline="true" :disabled="init.state" :rules="freqRules" :ref="init.ref" :model="freqObj[init.model]" class="content-wrap" label-width="80px">
            <template v-for="list in init.lists">
              <p class="ctn-tit">
                <span>{{ list.title }}</span>
              </p>
              <template v-for="item in list.options">
                 // 重点来了,:prop 直接使用 当前的item.key,不需要要层层嵌套
                <el-form-item 
                  v-if="item.type === 'select'" 
                  :label="item.title" 
                  :prop="item.key"
                  :rules="{ required: true, message: '请选择频控分组', trigger: 'change' }"
                >
                   // v-model 动态变量
                  <el-select v-model="freqObj[init.model][item.key]" size="medium" :placeholder="item.placeholder">
                    <el-option v-for="option in item.options" :key="option.code" :label="option.name" :value="option.code"></el-option>
                  </el-select>
                </el-form-item>

                <div class="config-item" v-else-if="item.type === 'input'">
                  <div v-for="(config, idx) in item.defaultVal">
                    <span class="txt mr-10">每个用户</span>
                     // 重点来了,:prop 直接使用 当前的item.key + '.' + idx + '.0' ,注意这个数据结构为二维数组[ ['1', ''], ['7', ''] ]
                    <el-form-item 
                    :prop="item.key + '.' + idx + '.0' "
                    :rules="{ required: true, message: '请输入天数', trigger: 'blur' }"
                    >
                      <el-input placeholder="请输入" disabled clearable v-model.number="freqObj[init.model][item.key][idx][0]" size="medium" class="input-txt"></el-input>
                    </el-form-item>
                    <span class="txt mr-10">天内,最多接收</span>
                    <el-form-item 
                    :prop="item.key + '.' + idx + '.1' "
                      :rules="{ required: true, message: '请输入短信条数', trigger: 'blur' }"
                    >
                      <el-input placeholder="请输入" clearable v-model.number="freqObj[init.model][item.key][idx][1]" size="medium" class="input-txt"></el-input>
                    </el-form-item>
                    <span class="txt mr-10">条短信</span>
                  </div>
                </div>
              </template>
            </template>
          </el-form>
        </el-collapse-item>
      </el-collapse>
    </el-card>
  </div>
</template>

 

标签:el,频控,form,title,elementUI,key,数据结构
From: https://www.cnblogs.com/cp-cookie/p/17384119.html

相关文章

  • vue 导致el-menu高亮会失效的问题
    一个router转到另一个router常用的方法:this.$router.push({path:'',params:{}});this.$router.push({path:'',query:{}});这种方式传参都是可以接收到的。但是有个问题,导致中的el-menu不能高亮显示,进行跟踪以后会现:default-active与router的index都是一致。但就是不能高亮,除......
  • Laravel10 Auth 多用户(管理员、用户的区分)
    参考https://learnku.com/docs/laravel/10.x/authenticationmd/14876#retrieving-the-authenticated-user环境软件/系统版本说明windows10php8.1.9-Win32-vs16-x64composer2.5.5laravel10.8.0mysql8.0.28注意如果需要使用密码功能,还需......
  • 用DevExpress WinForms富文本编辑器,集成高级文本编辑功能(一)
    DevExpressWinForm富文本编辑器(RTF编辑器)控件允许用户将高级文本编辑功能集成到下一个WinForms项目中,它包括全面的文本格式选项、支持邮件合并,并附带了丰富的终端用户选项集,因此可以轻松交付受Microsoftword启发的功能。PS:DevExpressWinForm拥有180+组件和UI库,能为WindowsFor......
  • 高维数据惩罚回归方法:主成分回归PCR、岭回归、lasso、弹性网络elastic net分析基因数
    全文链接:http://tecdat.cn/?p=23378最近我们被客户要求撰写关于高维数据惩罚回归方法的研究报告,包括一些图形和统计输出。在本文中,我们将使用基因表达数据。这个数据集包含120个样本的200个基因的基因表达数据。这些数据来源于哺乳动物眼组织样本的微阵列实验1介绍在本文中,我......
  • Celery
    Celery一、什么是Celery?Celery是一个简单、灵活且可靠的,处理大量消息的分布式系统专注于实时处理的异步任务队列同时也支持任务调度二、Celery架构Celery的架构由三部分组成,消息中间件(messagebroker),任务执行单元(worker)和任务执行结果存储(taskresultstore)组成。1、消息中......
  • shell脚本
    1.检测httpd软件是否安装,没有的话则安装2.判断80端口的状态,未开启则重启  3. 4.编写监控脚本,如果根分区剩余空间小于10%内存的可用空间小于30%向用户egon发送告警邮件,邮件的内容包含使用率相关信息 5.检测指定的主机是否可以ping通,必须使用$1变量 6.判断一个......
  • Transformer 估算 101
    Transformer估算101 本文主要介绍用于估算transformer类模型计算量需求和内存需求的相关数学方法。引言其实,很多有关transformer语言模型的一些基本且重要的信息都可以用很简单的方法估算出来。不幸的是,这些公式在NLP社区中鲜为人知。本文的目的是总结这些公式,阐明......
  • 通过 PowerShell 删除所有running状态的flow
    我们经常会出现流出现多个running并且run不完的情况下。并且积攒过多会导致降速问题。所以我们可以通过powershell来运行cancel这些running状态运行。  首先我们要安装NPM,并且运行npmi-g@pnp/cli-microsoft365  安装成功之后,我们要登陆m365login 这里......
  • CodeForces - 630F Selection of Personnel (组合数学)
    TimeLimit: 500MS MemoryLimit: 65536KB 64bitIOFormat: %I64d&%I64uCodeForces-630FSelectionofPersonnelSubmit StatusDescriptionOnecompanyofITCitydecidedtocreateagroupofinnovativedevelopmentsconsistingfrom 5 to 7 peopleandhir......
  • LightOJ - 1058 Parallelogram Counting (数学几何&技巧)给n个点求组成平行四边形个数
    LightOJ-1058ParallelogramCountingTimeLimit: 2000MSMemoryLimit: 32768KB64bitIOFormat: %lld&%lluSubmit StatusDescriptionThereare n distinctpointsintheplane,givenbytheirintegercoordinates.Findthenumberofparallelogramswhosever......