Files
orange-admin/OrangeFormsOpen-VUE3/src/common/hooks/useWindowResize.ts
2024-09-26 15:01:08 +08:00

50 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { onMounted, onUnmounted, provide, ref } from 'vue';
import { useLayoutStore } from '@/store';
import { getAppId } from '../utils';
// 屏幕宽度分界值,影响整体样式
const WIDTH = 1900;
const documentClientHeight = ref(0);
/**
* 在最顶层使用该hook一方面监听窗口大小变化同时向下面提供一个计算属性
*/
export const useWindowResize = () => {
const windowResize = () => {
documentClientHeight.value = document.documentElement.clientHeight;
if (window.innerWidth <= WIDTH) {
layoutStore.defaultFormItemSize = 'default';
document.body.className = 'orange-project container-default';
} else {
layoutStore.defaultFormItemSize = 'default';
document.body.className = 'orange-project container-default';
}
layoutStore.documentClientHeight = document.documentElement.clientHeight;
layoutStore.mainContextHeight = mainContextHeight.value;
};
const layoutStore = useLayoutStore();
const mainContextHeight = computed(() => {
const appId = getAppId();
if (appId == null) {
return documentClientHeight.value - (layoutStore.supportTags ? 110 : 60);
} else {
return documentClientHeight.value;
}
});
provide('documentClientHeight', documentClientHeight);
provide('mainContextHeight', mainContextHeight);
onMounted(() => {
windowResize();
window.addEventListener('resize', windowResize);
});
onUnmounted(() => {
window.removeEventListener('resize', windowResize);
});
};