<script>
  import * as service from '../../service/LicenseService'

  // 资源显示组件，显示资源名称，授权信息等内容
  export default {
    props: {
      // 要显示的资源
      resource: {
        type: Object,
        require: true
      }
    },
    data() {
      return {
        // 资源授权全路径串
        licenseNames: ''
      }
    },
    ready() {
      this.refresh()
    },
    watch: {
      resource () {
        this.refresh()
      }
    },
    methods: {
      // 刷新数据
      refresh () {
        // 取得授权内容
        if (this.resource) {
          service.getDataNames(this.resource).then((names) => {
            this.licenseNames = names
            console.log('name' + this.licenseNames)
            // 告诉测试环境，ready执行完毕
            this.$emit('ready')
          })
        }
      },
    }
  }
</script>

<template>
  <span>
    <span>{{resource.name}}</span>
    <span>{{licenseNames}}</span>
  </span>
</template>
