Merge 46e8effa409011d140dafb53beb23b712149fc84 into 97af61fb234077cdd8baf51f274af7675e810c9e

This commit is contained in:
monkey 2025-08-04 02:20:18 +08:00 committed by GitHub
commit 12ddd5d12e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 42 additions and 2 deletions

View File

@ -23,6 +23,11 @@
'--app-theme-color',
appTheme,
)
// 初始设置视口高度偏移量
const vh = window.innerHeight * 0.01
document.documentElement.style.setProperty('--vh-offset', `${(vh * 100) * 0.05}px`)
document.documentElement.style.setProperty('--vh', `${vh}px`)
})()
</script>
<style>
@ -35,7 +40,8 @@
.first-loading-wrap {
display: flex;
width: 100%;
height: 100vh;
height: calc(100vh - var(--vh-offset, 0px));
height: 100dvh;
justify-content: center;
align-items: center;
flex-direction: column;

View File

@ -1,6 +1,6 @@
<!-- eslint-disable prettier/prettier -->
<template>
<div class="h-screen flex flex-col">
<div class="h-[calc(100vh-var(--vh-offset,0px))] h-[100dvh] flex flex-col">
<van-nav-bar v-if="getShowHeader" placeholder fixed :title="getTitle" />
<routerView class="flex-1 overflow-x-hidden">
<template #default="{ Component, route }">

View File

@ -14,6 +14,7 @@ import { createApp } from 'vue'
import App from './App.vue'
import router, { setupRouter } from './router'
import { setupStore } from '@/store'
import { setupViewportHeight } from '@/utils/viewportHeight'
async function bootstrap() {
const app = createApp(App)
@ -21,6 +22,8 @@ async function bootstrap() {
setupStore(app)
// 挂载路由
setupRouter(app)
// 设置视口高度处理
setupViewportHeight()
await router.isReady()
// 路由准备就绪后挂载APP实例
app.mount('#app', true)

View File

@ -2,3 +2,8 @@
@primaryColor: #5d9dfe;
@header-height: 46px;
@footer-height: 50px;
// 视口高度偏移量,用于移动端浏览器地址栏的处理
:root {
--vh-offset: 0px;
}

View File

@ -0,0 +1,26 @@
/**
*
*/
const supportsDvh = () => {
const div = document.createElement('div')
div.style.height = '100dvh'
return div.style.height === '100dvh'
}
export const setupViewportHeight = () => {
if (supportsDvh()) {
return
}
updateViewportHeight()
window.addEventListener('resize', updateViewportHeight)
window.addEventListener('orientationchange', updateViewportHeight)
}
const updateViewportHeight = () => {
const vh = window.innerHeight * 0.01
document.documentElement.style.setProperty('--vh-offset', `${(vh * 100) * 0.05}px`)
document.documentElement.style.setProperty('--vh', `${vh}px`)
}