Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/layout/hooks/usePageHeight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { computed } from "vue";

import { useGlobal } from "@pureadmin/utils";
import { useTags } from "@/layout/hooks/useTag";

const NAVBAR_HEIGHT = 48; // 顶部导航栏高度
const TAGS_HEIGHT_CHROME = 38; // Chrome 模式标签页高度
const TAGS_HEIGHT_DEFAULT = 34; // 默认标签页高度
const FOOTER_HEIGHT = 32; // 页脚高度

/**
* 获取当前页面内容区的可用高度
*/
export function usePageHeight() {
const { $storage } = useGlobal<GlobalPropertiesApi>();
const { showModel } = useTags();

const hideTabs = computed(() => $storage?.configure.hideTabs);
const hideFooter = computed(() => $storage?.configure.hideFooter);

const tagsHeight = computed(() => {
if (hideTabs.value) return 0;
return showModel.value === "chrome"
? TAGS_HEIGHT_CHROME
: TAGS_HEIGHT_DEFAULT;
});

const footerHeight = computed(() => {
return hideFooter.value ? 0 : FOOTER_HEIGHT;
});

const pageHeight = computed(() => {
const offset = NAVBAR_HEIGHT + tagsHeight.value + footerHeight.value;
return `calc(100vh - ${offset}px)`;
});

return pageHeight;
}