- 使用真实讲解编号解析接口替换本地演示映射 - 成功后复用现有详情页并自动播放讲解 - 增加查询状态、业务错误提示和相关测试 Made-with: Proma
This commit is contained in:
31
src/utils/explainCodeEntry.ts
Normal file
31
src/utils/explainCodeEntry.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export interface ExplainCodeEntryTarget {
|
||||
code: string
|
||||
stopId: string
|
||||
hallName?: string
|
||||
}
|
||||
|
||||
export const normalizeExplainCode = (code: string) => code.trim()
|
||||
|
||||
export const explainCodeErrorMessage = (error: unknown) => {
|
||||
const code = error && typeof error === 'object' && 'code' in error
|
||||
? Number((error as { code?: unknown }).code)
|
||||
: undefined
|
||||
if (code === 1020007000) return '请输入有效的 4 位讲解编号'
|
||||
if (code === 1020007001) return '未找到该讲解编号,请确认后重试'
|
||||
if (code === 1020007002) return '该编号的讲解内容暂不可用'
|
||||
if (code === 429) return '查询过于频繁,请稍后再试'
|
||||
return '编号查询失败,请检查网络后重试'
|
||||
}
|
||||
|
||||
export const explainCodeDetailUrl = (target: ExplainCodeEntryTarget) => {
|
||||
const params = new URLSearchParams({
|
||||
id: target.stopId,
|
||||
stopId: target.stopId,
|
||||
tab: 'explain',
|
||||
autoplay: '1',
|
||||
entry: 'code',
|
||||
guideCode: target.code
|
||||
})
|
||||
if (target.hallName) params.set('hallName', target.hallName)
|
||||
return `/pages/exhibit/detail?${params.toString()}`
|
||||
}
|
||||
Reference in New Issue
Block a user