VUE+TS使用elementUI的el-checkbox双重v-for循环做勾选

html部分

<template>
  <div class="hello">
    <el-form :model="elForm">
<!-- cities对象数组形式 -->
      <el-form-item v-for="(item, topIndex) in cities" :key="topIndex">
<!--item.checked 是每一个item的勾选状态,字段里可以没有  -->
        <el-checkbox class="textCheck" :indeterminate="item.indeterminate" v-model="item.checked" @change="onChangeTop(topIndex, item.tagParamId, $event, item)">{{ item.tagParamName }}</el-checkbox>
<!-- dialogCheckedCities是空对象,保存勾选的每一个子选项的数据集合 -->
        <el-checkbox-group v-model="dialogCheckedCities">
<!-- city.needAlarm子选项的needAlarm字段,true/false -->
          <el-checkbox v-for="city in item.tagKnowledgeRule" v-model="city.needAlarm" :key="city.tagKnowledgeId" :label="city" @change="onChangeSon(topIndex, city.tagKnowledgeId, item.tagParamId, $event, item, city)">{{ city.tagKnowledgeName }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
    <el-button @click="getArr">点击</el-button>
  </div>
</template>

data数据部分

 data() {
    return {
      cities: [
        {
          tagParamId: '1759763720885637120',
          tagParamName: '报警1',
          tagKnowledgeRule: [
            {
              tagKnowledgeId: 'fu1zi1',
              tagKnowledgeName: '统计报表',
              needAlarm: true
            },
            {
              tagKnowledgeId: 'fu1zi2',
              tagKnowledgeName: '统计',
              needAlarm: true
            },
            {
              tagKnowledgeId: 'fu1zi3',
              tagKnowledgeName: '报表',
              needAlarm: true
            }
          ]
        },
        {
          tagParamId: '报警2',
          tagParamName: '文字档案2',
          tagKnowledgeRule: [
            {
              tagKnowledgeId: 'fu2zi1',
              tagKnowledgeName: '好好学习',
              needAlarm: false
            },
            {
              tagKnowledgeId: 'fu2zi2',
              tagKnowledgeName: '学习',
              needAlarm: true
            }
          ]
        },
        {
          tagParamId: '报警3',
          tagParamName: '文字档案3',
          tagKnowledgeRule: [
            {
              tagKnowledgeId: 'fu3zi1',
              tagKnowledgeName: '上班',
              needAlarm: false
            },
            {
              tagKnowledgeId: 'fu3zi2',
              tagKnowledgeName: '一直上班',
              needAlarm: false
            }
          ]
        }
      ],
      dialogCheckedCities: [],
      elForm: {}
    }
  },

JS脚本部分/重要

<template>
  <div class="hello">
    <el-form :model="elForm">
      <el-form-item v-for="(item, topIndex) in cities" :key="topIndex">
        <el-checkbox class="textCheck" :indeterminate="item.indeterminate" v-model="item.checked" @change="onChangeTop(topIndex, item.tagParamId, $event, item)">{{ item.tagParamName }}</el-checkbox>
        <el-checkbox-group v-model="dialogCheckedCities">
          <el-checkbox v-for="city in item.tagKnowledgeRule" v-model="city.needAlarm" :key="city.tagKnowledgeId" :label="city" @change="onChangeSon(topIndex, city.tagKnowledgeId, item.tagParamId, $event, item, city)">{{ city.tagKnowledgeName }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
    <el-button @click="getArr">点击</el-button>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  mounted() {
    this.cities.forEach(item => {
      // 回显为true的数据
      item.tagKnowledgeRule.forEach(items => {
        if (items.needAlarm) {
          this.dialogCheckedCities.push(items)
        }
      })
      //回显全选
      item.checked = item.tagKnowledgeRule.every(ele => {
        return ele.needAlarm === true
      })
    })
  },
  data() {
    return {
      cities: [
        {
          tagParamId: '1759763720885637120',
          tagParamName: '报警1',
          tagKnowledgeRule: [
            {
              tagKnowledgeId: 'fu1zi1',
              tagKnowledgeName: '统计报表',
              needAlarm: true
            },
            {
              tagKnowledgeId: 'fu1zi2',
              tagKnowledgeName: '统计',
              needAlarm: true
            },
            {
              tagKnowledgeId: 'fu1zi3',
              tagKnowledgeName: '报表',
              needAlarm: true
            }
          ]
        },
        {
          tagParamId: '报警2',
          tagParamName: '文字档案2',
          tagKnowledgeRule: [
            {
              tagKnowledgeId: 'fu2zi1',
              tagKnowledgeName: '好好学习',
              needAlarm: false
            },
            {
              tagKnowledgeId: 'fu2zi2',
              tagKnowledgeName: '学习',
              needAlarm: true
            }
          ]
        },
        {
          tagParamId: '报警3',
          tagParamName: '文字档案3',
          tagKnowledgeRule: [
            {
              tagKnowledgeId: 'fu3zi1',
              tagKnowledgeName: '上班',
              needAlarm: false
            },
            {
              tagKnowledgeId: 'fu3zi2',
              tagKnowledgeName: '一直上班',
              needAlarm: false
            }
          ]
        }
      ],
      dialogCheckedCities: [],
      elForm: {}
    }
  },
  methods: {



    //点击的''全部''(全选)
    onChangeTop(index, tagParamId, e, item) {
      //点击的谁的下标,对应的id,点击的true/false状态,点击的这个对象所有的数据
      //父级change事件
      this.cities[index].checked = e 
      if (e == false) this.cities[index].indeterminate = false //去掉不确定状态

     //父级勾选后,子级全部勾选或者取消
	//这里注意是选取一级下的二级数据,也是所有子选项的数据集合
      var childrenArray = this.cities[index].tagKnowledgeRule 
	//某一个对象下子选项的数组集合长度
      // var len = childrenArray.length
	//如果某一个勾选的对象的checked状态为true,就是全选状态时
      if (this.cities[index].checked == true) {
        // 点击全选往v-model添加选中的
	//dialogCheckedCities里面把某一个对象下的二级子选项全部放入dialogCheckedCities里,这是点击全部,勾选全部子数据的
	// :label="city"  想控制全选要看你子选项的label绑定的是什么,此处我绑定的是对象,所以说下方要塞入对象
	//dialogCheckedCities是存放的勾选的数据,里面有什么,就勾什么
        for (var i = 0; i < childrenArray.length; i++) this.dialogCheckedCities.push(childrenArray[i])
      } else {
        //取消全选删除重复的id
	//从 this.dialogCheckedCities 中移除那些在 childrenArray 中存在的元素。
	//childrenArray.some() 意思是,如果有一项数据相同,返回true,保存,如果都不相同,返回false,过滤
	// !childrenArray.some() 意思是,如果有一项数据相同,返回false,都不相同,返回true
	//dialogCheckedCities的数据过滤,如果childrenArray里的数据和它的每一项都相同,返回false,表示不保存,直接过滤掉
        this.dialogCheckedCities = this.dialogCheckedCities.filter(item => !childrenArray.some(ele => ele === item))
      }
    },
    onChangeSon(topIndex, sonId, topId, e, item, city) {
      console.log('点击的儿子', topIndex, sonId, topId, e, item, city)
      //子级change事件
      var childrenArray = this.cities[topIndex].tagKnowledgeRule //这里注意是选取一级下的二级数据
      var tickCount = 0,
        unTickCount = 0,
        len = childrenArray.length
      console.log('选取一级下的二级数据', childrenArray)
      for (var i = 0; i < len; i++) {
        if (sonId == childrenArray[i].tagKnowledgeId) childrenArray[i].needAlarm = e
        if (childrenArray[i].needAlarm == true) tickCount++
        if (childrenArray[i].needAlarm == false) unTickCount++
      }
      if (tickCount == len) {
        //子级全勾选
        this.cities[topIndex].checked = true
        this.cities[topIndex].indeterminate = false
      } else if (unTickCount == len) {
        //子级全不勾选
        this.cities[topIndex].checked = false
        this.cities[topIndex].indeterminate = false
      } else {
        this.cities[topIndex].checked = false
        this.cities[topIndex].indeterminate = true //添加不确定状态
      }
    },







    getArr() {
      console.log('获取数据', this.dialogCheckedCities)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>

以下为本人使用到的

   <!-- 仪表报警 -->
          <div class="instrumentalarm">
            <div>仪表报警</div>
            <div class="instrumentalarm_content">
              <div>
                <span style="color:#ff5959">故障</span>
                /
                <span style="color:#6e87ff">信息</span>
                <span style="font-size: 15px;font-weight: normal;margin-left: 15px;">流量计点位知识库报警</span>
                <div style="margin-left:20px;overflow-x: auto;">
                  <div style="display:flex;justify-content: space-between;">
                    <div style="width:30%" v-for="(item, topIndex) in errInfoStateArr" :key="topIndex">
                      <el-checkbox :indeterminate="item.indeterminate" v-model="item.checked" @change="onChangeTop(topIndex, item.tagParamId, $event, item)">{{ item.tagParamName }}</el-checkbox>

                      <div style="overflow-y: scroll;overflow-x: hidden;height:245px">
                        <el-checkbox-group v-model="dialogCheckedCities">
                          <el-checkbox v-for="item2 in item.tagKnowledgeRule" :key="item2.tagKnowledgeId" :v-model="item2.needAlarm" :label="item2" @change="onChangeSon(topIndex, item2.tagKnowledgeId, item.tagParamId, $event, item, item2)">{{ item2.tagKnowledgeName }}</el-checkbox>
                        </el-checkbox-group>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

//进入页面获取接口数据时需要回显勾选状态
//this.dialogCheckedCities控制的,里面放的要是和label一样的,才勾选
this.errInfoStateArr.forEach((item) => {
      // 回显为true的数据
      item.tagKnowledgeRule.forEach((items) => {
        if (items.needAlarm) {
          this.dialogCheckedCities.push(items)
        }
      })
      //回显全选
      item.checked = item.tagKnowledgeRule.every((ele) => {
        return ele.needAlarm === true
      })
      //如果子选项有一个勾选了,true
      let checkstate = null
      checkstate = item.tagKnowledgeRule.some((ele) => {
        return ele.needAlarm === true
      })
      if (checkstate) {
        //把勾选了的数据push进instrumentalarmOption用于后续数据操作
        this.instrumentalarmOption.push(item)
      }
    })
private instrumentalarmOption: any[] = []

  private onChangeTop(index, tagParamId, e, item) {
    console.log('点击的全部', index, tagParamId, e, item)
    //父级change事件
    this.errInfoStateArr[index].checked = e //父级勾选后,子级全部勾选或者取消
    if (e == false) this.errInfoStateArr[index].indeterminate = false //去掉不确定状态

    var childrenArray = this.errInfoStateArr[index].tagKnowledgeRule //这里注意是选取一级下的二级数据
    // var len = childrenArray.length
    if (this.errInfoStateArr[index].checked == true) {
      // 点击全选往v-model添加选中的
      for (var i = 0; i < childrenArray.length; i++) this.dialogCheckedCities.push(childrenArray[i])
    } else {
      //取消全选删除重复的id
      this.dialogCheckedCities = this.dialogCheckedCities.filter((item) => !childrenArray.some((ele) => ele === item))
    }
    // 如果勾选了,为true
    if (item.checked) {
      // 把里面所有对象的needAlarm变为true
      item.tagKnowledgeRule.forEach((item2) => {
        item2.needAlarm = true
      })

      const index = this.instrumentalarmOption.findIndex((ele) => ele.tagParamName === item.tagParamName)
      if (index !== -1) {
        // 如果存在,则替换该对象
        this.instrumentalarmOption.splice(index, 1, item)
      } else {
        // 如果不存在,则添加新对象到数组中
        this.instrumentalarmOption.push(item)
      }
    } else {
      item.tagKnowledgeRule.forEach((item2) => {
        item2.needAlarm = false
      })
      const index = this.instrumentalarmOption.findIndex((ele) => ele.tagParamName === item.tagParamName)
      if (index !== -1) {
        // 如果存在,则替换该对象
        this.instrumentalarmOption.splice(index, 1, item)
      } else {
        // 如果不存在,则添加新对象到数组中
        this.instrumentalarmOption.push(item)
      }
    }
  }

  private onChangeSon(topIndex, sonId, topId, e, item, city) {
    console.log('点击的子', e, item, city)
    //子级change事件
    var childrenArray = this.errInfoStateArr[topIndex].tagKnowledgeRule //这里注意是选取一级下的二级数据
    var tickCount = 0,
      unTickCount = 0,
      len = childrenArray.length
    for (var i = 0; i < len; i++) {
      if (sonId == childrenArray[i].tagKnowledgeId) childrenArray[i].needAlarm = e
      if (childrenArray[i].needAlarm == true) tickCount++
      if (childrenArray[i].needAlarm == false) unTickCount++
    }
    if (tickCount == len) {
      //子级全勾选
      // this.instrumentalarmOption = []
      this.errInfoStateArr[topIndex].checked = true
      this.errInfoStateArr[topIndex].indeterminate = false
      const index = this.instrumentalarmOption.findIndex((ele) => ele.tagParamName === item.tagParamName)
      if (index !== -1) {
        // 如果存在,则替换该对象
        this.instrumentalarmOption.splice(index, 1, item)
      } else {
        // 如果不存在,则添加新对象到数组中
        this.instrumentalarmOption.push(item)
      }
      // this.instrumentalarmOption.push(item)
    } else if (unTickCount == len) {
      //子级全不勾选
      this.errInfoStateArr[topIndex].checked = false
      this.errInfoStateArr[topIndex].indeterminate = false
      const index = this.instrumentalarmOption.findIndex((ele) => ele.tagParamName === item.tagParamName)
      if (index !== -1) {
        // 如果存在,则替换该对象
        this.instrumentalarmOption.splice(index, 1, item)
      } else {
        // 如果不存在,则添加新对象到数组中
        this.instrumentalarmOption.push(item)
      }
    } else {
      this.errInfoStateArr[topIndex].checked = false
      this.errInfoStateArr[topIndex].indeterminate = true //添加不确定状态
    }
    // 判断数组中是否已存在与新对象某个字段相同的对象
    const index = this.instrumentalarmOption.findIndex((ele) => ele.tagParamName === item.tagParamName)
    if (index !== -1) {
      // 如果存在,则替换该对象
      this.instrumentalarmOption.splice(index, 1, item)
    } else {
      // 如果不存在,则添加新对象到数组中
      this.instrumentalarmOption.push(item)
    }

   
  }

一整块代码

<template>
  <el-dialog :show-close="false" title="报警规则" :visible.sync="alarmRuleVisible" top="0px" width="80%" center :close-on-click-modal="false" destroy-on-close append-to-body>
    <!-- 中间高度 -->
    <div class="alarmMain">
      <!-- 左侧规则 -->
      <div class="alarmRule">
        <div class="alarmRule_title">报警规则</div>
        <div class="alarmRule_contetn">
          <!-- 通讯报警 -->
          <div class="communicationalarm">
            <div>通讯报警</div>

            <el-checkbox v-model="connectionAlarmState" style="color:#c50b0b">断开</el-checkbox>
            <el-checkbox v-model="communicationdkAlarm" style="color:#ed5f00">通讯中断</el-checkbox>
            <div>
              <span style="margin-left:25px;font-size:15px;font-weight:normal">采集站无法连接到网关</span>
              <span style="margin-left:35px;font-size:15px;font-weight:normal">网关未能连接到流量计</span>
            </div>

            <!-- <div class="disconnect">
              <div>断开</div>
            </div> -->
          </div>
          <!-- 仪表报警 -->
          <div class="instrumentalarm">
            <div>仪表报警</div>
            <div class="instrumentalarm_content">
              <div>
                <span style="color:#ff5959">故障</span>
                /
                <span style="color:#6e87ff">信息</span>
                <span style="font-size: 15px;font-weight: normal;margin-left: 15px;">流量计点位知识库报警</span>
                <div style="margin-left:20px;overflow-x: auto;">
                  <div style="display:flex;justify-content: space-between;">
                    <div style="width:30%" v-for="(item, topIndex) in errInfoStateArr" :key="topIndex">
                      <el-checkbox :indeterminate="item.indeterminate" v-model="item.checked" @change="onChangeTop(topIndex, item.tagParamId, $event, item)">{{ item.tagParamName }}</el-checkbox>

                      <div style="overflow-y: scroll;overflow-x: hidden;height:245px">
                        <el-checkbox-group v-model="dialogCheckedCities">
                          <el-checkbox v-for="item2 in item.tagKnowledgeRule" :key="item2.tagKnowledgeId" :v-model="item2.needAlarm" :label="item2" @change="onChangeSon(topIndex, item2.tagKnowledgeId, item.tagParamId, $event, item, item2)">{{ item2.tagKnowledgeName }}</el-checkbox>
                        </el-checkbox-group>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!-- 系统预警 -->
          <div class="systemwarning">
            <div>系统预警</div>
            <div class="systemwarning_content">
              <div>
                <span style="color:#ed0f5d">系数异常</span>
                <span style="font-size: 15px;font-weight: normal;margin-left: 15px;">流量计系数或组态参数发生改变</span>

                <div style="margin-left:20px;height:100px">
                  <div style="margin: 15px 0;"></div>
                  <!-- id="checkbox-container" -->
                  <el-checkbox-group v-model="systemwarningOption" @change="handleCheckedsystemwarning">
                    <el-checkbox v-for="item in coefficientAnomalyArr" :label="item.tagParamName" :key="item.tagParamId">
                      {{ item.tagParamName }}
                      &nbsp;&nbsp;&nbsp;
                      <span>设定值:</span>
                      <el-input v-model="item.settingValue" placeholder="请输入内容"></el-input>
                      <!-- factoryZeroPoint -->
                    </el-checkbox>
                  </el-checkbox-group>
                </div>
              </div>
            </div>
            <div class="overlimit_content">
              <div>
                <span style="color:#dbae03">超限</span>
                <span style="font-size: 15px;font-weight: normal;margin-left: 15px;">流量计相关数据超过系统设置的上下限</span>
                <div style="margin-left:20px;overflow-y: scroll;height:200px">
                  <div style="margin: 15px 0;"></div>
                  <el-checkbox-group id="checkbox-container" v-model="overLimitOption" @change="handleCheckedoverLimit">
                    <el-checkbox v-for="item in overLimitArr" :label="item.tagParamName" :key="item.tagParamId">
                      {{ item.tagParamName }}
                      <!-- <div style="display:flex">
                        <div class="alarmUpLow"> -->
                      <span v-if="overLimitOption.includes(item.tagParamName)">
                        <span style="margin-left:80px" class="alarmUpLow_text">上限警告:</span>
                        <el-input v-model="item.upperAlarm" placeholder="请输入"></el-input>

                        <span class="alarmUpLow_text">上限报警:</span>
                        <el-input v-model="item.upperWarn" placeholder="请输入"></el-input>

                        <span class="alarmUpLow_text">下限警告:</span>
                        <el-input v-model="item.lowerAlarm" placeholder="请输入"></el-input>

                        <span class="alarmUpLow_text">下限报警:</span>
                        <el-input v-model="item.lowerWarn" placeholder="请输入"></el-input>
                      </span>
                    </el-checkbox>
                  </el-checkbox-group>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 右侧发送人 -->
      <div class="pusher">
        <div class="alarmPush_title">报警推送人员</div>

        <!-- :default-checked-keys="defaultCheckedKeys" -->

        <div style="margin-top:15px;margin-left:10px;background: #5d7394">
          <div style="margin-left:3px;">
            <el-tree :data="treeData" ref="tree" check-on-click-node highlight-current node-key="userId" default-expand-all :default-checked-keys="defaultCheckedKeys" show-checkbox :props="defaultProps"></el-tree>
          </div>
        </div>
      </div>
    </div>

    <div slot="footer" class="dialog-footer">
      <el-button @click="onCancelChoose">{{ $t('i18n.cancelBtn') }}</el-button>
      <el-button type="primary" @click="onSureChoose">{{ $t('i18n.sureBtn') }}</el-button>
    </div>
  </el-dialog>
  <!-- 备用 -->
  <!-- <el-form ref="form" :model="form" label-width="80px">
      </el-form> -->
</template>

<script lang="ts">
import { Component, Prop, Vue, Emit, Watch } from 'vue-property-decorator'
import ComponentBase from '@src/views/ComponentBase'
import { Route } from 'vue-router'
import { GetByAlarmFlowmeterId, AddOrUpdateAlarmRule, GetTagParamByPackageId, GetTagKnowledgePage } from '@src/apis/flowmeterInfo'
import { GetAllOranizationInfo } from '@src/apis/userRole'
class TreeNodeDC {
  id: string
  parentGroupId: string
  label: string
  type: string
  index: number
  userId: string
  children: TreeNodeDC[] = []
}
@Component({
  components: {}
})
export default class editDialog extends ComponentBase {
  mounted() {}

  @Watch('dialogCheckedCities', { deep: true })
  private watchdialogCheckArr(val: any) {}

  private instrumentalarmOption: any[] = []

  private onChangeTop(index, tagParamId, e, item) {
    console.log('点击的全部', index, tagParamId, e, item)
    //父级change事件
    this.errInfoStateArr[index].checked = e //父级勾选后,子级全部勾选或者取消
    if (e == false) this.errInfoStateArr[index].indeterminate = false //去掉不确定状态

    var childrenArray = this.errInfoStateArr[index].tagKnowledgeRule //这里注意是选取一级下的二级数据
    // var len = childrenArray.length
    if (this.errInfoStateArr[index].checked == true) {
      // 点击全选往v-model添加选中的
      for (var i = 0; i < childrenArray.length; i++) this.dialogCheckedCities.push(childrenArray[i])
    } else {
      //取消全选删除重复的id
      this.dialogCheckedCities = this.dialogCheckedCities.filter((item) => !childrenArray.some((ele) => ele === item))
    }
    // 如果勾选了,为true
    if (item.checked) {
      // 把里面所有对象的needAlarm变为true
      item.tagKnowledgeRule.forEach((item2) => {
        item2.needAlarm = true
      })

      const index = this.instrumentalarmOption.findIndex((ele) => ele.tagParamName === item.tagParamName)
      if (index !== -1) {
        // 如果存在,则替换该对象
        this.instrumentalarmOption.splice(index, 1, item)
      } else {
        // 如果不存在,则添加新对象到数组中
        this.instrumentalarmOption.push(item)
      }
    } else {
      item.tagKnowledgeRule.forEach((item2) => {
        item2.needAlarm = false
      })
      const index = this.instrumentalarmOption.findIndex((ele) => ele.tagParamName === item.tagParamName)
      if (index !== -1) {
        // 如果存在,则替换该对象
        this.instrumentalarmOption.splice(index, 1, item)
      } else {
        // 如果不存在,则添加新对象到数组中
        this.instrumentalarmOption.push(item)
      }
    }
  }

  private onChangeSon(topIndex, sonId, topId, e, item, city) {
    console.log('点击的子', e, item, city)
    //子级change事件
    var childrenArray = this.errInfoStateArr[topIndex].tagKnowledgeRule //这里注意是选取一级下的二级数据
    var tickCount = 0,
      unTickCount = 0,
      len = childrenArray.length
    for (var i = 0; i < len; i++) {
      if (sonId == childrenArray[i].tagKnowledgeId) childrenArray[i].needAlarm = e
      if (childrenArray[i].needAlarm == true) tickCount++
      if (childrenArray[i].needAlarm == false) unTickCount++
    }
    if (tickCount == len) {
      //子级全勾选
      // this.instrumentalarmOption = []
      this.errInfoStateArr[topIndex].checked = true
      this.errInfoStateArr[topIndex].indeterminate = false
      const index = this.instrumentalarmOption.findIndex((ele) => ele.tagParamName === item.tagParamName)
      if (index !== -1) {
        // 如果存在,则替换该对象
        this.instrumentalarmOption.splice(index, 1, item)
      } else {
        // 如果不存在,则添加新对象到数组中
        this.instrumentalarmOption.push(item)
      }
      // this.instrumentalarmOption.push(item)
    } else if (unTickCount == len) {
      //子级全不勾选
      this.errInfoStateArr[topIndex].checked = false
      this.errInfoStateArr[topIndex].indeterminate = false
      const index = this.instrumentalarmOption.findIndex((ele) => ele.tagParamName === item.tagParamName)
      if (index !== -1) {
        // 如果存在,则替换该对象
        this.instrumentalarmOption.splice(index, 1, item)
      } else {
        // 如果不存在,则添加新对象到数组中
        this.instrumentalarmOption.push(item)
      }
    } else {
      this.errInfoStateArr[topIndex].checked = false
      this.errInfoStateArr[topIndex].indeterminate = true //添加不确定状态
    }
    // 判断数组中是否已存在与新对象某个字段相同的对象
    const index = this.instrumentalarmOption.findIndex((ele) => ele.tagParamName === item.tagParamName)
    if (index !== -1) {
      // 如果存在,则替换该对象
      this.instrumentalarmOption.splice(index, 1, item)
    } else {
      // 如果不存在,则添加新对象到数组中
      this.instrumentalarmOption.push(item)
    }

   
  }

  private alarmRuleVisible: boolean = false
  private dialogCheckedCities: any[] = []
  private tagKnowledChooseItem: any[] = []
  public openAlarmRule(val) {
    // 存报警1,2,3,4

    this.tagKnowledChooseItem = []
    this.systemwarningOption = []
    this.overLimitOption = []
    this.getAlarmById(val)
    this.initData()
    this.getKnowDetail()
    this.getTagParamByPackageId(val.tagPackageId)

    this.alarmRuleVisible = true
  }

  private tablePage: any = {
    total: 0,
    currentPage: 1,
    pageSize: 100
  }
  private knowDetailArr: any[] = []
  private async getKnowDetail() {
    let res = await GetTagKnowledgePage(this.tablePage.currentPage, this.tablePage.pageSize, '')
    this.knowDetailArr = res.data
  }

  private lljInfoData: any[] = []
  //根据id获取每个流量计的报警规则数据
  private async getAlarmById(val) {
    this.instrumentalarmOption = []
    this.dialogCheckedCities = []

    this.errInfoStateArr = []
    this.overLimitArr = []
    this.coefficientAnomalyArr = []
    let res = await GetByAlarmFlowmeterId(val.id)
    this.defaultCheckedKeys = res.notifyUserIds
    // 通讯报警的勾选回显
    this.communicationdkAlarm = res.communicationAlarm
    this.connectionAlarmState = res.connectionAlarm

    res.tagParamRule.forEach((item) => {
      if (item.paramType == 4) {
        this.errInfoStateArr.push(item)
      } else if (item.paramType == 3) {
        // 系数异常的回显
        if (item.settingValue != null) {
          this.systemwarningOption.push(item.tagParamName)
        }

        this.coefficientAnomalyArr.push(item)
      } else {
        // 超限的勾选回显
        if (item.lowerAlarm != null && item.lowerWarn != null && item.upperAlarm != null && item.upperWarn != null) {
          this.overLimitOption.push(item.tagParamName)
        }
        this.overLimitArr.push(item)
      }
    })

    this.errInfoStateArr.forEach((item) => {
      // 回显为true的数据
      item.tagKnowledgeRule.forEach((items) => {
        if (items.needAlarm) {
          this.dialogCheckedCities.push(items)
        }
      })
      //回显全选
      item.checked = item.tagKnowledgeRule.every((ele) => {
        return ele.needAlarm === true
      })
      let checkstate = null
      checkstate = item.tagKnowledgeRule.some((ele) => {
        return ele.needAlarm === true
      })
      if (checkstate) {
        this.instrumentalarmOption.push(item)
      }
    })
    console.log('一开始的instrumentalarmOption', this.instrumentalarmOption)

    console.log('errInfoStateArr', this.errInfoStateArr)

    this.lljInfoData = res.tagParamRule

    //******************************************************************************************************
    this.alarmRulesArr.id = res.id
    this.alarmRulesArr.modefiedUserId = res.modefiedUserId
    this.alarmRulesArr.modifiedUserName = res.modifiedUserName
    this.alarmRulesArr.isDeleted = res.isDeleted
    this.alarmRulesArr.modifiedTime = res.modifiedTime
    this.alarmRulesArr.flowmeterId = res.flowmeterId
  }
  //故障/信息 1/6
  private errInfoStateArr: any[] = []
  // 超限 3
  private overLimitArr: any[] = []
  // 系数异常 4
  private coefficientAnomalyArr: any[] = []

  // 通讯报警
  private connectionAlarmState: boolean = false
  private communicationdkAlarm: boolean = false

  //仪表报警
  private isIndeterminate: boolean = true
  private checkAll: boolean = false

  // 系统预警
  private isIndeterminate2: boolean = true
  private systemwarningOption: any[] = []
  private factoryZeroPoint: number = null
  private handleCheckedsystemwarning(val) {}

  // 超限
  private overLimitOption: any[] = []
  private upAlarm: number = null
  private upAlarmWarning: number = null
  private lowAlarm: number = null
  private lowAlarmWarning: number = null

  private handleCheckedoverLimit(val) {}

  // 右侧发送人

  private treeData: TreeNodeDC[] = []
  private defaultCheckedKeys: any[] = []

  private defaultProps: any = {
    children: 'children',
    label: 'label'
  }
  private async initData() {
    let res = await GetAllOranizationInfo()
    this.treeData = this.organData(res, null)
  }

  private organData(allData: any[], topparentId: string): TreeNodeDC[] {
    let res: TreeNodeDC[] = []
    let filters = allData.filter((o) => o.parentId === topparentId)

    for (let index = 0; index < filters.length; index++) {
      const element = filters[index]
      let node: TreeNodeDC = {
        id: element.id,
        label: element.name,
        parentGroupId: element.parentId,
        index: element.index,
        userId: null,
        children: [],
        type: 'group'
      }

      if (element.type === 1) {
        node.type = 'people'
        node.id = element.id
        node.userId = element.userId
      }

      let nodeChildren = this.organData(allData, node.id)
      node.children = nodeChildren.sort(function(a, b) {
        return a.index - b.index
      })
      res.push(node)
    }
    return res
  }
  private flattenData: any[] = []
  private flattenTree(node) {
    // 将当前节点添加到扁平化数组中
    this.flattenData.push(node)

    // 判断当前节点是否有子节点
    if (node.children && node.children.length > 0) {
      // 遍历子节点,递归调用flattenTree函数
      node.children.forEach((child) => {
        this.flattenTree(child)
      })
    }
  }

  // 根据这个流量计绑定的点位包的id 查所有信息 ,再根据数据 找到每个点位知识库的   id
  private ParamByPackageArr: any[] = []
  private async getTagParamByPackageId(id) {
    let res = await GetTagParamByPackageId(id)
    // tagKnowledgeId 点位库id  但是没有点位库名称
    this.ParamByPackageArr = res
  }

  // 存放最终数据的数组,
  private alarmRulesArr: any = {}

  // 最下方  确定/取消按钮
  private async onSureChoose() {
    var nodes = (this.$refs.tree as any).getCheckedNodes()
    //数组扁平化
    nodes.forEach((item) => {
      this.flattenTree(item)
    })
    let peopleIdsArr = []
    //去重
    this.flattenData.forEach((item) => {
      if (item.type == 'people') {
        peopleIdsArr.push(item.userId)
      }
    })
    //推送人员的id集合
    let peopleUniqueArr = Array.from(new Set(peopleIdsArr))

    this.alarmRulesArr.connectionAlarm = this.connectionAlarmState
    this.alarmRulesArr.communicationAlarm = this.communicationdkAlarm
    //tagParamRule
    this.alarmRulesArr.tagParamRule = []
    //获取推送人id集合/赛数据     //这些是我选中的报警的名称集合
    let combinedArray = [...this.systemwarningOption, ...this.overLimitOption]

    this.onSure(combinedArray)

    combinedArray.forEach((item) => {
      this.lljInfoData.forEach((item2) => {
        if (item2.tagParamName === item) {
          item2.settingValue = item2.settingValue ? parseInt(item2.settingValue) : null
          item2.lowerAlarm = item2.lowerAlarm ? parseInt(item2.lowerAlarm) : null
          item2.lowerWarn = item2.lowerWarn ? parseInt(item2.lowerWarn) : null
          item2.upperAlarm = item2.upperAlarm ? parseInt(item2.upperAlarm) : null
          item2.upperWarn = item2.upperWarn ? parseInt(item2.upperWarn) : null

          this.alarmRulesArr.tagParamRule.push(item2)
        }
      })
    })
    this.alarmRulesArr.tagParamRule = this.alarmRulesArr.tagParamRule.concat(this.instrumentalarmOption)
    // 勾选的数据 的对应的点位知识库信息
    this.alarmRulesArr.notifyUserIds = peopleUniqueArr
    //第一层加Id
    // this.alarmRulesArr.tagParamRule.forEach((item) => {})
    console.log('最终处理的数据', this.alarmRulesArr.tagParamRule)

    let res = await AddOrUpdateAlarmRule(this.alarmRulesArr)
    if (res) {
      this.$message({
        message: '规则新增成功',
        type: 'success'
      })
      this.alarmRuleVisible = false
    } else {
      this.$message({
        message: '规则新增失败',
        type: 'warning'
      })
      this.alarmRuleVisible = true
    }
  }
  private onCancelChoose() {
    this.alarmRuleVisible = false
  }
  @Emit('onSure')
  private onSure(checkArr: any[]) {}
}
</script>
<style lang="less" scoped>
.alarmMain {
  height: 100%;
  display: flex;
  // justify-content:
}
.alarmRule {
  width: 80%;
  height: 100%;
}
.alarmRule_title {
  font-size: 30px;
  font-weight: bold;
  color: black;
}
.alarmPush_title {
  font-size: 20px;
  font-weight: bold;
  color: black;
}
.alarmRule_contetn {
  width: calc(100% - 30px);
  height: 100%;
  overflow: hidden;
  padding-left: 30px;
  // box-shadow: rgba(50, 50, 93, 0.25) 0px 30px 60px -12px inset, rgba(0, 0, 0, 0.3) 0px 18px 36px -18px inset;
}
.communicationalarm {
  font-size: 24px;
  height: 77px;
  font-weight: bold;
  color: black;
  margin-top: 10px;
}
.disconnect {
  width: 300px;
  height: 100%px;
}
/deep/ .communicationalarm .el-checkbox:last-of-type {
  margin-left: 100px;
}
/deep/ .el-checkbox__label {
  display: inline-block;
  padding-left: 10px;
  line-height: 19px;
  font-size: 16px;
  font-weight: bold;
}
/deep/ .el-checkbox-group {
  margin-left: 20px;
}

.instrumentalarm {
  font-size: 24px;
  height: 300px;
  font-weight: bold;
  color: black;
  margin-top: 10px;
}
.instrumentalarm_content {
  width: 97%;
  height: 100%;
  border: 1px solid gray;
  margin-left: 20px;
  padding-left: 5px;
  overflow: hidden;
  margin-top: 5px;
  // box-shadow: rgba(255, 113, 73, 0.3) 0px 0px 0px 3px;
}
.systemwarning {
  font-size: 24px;
  height: 200px;
  font-weight: bold;
  color: black;
  margin-top: 4%;
}
.systemwarning_content {
  width: 97%;
  height: 70%;
  border: 1px solid gray;
  margin-left: 20px;
  margin-top: 5px;
  padding-left: 5px;
  // box-shadow: rgba(237, 15, 93, 0.3) 0px 0px 0px 3px;
}
.overlimit_content {
  width: 97%;
  border: 1px solid gray;
  margin-left: 20px;
  padding-left: 5px;
  margin-top: 20px;
  padding-bottom: 10px;
  // box-shadow: rgba(219, 174, 3, 0.3) 0px 0px 0px 3px;
}
#checkbox-container {
  display: flex;
  flex-direction: column;
}
/deep/ .systemwarning_content .el-input__inner {
  width: 100px !important;
  height: 30px;
}
/deep/ .overlimit_content .el-input {
  position: relative;
  font-size: 14px;
  display: inline-block;
  width: 100px;
}
/deep/ .overlimit_content .el-input__inner {
  width: 80px !important;
  height: 30px;
}

.alarmUpLow {
  display: flex;
  font-size: 16px;
  font-weight: normal;
  margin-top: 5px;
  margin-left: 20px;
}
.alarmUpLow_text {
  width: 78px;
  line-height: 39px;
  font-size: 12px;
}

.pusher {
  width: 20%;
  height: 100%;
}

// /deep/.el-dialog {
//   border-radius: 6px;
// }
// /deep/.el-form {
//   display: flex;
//   flex-wrap: wrap;
//   .el-form-item {
//     width: calc(50% - 10px);
//     display: flex;
//     align-items: center;
//     justify-content: left !important;
//     margin-right: 10px;
//     box-sizing: border-box;
//     .el-form-item__label {
//       width: 35% !important;
//       text-align: left;
//     }
//     .el-form-item__content {
//       width: 100% !important;
//       margin-left: 0 !important;
//     }
//   }
// }
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/585135.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

深度解析 Spring 源码:从BeanDefinition源码探索Bean的本质

文章目录 一、BeanDefinition 的概述1.1 BeanDefinition 的定位1.2 BeanDefition 的作用 二、BeanDefinition 源码解读2.1 BeanDefinition 接口的主要方法2.2 BeanDefinition 的实现类2.2.1 实现类的区别2.2.2 setBeanClassName()2.2.3 getDependsOn()2.2.4 setScope() 2.3 Bea…

用Python Turtle画一个中国结

中国结&#xff0c;作为中华民族传统文化的象征之一&#xff0c;以其独特的编织技艺和深厚的文化内涵&#xff0c;深受人们喜爱。今天&#xff0c;我们就来用Python的turtle模块&#xff0c;尝试绘制一个充满韵味的中国结。 我们先来看看整个中国结生成的过程&#xff1a; 中国…

ros2 node 之间的通信方式之 —— Topic通信案例

文章目录 ros2 node 之间的通信方式之 Topic通信Topic 通信案例1、创建工作空间2、创建功能包3、编写发布者和订阅者代码3.1 topic_helloworld_pub.cpp3.2 topic_helloworld_sub.cpp 4、编写CMakeLists.txt5、编译工作空间下的功能包6、运行结果 ros2 node 之间的通信方式之 To…

2024年,如何实现高效的自动化渗透测试?

随着当前网络安全威胁的不断扩展与升级&#xff0c;开展渗透测试工作已经成为广大企业组织主动识别安全漏洞与潜在风险的关键过程。然而&#xff0c;传统的人工渗透测试模式对测试人员的专业能力和经验水平有很高的要求&#xff0c;企业需要投入较大的时间和资源才能完成。在此…

Seata分布式事务使用!!!!

1.版本说明 版本说明 alibaba/spring-cloud-alibaba Wiki GitHub 2.建立Seata Server数据库&#xff08;TC-带头大哥的数据库&#xff09; incubator-seata/script/server/db at v1.6.1 apache/incubator-seata GitHub 3.业务库建表 incubator-seata/script/client/at/…

对于button按钮引发的bug

主要原因就是今天在给button按钮添加一个点击事件的时候&#xff0c;并没有声明button的type类型&#xff0c;就一直发生点击按钮但事件并不触发的问题。 触发这种问题的原因就是: 按钮默认的 type 类型是 "submit"&#xff0c;而不是 "button"。当你不显式…

探索潜力:中心化交易所平台币的对比分析

核心观点 平台币在过去一年里表现差异显著&#xff1a; 在过去的一年里&#xff0c;只有少数几个平台币如BMX、BGB和MX的涨幅超过了100%。相比之下&#xff0c;由于市值较高&#xff0c;BNB和OKB的涨幅相对较低。 回购和销毁机制在平台币价值中起决定性作用&#xff1a; 像M…

OpenHarmony实战开发-基础知识

Svg组件主要作为svg画布的根节点使用&#xff0c;也可以在svg中嵌套使用。 说明&#xff1a; svg父组件或者svg组件需要定义宽高值&#xff0c;否则不进行绘制。 创建Svg组件 在pages/index目录下的hml文件中创建一个Svg组件。 <!-- xxx.hml --> <div class"co…

[华为OD] C卷 5G网络 现需要在某城市进行5G网络建设,已经选取N个地点设置5G基站 200

题目 现需要在某城市进行5G网络建设&#xff0c;已经选取N个地点设置5G基站&#xff0c;编号固定为1到N,接 下来需要各个基站之间使用光纤进行连接以确保基站能互联互通&#xff0c;不同基站之间架设光纤的成 本各不相同&#xff0c;且有些节点之间已经存在光纤相连&#…

力扣刷题 63.不同路径 II

题干 一个机器人位于一个 m x n 网格的左上角 &#xff08;起始点在下图中标记为 “Start” &#xff09;。 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角&#xff08;在下图中标记为 “Finish”&#xff09;。 现在考虑网格中有障碍物。那么从左上角到…

(css)鼠标移出样式不变

(css)鼠标移出样式不变 需求&#xff1a;列表鼠标移入切换样式&#xff0c;移出保持不变 <divv-for"(item, index) of newsList":key"index"class"news-list":class"{active : change index}"tabindex"1"mouseenter&quo…

docker各目录含义

目录含义builder构建docker镜像的工具或过程buildkit用于构建和打包容器镜像&#xff0c;官方构建引擎&#xff0c;支持多阶段构建、缓存管理、并行化构建和多平台构建等功能containerd负责容器生命周期管理&#xff0c;能起、停、重启&#xff0c;确保容器运行。负责镜管理&am…

2024最新的,免费的 ChatGPT 网站AI(八个)

ChatGPT是美国人工智能研究实验室OpenAI在2022年11月推出的一款人工智能技术驱动的语言模型应用。它基于GPT-3.5架构&#xff08;后续还有GPT-4架构的升级版&#xff09;构建&#xff0c;拥有强大的自然语言处理能力和上下文理解能力&#xff0c;能够参与多轮对话&#xff0c;为…

恩智浦如何使用DITA

▲ 搜索“大龙谈智能内容”关注公众号▲ 作者 | John Walker - NXP销售和市场营销业务分析师 2013年4月18日 作为恩智浦半导体公司销售和市场部的业务分析师&#xff0c;我负责恩智浦半导公司产品信息的数据/内容模型、流程和工具。我来自英国&#xff0c;但自2000年以来一…

Python3 循环语句

Python 中的循环语句有 for 和 while。 Python 循环语句的控制结构图如下所示&#xff1a; while 循环 Python 中 while 语句的一般形式&#xff1a; while 判断条件(condition)&#xff1a;执行语句(statements)…… 执行流程图如下&#xff1a; 同样需要注意冒号和缩进。…

go语言实现简单登陆返回token样例

目录 1、代码实现样例&#xff1a; 2、postman调用&#xff0c;获取登陆后的token&#xff1a; 1、代码实现样例&#xff1a; package mainimport ("net/http""time""github.com/dgrijalva/jwt-go""github.com/gin-gonic/gin" )var …

Leetcode—2639. 查询网格图中每一列的宽度【简单】

2024每日刷题&#xff08;121&#xff09; Leetcode—2639. 查询网格图中每一列的宽度 实现代码 class Solution { public:int func(int num) {if(num 0) {return 1;}int len 0;while(num ! 0) {len;num / 10;}return len;}vector<int> findColumnWidth(vector<ve…

怎么通过isinstance(Obj,Class)验证?【isinstance】

最近有这样一个项目&#xff0c;这个项目可以用一个成熟的项目的构造树&#xff0c;读取树&#xff0c;再检索的过程&#xff0c;现在有新的需求&#xff0c;另一个逻辑构造同样节点结构的树&#xff0c;pickle序列化保存&#xff0c;再使用原来项目的读取、检索函数&#xff0…

Altair® PBS Professional®——行业超前的 HPC 和高吞吐量计算工作负载管理器和作业调度程序

PBS Professional 是一款快速、强大的工作负载管理器&#xff0c;旨在提高生产力、优化利用率和效率&#xff0c;并简化集群、云和超级计算机的管理——从极大的 HPC 工作负载到数百万个小型、高吞吐量作业。PBS Professional 能够自动执行作业调度、管理、监视和报告任务&…

4月25日 C++day3

#include <iostream> using namespace std;class Person {const string name;int age;char sex; public:Person():name("lisi"){cout << "Person无参构造" << endl;}Person(string name,int age,char sex):name(name),age(age),sex(sex)…