FullScreen.vue
2.25 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
<template>
<i class="el-icon-full-screen" @click="fullScreen(true)"></i>
</template>
<script>
import { reactive, toRefs, onMounted } from 'vue';
import { useStore } from 'vuex';
export default {
name: 'SettingButton',
data() {
return {
fullscreen: true,
fullarea: ''
}
},
components: {
// FullscreenOutlined
},
setup() {
const store = useStore();
const state = reactive({
fullscreen: true,
fullarea: ''
});
const checkFull = () => {
var isFull = window.fullScreen || document.webkitIsFullScreen || document.msFullscreenEnabled;
//to fix : false || undefined == undefined
if (isFull === undefined) {isFull = false;}
return isFull;
}
onMounted(() => {
state.fullarea = document.getElementById('sub-system-frame');
//监听退出全屏事件
window.onresize = function() {
const fullStatus = checkFull();
store.dispatch('app/setFullscreen', fullStatus);
}
})
// 登出操作
const fullScreen = (isFull) => {
let { fullarea: element } = state;
// 判断各种浏览器,找到正确的方法
var requestMethod = element.requestFullScreen || //W3C
element.webkitRequestFullScreen || //FireFox
element.mozRequestFullScreen || //Chrome等
element.msRequestFullScreen; //IE11
if (requestMethod) {
requestMethod.call(element);
} else if (typeof window.ActiveXObject !== "undefined") { //for Internet Explorer
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
}
return {
...toRefs(state),
fullScreen
}
}
}
</script>
<style lang="less" scoped>
@import 'styles/common.less';
@import 'styles/variables.less';
.el-icon-full-screen {
margin-right: 20px;
font-size: 25px;
color: @defaultThemeColor;
cursor: pointer;
}
</style>