vue-vben-admin/src/layouts/default/header/components/FullScreen.vue

45 lines
1.3 KiB
Vue
Raw Normal View History

2020-12-15 00:13:23 +08:00
<template>
<Tooltip :title="getTitle" placement="bottom" :mouseEnterDelay="0.5">
2021-03-27 01:11:22 +08:00
<span @click="toggle">
2020-12-15 00:13:23 +08:00
<FullscreenOutlined v-if="!isFullscreen" />
<FullscreenExitOutlined v-else />
</span>
</Tooltip>
</template>
<script lang="ts">
import { defineComponent, computed, unref } from 'vue';
import { Tooltip } from 'ant-design-vue';
import { useI18n } from '/@/hooks/web/useI18n';
2021-03-27 01:11:22 +08:00
import { useFullscreen } from '@vueuse/core';
2020-12-15 00:13:23 +08:00
import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons-vue';
export default defineComponent({
name: 'FullScreen',
components: { FullscreenExitOutlined, FullscreenOutlined, Tooltip },
setup() {
const { t } = useI18n();
2021-03-27 01:11:22 +08:00
const { toggle, isFullscreen } = useFullscreen();
// 重新检查全屏状态
isFullscreen.value = !!(
document.fullscreenElement ||
document.webkitFullscreenElement ||
document.mozFullScreenElement ||
document.msFullscreenElement
);
2020-12-15 00:13:23 +08:00
const getTitle = computed(() => {
2021-03-27 01:11:22 +08:00
return unref(isFullscreen)
2020-12-15 00:13:23 +08:00
? t('layout.header.tooltipExitFull')
: t('layout.header.tooltipEntryFull');
});
return {
getTitle,
2021-03-27 01:11:22 +08:00
isFullscreen,
toggle,
2020-12-15 00:13:23 +08:00
};
},
});
</script>