Procházet zdrojové kódy

:sparkles: 懒加载树增加只选择最后一个子节点功能

Twelve615 před 1 rokem
rodič
revize
323f31b7e9

+ 28 - 1
jlsb-vue/src/components/jeecg/JTreeSelect.vue

@@ -74,7 +74,12 @@
         type: Boolean,
         default: false,
         required:false
-      }
+      },
+      // 是否只选择子节点,为True时只有叶子节点可以选择
+      chooseChild: {
+        type: Boolean,
+        default: false,
+      },
     },
     data () {
       return {
@@ -156,8 +161,14 @@
                 i.value = i.key
                 if(i.leaf==false){
                   i.isLeaf=false
+                  if(this.chooseChild) {
+                    i.selectable = false;
+                  }
                 }else if(i.leaf==true){
                   i.isLeaf=true
+                  if(this.chooseChild && i.parentId ==='0') {
+                    i.selectable = false;
+                  }
                 }
               }
               this.addChildren(pid,res.result,this.treeData)
@@ -173,14 +184,24 @@
             if(item.key == pid){
               if(!children || children.length==0){
                 item.isLeaf=true
+                if(this.chooseChild && item.parentId ==='0') {
+                  children.selectable = false;
+                }
               }else{
                 item.children = children
+                if(this.chooseChild) {
+                  item.selectable = false;
+                }
               }
               break
             }else{
               this.addChildren(pid,children,item.children)
             }
           }
+        } else {
+          if(this.chooseChild && children.parentId ==='0') {
+            children.selectable = false;
+          }
         }
       },
       loadRoot(){
@@ -199,8 +220,14 @@
               i.value = i.key
               if(i.leaf==false){
                 i.isLeaf=false
+                if(this.chooseChild) {
+                  i.selectable = false;
+                }
               }else if(i.leaf==true){
                 i.isLeaf=true
+                if(this.chooseChild && i.parentId ==='0') {
+                  i.selectable = false;
+                }
               }
             }
             this.treeData = [...res.result]

+ 2 - 0
jlsb-vue/src/views/aa/modules/AaCommodityForm.vue

@@ -41,10 +41,12 @@
           <a-col :span="24">
             <a-form-model-item label="分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="typeId">
   	          <j-tree-select
+                :choose-child="true"
                 ref="treeSelect"
                 placeholder="请选择分类"
                 v-model="model.typeId"
                 dict="aa_commodity_fl,name,id"
+                :hasChildField="'has_child'"
                 pidValue="0"
                 >
               </j-tree-select>