@@ -164,6 +164,7 @@ import {
|
|||||||
} from '@/utils/placeholders'
|
} from '@/utils/placeholders'
|
||||||
import { isEmbeddedInWechatMiniProgram } from '@/utils/hostEnvironment'
|
import { isEmbeddedInWechatMiniProgram } from '@/utils/hostEnvironment'
|
||||||
import { normalizeGuideAudioLanguage } from '@/data/adapters/guideStopInfoAdapter'
|
import { normalizeGuideAudioLanguage } from '@/data/adapters/guideStopInfoAdapter'
|
||||||
|
import { explainGuideStopListUrl } from '@/utils/explainNavigation'
|
||||||
|
|
||||||
const defaultDetail: ExplainDetailPageViewModel = {
|
const defaultDetail: ExplainDetailPageViewModel = {
|
||||||
id: '',
|
id: '',
|
||||||
@@ -871,23 +872,53 @@ const handleNavigate = async () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const fallbackToExplainHome = () => {
|
type ExplainDetailPageStackEntry = {
|
||||||
|
route?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const decodeRouteParam = (value: string) => {
|
||||||
|
let decoded = value
|
||||||
|
// Hash route parameters can accumulate extra encoding layers across H5 transitions.
|
||||||
|
for (let index = 0; index < 8; index += 1) {
|
||||||
|
try {
|
||||||
|
const next = decodeURIComponent(decoded)
|
||||||
|
if (next === decoded) break
|
||||||
|
decoded = next
|
||||||
|
} catch {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return decoded
|
||||||
|
}
|
||||||
|
|
||||||
|
const fallbackToExplainObjectList = () => {
|
||||||
|
const hallId = detailEntryRequest.value?.hallId || exhibit.value.hallId
|
||||||
|
const hallName = decodeRouteParam(detailEntryRequest.value?.hallName || exhibit.value.hallName || '讲解')
|
||||||
|
const url = hallId
|
||||||
|
? explainGuideStopListUrl(hallId, hallName)
|
||||||
|
: '/pages/explain/list'
|
||||||
|
|
||||||
uni.redirectTo({
|
uni.redirectTo({
|
||||||
url: '/pages/index/index?tab=explain',
|
url,
|
||||||
fail: () => {
|
fail: () => {
|
||||||
uni.reLaunch({
|
uni.reLaunch({ url })
|
||||||
url: '/pages/index/index?tab=explain'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleBack = () => {
|
const returnToExplainObjectList = () => {
|
||||||
uni.navigateBack({
|
const pages = getCurrentPages()
|
||||||
delta: 1,
|
const previousPage = pages[pages.length - 2] as ExplainDetailPageStackEntry | undefined
|
||||||
fail: fallbackToExplainHome
|
if (previousPage?.route === 'pages/explain/guide-stop-list') {
|
||||||
})
|
uni.navigateBack({ delta: 1, fail: fallbackToExplainObjectList })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fallbackToExplainObjectList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleBack = returnToExplainObjectList
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ describe('讲解详情音频优先布局', () => {
|
|||||||
redirectTo: vi.fn(),
|
redirectTo: vi.fn(),
|
||||||
reLaunch: vi.fn()
|
reLaunch: vi.fn()
|
||||||
})
|
})
|
||||||
|
vi.stubGlobal('getCurrentPages', vi.fn(() => []))
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -284,7 +285,11 @@ describe('讲解详情音频优先布局', () => {
|
|||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('顶部返回统一使用页面栈,以便导览首页 onShow 消费复位上下文', async () => {
|
it('上一页是讲解对象列表时使用页面栈返回', async () => {
|
||||||
|
vi.stubGlobal('getCurrentPages', vi.fn(() => [
|
||||||
|
{ route: 'pages/explain/guide-stop-list', options: {} },
|
||||||
|
{ route: 'pages/exhibit/detail', options: {} }
|
||||||
|
]))
|
||||||
const wrapper = mount(ExhibitDetail, {
|
const wrapper = mount(ExhibitDetail, {
|
||||||
global: { stubs: { GuidePageFrame: GuidePageFrameStub } }
|
global: { stubs: { GuidePageFrame: GuidePageFrameStub } }
|
||||||
})
|
})
|
||||||
@@ -293,5 +298,31 @@ describe('讲解详情音频优先布局', () => {
|
|||||||
await flushPromises()
|
await flushPromises()
|
||||||
|
|
||||||
expect(uni.navigateBack).toHaveBeenCalledWith(expect.objectContaining({ delta: 1 }))
|
expect(uni.navigateBack).toHaveBeenCalledWith(expect.objectContaining({ delta: 1 }))
|
||||||
|
expect(uni.redirectTo).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('深链详情按展厅上下文回退至讲解对象列表', async () => {
|
||||||
|
const wrapper = mount(ExhibitDetail, {
|
||||||
|
global: { stubs: { GuidePageFrame: GuidePageFrameStub } }
|
||||||
|
})
|
||||||
|
await mocks.onLoadHandler?.({
|
||||||
|
id: exhibit.id,
|
||||||
|
lang: 'en-US',
|
||||||
|
targetType: 'STOP',
|
||||||
|
targetId: 'stop-1',
|
||||||
|
hallId: 'hall-1',
|
||||||
|
hallName: '%2525E6%252581%252590%2525E9%2525BE%252599%2525E5%25258E%252585'
|
||||||
|
})
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
wrapper.getComponent(GuidePageFrameStub).vm.$emit('back')
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const url = vi.mocked(uni.redirectTo).mock.calls[0]?.[0]?.url || ''
|
||||||
|
const params = new URLSearchParams(url.split('?')[1])
|
||||||
|
expect(url.split('?')[0]).toBe('/pages/explain/guide-stop-list')
|
||||||
|
expect(params.get('hallId')).toBe('hall-1')
|
||||||
|
expect(params.get('hallName')).toBe('恐龙厅')
|
||||||
|
expect(uni.navigateBack).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user