记录-- vue+element树节点的标注

Posted wwj007

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了记录-- vue+element树节点的标注相关的知识,希望对你有一定的参考价值。

html(背景:状态标注3钟颜色红黄绿对应0,1,2,)

    <el-tree 
                    @check="slclasscheck" 
                    v-if="treeShow" 
                    :data="slclass"  
                    show-checkbox  
                    node-key="id" 
                    :default-expanded-keys="baseCheckedKeys" 
                    :default-checked-keys="baseCheckedKeys" 
                    ref="bstree">
                    <span class="custom-tree-node" slot-scope="obj">
                        <span style="user-select: none;">obj.data && obj.data.label</span>
                        <span v-if="obj.data.num!=0&&obj.data.state==0" class="red-circle"></span>
                        <span v-else-if="obj.data.num!=0&&obj.data.state==1" class="yellow-circle"></span>
                        <span v-else-if="obj.data.num!=0&&obj.data.state==2" class="gray-circle"></span>
                    </span>
                </el-tree>

js

      // 状态获取
      getState: function(obj, id, over, mid, err) 
        if (over.indexOf(id) != -1) 
          obj.state = 0;
         else if (mid.indexOf(id) != -1) 
          obj.state = 1;
         else if (err.indexOf(id) != -1) 
          obj.state = 2;
        
      ,
      // 获取子站数目
      getNum:function (data,id,obj) 
          for (let i = 0; i < 3; i++) 
             for(let key in data[i])
                 if(id &&id==key)
                  obj.num=data[i][key]
                 else
                     let arr=obj.children
                     if(arr)
                         arr.forEach(a => 
                             if(a.id==key)
                                 a.num=data[i][key]
                             
                         );
                     
                 
             
         
      ,
      // 获取预警统计数目
      getWarnCount: function() 
    //模拟数据
        var data = 
          "0": 
            waterQuality1: 1,     //数目为0时不做标注
          ,
          "1": 
            waterQuality1: 12,//数目为0时不做标注
          ,
          "2": 
            waterQuality1: 18,//数目为0时不做标注
          
        ;
        var over = [];
        var mid = [];
        var err = [];
        function classify(array, i) 
          for (let key in data[i]) 
            array.push(key);
                          
        
        classify(over, 0);
        classify(mid, 1);
        classify(err, 2);
        
        slclass.forEach(obj => 
          let id = obj.id;
          this.getNum(data,id,obj)
          if (id) 
            this.getState(obj, id, over, mid, err);
           else 
            if (obj.children) 
              let arr = obj.children;
              arr.forEach(a => 
                this.getState(a, a.id, over, mid, err);
              );
            
          
        );
      ,
        created()
                     this.getWarnCount();
            this.slclass = slclass
        ,

slclass部分数据

var slclass = [
    
        label: "地表水质监测",
        children: [
            
                id: "waterQuality1",
                label: "水质集装箱站",
            ,
            
                id: "waterQuality2",
                label: "水质微型站",
            ,
        ]
    ,
    
        label: "土壤采样点",
        children: [
            
                label: "园地采样点",
                disabled: true
            ,
            
                label: "水源地二级保护区采样点",
                disabled: true
            
        ]
    ,
    
        id: '雨量',
        label: '园地',
    
]

以上是关于记录-- vue+element树节点的标注的主要内容,如果未能解决你的问题,请参考以下文章

vue + element 中的tree树,自定义增加单选按钮radio实现单选

vue+element:current-node-key和setCurrentKey设置默认选中并高亮节点,附带全部展开,全部关闭,重新渲染树结构函数render-content

antd vue tree树形结构问题记录

vue使用vue+element搭建项目,Tree树形控件使用

怎么改变element tree节点垂直距离

Cat-Tree-Select 基于Vue+Element的树选择器