Pārlūkot izejas kodu

修改下拉树组件属性是否默认展开所有节点及值的设置

ymy 2 gadi atpakaļ
vecāks
revīzija
26db346358

+ 6 - 4
src/benyun/components/byForm/byForm.vue

@@ -176,11 +176,13 @@ export default class ByForm extends VueViews {
 
 
   //设置下级组件值
   //设置下级组件值
   setChildrenComValue(){
   setChildrenComValue(){
-    if(this.value){
-      for(const key in (this as any).$refs){
-        if(key.indexOf('Comp') >= 0 && (this as any).$refs[key] && (this as any).$refs[key][0] && (this as any).$refs[key][0].setValue){
-          const code = key.split('Comp')[0];
+    for(const key in (this as any).$refs){
+      if(key.indexOf('Comp') >= 0 && (this as any).$refs[key] && (this as any).$refs[key][0] && (this as any).$refs[key][0].setValue){
+        const code = key.split('Comp')[0];
+        if(this.value){
           (this as any).$refs[key][0].setValue(this.value[code])
           (this as any).$refs[key][0].setValue(this.value[code])
+        }else{
+          (this as any).$refs[key][0].setValue(null)
         }
         }
       }
       }
     }
     }

+ 32 - 4
src/benyun/components/selectTree/selectTree.vue

@@ -4,8 +4,8 @@
     :width="attrs.width?attrs.width:'300'"
     :width="attrs.width?attrs.width:'300'"
     trigger="click"
     trigger="click"
     >
     >
-    <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick" highlight-current node-key="id"></el-tree>
-    <el-input :value="value" slot="reference" :placeholder="attrs.placeholder?attrs.placeholder:'请选择'" :clearable="attrs.clearable" @clear="clear" suffix-icon="el-icon-arrow-down"></el-input>
+    <el-tree :data="data" :props="defaultProps" :default-expand-all="attrs.defaultExpandAll" @node-click="handleNodeClick" highlight-current node-key="id"></el-tree>
+    <el-input :value="titleName" slot="reference" :placeholder="attrs.placeholder?attrs.placeholder:'请选择'" :clearable="attrs.clearable" @clear="clear" suffix-icon="el-icon-arrow-down"></el-input>
   </el-popover>
   </el-popover>
 </template>
 </template>
 
 
@@ -24,6 +24,7 @@
       placeholder:''  //占位符
       placeholder:''  //占位符
       label:''  //标签
       label:''  //标签
       children:'' //下一级
       children:'' //下一级
+      defaultExpandAll:false/true  //是否默认展开所有节点
     },
     },
     request:{}
     request:{}
   }
   }
@@ -33,7 +34,7 @@ import VueViews from '@/benyun/compVue/VueViews'
 @Component
 @Component
 export default class SelectTree extends VueViews {
 export default class SelectTree extends VueViews {
   data:Array<any>=[]
   data:Array<any>=[]
-
+  titleName='';
   get defaultProps(){
   get defaultProps(){
     let c:any={
     let c:any={
       children: 'children',
       children: 'children',
@@ -69,6 +70,7 @@ export default class SelectTree extends VueViews {
   clear(){
   clear(){
     this.value='';
     this.value='';
     let obj:any = {};
     let obj:any = {};
+    this.titleName = '';
     try{
     try{
       if(this.attrs.retConfig){
       if(this.attrs.retConfig){
         for(const key in this.attrs.retConfig){
         for(const key in this.attrs.retConfig){
@@ -82,10 +84,36 @@ export default class SelectTree extends VueViews {
   }
   }
   setData(data:Array<any>){
   setData(data:Array<any>){
     this.data = data;
     this.data = data;
+    if(this.value){
+      this.getLabel(this.data);
+    }
+  }
+
+  getLabel(data:Array<any>){
+    for(const item of data){
+      let t = false;
+      for(const key in this.attrs.retConfig){
+        const code = this.attrs.retConfig[key];
+        if(item[code] == this.value){
+          this.titleName = item[this.defaultProps.label]
+          t = true;
+          break;
+        }
+      }
+
+      if(!t && item[this.defaultProps.children]){
+        this.getLabel(item[this.defaultProps.children]);
+      }
+    }
   }
   }
 
 
   setValue(v:any){
   setValue(v:any){
     this.value = v;
     this.value = v;
+    if(v && this.data.length > 0){
+      this.getLabel(this.data);
+    }else{
+      this.titleName = '';
+    }
   }
   }
 
 
   getValue(){
   getValue(){
@@ -93,7 +121,7 @@ export default class SelectTree extends VueViews {
   }
   }
 
 
   handleNodeClick(data:any){
   handleNodeClick(data:any){
-    this.value = data[this.defaultProps.label];
+    this.titleName = data[this.defaultProps.label];
     let obj:any = {};
     let obj:any = {};
     try{
     try{
       if(this.attrs.retConfig){
       if(this.attrs.retConfig){