element-ui的树形结构样式调整,添加线条和边框样式

element-ui的树形结构样式调整,添加线条和边框样式

先看图效果:

javascript 复制代码
<template>
  <div class="temperature_monitoring">
    <div class="temperature_monitoring_left">
      <div class="tree-container">
        <el-tree
          ref="tree"
          class="tree filter-tree"
          :data="datalist"
          :props="defaultProps"
        >
          <span slot-scope="{ node, data }" class="custom-tree-node">
            <span :dataType="data.type">
              {{ node.label }}
            </span>
          </span>
        </el-tree>
      </div>
    </div>
    <div class="temperature_monitoring_right">内容</div>
  </div>
</template>

<script>
export default {
  name: 'TemperatureMonitoring',
  components: {},
  props: {},
  data() {
    return {
      datalist: [
        {
          label: '园区A',
          children: [
            {
              label: 'A栋',
              children: [
                {
                  label: '厂房1',
                  children: [
                    {
                      label: '车间1',
                      children: [
                        {
                          label: '101'
                        },
                        {
                          label: '102'
                        },
                        {
                          label: '103'
                        },
                        {
                          label: '104'
                        }
                      ]
                    },
                    {
                      label: '车间2'
                    },
                    {
                      label: '车间3'
                    },
                    {
                      label: '车间4'
                    }
                  ]
                },
                {
                  label: '厂房2',
                  children: [
                    {
                      label: '车间1'
                    },
                    {
                      label: '车间2'
                    },
                    {
                      label: '车间3'
                    },
                    {
                      label: '车间4'
                    }
                  ]
                },
                {
                  label: '厂房3',
                  children: [
                    {
                      label: '车间1'
                    },
                    {
                      label: '车间2'
                    },
                    {
                      label: '车间3'
                    },
                    {
                      label: '车间4'
                    }
                  ]
                },
                {
                  label: '厂房4',
                  children: [
                    {
                      label: '车间1'
                    },
                    {
                      label: '车间2'
                    },
                    {
                      label: '车间3'
                    },
                    {
                      label: '车间4'
                    }
                  ]
                },
                {
                  label: '厂房5',
                  children: [
                    {
                      label: '车间1'
                    },
                    {
                      label: '车间2'
                    },
                    {
                      label: '车间3'
                    },
                    {
                      label: '车间4'
                    }
                  ]
                }
              ]
            },
            {
              label: 'B栋',
              children: [
                {
                  label: '厂房1'
                }
              ]
            }
          ]
        }
      ],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    handleNodeClick(data) {
      console.log(data)
    }
  }
}
</script>

<style lang="scss" scoped>
.temperature_monitoring {
  display: flex;
  padding: 12px;
  .temperature_monitoring_left {
    width: 200px;
    padding-right: 12px;
  }
}
</style>

<style  lang='scss'>
.temperature_monitoring {
  /* 树形结构节点添加连线 */
  .tree .el-tree-node {
    position: relative;
  }

  .tree .el-tree-node__children {
    padding-left: 24px;
  }

  .tree .el-tree-node :last-child:before {
    height: 38px;
  }

  .tree .el-tree > .el-tree-node:before {
    border-left: none;
  }
  .tree-container .el-tree > .el-tree-node:after {
    border-top: none;
  }

  .tree .el-tree-node__children .el-tree-node:before {
    content: '';
    left: -4px;
    position: absolute;
    right: auto;
    border-width: 1px;
  }

  .tree .el-tree-node:after {
    content: '';
    left: -4px;
    position: absolute;
    right: auto;
    border-width: 1px;
  }
  .tree .el-tree-node__expand-icon.is-leaf {
    display: none;
  }

  .tree .el-tree-node:before {
    border-left: 1px solid #1173e6;
    bottom: 0px;
    height: 140%;
    top: -26px;
    width: 1px;
  }

  .tree .el-tree-node:after {
    border-top: 1px solid #1173e6;
    height: 20px;
    top: 12px;
    width: 24px;
  }

  .tree .el-tree-node {
    &:last-child:after {
      border-left: 1px solid #fff;
      height: 100%;
    }
  }

  .tree .custom-tree-node {
    padding-left: 10px;
  }
  .el-tree-node__content {
    border: 1px solid #1173e6;
    padding-left: 0 !important;
    padding-right: 32px;
    margin-left: 20px;
    margin-top: 8px;
  }
  .el-tree-node__content:hover {
    background: #1173e6;
    color: #fff;
    .el-tree-node__expand-icon {
      color: #fff;
    }
  }
  .el-tree-node__expand-icon {
    position: absolute;
    right: 2%;
    color: #1173e6;
  }
  .el-tree-node.is-current > .el-tree-node__content {
    color: #fff;
    background-color: #1067ee;
    .el-tree-node__expand-icon {
      color: #fff;
    }
  }
}
</style>
相关推荐
QQ1__8115175157 小时前
Spring boot名城小区物业管理系统信息管理系统源码-SpringBoot后端+Vue前端+MySQL【可直接运行】
前端·vue.js·spring boot
一粒黑子7 小时前
【实战解析】阿里开源 PageAgent:纯前端 GUI Agent,一行JS让网页支持自然语言操控
前端·javascript·开源
IT枫斗者7 小时前
前端部署后如何判断“页面是不是最新”?一套可落地的版本检测方案(适配 Vite/Vue/React/任意 SPA)
前端·javascript·vue.js·react.js·架构·bug
John_ToDebug7 小时前
隐于无形,触手可及:Chrome 互动滚动条的六个设计密码
chrome·windows·ui
Beginner x_u8 小时前
链表专题:JS 实现原理与高频算法题总结
javascript·算法·链表
我叫汪枫8 小时前
在后台管理系统中,如何递归和选择保留的思路来过滤菜单
开发语言·javascript·node.js·ecmascript
_.Switch8 小时前
东方财富股票数据JS逆向:secids字段和AES加密实战
开发语言·前端·javascript·网络·爬虫·python·ecmascript
软件技术NINI8 小时前
webkit简介及工作流程
开发语言·前端·javascript·udp·ecmascript·webkit·yarn
Brendan_0018 小时前
JavaScript的Stomp.over
开发语言·javascript·ecmascript
念2348 小时前
f5 shape分析
开发语言·javascript·ecmascript