59 lines
1.5 KiB
Vue
59 lines
1.5 KiB
Vue
<script setup lang="ts">
|
|
import type { PageDataResourceGroup } from '#layers/types/api/pageData'
|
|
|
|
interface Props {
|
|
resourcesData?: PageDataResourceGroup
|
|
objectFit?: 'contain' | 'cover'
|
|
alt?: string
|
|
}
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
objectFit: 'contain',
|
|
})
|
|
|
|
const breakpoints = useResponsiveBreakpointsReliable()
|
|
|
|
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(() => {
|
|
return displayText.value?.replace(/\n/g, '<br/>') || ''
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<!-- 이미지 -->
|
|
<img
|
|
v-if="isTypeImage(resourcesData?.resource_type) && currentImageSrc"
|
|
:src="currentImageSrc"
|
|
:alt="alt || displayText"
|
|
:class="`w-full h-full object-${objectFit}`"
|
|
loading="lazy"
|
|
/>
|
|
<!-- 텍스트 -->
|
|
<span
|
|
v-else-if="isTypeText(resourcesData?.resource_type)"
|
|
v-dompurify-html="sanitizedContent"
|
|
:style="{ color: getColorCode({ colorName, colorCode }) }"
|
|
class="block"
|
|
/>
|
|
</template>
|