首页 > 其他分享 >树形多选

树形多选

时间:2024-09-12 17:26:45浏览次数:1  
标签:checkContentList 多选 form value item length 树形 any

 


<script setup lang="ts"> import { useVModel } from '@vueuse/core'; const props = defineProps({ modelValue: { type: Object, default: () => { }, }, }); /* AI视觉应用 */ const emit = defineEmits(['update:modelValue']); const form = useVModel(props, 'modelValue', emit); const lastDataHandleai = ref(null); // 上次选择的dataHandle值 if (form.value) { form.value.aiApplyChecked = form.value.isAi === 1; if (form.value.dataSources) { form.value.dataSourcearr = [form.value.dataSources]; setLastDataHandle1('dataSourcearr'); } if (form.value.outType) { form.value.resultOut = [form.value.outType]; setLastDataHandle1('resultOut'); } _getAlgorithmSceneTree(); } const isOpen3 = ref<boolean>(true); const dataSourceList = ref([ { label: '照片', value: 1 }, { label: '视频', value: 2 }, ]); const resultOutList = ref([ { label: '同步', value: 1 }, { label: '异步', value: 2 }, ]); // 节点数列表 const checkContentList: any = ref([ ]); function openClose() { isOpen3.value = !isOpen3.value; } // 获取节点树 function _getAlgorithmSceneTree() { getAlgorithmSceneTree().then((res) => { if (res.success) { const d = res.data ? res.data : []; let d2 = []; if (d && d.length) { d2 = d.map((item) => { if (item.sceneList && item.sceneList.length) { item.sceneList.forEach((element) => { element.label = element.name; element.value = element.id; }); } return { checkedAll: false, // 全选 indeterminate: false, // 半勾选 checkedList: [], // 选中的 children: item.sceneList, ...item, }; }); checkContentList.value = d2; } } // 编辑回显检测内容 if (form.value.detection) { checkEdit(form.value.detection); } }); } function getisAi1(v: any) { form.value.isAi = v ? 1 : 0; // 没有勾选 检查内容都置空 if (!v) { form.value.dataSources = ''; form.value.outType = ''; form.value.detection = ''; } } // 编辑回显检测内容 function checkEdit(val: any) { const detectionarr = val.split(','); if (checkContentList.value && checkContentList.value.length) { checkContentList.value.forEach((item: any) => { if (item.children && item.children.length) { item.indeterminate = false; item.checkedAll = false; item.checkedList = []; item.children.forEach((itemchild: any) => { detectionarr.forEach((deteitem: any) => { if (+deteitem === itemchild.id) { item.checkedList.push(+deteitem); } }); }); } // 全选半选回显 if (item.checkedList.length) { item.indeterminate = true; item.checkedAll = false; if (item.children.length === item.checkedList.length) { item.checkedAll = true; item.indeterminate = false; } } }); } } // 监听变化 watch(() => form.value, (val) => { // console.log('1', val) if (val) { form.value.aiApplyChecked = val.isAi === 1; if (val.dataSources) { form.value.dataSourcearr = [val.dataSources]; setLastDataHandle1('dataSourcearr'); } if (val.outType) { form.value.resultOut = [val.outType]; setLastDataHandle1('resultOut'); } // 编辑回显检测内容 if (val.detection) { checkEdit(val.detection); } else { // 切换清空 checkContentList.value.forEach((item: any) => { if (item.children && item.children.length) { item.indeterminate = false; item.checkedAll = false; item.checkedList = []; } // 全选半选回显 if (item.checkedList.length) { item.indeterminate = true; item.checkedAll = false; if (item.children.length === item.checkedList.length) { item.checkedAll = true; item.indeterminate = false; } } }); } } }, { immediate: true, }); // 检测内容勾选所有 function checkedAll(e: any, index: any) { checkContentList.value[index].checkedList = e.target.checked ? checkContentList.value[index].children.map(v => v.value) : []; checkContentList.value[index].indeterminate = false; handleAiApply(); } // 检测内容勾选单个 function checkedOne(val: any, index: any) { const checkedCount = val.length; checkContentList.value[index].checkedAll = checkedCount === checkContentList.value[index].children.length; checkContentList.value[index].indeterminate = checkedCount > 0 && checkedCount < checkContentList.value[index].children.length; handleAiApply(); } function setLastDataHandle1(field: any) { lastDataHandleai.value = form.value[field].length > 0 ? form.value[field][0] : null; } // 处理AI应用 function handleAiApply() { form.value.detection = checkContentList.value.flatMap((o: any) => o.checkedList).join(','); } // 数据来源 function handleAiApply1(checkedValue: any) { form.value.dataSourcearr = checkedValue.filter((item: any) => lastDataHandleai.value !== item); setLastDataHandle1('dataSourcearr'); if (form.value.dataSourcearr && form.value.dataSourcearr.length) { form.value.dataSources = form.value.dataSourcearr[0]; } else { form.value.dataSources = ''; } } // 结果输出 function handleAiApply2(checkedValue: any) { form.value.resultOut = checkedValue.filter((item: any) => lastDataHandleai.value !== item); setLastDataHandle1('resultOut'); if (form.value.resultOut && form.value.resultOut.length) { form.value.outType = form.value.resultOut[0]; } else { form.value.outType = ''; } } </script> <template> <!-- AI视觉识别应用 全局和单点都需要 --> <!-- 全局 --> <div class="mt-3" :class="isOpen3 ? 'border_box_6' : 'border_box_6_title'" style="z-index: 1;"> <div class="h-12 px-4 flex items-center justify-between"> <div class="flex items-center"> <PubSvgIcon name="ai-icon" size="2.4rem" /> <span class="text-white text-lg font-medium ml-2">AI视觉识别应用信息</span> </div> <div class="flex items-center"> <a-switch v-model:checked="form.aiApplyChecked" @change="getisAi1" /> <PubSvgIcon class="toggle-icon cursor-pointer ml-2" :class="isOpen3 ? '' : 'close'" name="doubleleft" :size="16" @click="openClose()" /> </div> </div> <div v-show="isOpen3" class="p-4"> <a-form v-if="form.aiApplyChecked" :colon="false" label-align="left" :label-col="{ style: { width: '7rem' } }"> <a-form-item label="数据来源"> <a-checkbox-group v-model:value="form.dataSourcearr" :options="dataSourceList" @change="handleAiApply1" /> </a-form-item> <a-form-item> <template #label> <div class="flex items-center"> <span class="mr-1">结果输出</span> <PubSvgIcon name="notice-icon" size="1.2rem" /> </div> </template> <a-checkbox-group v-model:value="form.resultOut" :options="resultOutList" @change="handleAiApply2" /> </a-form-item> <a-form-item label="检测内容"> <div v-for="(item, index) in checkContentList" :key="index" class="w-full"> <div class="flex items-center" style="min-height: 32px;"> <!-- 父级 --> <a-checkbox v-model:checked="item.checkedAll" :indeterminate="item.indeterminate" @change="checkedAll($event, index)" > {{ item.name }} </a-checkbox> </div> <div class="pl-4 py-1 -ml-4 mb-3 bg-white/10 flex items-center" style="min-height: 32px;" v-if="item.children?.length"> <a-checkbox-group v-model:value="item.checkedList" :options="item.children" @change="checkedOne($event, index)" /> </div> </div> </a-form-item> </a-form> </div> </div> </template> <style lang="less" scoped> // 展开收起 :deep(.toggle-icon) { transition: all 0.3s ease; transform: rotate(90deg); &.close { transform: rotate(-90deg); } } </style>

 

