syncTree.vue 1.86 KB
<template>
  <div class="sync-tree scrollbar">
    <el-tree
      ref="synctree"
      v-if="isLoadingTree"
      :accordion="true"
      :filter-node-method="filterNode"
      :data="syncTreeData"
      class="resource-wrap"
      node-key="id"
      :expand-on-click-node="false"
      @node-click="handleNodeClick"
    ></el-tree>
  </div>
</template>

<script>
// import TreeRender from "../treeRender";
export default {
  data() {
    return {
      isLoadingTree: false,
      syncTreeData: [
        {
          id: "0",
          unid: "0",
          label: "平台同步资源",
          root: "平台同步资源",
          children: []
        }
      ],
      defaultProps: {
        children: "children",
        label: "label"
      }
    };
  },
  props: {
    filterText: {
      type: String,
      default: ""
    },
    treeDatas: {
      type: Array,
      defalut: []
    }
  },
  components: {},
 watch: {
    filterText(val) {
      this.$refs.synctree.filter(val);
    },
    treeDatas(val) {
      this.treeData[0].childs = val;
    }
  },
  methods: {
    initTree(data) {
      this.syncTreeData[0].children = data;
      this.isLoadingTree = true;
    },
    filterNode(value, data) {
      // console.log('filterNode:', data)
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    handleNodeClick(data){
      if(data.label === "平台同步资源") return;
        this.$emit('syncTable', data)
    },
    handleRefresh(s, d, n) {
      // console.log(s, d, n)
      console.log("调用父级方法: ", this);
      this.syncTreeData = [
        {
          id: "1",
          label: "平台同步资源",
          root: "平台同步资源",
          children: []
        }
      ];
      this.$parent.getSyncTree();
    }
  }
};
</script>

<style scoped>
.sync-tree {
  /* max-height: 216px; */
  /* overflow: hidden; */
}
</style>