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>
相关推荐
前端君5 小时前
实现最大异步并发执行队列
javascript
知识分享小能手6 小时前
React学习教程,从入门到精通,React 组件核心语法知识点详解(类组件体系)(19)
前端·javascript·vue.js·学习·react.js·react·anti-design-vue
蚂蚁RichLab前端团队7 小时前
🚀🚀🚀 RichLab - 花呗前端团队招贤纳士 - 【转岗/内推/社招】
前端·javascript·人工智能
萌萌哒草头将军8 小时前
Oxc 和 Rolldown Q4 更新计划速览!🚀🚀🚀
javascript·vue.js·vite
Qlittleboy8 小时前
uniapp如何使用本身的字体图标
javascript·vue.js·uni-app
小白菜学前端8 小时前
vue2 常用内置指令总结
前端·vue.js
林_深时见鹿8 小时前
Vue + ElementPlus 自定义指令控制输入框只可以输入数字
前端·javascript·vue.js
GDAL8 小时前
Knockout.js 任务调度模块详解
javascript·knockout
椒盐螺丝钉8 小时前
Vue组件化开发介绍
前端·javascript·vue.js
koooo~8 小时前
v-model与-sync的演变和融合
前端·javascript·vue.js