修复讲解详情返回对象列表
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
lyf
2026-07-18 01:29:06 +08:00
parent 5a711377b0
commit d86f24566e
2 changed files with 28 additions and 3 deletions

View File

@@ -134,8 +134,11 @@ const handleExplainGuideStopClick = (stop: ExplainGuideStopCatalogItem) => {
? { targetType: stop.playTargetType, targetId: stop.playTargetId }
: normalizeExplainDetailTargetFromGuideStop({ id: stop.id })
const params = new URLSearchParams({ id: stop.id, tab: 'explain', targetType: target.targetType, targetId: target.targetId })
if (stop.hallId) params.set('hallId', stop.hallId)
if (stop.hallName) params.set('hallName', stop.hallName)
// 分页对象可能未回填展厅字段,详情返回必须保留当前列表的展厅上下文。
const hallId = stop.hallId || selectedExplainHallId.value
const hallName = stop.hallName || selectedExplainHallName.value
if (hallId) params.set('hallId', hallId)
if (hallName) params.set('hallName', hallName)
if (stop.floorId) params.set('floorId', stop.floorId)
if (stop.poiId) params.set('poiId', stop.poiId)
uni.navigateTo({ url: `/pages/exhibit/detail?${params.toString()}` })

View File

@@ -34,7 +34,12 @@ const ExplainGuideStopCatalogStub = defineComponent({
name: 'ExplainGuideStopCatalog',
props: ['guideStops', 'selectedHallName', 'loading', 'loadingMore', 'hasMore', 'error', 'loadMoreError'],
emits: ['back', 'retry', 'retryMore', 'guideStopClick'],
template: '<button data-testid="list-back" @click="$emit(\'back\')">返回</button><button data-testid="retry-more" @click="$emit(\'retryMore\')">重试更多</button>'
setup(_, { emit }) {
return {
emitDetail: () => emit('guideStopClick', { id: 'stop-1', name: '对象', playTargetType: 'STOP', playTargetId: 'target-1' })
}
},
template: '<button data-testid="list-back" @click="$emit(\'back\')">返回</button><button data-testid="retry-more" @click="$emit(\'retryMore\')">重试更多</button><button data-testid="detail-click" @click="emitDetail">详情</button>'
})
const mountGuideStopList = () => mount(ExplainGuideStopListPage, {
@@ -93,6 +98,23 @@ describe('讲解对象列表返回', () => {
wrapper.unmount()
})
it('keeps the selected hall context when an object payload omits hall fields', async () => {
const wrapper = mountGuideStopList()
testState.onLoadHandler?.({ hallId: 'hall-1', hallName: '恐龙厅' })
await flushPromises()
await wrapper.get('[data-testid="detail-click"]').trigger('click')
const url = vi.mocked(uni.navigateTo).mock.calls[0]?.[0]?.url || ''
const params = new URLSearchParams(url.split('?')[1])
expect(url.split('?')[0]).toBe('/pages/exhibit/detail')
expect(params.get('hallId')).toBe('hall-1')
expect(params.get('hallName')).toBe('恐龙厅')
expect(params.get('targetType')).toBe('STOP')
expect(params.get('targetId')).toBe('target-1')
wrapper.unmount()
})
it('上一页是独立展厅列表时回到该列表', async () => {
vi.stubGlobal('getCurrentPages', vi.fn(() => [
{ route: 'pages/explain/list', options: {} },