Blame view

src/components/Screenfull/index.vue 1.29 KB
c21fb5b0   monkeyhouyi   巡查上报页面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  <template>
    <el-tooltip effect="dark"
      :content="isFullscreen?$t('common.outFullScreen'):$t('common.fullScreen')" placement="top">
      <el-link
        :icon="`icon-ym ${isFullscreen?'icon-ym-compress-screen1':'icon-ym-full-screen1'} NCC-common-head-icon`"
        :underline="false" @click="click()" />
    </el-tooltip>
  </template>
  
  <script>
  import screenfull from 'screenfull'
  
  export default {
    props: {
      isContainer: {
        type: Boolean,
        default: true
      }
    },
    name: 'Screenfull',
    data() {
      return {
        refEle: '',
        isFullscreen: false
      }
    },
    mounted() {
      this.init()
      this.refEle = this.$options.parent.$el
    },
    beforeDestroy() {
      this.destroy()
    },
    methods: {
      click() {
        if (!screenfull.enabled) {
          this.$message({
            message: '不支持全屏',
            type: 'warning'
          })
          return false
        }
        if (this.isContainer) {
          screenfull.toggle(this.refEle)
        } else {
          screenfull.toggle()
        }
      },
      change() {
        this.isFullscreen = screenfull.isFullscreen
      },
      init() {
        if (screenfull.enabled) {
          screenfull.on('change', this.change)
        }
      },
      destroy() {
        if (screenfull.enabled) {
          screenfull.off('change', this.change)
        }
      }
    }
  }
  </script>