element-ui table-tree 组件

此组件主要是在element-ui的el-tree的基础上,实现table-tree的组件封装,此组件主要是提供封装的思路,具体的代码模块还没有来的及上传到GitHub,如果有需求的同行可以私信。
话不多说直接上效果


效果图.png

具体代码
html

  • 学科名称
  • 课程数
  • 创建时间
  • 操作

style

.content-tab {
    .tree-super {
      padding: 11px 20px;
      .titie {
        width: 100%;
        overflow: hidden;
        display: flex;
        box-sizing: border-box;
        li {
          height: 40px;
          line-height: 40px;
          background-color: #ebedf8;
          text-align: center;
          border-left: 1px solid #d4d9e1;
        }
        li:first-child {
          padding-left: 22px;
          height: 40px;
          line-height: 40px;
          width: 303px;
          background-color: #ebedf8;
          box-sizing: border-box;
          border-left: 0;
        }
        li:nth-child(n + 2) {
          flex: 1;
        }
      }
    }
  }

js

import BreadTab from "@/components/BreadTab/BreadTab.vue";
import DialogAdd from "@/components/DialogTemplate/DialogTemplate.vue";

export default {
  data() {
    return {
      selectDis: "1",
      options: [
        {
          value: "1",
          label: "全部"
        },
        {
          value: "2",
          label: "PMP"
        }
      ],
      props: {
        label: "name",
        children: "children",
        value: "id"
      },
      treeData: [
        {
          id: 1,
          name: "PMP",
          children: [
            {
              id: 3,
              name: "PMP"
            },
            {
              id: 4,
              name: "PMP培训考试"
            }
          ]
        },
        {
          id: 2,
          name: "软考",
          children: [
            {
              id: 5,
              name: "软考"
            },
            {
              id: 6,
              name: "软考在线"
            },
            {
              id: 7,
              name: "软考培训"
            }
          ]
        }
      ],
      isShowAdd: false,
      inputDisName: ""
    };
  },
  components: {
    BreadTab,
    DialogAdd
  },
  methods: {
    addDis() {
      console.log("添加学科");
      this.isShowAdd = true;
    },
    renderContent(h, { node, data }) {
      let titie = "";
      let wid = "";

      if (node.level != 1) {
        wid = 280 - (node.level - 1) * 18 + "px";
        titie = h(
          "span",
          {
            style: {
              display: "inline-block",
              width: wid,
              height: "50px",
              "line-height": "50px"
            }
          },
          node.label
        );
      } else {
        titie = (
          
            {node.label}
             this.addSubDis(node, data)}
            >
          
        );
      }

      return (
        
{titie} 200 2020-05-22 16:03:22 this.append(data, node)} > 编辑 this.remove(node, data)} > 删除
); }, addSubDis(node, data) { console.log(node); console.log(data); this.isShowAdd = true; }, hiddenShow(data) { if (data.num === 2 && !this.inputDisName) { this.$message.error("输入学科名称不能为空呦"); } else { this.isShowAdd = false; } }, remove(node, data) {}, append(node, data) {} } };

结论说明

此组件主要的技术是使用el-tree:render-content="renderContent" 来做自定义话的配置。
如果对阁下有帮助,请不惜点个赞,谢谢!

你可能感兴趣的:(element-ui table-tree 组件)