修复小程序内嵌页面标题同步
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
lyf
2026-07-27 19:56:53 +08:00
parent 9ea1bfab71
commit f1047414bb
6 changed files with 113 additions and 3 deletions

View File

@@ -25,7 +25,7 @@
{
"path": "pages/explain/list",
"style": {
"navigationBarTitleText": "全部讲解",
"navigationBarTitleText": "免费讲解",
"navigationBarBackgroundColor": "#FFFFFF",
"navigationStyle": "custom"
}

View File

@@ -10,7 +10,6 @@
<ExplainHallSelect
:halls="explainHallItems"
stage="hall"
force-internal-header
:loading="explainLoading"
:error="explainError"
@hall-click="handleExplainHallClick"
@@ -40,6 +39,7 @@ import {
type GuideTopTab
} from '@/utils/guideTopTabs'
import { isEmbeddedInWechatMiniProgram } from '@/utils/hostEnvironment'
import { syncHostNavigationTitle } from '@/utils/hostNavigationTitle'
import { explainGuideStopListUrl } from '@/utils/explainNavigation'
const explainHallItems = ref<ExplainHallSelectItem[]>([])
@@ -218,6 +218,7 @@ const loadExplainHalls = async () => {
}
onLoad(() => {
syncHostNavigationTitle('免费讲解')
pushExplainListHistory()
void loadExplainHalls()
})

View File

@@ -276,6 +276,7 @@ import {
type GuideTopTab
} from '@/utils/guideTopTabs'
import { isEmbeddedInWechatMiniProgram } from '@/utils/hostEnvironment'
import { syncHostNavigationTitle } from '@/utils/hostNavigationTitle'
import {
guideUseCase
} from '@/usecases/guideUseCase'
@@ -419,6 +420,14 @@ let pendingPoiDetailUiContext: Readonly<{
// 状态
const currentTab = ref<GuideTopTab>(initialTopTab())
const topTabNavigationTitle = (tab: GuideTopTab) => (
tab === 'explain' ? '免费讲解' : '地图导览'
)
watch(currentTab, (tab) => {
syncHostNavigationTitle(topTabNavigationTitle(tab))
}, { immediate: true })
const launchOverlayVisible = ref(shouldShowLaunchOverlay())
const launchOverlayLeaving = ref(false)
const launchProgress = ref(8)

View File

@@ -0,0 +1,39 @@
import { isEmbeddedInWechatMiniProgram } from '@/utils/hostEnvironment'
export const MINI_PROGRAM_NAVIGATION_TITLE_MESSAGE = 'museum-guide:navigation-title'
type MiniProgramBridge = {
postMessage?: (options: {
data: {
type: typeof MINI_PROGRAM_NAVIGATION_TITLE_MESSAGE
title: string
}
}) => void
}
const getMiniProgramBridge = () => {
if (typeof window === 'undefined') return undefined
return (window as Window & {
wx?: {
miniProgram?: MiniProgramBridge
}
}).wx?.miniProgram
}
export const syncHostNavigationTitle = (title: string) => {
if (typeof document !== 'undefined') document.title = title
if (typeof uni !== 'undefined' && typeof uni.setNavigationBarTitle === 'function') {
uni.setNavigationBarTitle({ title })
}
if (!isEmbeddedInWechatMiniProgram()) return
getMiniProgramBridge()?.postMessage?.({
data: {
type: MINI_PROGRAM_NAVIGATION_TITLE_MESSAGE,
title
}
})
}