<template>
  <div class="el-treecontain">
  <el-tree :data="data" :props="defaultProps"  class="el-treemain" @node-click="handleNodeClick"/>
  </div>
  <button @click="onopendata">click</button>
</template>

<script>
export default {
  name: "GuiLeftSider",
  data() {
    return {
      data: [{
        label: '请选择',
        children: [],
      },
      ],
      defaultProps: {
        children: 'children',
        label: 'label',
      },
      DefualtPath: "\\ARS_data"
    }
  },
  async mounted() {
    //if(this.$isElectron()) {
      this.DefualtPath="";
      return

  //  };
    await  this.onopendata();
  },
  methods: {
    handleNodeClick(data) {
      if (data.isLeaf)
       // console.log(getParentPath(data));
      this.$emit("NodeClicked", this.DefualtPath+getParentPath(data));

    },
    async onopendata() {
      let cfiles =  await this.$MyGetFolderlist(this.DefualtPath);
      this.data = [];
      this.data.push(cfiles);

    }
  }
}

function getParentPath(node) {
  if (!node) {
    return '';
  }

  if (node.parent) {
    return getParentPath(node.parent) + '\\' + node.label;
  } else {
    return '';
  }
}

</script>

<style scoped>
el-tree{
  height: 100vh;
  overflow: auto;
}
.el-treemain {
  min-width: 100%;
  white-space: nowrap; /* 不换行，使树节点水平排列 */
  display: inline-block; /* 横向排列 */
  text-align: left;
}
.el-treecontain{
  width: 100%;
  text-align: left;
}
</style>
