Blame view

HHECS.Web/src/components/Screenfull/index.vue 1.24 KB
1
2
<template>
  <div>
胡菁 authored
3
4
5
6
    <svg-icon
      :icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'"
      @click="click"
    />
7
8
9
10
  </div>
</template>

<script>
胡菁 authored
11
import screenfull from "screenfull";
12
export default {
胡菁 authored
13
  name: "Screenfull",
14
15
  data() {
    return {
胡菁 authored
16
17
      isFullscreen: false,
    };
18
19
  },
  mounted() {
胡菁 authored
20
    this.init();
21
    // 默认进入全屏
胡菁 authored
22
23
    if (window.appConfig.isFullscreen) {
      if (screenfull.isEnabled) {
胡菁 authored
24
25
        screenfull.request();
        this.isFullscreen = true;
胡菁 authored
26
      }
27
    }
28
29
  },
  beforeDestroy() {
胡菁 authored
30
    this.destroy();
31
32
33
34
35
  },
  methods: {
    click() {
      if (!screenfull.isEnabled) {
        this.$message({
胡菁 authored
36
37
38
39
          message: "you browser can not work",
          type: "warning",
        });
        return false;
40
      }
胡菁 authored
41
      screenfull.toggle();
42
43
    },
    change() {
胡菁 authored
44
      this.isFullscreen = screenfull.isFullscreen;
45
46
    },
    init() {
胡菁 authored
47
      if (screenfull.isEnabled) {
胡菁 authored
48
        screenfull.on("change", this.change);
49
50
51
      }
    },
    destroy() {
胡菁 authored
52
      if (screenfull.isEnabled) {
胡菁 authored
53
        screenfull.off("change", this.change);
54
      }
胡菁 authored
55
56
57
    },
  },
};
58
59
</script>
胡菁 authored
60
61
62
63
64
65
66
67
68
69
<style scoped>
.screenfull-svg {
  display: inline-block;
  cursor: pointer;
  fill: #5a5e66;
  width: 20px;
  height: 20px;
  vertical-align: 10px;
}
</style>