FullScreen.vue 2.39 KB
<template>
    <div>
        <FullscreenOutlined id="full-screen-btn" v-show="fullScreen" class="top-nav-right-btn full-screen-btn" @click="fullScreen(true)"/>
    </div>
</template>

<script>
import {
  FullscreenOutlined,
  FullscreenExitOutlined
} from '@ant-design/icons-vue';
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';
.full-screen-btn {
    display: block;
    font-size: 20px;
    color: @defaultThemeColor;
}
</style>