62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import type {
|
|
PageDataValue,
|
|
PageDataResourceGroupResPath,
|
|
} from '#layers/types/api/pageData'
|
|
|
|
// 레이아웃 타입 리턴하는 함수
|
|
export const getLayoutType = (
|
|
pageData: PageDataValue | null
|
|
): 'default' | 'promotion' => {
|
|
return pageData?.page_type === 1 ? 'default' : 'promotion'
|
|
}
|
|
|
|
// 이미지 호스트 리턴하는 함수
|
|
// [TODO] 환경변수 처리 수정
|
|
export const getResolvedHost = (path: string): string => {
|
|
const config = useRuntimeConfig()
|
|
// const isDev = process.env.NODE_ENV === "development";
|
|
// const rootPath = isDev ? "/images" : `${config.public.staticUrl}`;
|
|
|
|
const rootPath = config.public.staticUrl
|
|
|
|
return `${rootPath}${path}`
|
|
}
|
|
|
|
// 반응형 클래스 리턴하는 함수
|
|
export const getResponsiveClass = () => {
|
|
return ['bg-[image:var(--mobile-bg)]', 'sm:bg-[image:var(--pc-bg)]']
|
|
}
|
|
|
|
// 통합된 반응형 리소스 함수
|
|
export const getResponsiveSrc = (
|
|
pathArray: PageDataResourceGroupResPath,
|
|
options: {
|
|
resourcesType?: 'image' | 'bg' | 'video'
|
|
} = {}
|
|
) => {
|
|
const { resourcesType = 'image' } = options
|
|
const pcField = resourcesType === 'video' ? 'path_vid_pc' : 'path_pc'
|
|
const mobileField = resourcesType === 'video' ? 'path_vid_mo' : 'path_mo'
|
|
|
|
if (!pathArray?.[mobileField]) {
|
|
return null
|
|
}
|
|
|
|
const resolvedImages = {
|
|
pc: getResolvedHost(pathArray[pcField] || pathArray[mobileField]),
|
|
mobile: getResolvedHost(pathArray[mobileField]),
|
|
}
|
|
|
|
if (resourcesType === 'bg') {
|
|
return {
|
|
'--pc-bg': `url(${resolvedImages.pc})`,
|
|
'--mobile-bg': `url(${resolvedImages.mobile})`,
|
|
}
|
|
}
|
|
|
|
return {
|
|
mobileSrc: resolvedImages.mobile,
|
|
pcSrc: resolvedImages.pc,
|
|
}
|
|
}
|