<template>
  <el-container>
    <el-header>
      <h3>构建数据目录</h3>
    </el-header>
    <el-main>
      <el-table
        :data="dataList"
        border
        height="480"
        style="width: 100%"
      >
        <el-table-column
          prop="machineIpv4"
          label="机器地址"
        />
        <el-table-column
          prop="dirPath"
          label="本地目录"
        />
        <el-table-column
          prop="mountedOn"
          label="所属分区"
        />
        <el-table-column
          prop="totalStr"
          label="分区总量"
        />
        <el-table-column
          prop="availStr"
          label="分区可用"
        />
        <el-table-column
          fixed="right"
          label="操作"
          width="280"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
            >清空</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
  </el-container>
</template>

<script>
import { eraseBuildDir, getBuildDir } from '@/api/devops'

export default {
  name: 'BuildDir',
  data() {
    return {
      dataList: []
    }
  },
  created() {
    document.title = '构建目录'
    this.getData()
  },
  methods: {
    getData() {
      this.dataList = []
      getBuildDir().then(resp => {
        if (resp.code === 0) {
          this.dataList = resp.data
        } else {
          this.$message.error(resp.msg)
        }
      }).catch(error => {
        this.$message.error(error.message)
      })
    },
    handleEdit(index, row) {
      eraseBuildDir().then(resp => {
        this.getData()
        this.$message.info(resp.msg)
      }).catch(error => {
        this.$message.error(error.message)
      })
    }
  }
}
</script>

<style>
</style>
