<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) {
          console.log("资源名字",this.resource.name)
          service.getRightsMsg(this.resource).then((names) => {
           let str=''
            names.data.forEach((row) => {
              str=str+row.name+","
            })
            this.licenseNames=str
            this.$emit('ready')
          })
        }
      },
    }
  }
</script>

<template>
  <div class="auto">
    <div class="datapanel form-horizontal" style="min-height: 400px">
      <h3 class="txtline">&nbsp;&nbsp;拥有权限</h3>
      <h4>【{{licenseNames}}】</h4>
    </div>
  </div>
</template>
