fix. utils 함수 리팩토링
This commit is contained in:
@@ -44,6 +44,7 @@ export const getSupportedPlatforms = (
|
||||
return storePlatforms
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 페이지 데이터를 기반으로 레이아웃 타입을 결정합니다.
|
||||
* @param pageData 페이지 데이터
|
||||
@@ -62,7 +63,10 @@ export const getLayoutType = (
|
||||
*/
|
||||
export const isTypeImage = (type: PageDataResourceGroupType): boolean => {
|
||||
return (
|
||||
type === 'IMG_COMM' || type === 'IMG_LANG' || type === 'IMG_COMM_GLOBAL'
|
||||
type === 'IMG_COMM' ||
|
||||
type === 'IMG_LANG' ||
|
||||
type === 'IMG_COMM_GLOBAL' ||
|
||||
type === 'IMG'
|
||||
)
|
||||
}
|
||||
|
||||
@@ -163,20 +167,6 @@ export const getComponentGroupAry = (
|
||||
return components[componentName]?.groups || []
|
||||
}
|
||||
|
||||
export const getImagePaths = (resourcesData: PageDataResourceGroup) => {
|
||||
if (!resourcesData?.res_path) return null
|
||||
|
||||
const pcPath = resourcesData.res_path.path_pc
|
||||
const moPath = resourcesData.res_path.path_mo
|
||||
|
||||
if (!pcPath || !moPath) return pcPath || moPath
|
||||
|
||||
return {
|
||||
pc: pcPath,
|
||||
mo: moPath,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 컴포넌트 그룹의 첫 번째 데이터를 반환합니다.
|
||||
* @param components props.components 또는 group 객체
|
||||
@@ -191,3 +181,34 @@ export const getComponentGroup = (
|
||||
|
||||
return components[componentName]?.groups?.[0] || null
|
||||
}
|
||||
|
||||
/**
|
||||
* 리소스 데이터를 기반으로 리소스 경로를 반환합니다.
|
||||
* @param resourcesData 리소스 데이터
|
||||
* @param resourcesType 리소스 타입
|
||||
* - IMG: 이미지
|
||||
* - VID: 비디오
|
||||
* @returns 리소스 경로 객체 (pc: PC 버전, mo: 모바일 버전) 또는 null
|
||||
*/
|
||||
export const getResourceSrc = (
|
||||
resourcesData: PageDataResourceGroup,
|
||||
resourcesType?: 'IMG' | 'VID'
|
||||
) => {
|
||||
if (!resourcesData) return null
|
||||
const resPath = resourcesData.res_path
|
||||
const resType = resourcesType || resourcesData.resource_type
|
||||
|
||||
const pcField = isTypeVideo(resType) ? 'path_vid_pc' : 'path_pc'
|
||||
const mobileField = isTypeVideo(resType) ? 'path_vid_mo' : 'path_mo'
|
||||
|
||||
const pcPath = resPath[pcField] || resPath[mobileField]
|
||||
const mobilePath = resPath[mobileField] || resPath[pcField]
|
||||
|
||||
// 경로가 없으면 null 반환
|
||||
if (!pcPath && !mobilePath) return null
|
||||
|
||||
return {
|
||||
pc: pcPath,
|
||||
mo: mobilePath,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user