feat. getResolvedHost 함수 추가, img 컴포넌트 추가

This commit is contained in:
clkim
2025-10-30 21:32:17 +09:00
parent d07ec96b34
commit 8229550220
6 changed files with 84 additions and 25 deletions

View File

@@ -49,9 +49,6 @@ const componentTag = computed(() => {
const isDuplication = computed(() => props.type === 'duplication')
const isSingle = computed(() => props.type === 'single')
const platformIcon = computed(() => PLATFORM_ICON_MAP[props.platform])
const duplicationImage = computed(() =>
isDuplication.value ? DUP_IMAGE_MAP[props.platform] : ''
)
const inlineStyle = computed<CSSProperties>(() => {
const style: CSSProperties = {}
@@ -63,7 +60,7 @@ const inlineStyle = computed<CSSProperties>(() => {
style.color = props.textColor
}
if (props.type === 'duplication') {
style.backgroundImage = `url(${duplicationImage.value})`
style.backgroundImage = `url(${getImageHost(DUP_IMAGE_MAP[props.platform])})`
}
return style
})

View File

@@ -77,7 +77,7 @@ const handleCopy = async () => {
target="_blank"
class="sns-item"
:style="{
backgroundImage: `url(/images/common/ic-v2-logo-${key}-fill.svg)`,
backgroundImage: `url(${getImageHost(`/images/common/ic-v2-logo-${key}-fill.svg`)})`,
}"
>
<span class="sr-only">{{ key }}</span>
@@ -87,7 +87,7 @@ const handleCopy = async () => {
type="button"
class="sns-item"
:style="{
backgroundImage: `url(/images/common/ic-v2-community-link-line.svg)`,
backgroundImage: `url(${getImageHost('/images/common/ic-v2-community-link-line.svg')})`,
}"
@click="handleCopy"
>

View File

@@ -1,38 +1,45 @@
<script setup lang="ts">
import { getResolvedHost } from '#layers/utils/styleUtil'
import type { PageDataResourceGroup } from '#layers/types/api/pageData'
interface Props {
resourcesData?: PageDataResourceGroup
objectFit?: 'contain' | 'cover'
src: {
pc?: string
mo?: string
}
alt?: string
objectFit?: 'contain' | 'cover'
}
const props = withDefaults(defineProps<Props>(), {
objectFit: 'contain',
alt: 'image',
objectFit: 'contain',
})
const imagePaths = computed(() => {
if (!props.resourcesData?.res_path) return null
const isDev = process.env.NODE_ENV === 'development'
const rootPath = isDev ? '' : '/templates/brand'
const pc =
props.resourcesData.res_path.path_pc ?? props.resourcesData.res_path.path_mo
const mo =
props.resourcesData.res_path.path_mo ?? props.resourcesData.res_path.path_pc
const imagePaths = computed(() => {
return {
pc: pc ? getResolvedHost(pc) : '',
mo: mo ? getResolvedHost(mo) : '',
pc: props.src.pc ? getResolvedHost(`${rootPath}${props.src.pc}`) : '',
mo: props.src.mo ? getResolvedHost(`${rootPath}${props.src.mo}`) : '',
}
})
</script>
<template>
<picture v-if="imagePaths" ref="pictureRef">
<source media="(min-width: 1024px)" :srcset="imagePaths.pc" />
<source media="(max-width: 1023px)" :srcset="imagePaths.mo" />
<source
v-if="imagePaths.pc"
media="(min-width: 1024px)"
:srcset="imagePaths.pc"
/>
<source
v-if="imagePaths.mo"
media="(max-width: 1023px)"
:srcset="imagePaths.mo"
/>
<img
:src="imagePaths.pc"
:src="imagePaths.pc || imagePaths.mo"
:alt="alt"
:class="`w-full h-full object-${objectFit}`"
loading="lazy"

View File

@@ -0,0 +1,41 @@
<script setup lang="ts">
import { getResolvedHost } from '#layers/utils/styleUtil'
import type { PageDataResourceGroup } from '#layers/types/api/pageData'
interface Props {
resourcesData?: PageDataResourceGroup
objectFit?: 'contain' | 'cover'
alt?: string
}
const props = withDefaults(defineProps<Props>(), {
objectFit: 'contain',
alt: 'image',
})
const imagePaths = computed(() => {
if (!props.resourcesData?.res_path) return null
const pc =
props.resourcesData.res_path.path_pc ?? props.resourcesData.res_path.path_mo
const mo =
props.resourcesData.res_path.path_mo ?? props.resourcesData.res_path.path_pc
return {
pc: pc ? getResolvedHost(pc) : '',
mo: mo ? getResolvedHost(mo) : '',
}
})
</script>
<template>
<picture v-if="imagePaths" ref="pictureRef">
<source media="(min-width: 1024px)" :srcset="imagePaths.pc" />
<source media="(max-width: 1023px)" :srcset="imagePaths.mo" />
<img
:src="imagePaths.pc"
:alt="alt"
:class="`w-full h-full object-${objectFit}`"
loading="lazy"
/>
</picture>
</template>