All checks were successful
Build and Deploy Front / deploy (push) Successful in 3m31s
统一断点/Token 与跨端规范,窄屏收紧页面壳;精选线路区上移 50px。 Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { onMounted, onBeforeMount, onBeforeUnmount } from 'vue';
|
||
import { useDebounceFn } from '@vueuse/core';
|
||
import { APP_BREAKPOINTS } from '@/constants/breakpoints';
|
||
import { useAppStore } from '@/store';
|
||
import { addEventListen, removeEventListen } from '@/utils/event';
|
||
|
||
/** 与 @screen-lg / --app-bp-lg 一致;https://arco.design/vue/component/grid#responsivevalue */
|
||
const WIDTH = APP_BREAKPOINTS.lg;
|
||
|
||
function queryDevice() {
|
||
const rect = document.body.getBoundingClientRect();
|
||
return rect.width - 1 < WIDTH;
|
||
}
|
||
|
||
export default function useResponsive(immediate?: boolean) {
|
||
const appStore = useAppStore();
|
||
function resizeHandler() {
|
||
if (!document.hidden) {
|
||
const isMobile = queryDevice();
|
||
appStore.toggleDevice(isMobile ? 'mobile' : 'desktop');
|
||
appStore.toggleMenu(isMobile);
|
||
}
|
||
}
|
||
const debounceFn = useDebounceFn(resizeHandler, 100);
|
||
onMounted(() => {
|
||
if (immediate) debounceFn();
|
||
});
|
||
onBeforeMount(() => {
|
||
addEventListen(window, 'resize', debounceFn);
|
||
});
|
||
onBeforeUnmount(() => {
|
||
removeEventListen(window, 'resize', debounceFn);
|
||
});
|
||
}
|