接入H5讲解后端数据闭环
This commit is contained in:
@@ -96,6 +96,18 @@ const buildBadges = (exhibit: MuseumExhibit) => {
|
||||
return Array.from(new Set(badges)).slice(0, 3)
|
||||
}
|
||||
|
||||
const formatDuration = (duration?: number) => (
|
||||
typeof duration === 'number' && Number.isFinite(duration) && duration > 0
|
||||
? `${Math.round(duration)}秒`
|
||||
: undefined
|
||||
)
|
||||
|
||||
const languageLabelFor = (language?: string) => {
|
||||
if (language === 'en-US') return '英文'
|
||||
if (language === 'zh-CN') return '中文'
|
||||
return language || undefined
|
||||
}
|
||||
|
||||
export const toExplainCardViewModel = (exhibit: MuseumExhibit): ExplainCardViewModel => {
|
||||
const hasPlayableAudio = exhibit.audioAvailable === true || Boolean(exhibit.audioUrl)
|
||||
const audioStatus: ExplainAudioStatus = hasPlayableAudio ? 'playable' : 'unavailable'
|
||||
@@ -111,10 +123,10 @@ export const toExplainCardViewModel = (exhibit: MuseumExhibit): ExplainCardViewM
|
||||
hallId: exhibit.hallId,
|
||||
hallName: exhibit.hallName,
|
||||
floorLabel: exhibit.floorLabel,
|
||||
durationLabel: exhibit.audioDuration ? `${Math.round(exhibit.audioDuration)}秒` : undefined,
|
||||
durationLabel: formatDuration(exhibit.audioDuration),
|
||||
audioUrl: exhibit.audioUrl,
|
||||
audioDuration: exhibit.audioDuration,
|
||||
languageLabel: '中文',
|
||||
languageLabel: languageLabelFor(exhibit.audioLanguage),
|
||||
audioStatus,
|
||||
audioStatusText: hasPlayableAudio ? '可播放' : '图文讲解',
|
||||
badges: buildBadges(exhibit),
|
||||
@@ -134,8 +146,9 @@ export const toExplainDetailPageViewModel = (exhibit: MuseumExhibit): ExplainDet
|
||||
exhibit.year ? `年代:${exhibit.year}` : '',
|
||||
exhibit.material ? `来源:${exhibit.material}` : ''
|
||||
].filter(Boolean)
|
||||
const transcript = exhibit.audioText || exhibit.guideText || exhibit.description
|
||||
const body = [
|
||||
exhibit.guideText || exhibit.description || '该展项暂无讲解文稿。',
|
||||
transcript || '该展项暂无讲解文稿。',
|
||||
metadataLines.join('\n')
|
||||
].filter(Boolean).join('\n\n')
|
||||
|
||||
@@ -148,14 +161,16 @@ export const toExplainDetailPageViewModel = (exhibit: MuseumExhibit): ExplainDet
|
||||
hallId: exhibit.hallId,
|
||||
hallName: exhibit.hallName,
|
||||
floorLabel: exhibit.floorLabel,
|
||||
summary: exhibit.guideText || exhibit.description || '该展项暂无讲解文稿。',
|
||||
summary: transcript || '该展项暂无讲解文稿。',
|
||||
body,
|
||||
audio: {
|
||||
status: hasPlayableAudio ? 'playable' : 'unavailable',
|
||||
url: exhibit.audioUrl,
|
||||
durationLabel: exhibit.audioDuration ? `${Math.round(exhibit.audioDuration)}秒` : undefined,
|
||||
language: 'zh-CN',
|
||||
unavailableReason: hasPlayableAudio ? undefined : '该展项暂无已发布音频,当前提供图文讲解。'
|
||||
durationLabel: formatDuration(exhibit.audioDuration),
|
||||
language: exhibit.audioLanguage,
|
||||
unavailableReason: hasPlayableAudio
|
||||
? undefined
|
||||
: exhibit.audioUnavailableReason || '该展项暂无已发布音频,当前提供图文讲解。'
|
||||
},
|
||||
chapters: metadataLines.length
|
||||
? metadataLines.map((line, index) => ({
|
||||
@@ -163,7 +178,7 @@ export const toExplainDetailPageViewModel = (exhibit: MuseumExhibit): ExplainDet
|
||||
title: line
|
||||
}))
|
||||
: [],
|
||||
transcript: exhibit.guideText || exhibit.description,
|
||||
transcript,
|
||||
location: exhibit.location,
|
||||
relatedItems: []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user