标签:checkContentList,多选,form,value,item,length,树形,any
From: https://www.cnblogs.com/Byme/p/18410663

相关文章

  • NOIP2024集训Day27 DP常见模型4 - 树形
    NOIP2024集训Day27DP常见模型4-树形E.[COCI2014-2015#1]Kamp首先只考虑一个点,发现如果回到原来位置是比较好搞的,就每次走完子树的里面要的就上来,如果子树里面没有要走的就不走。(大概是\(f_x=\sumf_y+2\cdote_x\),因为要走过去走回来,注意\(y\)要保证子树里面有人)......
  • 单选和多选在table里的报错问题Blocked aria-hidden on a <input> element because the
    单选在main.js里//table单选报错问题Vue.directive('removeAriaHidden',{bind(el,binding){constariaEls=el.querySelectorAll('.el-radio__original')ariaEls.forEach((item)=>{item.removeAttribute('aria-hidden')......
  • 【题解】Solution Set - NOIP2024集训Day27 树形 dp
    【题解】SolutionSet-NOIP2024集训Day27树形dphttps://www.becoder.com.cn/contest/5521「HDU4661」MessagePassing「BZOJ3935」Rbtree「ARC101E」RibbonsonTree「AGC034E」CompleteCompress「COCI2014.10」Kamp「SCOI2015」小凸玩密室「AGC008F」Black......
  • 树形DP做题回顾(上)
    题目一 ​​​​Problem-2196大致意思就是求每个点为根的最大深度;对于这个问题,很快速的我们可以想到跑两次dfs,第一次预处理出以u为根的子树的第一,二深的深度,第二次dfs进行树形dp,从u->v时推出v的最大深度,用up[v]来存储;代码如下:注意分走到第一大和第二大的路径上的决策,以......
  • 虚树+树形dp
    虚树实际上是一颗浓缩子树;使用虚树的题目大部分具有查询的点有限,同时虚树构建的信息符合规则;做虚树的题目:步骤为先想出原树的暴力求解做法,然后构建虚树同时向其中添加有用信息(比如边权);虚树的构建过程:虚树的构建大致有两种,但是两种方式都与dfs序有关;首先解释为什么与dfs序有......
  • 利用vue2+element ui做一个购物车的复选框多选
    @TOC......
  • el-table树形懒加载表格展开后 子节点修改数据后实时刷新
    问题描述在项目中遇到一个关于el-table的懒加载树型结构修改数据后需要刷新数据的问题,需要手动刷新页面之后才能刷新问题解决:1.首先创建map来用于存取数据,constloadMap=newMap();//存储load加载的子节点以能够编辑后更新2.在table展开子节点时,用map存下每次被加载......
  • echart map图标切换多选,单选,默认选中
    需求是echart默认地图选中之前的去过的城市,一开始多选,后面点击为单选constoption={tooltip:{trigger:'item',formatter:'{b}'},series:[{type:'map',roam:true,//是否开启缩放和平移zoom:1,//当前视角缩放比例......
  • 【算法笔记】树形DP算法总结&详解
    0.定义树形DP,又称树状DP,即在树上进行的DP,是DP(动态规划)算法中较为复杂的一种。1.基础令\(f[u]=~\)与树上顶点\(u\)有关的某些数据,并按照拓扑序(从叶子节点向上到根节点的顺序)进行\(\text{DP}\),确保在更新一个顶点时其子节点的dp值已经被更新好,以更新当前节点的\(\text{DP}\)值......
  • 树形结构-数据结构
    一、基本知识树:一对多的树形结构顶层的结点:称为根节点叶子结点(终端结点):最外围的结点,只有前驱结点,没有后继结点的结点,其结点的度是0分支结点:分支点是描述数据结构中的从根部出发(对有向图而言)有入度和出度的节点,(对无向图而言)不属于叶子节点的节点。出度不为0的结点称为分枝点......