修复小程序讲解页面返回回退
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
lyf
2026-07-28 10:40:25 +08:00
parent 0b3a31f556
commit 8b3e3f8d55
10 changed files with 281 additions and 82 deletions

View File

@@ -159,7 +159,7 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, watch } from 'vue'
import { onHide, onLoad, onUnload } from '@dcloudio/uni-app'
import { onBackPress, onHide, onLoad, onUnload } from '@dcloudio/uni-app'
import GuidePageFrame from '@/components/navigation/GuidePageFrame.vue'
import GuideFeedbackState from '@/components/navigation/GuideFeedbackState.vue'
import GuideLoadingState from '@/components/navigation/GuideLoadingState.vue'
@@ -188,6 +188,7 @@ import {
} from '@/utils/placeholders'
import { normalizeSameOriginPublicUrl } from '@/utils/publicUrl'
import { isEmbeddedInWechatMiniProgram } from '@/utils/hostEnvironment'
import { returnToWechatMiniProgram } from '@/services/WechatMiniProgramBridgeService'
import { normalizeGuideAudioLanguage } from '@/data/adapters/guideStopInfoAdapter'
import { explainGuideStopListUrl } from '@/utils/explainNavigation'
import {
@@ -355,6 +356,7 @@ const isCurrentDetailAudioTarget = computed(() => {
)
})
let detailAudioClosedOnExit = false
let returningToMiniProgram = false
const closeDetailAudioOnExit = () => {
if (detailAudioClosedOnExit || !isCurrentDetailAudioTarget.value) return
@@ -945,15 +947,42 @@ const fallbackToExplainObjectList = () => {
})
}
const returnToExplainObjectList = () => {
closeDetailAudioOnExit()
uni.navigateBack({
delta: 1,
fail: fallbackToExplainObjectList
})
const cameFromExplainObjectList = () => {
const pages = getCurrentPages()
const previousPage = pages[pages.length - 2] as { route?: string } | undefined
return previousPage?.route === 'pages/explain/guide-stop-list'
}
const handleBack = returnToExplainObjectList
const returnToExplainObjectList = async () => {
closeDetailAudioOnExit()
if (cameFromExplainObjectList()) {
uni.navigateBack({
delta: 1,
fail: fallbackToExplainObjectList
})
return
}
if (isEmbeddedInWechatMiniProgram()) {
if (returningToMiniProgram) return
returningToMiniProgram = true
const result = await returnToWechatMiniProgram()
if (result.status === 'returned') return
returningToMiniProgram = false
uni.showToast({ title: '返回小程序失败,请重试', icon: 'none' })
return
}
fallbackToExplainObjectList()
}
const handleBack = () => { void returnToExplainObjectList() }
onBackPress(() => {
void returnToExplainObjectList()
return true
})
</script>
<style scoped lang="scss">