修复 H5 嵌入小程序导航栏冲突
Some checks failed
CI / verify (push) Has been cancelled

- 识别微信小程序 web-view 宿主环境
- 宿主导航存在时隐藏 H5 自绘返回与页面标题
- 收回详情、搜索、讲解列表页面顶部预留空间

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
lyf
2026-07-10 10:57:06 +08:00
parent 8758fe66c6
commit 2a21108157
6 changed files with 93 additions and 18 deletions

View File

@@ -0,0 +1,34 @@
const getCurrentUrlSearchParams = () => {
if (typeof window === 'undefined') return new URLSearchParams()
const params = new URLSearchParams(window.location.search)
const hash = window.location.hash || ''
const hashQueryStart = hash.indexOf('?')
if (hashQueryStart >= 0) {
const hashParams = new URLSearchParams(hash.slice(hashQueryStart + 1))
hashParams.forEach((value, key) => {
if (!params.has(key)) params.set(key, value)
})
}
return params
}
export const isEmbeddedInWechatMiniProgram = () => {
if (typeof window === 'undefined') return false
const params = getCurrentUrlSearchParams()
const embedded = params.get('embedded') || params.get('embed') || params.get('host')
if (embedded === 'wechat-mini-program' || embedded === 'weapp' || embedded === 'mini-program') {
return true
}
const wxEnvironment = (window as Window & {
__wxjs_environment?: string
}).__wxjs_environment
if (wxEnvironment === 'miniprogram') return true
return /miniProgram/i.test(window.navigator?.userAgent || '')
}