fix. 코드 리팩토링
This commit is contained in:
@@ -2,15 +2,85 @@
|
||||
interface Props {
|
||||
src: string
|
||||
type?: 'mp4' | 'webm'
|
||||
play?: boolean
|
||||
autoplay?: boolean
|
||||
muted?: boolean
|
||||
loop?: boolean
|
||||
playsinline?: boolean
|
||||
class?: ClassType
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
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>
|
||||
|
||||
<template>
|
||||
<video v-if="props.src" v-bind="$attrs">
|
||||
<source :src="props.src" :type="`video/${props.type}`" />
|
||||
</video>
|
||||
<div v-if="props.src" :class="['video-box', props.class]">
|
||||
<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>
|
||||
|
||||
<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',
|
||||
})
|
||||
|
||||
const breakpoints = useResponsiveBreakpointsReliable()
|
||||
const { getCurrentSrc } = useResponsiveSrc()
|
||||
|
||||
const imageSrc = computed(() => {
|
||||
return getCurrentSrc(props.resourcesData?.res_path)
|
||||
})
|
||||
const displayText = computed(() => {
|
||||
return props.resourcesData?.display?.text || 'image'
|
||||
})
|
||||
const imageSrc = computed(() => {
|
||||
return getResponsiveSrc(props.resourcesData?.res_path)
|
||||
})
|
||||
const colorName = computed(() => {
|
||||
return props.resourcesData?.display?.color_name
|
||||
})
|
||||
const colorCode = computed(() => {
|
||||
return props.resourcesData?.display?.color_code
|
||||
})
|
||||
const currentImageSrc = computed(() => {
|
||||
if (!imageSrc.value) return ''
|
||||
|
||||
return breakpoints.value.isMobile
|
||||
? imageSrc.value.mobileSrc || ''
|
||||
: imageSrc.value.pcSrc || ''
|
||||
})
|
||||
|
||||
// HTML 콘텐츠 정리 (줄바꿈 처리)
|
||||
const sanitizedContent = computed(() => {
|
||||
@@ -42,8 +35,8 @@ const sanitizedContent = computed(() => {
|
||||
<template>
|
||||
<!-- 이미지 -->
|
||||
<img
|
||||
v-if="isTypeImage(resourcesData?.resource_type) && currentImageSrc"
|
||||
:src="currentImageSrc"
|
||||
v-if="isTypeImage(resourcesData?.resource_type) && imageSrc"
|
||||
:src="imageSrc"
|
||||
:alt="alt || displayText"
|
||||
:class="`w-full h-full object-${objectFit}`"
|
||||
loading="lazy"
|
||||
|
||||
@@ -32,8 +32,6 @@ defineExpose({
|
||||
thumbsInst: computed(() => thumbsInst),
|
||||
})
|
||||
|
||||
const breakpoints = useResponsiveBreakpointsReliable()
|
||||
|
||||
const mainRef = 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) : ''
|
||||
}
|
||||
|
||||
const pagenaviThumbnailComponent = getComponentGroup(
|
||||
item,
|
||||
'pagenaviThumbnail'
|
||||
)
|
||||
const pagenaviThumbnailSrc = getResponsiveSrc(
|
||||
pagenaviThumbnailComponent?.res_path
|
||||
)
|
||||
const thumbnailComponent = getComponentGroup(item, 'pagenaviThumbnail')
|
||||
const thumbnailPath = getDeviceSrc(thumbnailComponent?.res_path)
|
||||
|
||||
return breakpoints.value.isMobile
|
||||
? pagenaviThumbnailSrc?.mobileSrc
|
||||
: pagenaviThumbnailSrc?.pcSrc || ''
|
||||
return thumbnailPath?.pcSrc
|
||||
}
|
||||
|
||||
const handleMove = (
|
||||
|
||||
@@ -12,71 +12,62 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
size: 'cover',
|
||||
})
|
||||
|
||||
const breakpoints = useResponsiveBreakpointsReliable()
|
||||
const { getCurrentSrc } = useResponsiveSrc()
|
||||
|
||||
const resPath = computed(() => {
|
||||
return props.resourcesData?.res_path
|
||||
})
|
||||
const bgStyles = computed(() => {
|
||||
return getResponsiveSrc(resPath.value, {
|
||||
resourcesType: 'bg',
|
||||
})
|
||||
const videoRef = ref<HTMLVideoElement | null>(null)
|
||||
|
||||
const resPath = computed(() => props.resourcesData?.res_path)
|
||||
const imageSrc = computed(() => {
|
||||
return getCurrentSrc(resPath.value)
|
||||
})
|
||||
const videoSrc = computed(() => {
|
||||
return getResponsiveSrc(resPath.value, {
|
||||
resourcesType: 'video',
|
||||
})
|
||||
return getCurrentSrc(resPath.value, { resourcesType: 'video' })
|
||||
})
|
||||
const posterSrc = computed(() => {
|
||||
return getResponsiveSrc(resPath.value)
|
||||
return getCurrentSrc(resPath.value)
|
||||
})
|
||||
const currentVideoSrc = computed(() => {
|
||||
if (!videoSrc.value) return ''
|
||||
return breakpoints.value.isMobile
|
||||
? videoSrc.value.mobileSrc
|
||||
: videoSrc.value.pcSrc
|
||||
})
|
||||
const currentPosterSrc = computed(() => {
|
||||
if (!posterSrc.value) return ''
|
||||
return breakpoints.value.isMobile
|
||||
? posterSrc.value.mobileSrc
|
||||
: posterSrc.value.pcSrc
|
||||
const imageClasses = computed(() => [
|
||||
`w-full h-full bg-center bg-no-repeat`,
|
||||
props.size === 'contain' ? 'bg-contain' : 'bg-cover',
|
||||
])
|
||||
const gradientClasses = computed(() => [
|
||||
'absolute bottom-0 left-0 right-0',
|
||||
props.gradient,
|
||||
])
|
||||
|
||||
// src 변경 시 비디오 다시 로드
|
||||
watch(videoSrc, () => {
|
||||
if (!videoRef.value) return
|
||||
|
||||
videoRef.value.currentTime = 0
|
||||
videoRef.value.load()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="absolute inset-0 w-full h-full">
|
||||
<!-- 이미지 타입-->
|
||||
<!-- 이미지 타입 -->
|
||||
<div
|
||||
v-if="isTypeImage(resourcesData?.resource_type)"
|
||||
:class="[
|
||||
'w-full h-full bg-cover bg-center bg-no-repeat',
|
||||
{
|
||||
'object-contain': props.size === 'contain',
|
||||
'object-cover': props.size === 'cover',
|
||||
},
|
||||
]"
|
||||
:style="bgStyles"
|
||||
v-if="isTypeImage(resourcesData?.resource_type) && imageSrc"
|
||||
:class="imageClasses"
|
||||
:style="{ backgroundImage: `url(${imageSrc})` }"
|
||||
/>
|
||||
|
||||
<!-- 비디오 타입 -->
|
||||
<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"
|
||||
:poster="currentPosterSrc"
|
||||
:poster="posterSrc"
|
||||
autoplay
|
||||
muted
|
||||
loop
|
||||
playsinline
|
||||
>
|
||||
<source :src="currentVideoSrc" type="video/mp4" />
|
||||
<source :src="currentVideoSrc" type="video/webm" />
|
||||
<source :src="videoSrc" type="video/mp4" />
|
||||
</video>
|
||||
|
||||
<!-- 그라디언트 오버레이 (gradient가 true일 때만) -->
|
||||
<div
|
||||
v-if="props.gradient"
|
||||
:class="`absolute bottom-0 left-0 right-0 ${props.gradient}`"
|
||||
/>
|
||||
<!-- 그라디언트 오버레이 -->
|
||||
<div v-if="gradient" :class="gradientClasses" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user