<!--
@description: pdf查看 全局使用
@author: 肖文龙
@date：  2020-2-6 15:12:17
-->
<template>
  <div style="postion:relative">
    <iframe
      v-if="isShow"
      :src="pdfDomainURL + pdfUrl"
      :height="height"
      frameborder="0"
      width="100%"
    />
    <!--正在加载中-->
    <div v-else id="loadingBar">
      <div class="progress">
        <div class="glimmer" />
        暂无数据...
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'Pdf',
  props: {
    // pdf地址
    pdfUrl: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      height: 0,
      isShow: false, // 是否加载pdf
      pdfDomainURL: '/static/pdf/web/viewer.html?file='// 地址
    }
  },
  computed: {
    /* contextPath 配置环境路径*/
    ...mapGetters(['contextPath'])
  },
  watch: {
    pdfUrl(val) {
      if (val) {
        this.isShow = true
      }
    }
  },
  created() {
    this.pdfDomainURL = this.contextPath + this.pdfDomainURL// 配置环境路径
    if (this.pdfUrl) {
      this.isShow = true
    }
    // 获取公告内容pdf
    this.height = document.body.clientHeight - 56 - 70 - 50
    window.onresize = () => {
      this.height = document.body.clientHeight - 56 - 70 - 50
    }
  }
}
</script>
<style lang='less' scoped>
</style>
