目录
表头:
表身:
可以通过以下方式控制表格全屏状态:
-
- <template>
- <el-tooltip
- effect="dark"
- :content="fullScreen ? '取消全屏' : '全屏'"
- placement="top"
- :auto-close="1000"
- >
- <span class="tooltip-outline-none" @click="handleSetFullScreen()">
- <el-icon v-if="!fullScreen" class="pointer tooltip-icon" :size="18">
- <full-screen />
- el-icon>
- <i v-if="fullScreen" class="fa fa-compress pointer tooltip-icon">i>
- span>
- el-tooltip>
- template>
-
- <script lang="ts">
- import {
- reactive,
- toRefs,
- defineComponent,
- onMounted,
- onUnmounted,
- } from 'vue';
-
- export default defineComponent({
- name: 'TFullScreenButton',
- emits: ['full-screen-change'],
- setup(props, { emit }) {
- // 响应式数据
- const state = reactive({
- // 是否全屏
- fullScreen: false,
- });
-
- /**
- * esc 按键事件
- */
- const keydownEvent = (event: KeyboardEvent) => {
- if (document.fullscreenElement) {
- document.exitFullscreen();
- }
- if (event.keyCode === 27) {
- state.fullScreen = false;
- }
- // 发送事件,切换全屏状态
- emit('full-screen-change', state.fullScreen);
- };
-
- /**
- * esc 窗口尺寸变化事件
- */
- const windowResizeEvent = () => {
- state.fullScreen = document.fullscreen;
- // 发送事件,切换全屏状态
- emit('full-screen-change', state.fullScreen);
- };
-
- /**
- * 设置控制全屏显示状态值
- */
- const handleSetFullScreen = () => {
- // 设置状态值
- state.fullScreen = !state.fullScreen;
- // 浏览器全屏模式
- if (state.fullScreen && document.body.requestFullscreen) {
- document.body.requestFullscreen();
- } else if (document.fullscreenElement) {
- // 浏览器退出全屏模式
- document.exitFullscreen();
- }
- // 发送事件,切换全屏状态
- emit('full-screen-change', state.fullScreen);
- };
-
- onMounted(async () => {
- // 监听 esc 按键事件 退出全屏
- window.addEventListener('keyup', keydownEvent, false);
- // 监听窗口尺寸改变事件 退出全屏
- window.addEventListener('resize', windowResizeEvent, false);
- });
-
- onUnmounted(() => {
- // 移除监听事件
- window.removeEventListener('keyup', keydownEvent);
- window.removeEventListener('resize', windowResizeEvent);
- });
-
- return {
- ...toRefs(state),
- handleSetFullScreen,
- };
- },
- });
- script>
使用 el-dropd