/** * 全屏功能组合式函数 * 提供全屏状态管理和相关工具函数 * 适用于所有应用组件 */ import { ref, computed, inject } from 'vue'; /** * 使用全屏功能 * @param {Object} options - 配置选项 * @param {number} options.headerHeight - Header高度,默认64px * @returns {Object} 全屏相关的响应式数据和方法 * * @example * // 在组件中使用 * const { isFullscreen, containerHeight, fullscreenClass } = useFullscreen(); * * // 在模板中使用 *
* ... *
*/ export function useFullscreen(options = {}) { const { headerHeight = 64 } = options; // 从父组件获取全屏状态 const isFullscreen = inject('isFullscreen', ref(false)); // 计算容器高度 const containerHeight = computed(() => { return isFullscreen.value ? '100vh' : `calc(100vh - ${headerHeight}px)`; }); // 计算全屏样式类 const fullscreenClass = computed(() => { return isFullscreen.value ? 'app-fullscreen' : ''; }); // 计算容器高度值(用于JavaScript计算) const containerHeightValue = computed(() => { return isFullscreen.value ? window.innerHeight : window.innerHeight - headerHeight; }); /** * 获取容器高度(用于Canvas等需要数值的场景) * @returns {number} 容器高度值 */ const getContainerHeight = () => { return isFullscreen.value ? window.innerHeight : window.innerHeight - headerHeight; }; /** * 获取容器宽度 * @returns {number} 容器宽度值 */ const getContainerWidth = () => { return window.innerWidth; }; return { // 响应式状态 isFullscreen, containerHeight, containerHeightValue, fullscreenClass, // 方法 getContainerHeight, getContainerWidth }; }