From baa8568ea8026dea4bb765ee84b27be66ce94105 Mon Sep 17 00:00:00 2001 From: ln1778 <465410291@qq.com> Date: Tue, 10 Sep 2024 10:37:32 +0800 Subject: [PATCH] ww --- packages/agMutionCheckbox/src/index.vue | 99 +++++++++++++++++++++---- src/App.vue | 5 +- 2 files changed, 88 insertions(+), 16 deletions(-) diff --git a/packages/agMutionCheckbox/src/index.vue b/packages/agMutionCheckbox/src/index.vue index 961ba5b..767ea5a 100644 --- a/packages/agMutionCheckbox/src/index.vue +++ b/packages/agMutionCheckbox/src/index.vue @@ -10,7 +10,7 @@ > - {{ dropdownvalue }}{{ checkedList.length==0?placeholder:dropdownvalue }}+ {{ valuelength }}{ + return this.checkedList.find((c)=>c==f.value); + }); + if(filters.length>0){ + const [onedatas,...otherdatas]=filters; + this.valuelength=otherdatas.length; + this.dropdownvalue=onedatas.label; + if(filters.length==this.olddatas.length){ + this.checkAll=true; + this.isIndeterminate=false; + }else{ + this.checkAll=false; + this.isIndeterminate=true; + } + }else{ + this.valuelength=0; + this.dropdownvalue=""; + this.checkAll=false; + this.isIndeterminate=false; + } } }else{ this.olddatas=Object.assign([],this.dataList); @@ -121,6 +146,26 @@ } if(this.value){ this.checkedList=this.value; + const filters=this.olddatas.filter((f)=>{ + return this.checkedList.find((c)=>c==f.value); + }); + if(filters.length>0){ + const [onedatas,...otherdatas]=filters; + this.valuelength=otherdatas.length; + this.dropdownvalue=onedatas.label; + if(filters.length==this.olddatas.length){ + this.checkAll=true; + this.isIndeterminate=false; + }else{ + this.checkAll=false; + this.isIndeterminate=true; + } + }else{ + this.valuelength=0; + this.dropdownvalue=""; + this.checkAll=false; + this.isIndeterminate=false; + } } } else{ this.olddatas=Object.assign([],this.dataList); @@ -136,8 +181,9 @@ this.isIndeterminate = false; this.checkAll=false; }, - checkeddown(val){ - console.log(val,"val") + checkeddown(val){ + this.oldvalue={list:this.checkedList,checkAll:this.checkAll,isIndeterminate:this.isIndeterminate}; + }, dropdownchange(){ @@ -152,21 +198,42 @@ this.isIndeterminate = false; this.checkAll=val; }, - confirm(e){ - + confirm(e,type){ + if(e&&type=="only"){ + this.checkedList=[e.value]; + if(this.olddatas.length!=1){ + this.isIndeterminate=true; + this.checkAll=false; + }else{ + this.isIndeterminate=false; + this.checkAll=true; + } - if(e&&e.label=="only"){ const filters=this.olddatas.filter((f)=>{ - return e.value.find((c)=>c==f.value); - }); - const [onedatas,...otherdatas]=filters; - this.valuelength=otherdatas.length; - this.dropdownvalue=onedatas.label; - + return f.value==e.value + }); if(this.$listeners.onSearch){ this.$emit("onSearch",[e.value]); - } + } + if(filters.length==0){ + this.valuelength=0; + this.dropdownvalue=""; + this.$refs.multioncheckref.hide(); + return; + } + const [onedatas,...otherdatas]=filters; + this.valuelength=otherdatas.length; + this.dropdownvalue=onedatas.label; }else{ + if(this.checkedList.length==0){ + this.valuelength=0; + this.dropdownvalue=""; + if(this.$listeners.onSearch){ + this.$emit("onSearch",this.checkedList); + } + this.$refs.multioncheckref.hide(); + return; + } const filters=this.olddatas.filter((f)=>{ return this.checkedList.find((c)=>c==f.value); }); @@ -193,6 +260,10 @@ } }, cancel(){ + this.checkedList=this.oldvalue.list; + this.isIndeterminate=this.oldvalue.isIndeterminate; + this.checkAll=this.oldvalue.checkAll; + this.$refs.multioncheckref.hide(); } diff --git a/src/App.vue b/src/App.vue index 1fefb67..11b4d88 100644 --- a/src/App.vue +++ b/src/App.vue @@ -54,7 +54,7 @@ - +