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.lengthconsole.log('选取一级下的二级数据', childrenArray)for (var i = 0; i < len; i++) {if (sonId == childrenArray[i].tagKnowledgeId) childrenArray[i].needAlarm = eif (childrenArray[i].needAlarm == true) tickCount++if (childrenArray[i].needAlarm == false) unTickCount++}if (tickCount == len) {//子级全勾选this.cities[topIndex].checked = truethis.cities[topIndex].indeterminate = false} else if (unTickCount == len) {//子级全不勾选this.cities[topIndex].checked = falsethis.cities[topIndex].indeterminate = false} else {this.cities[topIndex].checked = falsethis.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})//如果子选项有一个勾选了,truelet checkstate = nullcheckstate = 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.lengthif (this.errInfoStateArr[index].checked == true) {// 点击全选往v-model添加选中的for (var i = 0; i < childrenArray.length; i++) this.dialogCheckedCities.push(childrenArray[i])} else {//取消全选删除重复的idthis.dialogCheckedCities = this.dialogCheckedCities.filter((item) => !childrenArray.some((ele) => ele === item))}// 如果勾选了,为trueif (item.checked) {// 把里面所有对象的needAlarm变为trueitem.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.lengthfor (var i = 0; i < len; i++) {if (sonId == childrenArray[i].tagKnowledgeId) childrenArray[i].needAlarm = eif (childrenArray[i].needAlarm == true) tickCount++if (childrenArray[i].needAlarm == false) unTickCount++}if (tickCount == len) {//子级全勾选// this.instrumentalarmOption = []this.errInfoStateArr[topIndex].checked = truethis.errInfoStateArr[topIndex].indeterminate = falseconst 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 = falsethis.errInfoStateArr[topIndex].indeterminate = falseconst 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 = falsethis.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: stringparentGroupId: stringlabel: stringtype: stringindex: numberuserId: stringchildren: 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.lengthif (this.errInfoStateArr[index].checked == true) {// 点击全选往v-model添加选中的for (var i = 0; i < childrenArray.length; i++) this.dialogCheckedCities.push(childrenArray[i])} else {//取消全选删除重复的idthis.dialogCheckedCities = this.dialogCheckedCities.filter((item) => !childrenArray.some((ele) => ele === item))}// 如果勾选了,为trueif (item.checked) {// 把里面所有对象的needAlarm变为trueitem.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.lengthfor (var i = 0; i < len; i++) {if (sonId == childrenArray[i].tagKnowledgeId) childrenArray[i].needAlarm = eif (childrenArray[i].needAlarm == true) tickCount++if (childrenArray[i].needAlarm == false) unTickCount++}if (tickCount == len) {//子级全勾选// this.instrumentalarmOption = []this.errInfoStateArr[topIndex].checked = truethis.errInfoStateArr[topIndex].indeterminate = falseconst 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 = falsethis.errInfoStateArr[topIndex].indeterminate = falseconst 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 = falsethis.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 = falseprivate dialogCheckedCities: any[] = []private tagKnowledChooseItem: any[] = []public openAlarmRule(val) {// 存报警1,2,3,4this.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.communicationAlarmthis.connectionAlarmState = res.connectionAlarmres.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 = nullcheckstate = 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.idthis.alarmRulesArr.modefiedUserId = res.modefiedUserIdthis.alarmRulesArr.modifiedUserName = res.modifiedUserNamethis.alarmRulesArr.isDeleted = res.isDeletedthis.alarmRulesArr.modifiedTime = res.modifiedTimethis.alarmRulesArr.flowmeterId = res.flowmeterId}//故障/信息 1/6private errInfoStateArr: any[] = []// 超限 3private overLimitArr: any[] = []// 系数异常 4private coefficientAnomalyArr: any[] = []// 通讯报警private connectionAlarmState: boolean = falseprivate communicationdkAlarm: boolean = false//仪表报警private isIndeterminate: boolean = trueprivate checkAll: boolean = false// 系统预警private isIndeterminate2: boolean = trueprivate systemwarningOption: any[] = []private factoryZeroPoint: number = nullprivate handleCheckedsystemwarning(val) {}// 超限private overLimitOption: any[] = []private upAlarm: number = nullprivate upAlarmWarning: number = nullprivate lowAlarm: number = nullprivate lowAlarmWarning: number = nullprivate 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.idnode.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 查所有信息 ,再根据数据 找到每个点位知识库的   idprivate 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.connectionAlarmStatethis.alarmRulesArr.communicationAlarm = this.communicationdkAlarm//tagParamRulethis.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) : nullitem2.lowerAlarm = item2.lowerAlarm ? parseInt(item2.lowerAlarm) : nullitem2.lowerWarn = item2.lowerWarn ? parseInt(item2.lowerWarn) : nullitem2.upperAlarm = item2.upperAlarm ? parseInt(item2.upperAlarm) : nullitem2.upperWarn = item2.upperWarn ? parseInt(item2.upperWarn) : nullthis.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.rhkb.cn/news/316878.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2分钟自己写小游戏:使用js和css编写石头剪刀布小游戏、扫雷小游戏、五子棋小游戏。新手老手毕业论文都能用。

系列文章目录 【复制就能用1】2分钟玩转轮播图,unslider的详细用法 【复制就能用2】css实现转动的大风车&#xff0c;效果很不错。 【复制就能用3】2分钟自己写小游戏&#xff1a;剪刀石头布小游戏、扫雷游戏、五子棋小游戏 【复制就能用4】2024最新智慧医疗智慧医院大数据…

sheng的学习笔记-AI-支持向量机(SVM)

目录&#xff1a;sheng的学习笔记-AI目录-CSDN博客 目录 什么是向量机 SVM算法原理 SVM基本模型 SVM对偶问题 什么是对偶问题&#xff1a; 为什么使用对偶问题 拉格朗日定理 拉格朗日乘子法 对偶问题算法 非线性SVM算法原理 核函数 常用核函数 软间隔与正则化 软…

数之寻软件怎么样?

数之寻软件是一款功能强大的数据恢复和备份软件&#xff0c;以下是对其特点和功能的详细评价&#xff1a; 一、数据恢复方面&#xff1a; 高效的数据恢复能力&#xff1a;数之寻软件采用了先进的算法和数据恢复技术&#xff0c;能够快速有效地恢复丢失或损坏的数据。无论是文…

Redis缓存介绍以及常见缓存问题:穿透、雪崩和击穿

概念 缓存就是数据交换的缓冲区&#xff08;Cache&#xff09;&#xff0c;是存贮数据的临时地方&#xff0c;一般读写性能较高。 作用&#xff1a; 降低后端负载 提高读写效率&#xff0c;降低相应时间 成本&#xff1a; 数据一致性成本 代码维护成本 运维成本 缓存更…

分享一个网站实现永久免费HTTPS访问的方法

免费SSL证书作为一种基础的网络安全工具&#xff0c;以其零成本的优势吸引了不少网站管理员的青睐。要实现免费HTTPS访问&#xff0c;您可以按照以下步骤操作&#xff1a; 一、 选择免费SSL证书提供商 选择一个提供免费SSL证书的服务商。如JoySSL&#xff0c;他们是国内为数不…

JWT原理解析

一、概述 虽然现在很多的开发框架会支持JWT的使用&#xff0c;但是对JWT还是没有一个详细的了解&#xff0c;有很多疑惑&#xff1a; JWT比之前的session或者token有什么好处&#xff1f;JWT的构成元素是什么&#xff1f;JWT从生成到使用的详细流程&#xff1f; 二、 JWT 2…

字节5面挂,恶心到了。。。

字节五面 今天脉脉看到一篇帖子&#xff1a; 楼主是 tx 的前员工&#xff0c;在字节五面&#xff08;加轮&#xff09;被挂后&#xff0c;认定&#xff08;或许私下做了一些调查&#xff09;是字节 HR 向 tx 背调&#xff0c;然后被前同事捏造虚假信息&#xff0c;导致的面试失…

网页基本标签

标题标签 <h1>一级标题</h1> <h2>二级标签</h2> <h3>三级标签</h3> <h4>四级标签</h4> <h5>五级标签</h5> <h6>六级标签</h6>标题标签一共有六级&#xff0c;大小从一级开始逐级往下递减&#x…

【数据结构】三、栈和队列:2.顺序栈共享栈(顺序栈的初始化,判空,进栈,出栈,读取栈顶,顺序栈实例)

文章目录 1.顺序栈1.1初始化1.2判空1.3进栈1.4出栈1.5读取栈顶1.6销毁栈❗1.7顺序栈c实例 2.共享栈2.1初始化2.2判满 1.顺序栈 用顺序存储实现的栈 顺序栈的缺点&#xff1a;栈的大小不可变。 #define MaxSize 10 //定义栈中元素的最大个数 typedef struct{ElemType data[…

nodejs写接口(一)

一、新手上路十大步 &#xff08;1&#xff09;先建一个常用的文件夹 &#xff08;2&#xff09;使用code打开 &#xff08;3&#xff09;在里面新建一个index.js文件 &#xff08;4&#xff09;新建项目 npm init -y //用于自己搭建一个项目框架&#xff08;写框架&#xf…

代码审计之SAST自动化

前言: 很久没写文章了&#xff0c;有点忙&#xff0c;落个笔&#xff0c;分享一些捣鼓或说适配好的一些好玩的东西。 脚本工具不开源&#xff0c;给一些思路&#xff0c;希望能给大家带来一些收获。 笔者能力有限&#xff0c;如有错误&#xff0c;欢迎斧正。 正文&#xff1a…

《软件设计师教程:计算机网络浅了解计算机之间相互运运作的模式》

​ 个人主页&#xff1a;李仙桎 &#x1f525; 个人专栏: 《软件设计师》 ⛺️生活的理想&#xff0c;就是为了理想的生活! ​ ⛺️前言&#xff1a;各位铁汁们好啊&#xff01;&#xff01;&#xff01;&#xff0c;今天开始继续学习中级软件设计师考试相关的内容&#xff0…

3节点ubuntu24.04服务器docker-compose方式部署高可用elk+kafka日志系统并接入nginx日志

一&#xff1a;系统版本: 二&#xff1a;部署环境&#xff1a; 节点名称 IP 部署组件及版本 配置文件路径 机器CPU 机器内存 机器存储 Log-001 10.10.100.1 zookeeper:3.4.13 kafka:2.8.1 elasticsearch:7.7.0 logstash:7.7.0 kibana:7.7.0 zookeeper:/data/zookeep…

数字电子:二进制逻辑和信号

目录 模拟值 数字值 真和假 下拉电阻和上拉电阻 模拟值 模拟值是随时间连续变化的量。它可以取无限多的值——例如&#xff0c;温度、电池电压或扬声器中的音频信号。图1显示了模拟值的时间过程。模拟的概念可以通过连续性条件来表示。在实践中&#xff0c;数值沿着一个以…

代码随想录算法训练营DAY32|C++贪心算法Part.2|122.买卖股票的最佳时机II、55.跳跃游戏、45.跳跃游戏II

文章目录 122.买卖股票的最佳时机II思路CPP代码 55.跳跃游戏思路CPP代码 45.跳跃游戏II思路方法一代码改善 CPP代码 122.买卖股票的最佳时机II 力扣题目链接 文章讲解&#xff1a;122.买卖股票的最佳时机II 视频讲解&#xff1a; 状态&#xff1a;本题可以用动态规划&#xff0…

企业智能名片小程序:AI智能跟进功能助力精准营销新篇章

在数字化浪潮的推动下&#xff0c;企业营销手段不断迭代升级。如今&#xff0c;一款集手机号授权自动获取、智能提醒、访客AI智能跟进及客户画像与行为记录于一体的企业智能名片小程序&#xff0c;正以其强大的AI智能跟进功能&#xff0c;助力企业开启精准营销的新篇章。 通过深…

小程序 rich-text 解析富文本 图片过大时如何自适应?

在微信小程序中&#xff0c;用rich-text 解析后端返回的数据&#xff0c;当图片尺寸太大时&#xff0c;会溢出屏幕&#xff0c;导致横向出现滚动 查看富文本代码 图片是用 <img 标签&#xff0c;所以写个正则匹配一下图片标签&#xff0c;手动加上样式即可 // content 为后…

​HTTP与HTTPS:网络通信的安全卫士

✨✨谢谢大家捧场&#xff0c;祝屏幕前的小伙伴们每天都有好运相伴左右&#xff0c;一定要天天开心哦&#xff01;✨✨ &#x1f388;&#x1f388;作者主页&#xff1a; 喔的嘛呀&#x1f388;&#x1f388; ✨✨ 帅哥美女们&#xff0c;我们共同加油&#xff01;一起进步&am…

C语言.自定义类型:结构体

自定义类型&#xff1a;结构体 1.结构体类型的声明1.1结构体回顾1.1.1结构体的声明1.1.2结构体变量的创建和初始化 1.2结构体的特殊声明1.3结构体的自引用 2.结构体内存对齐2.1对齐规则2.2为什么存在内存对齐2.3修改默认对齐数 3.结构体传参4.结构体实现位段4.1什么是位段4.2位…

配置jupyter的启动路径

jupyter的安装参考&#xff1a;python环境安装jupyter-CSDN博客 1&#xff0c;背景 继上一篇python环境安装jupyter&#xff0c;里面有一个问题&#xff0c;就是启动jupyter&#xff08;命令jupyter notebook&#xff09;之后&#xff0c;页面默认显示的是启动时候的路径。 …