fix. 코드 리팩토링
This commit is contained in:
13
app/app.vue
13
app/app.vue
@@ -125,12 +125,13 @@ gtag('event', 'screen_view', {
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
useEventListener('scroll', scrollStore.updateScrollValue)
|
useEventListener('scroll', scrollStore.updateScrollValue)
|
||||||
if (gameData.value?.comm_img_json) {
|
if (gameData.value?.comm_img_json?.groups) {
|
||||||
gameData.value?.comm_img_json.groups.forEach(group => {
|
const groups = gameData.value.comm_img_json.groups
|
||||||
const cssVarName = `--${group.img_name}`
|
groups.forEach(({ img_name, img_path }) => {
|
||||||
const imageUrl = `url(${getResolvedHost(group.img_path?.comm ?? '')})`
|
document.documentElement.style.setProperty(
|
||||||
|
`--${img_name}`,
|
||||||
document.documentElement.style.setProperty(cssVarName, imageUrl)
|
`url(${getResolvedHost(img_path?.comm ?? '')})`
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -25,6 +25,6 @@
|
|||||||
@apply line-clamp-2 text-[16px] font-[500] leading-[24px] drop-shadow-[0_2px_2px_rgba(0,0,0,0.6)] md:line-clamp-1 md:text-[24px] md:leading-[34px];
|
@apply line-clamp-2 text-[16px] font-[500] leading-[24px] drop-shadow-[0_2px_2px_rgba(0,0,0,0.6)] md:line-clamp-1 md:text-[24px] md:leading-[34px];
|
||||||
}
|
}
|
||||||
.title-xs {
|
.title-xs {
|
||||||
@apply text-[14px] leading-[20px] tracking-[-0.42px] md:text-[18px] md:leading-[26px] md:tracking-[-0.54px];
|
@apply text-[14px] font-[500] leading-[20px] tracking-[-0.42px] md:text-[18px] md:leading-[26px] md:tracking-[-0.54px];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,85 @@
|
|||||||
interface Props {
|
interface Props {
|
||||||
src: string
|
src: string
|
||||||
type?: 'mp4' | 'webm'
|
type?: 'mp4' | 'webm'
|
||||||
|
play?: boolean
|
||||||
|
autoplay?: boolean
|
||||||
|
muted?: boolean
|
||||||
|
loop?: boolean
|
||||||
|
playsinline?: boolean
|
||||||
|
class?: ClassType
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
type: 'mp4',
|
type: 'mp4',
|
||||||
|
play: false,
|
||||||
|
muted: true,
|
||||||
|
loop: true,
|
||||||
|
playsinline: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const videoRef = ref<HTMLVideoElement | null>(null)
|
||||||
|
|
||||||
|
// autoplay prop 변경 시 재생/정지 제어
|
||||||
|
watch(
|
||||||
|
() => props.play,
|
||||||
|
shouldPlay => {
|
||||||
|
if (!videoRef.value) return
|
||||||
|
|
||||||
|
if (shouldPlay) {
|
||||||
|
videoRef.value.play().catch(err => {
|
||||||
|
console.warn('Video play failed:', err)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
videoRef.value.pause()
|
||||||
|
videoRef.value.currentTime = 0
|
||||||
|
}, 200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// src 변경 시 비디오 다시 로드
|
||||||
|
watch(
|
||||||
|
() => props.src,
|
||||||
|
() => {
|
||||||
|
if (!videoRef.value) return
|
||||||
|
|
||||||
|
// 비디오 시간 초기화 및 새 소스 로드
|
||||||
|
videoRef.value.currentTime = 0
|
||||||
|
videoRef.value.load()
|
||||||
|
|
||||||
|
// 재생 중이었다면 다시 재생
|
||||||
|
if (props.play) {
|
||||||
|
nextTick(() => {
|
||||||
|
videoRef.value?.play().catch(err => {
|
||||||
|
console.warn('Video play failed:', err)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<video v-if="props.src" v-bind="$attrs">
|
<div v-if="props.src" :class="['video-box', props.class]">
|
||||||
<source :src="props.src" :type="`video/${props.type}`" />
|
<video
|
||||||
</video>
|
ref="videoRef"
|
||||||
|
:autoplay="props.autoplay"
|
||||||
|
:muted="props.muted"
|
||||||
|
:loop="props.loop"
|
||||||
|
:playsinline="props.playsinline"
|
||||||
|
>
|
||||||
|
<source :src="props.src" :type="`video/${props.type}`" />
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.video-box {
|
||||||
|
@apply overflow-hidden relative rounded-[4px] md:rounded-[8px]
|
||||||
|
after:content-[''] after:absolute after:top-0 after:left-0 after:w-full after:h-full after:border after:border-white after:opacity-10 after:rounded-[4px] after:md:rounded-[8px];
|
||||||
|
}
|
||||||
|
.video-box video {
|
||||||
|
@apply absolute top-0 left-0 w-full h-full object-cover;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -11,27 +11,20 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
objectFit: 'contain',
|
objectFit: 'contain',
|
||||||
})
|
})
|
||||||
|
|
||||||
const breakpoints = useResponsiveBreakpointsReliable()
|
const { getCurrentSrc } = useResponsiveSrc()
|
||||||
|
|
||||||
|
const imageSrc = computed(() => {
|
||||||
|
return getCurrentSrc(props.resourcesData?.res_path)
|
||||||
|
})
|
||||||
const displayText = computed(() => {
|
const displayText = computed(() => {
|
||||||
return props.resourcesData?.display?.text || 'image'
|
return props.resourcesData?.display?.text || 'image'
|
||||||
})
|
})
|
||||||
const imageSrc = computed(() => {
|
|
||||||
return getResponsiveSrc(props.resourcesData?.res_path)
|
|
||||||
})
|
|
||||||
const colorName = computed(() => {
|
const colorName = computed(() => {
|
||||||
return props.resourcesData?.display?.color_name
|
return props.resourcesData?.display?.color_name
|
||||||
})
|
})
|
||||||
const colorCode = computed(() => {
|
const colorCode = computed(() => {
|
||||||
return props.resourcesData?.display?.color_code
|
return props.resourcesData?.display?.color_code
|
||||||
})
|
})
|
||||||
const currentImageSrc = computed(() => {
|
|
||||||
if (!imageSrc.value) return ''
|
|
||||||
|
|
||||||
return breakpoints.value.isMobile
|
|
||||||
? imageSrc.value.mobileSrc || ''
|
|
||||||
: imageSrc.value.pcSrc || ''
|
|
||||||
})
|
|
||||||
|
|
||||||
// HTML 콘텐츠 정리 (줄바꿈 처리)
|
// HTML 콘텐츠 정리 (줄바꿈 처리)
|
||||||
const sanitizedContent = computed(() => {
|
const sanitizedContent = computed(() => {
|
||||||
@@ -42,8 +35,8 @@ const sanitizedContent = computed(() => {
|
|||||||
<template>
|
<template>
|
||||||
<!-- 이미지 -->
|
<!-- 이미지 -->
|
||||||
<img
|
<img
|
||||||
v-if="isTypeImage(resourcesData?.resource_type) && currentImageSrc"
|
v-if="isTypeImage(resourcesData?.resource_type) && imageSrc"
|
||||||
:src="currentImageSrc"
|
:src="imageSrc"
|
||||||
:alt="alt || displayText"
|
:alt="alt || displayText"
|
||||||
:class="`w-full h-full object-${objectFit}`"
|
:class="`w-full h-full object-${objectFit}`"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ defineExpose({
|
|||||||
thumbsInst: computed(() => thumbsInst),
|
thumbsInst: computed(() => thumbsInst),
|
||||||
})
|
})
|
||||||
|
|
||||||
const breakpoints = useResponsiveBreakpointsReliable()
|
|
||||||
|
|
||||||
const mainRef = ref<InstanceType<typeof Splide> | null>(null)
|
const mainRef = ref<InstanceType<typeof Splide> | null>(null)
|
||||||
const thumbsRef = ref<InstanceType<typeof Splide> | null>(null)
|
const thumbsRef = ref<InstanceType<typeof Splide> | null>(null)
|
||||||
|
|
||||||
@@ -72,17 +70,10 @@ const getThumbnailSrc = (item: PageDataTemplateComponentSet) => {
|
|||||||
return mediaComponent ? getMediaImgSrc(mediaComponent) : ''
|
return mediaComponent ? getMediaImgSrc(mediaComponent) : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const pagenaviThumbnailComponent = getComponentGroup(
|
const thumbnailComponent = getComponentGroup(item, 'pagenaviThumbnail')
|
||||||
item,
|
const thumbnailPath = getDeviceSrc(thumbnailComponent?.res_path)
|
||||||
'pagenaviThumbnail'
|
|
||||||
)
|
|
||||||
const pagenaviThumbnailSrc = getResponsiveSrc(
|
|
||||||
pagenaviThumbnailComponent?.res_path
|
|
||||||
)
|
|
||||||
|
|
||||||
return breakpoints.value.isMobile
|
return thumbnailPath?.pcSrc
|
||||||
? pagenaviThumbnailSrc?.mobileSrc
|
|
||||||
: pagenaviThumbnailSrc?.pcSrc || ''
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleMove = (
|
const handleMove = (
|
||||||
|
|||||||
@@ -12,71 +12,62 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
size: 'cover',
|
size: 'cover',
|
||||||
})
|
})
|
||||||
|
|
||||||
const breakpoints = useResponsiveBreakpointsReliable()
|
const { getCurrentSrc } = useResponsiveSrc()
|
||||||
|
|
||||||
const resPath = computed(() => {
|
const videoRef = ref<HTMLVideoElement | null>(null)
|
||||||
return props.resourcesData?.res_path
|
|
||||||
})
|
const resPath = computed(() => props.resourcesData?.res_path)
|
||||||
const bgStyles = computed(() => {
|
const imageSrc = computed(() => {
|
||||||
return getResponsiveSrc(resPath.value, {
|
return getCurrentSrc(resPath.value)
|
||||||
resourcesType: 'bg',
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
const videoSrc = computed(() => {
|
const videoSrc = computed(() => {
|
||||||
return getResponsiveSrc(resPath.value, {
|
return getCurrentSrc(resPath.value, { resourcesType: 'video' })
|
||||||
resourcesType: 'video',
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
const posterSrc = computed(() => {
|
const posterSrc = computed(() => {
|
||||||
return getResponsiveSrc(resPath.value)
|
return getCurrentSrc(resPath.value)
|
||||||
})
|
})
|
||||||
const currentVideoSrc = computed(() => {
|
const imageClasses = computed(() => [
|
||||||
if (!videoSrc.value) return ''
|
`w-full h-full bg-center bg-no-repeat`,
|
||||||
return breakpoints.value.isMobile
|
props.size === 'contain' ? 'bg-contain' : 'bg-cover',
|
||||||
? videoSrc.value.mobileSrc
|
])
|
||||||
: videoSrc.value.pcSrc
|
const gradientClasses = computed(() => [
|
||||||
})
|
'absolute bottom-0 left-0 right-0',
|
||||||
const currentPosterSrc = computed(() => {
|
props.gradient,
|
||||||
if (!posterSrc.value) return ''
|
])
|
||||||
return breakpoints.value.isMobile
|
|
||||||
? posterSrc.value.mobileSrc
|
// src 변경 시 비디오 다시 로드
|
||||||
: posterSrc.value.pcSrc
|
watch(videoSrc, () => {
|
||||||
|
if (!videoRef.value) return
|
||||||
|
|
||||||
|
videoRef.value.currentTime = 0
|
||||||
|
videoRef.value.load()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="absolute inset-0 w-full h-full">
|
<div class="absolute inset-0 w-full h-full">
|
||||||
<!-- 이미지 타입-->
|
<!-- 이미지 타입 -->
|
||||||
<div
|
<div
|
||||||
v-if="isTypeImage(resourcesData?.resource_type)"
|
v-if="isTypeImage(resourcesData?.resource_type) && imageSrc"
|
||||||
:class="[
|
:class="imageClasses"
|
||||||
'w-full h-full bg-cover bg-center bg-no-repeat',
|
:style="{ backgroundImage: `url(${imageSrc})` }"
|
||||||
{
|
|
||||||
'object-contain': props.size === 'contain',
|
|
||||||
'object-cover': props.size === 'cover',
|
|
||||||
},
|
|
||||||
]"
|
|
||||||
:style="bgStyles"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 비디오 타입 -->
|
<!-- 비디오 타입 -->
|
||||||
<video
|
<video
|
||||||
v-else-if="isTypeVideo(resourcesData?.resource_type) && currentVideoSrc"
|
v-else-if="isTypeVideo(resourcesData?.resource_type) && videoSrc"
|
||||||
|
ref="videoRef"
|
||||||
class="w-full h-full object-cover"
|
class="w-full h-full object-cover"
|
||||||
:poster="currentPosterSrc"
|
:poster="posterSrc"
|
||||||
autoplay
|
autoplay
|
||||||
muted
|
muted
|
||||||
loop
|
loop
|
||||||
playsinline
|
playsinline
|
||||||
>
|
>
|
||||||
<source :src="currentVideoSrc" type="video/mp4" />
|
<source :src="videoSrc" type="video/mp4" />
|
||||||
<source :src="currentVideoSrc" type="video/webm" />
|
|
||||||
</video>
|
</video>
|
||||||
|
|
||||||
<!-- 그라디언트 오버레이 (gradient가 true일 때만) -->
|
<!-- 그라디언트 오버레이 -->
|
||||||
<div
|
<div v-if="gradient" :class="gradientClasses" />
|
||||||
v-if="props.gradient"
|
|
||||||
:class="`absolute bottom-0 left-0 right-0 ${props.gradient}`"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -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 = {
|
const BREAKPOINTS = {
|
||||||
xs: 360,
|
xs: 360,
|
||||||
sm: 768,
|
sm: 768,
|
||||||
@@ -6,18 +10,49 @@ const BREAKPOINTS = {
|
|||||||
} as const
|
} as const
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 확실한 반응형 브레이크포인트 헬퍼 (useWindowSize 기반)
|
* useMediaQuery 기반 반응형 브레이크포인트
|
||||||
*/
|
*/
|
||||||
export const useResponsiveBreakpointsReliable = () => {
|
export const useResponsiveBreakpoints = () => {
|
||||||
const { width } = useWindowSize()
|
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(() => ({
|
return computed(() => ({
|
||||||
xs: width.value >= BREAKPOINTS.xs,
|
isXs: isXs.value,
|
||||||
sm: width.value >= BREAKPOINTS.sm,
|
isSm: isSm.value,
|
||||||
md: width.value >= BREAKPOINTS.md,
|
isMd: isMd.value,
|
||||||
lg: width.value >= BREAKPOINTS.lg,
|
isLg: isLg.value,
|
||||||
isMobile: width.value < BREAKPOINTS.md,
|
isMobile: isMobile.value,
|
||||||
isTablet: width.value >= BREAKPOINTS.sm && width.value < BREAKPOINTS.md,
|
isTablet: isTablet.value,
|
||||||
isDesktop: width.value >= BREAKPOINTS.md,
|
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 }
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
getComponentGroup,
|
getComponentGroup,
|
||||||
hasComponentGroup,
|
hasComponentGroup,
|
||||||
} from '#layers/utils/dataUtil'
|
} from '#layers/utils/dataUtil'
|
||||||
import { getResponsiveSrc } from '#layers/utils/styleUtil'
|
|
||||||
import type { Splide as SplideType } from '@splidejs/splide'
|
import type { Splide as SplideType } from '@splidejs/splide'
|
||||||
import type {
|
import type {
|
||||||
PageDataTemplateComponents,
|
PageDataTemplateComponents,
|
||||||
@@ -20,7 +19,7 @@ interface Props {
|
|||||||
|
|
||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
|
|
||||||
const breakpoints = useResponsiveBreakpointsReliable()
|
const { getCurrentSrc } = useResponsiveSrc()
|
||||||
|
|
||||||
const currentSlideIndex = ref<number>(0)
|
const currentSlideIndex = ref<number>(0)
|
||||||
|
|
||||||
@@ -33,15 +32,9 @@ const paginationData = computed(() => {
|
|||||||
return getComponentGroupAry(props.components, 'pagination')
|
return getComponentGroupAry(props.components, 'pagination')
|
||||||
})
|
})
|
||||||
|
|
||||||
const currentVideoSrc = (item: PageDataTemplateComponent) => {
|
const videoSrc = (item: PageDataTemplateComponent) => {
|
||||||
const videoSrc = getComponentGroup(item, 'video')?.res_path
|
const src = getComponentGroup(item, 'video')?.res_path
|
||||||
const responsiveSrc = getResponsiveSrc(videoSrc, {
|
return getCurrentSrc(src, { resourcesType: 'video' })
|
||||||
resourcesType: 'video',
|
|
||||||
})
|
|
||||||
|
|
||||||
return breakpoints.value.isMobile
|
|
||||||
? responsiveSrc.mobileSrc
|
|
||||||
: responsiveSrc.pcSrc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSplideMove = (_splide: SplideType, newIndex: number) => {
|
const handleSplideMove = (_splide: SplideType, newIndex: number) => {
|
||||||
@@ -66,7 +59,9 @@ const handleSplideMove = (_splide: SplideType, newIndex: number) => {
|
|||||||
size="contain"
|
size="contain"
|
||||||
:resources-data="getComponentGroup(item, 'foreground')"
|
:resources-data="getComponentGroup(item, 'foreground')"
|
||||||
/>
|
/>
|
||||||
<div class="section-content max-w-[1024px] mx-auto items-start">
|
<div
|
||||||
|
class="section-content max-w-[1024px] mx-auto items-start pt-[48px] md:pt-0"
|
||||||
|
>
|
||||||
<WidgetsSubTitle
|
<WidgetsSubTitle
|
||||||
v-if="hasComponentGroup(item, 'category')"
|
v-if="hasComponentGroup(item, 'category')"
|
||||||
:resources-data="getComponentGroup(item, 'category')"
|
:resources-data="getComponentGroup(item, 'category')"
|
||||||
@@ -90,11 +85,13 @@ const handleSplideMove = (_splide: SplideType, newIndex: number) => {
|
|||||||
/>
|
/>
|
||||||
<AtomsVideo
|
<AtomsVideo
|
||||||
v-if="hasComponentGroup(item, 'video')"
|
v-if="hasComponentGroup(item, 'video')"
|
||||||
:src="currentVideoSrc(item)"
|
:src="videoSrc(item)"
|
||||||
:autoplay="currentSlideIndex === index"
|
:play="currentSlideIndex === index"
|
||||||
|
autoplay
|
||||||
muted
|
muted
|
||||||
loop
|
loop
|
||||||
playsinline
|
playsinline
|
||||||
|
class="aspect-[16/10] w-[258px] mt-8 md:w-[496px] md:mt-10"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</SplideSlide>
|
</SplideSlide>
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ import type {
|
|||||||
* @returns 완전한 이미지 URL
|
* @returns 완전한 이미지 URL
|
||||||
*/
|
*/
|
||||||
export const getResolvedHost = (path: string): string => {
|
export const getResolvedHost = (path: string): string => {
|
||||||
|
// path가 없으면 빈 문자열 반환
|
||||||
|
if (!path || typeof path !== 'string') return ''
|
||||||
|
|
||||||
if (
|
if (
|
||||||
path.startsWith('http://') ||
|
path.startsWith('http://') ||
|
||||||
path.startsWith('https://') ||
|
path.startsWith('https://') ||
|
||||||
@@ -33,35 +36,33 @@ export const getResolvedHost = (path: string): string => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 반응형 리소스(이미지/비디오)를 처리하여 PC/모바일 버전을 반환합니다.
|
* 디바이스 리소스(이미지/비디오)를 처리하여 PC/모바일 버전을 반환합니다.
|
||||||
* @param pathArray 리소스 경로 배열
|
* @param pathArray 리소스 경로 배열
|
||||||
* @param options 리소스 타입 옵션
|
* @param options 리소스 타입 옵션
|
||||||
* @returns 반응형 리소스 객체 또는 null
|
* @returns 디바이스 리소스 객체 또는 null
|
||||||
*/
|
*/
|
||||||
export const getResponsiveSrc = (
|
export const getDeviceSrc = (
|
||||||
pathArray: PageDataResourceGroupResPath,
|
pathArray: PageDataResourceGroupResPath,
|
||||||
options: {
|
options?: {
|
||||||
resourcesType?: 'image' | 'bg' | 'video'
|
resourcesType?: 'image' | 'video'
|
||||||
} = {}
|
}
|
||||||
) => {
|
) => {
|
||||||
const { resourcesType = 'image' } = options
|
// pathArray가 없으면 null 반환
|
||||||
|
if (!pathArray) return null
|
||||||
|
|
||||||
|
const { resourcesType = 'image' } = options ?? {}
|
||||||
const pcField = resourcesType === 'video' ? 'path_vid_pc' : 'path_pc'
|
const pcField = resourcesType === 'video' ? 'path_vid_pc' : 'path_pc'
|
||||||
const mobileField = resourcesType === 'video' ? 'path_vid_mo' : 'path_mo'
|
const mobileField = resourcesType === 'video' ? 'path_vid_mo' : 'path_mo'
|
||||||
|
|
||||||
if (!pathArray?.[mobileField]) {
|
const pcPath = pathArray[pcField] || pathArray[mobileField]
|
||||||
return null
|
const mobilePath = pathArray[mobileField] || pathArray[pcField]
|
||||||
}
|
|
||||||
|
// 경로가 없으면 null 반환
|
||||||
|
if (!pcPath && !mobilePath) return null
|
||||||
|
|
||||||
const resolvedImages = {
|
const resolvedImages = {
|
||||||
pc: getResolvedHost(pathArray[pcField] || pathArray[mobileField]),
|
pc: pcPath ? getResolvedHost(pcPath) : '',
|
||||||
mobile: getResolvedHost(pathArray[mobileField]),
|
mobile: mobilePath ? getResolvedHost(mobilePath) : '',
|
||||||
}
|
|
||||||
|
|
||||||
if (resourcesType === 'bg') {
|
|
||||||
return {
|
|
||||||
'--pc-bg': `url(${resolvedImages.pc})`,
|
|
||||||
'--mobile-bg': `url(${resolvedImages.mobile})`,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -70,14 +71,6 @@ export const getResponsiveSrc = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 반응형 배경 이미지를 위한 CSS 클래스를 반환합니다.
|
|
||||||
* @returns 반응형 배경 클래스 배열
|
|
||||||
*/
|
|
||||||
export const getResponsiveClass = () => {
|
|
||||||
return ['bg-[image:var(--mobile-bg)]', 'md:bg-[image:var(--pc-bg)]']
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 색상값을 반환합니다.
|
* 색상값을 반환합니다.
|
||||||
* @param colorName 색상 이름
|
* @param colorName 색상 이름
|
||||||
|
|||||||
Reference in New Issue
Block a user