fix. 코드 리팩토링
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import { useMediaQuery } from '@vueuse/core'
|
||||
import { getDeviceSrc } from '#layers/utils/styleUtil'
|
||||
import type { PageDataResourceGroupResPath } from '#layers/types/api/pageData'
|
||||
|
||||
const BREAKPOINTS = {
|
||||
xs: 360,
|
||||
sm: 768,
|
||||
@@ -6,18 +10,49 @@ const BREAKPOINTS = {
|
||||
} as const
|
||||
|
||||
/**
|
||||
* 확실한 반응형 브레이크포인트 헬퍼 (useWindowSize 기반)
|
||||
* useMediaQuery 기반 반응형 브레이크포인트
|
||||
*/
|
||||
export const useResponsiveBreakpointsReliable = () => {
|
||||
const { width } = useWindowSize()
|
||||
export const useResponsiveBreakpoints = () => {
|
||||
const ssrWidth = BREAKPOINTS.xs
|
||||
const isXs = useMediaQuery(`(min-width: ${BREAKPOINTS.xs}px)`, { ssrWidth })
|
||||
const isSm = useMediaQuery(`(min-width: ${BREAKPOINTS.sm}px)`, { ssrWidth })
|
||||
const isMd = useMediaQuery(`(min-width: ${BREAKPOINTS.md}px)`, { ssrWidth })
|
||||
const isLg = useMediaQuery(`(min-width: ${BREAKPOINTS.lg}px)`, { ssrWidth })
|
||||
const isMobile = useMediaQuery(`(max-width: ${BREAKPOINTS.md - 1}px)`, {
|
||||
ssrWidth,
|
||||
})
|
||||
const isTablet = useMediaQuery(
|
||||
`(min-width: ${BREAKPOINTS.sm}px) and (max-width: ${BREAKPOINTS.md - 1}px)`,
|
||||
{ ssrWidth }
|
||||
)
|
||||
const isDesktop = useMediaQuery(`(min-width: ${BREAKPOINTS.md}px)`, {
|
||||
ssrWidth,
|
||||
})
|
||||
|
||||
return computed(() => ({
|
||||
xs: width.value >= BREAKPOINTS.xs,
|
||||
sm: width.value >= BREAKPOINTS.sm,
|
||||
md: width.value >= BREAKPOINTS.md,
|
||||
lg: width.value >= BREAKPOINTS.lg,
|
||||
isMobile: width.value < BREAKPOINTS.md,
|
||||
isTablet: width.value >= BREAKPOINTS.sm && width.value < BREAKPOINTS.md,
|
||||
isDesktop: width.value >= BREAKPOINTS.md,
|
||||
isXs: isXs.value,
|
||||
isSm: isSm.value,
|
||||
isMd: isMd.value,
|
||||
isLg: isLg.value,
|
||||
isMobile: isMobile.value,
|
||||
isTablet: isTablet.value,
|
||||
isDesktop: isDesktop.value,
|
||||
}))
|
||||
}
|
||||
|
||||
export const useResponsiveSrc = () => {
|
||||
const breakpoints = useResponsiveBreakpoints()
|
||||
|
||||
const getCurrentSrc = (
|
||||
path: PageDataResourceGroupResPath,
|
||||
options?: {
|
||||
resourcesType?: 'image' | 'video'
|
||||
}
|
||||
) => {
|
||||
const result = getDeviceSrc(path, options)
|
||||
if (!result) return ''
|
||||
return breakpoints.value.isMobile ? result.mobileSrc : result.pcSrc
|
||||
}
|
||||
|
||||
return { getCurrentSrc }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user