feat: alipay navbar

This commit is contained in:
zzc
2026-02-11 15:50:55 +08:00
parent f4cc6ff83d
commit c86d0f7351
3 changed files with 29 additions and 17 deletions

View File

@@ -15,16 +15,14 @@
height: navBarHeight + 'px', height: navBarHeight + 'px',
paddingTop: statusBarHeight + 'px', paddingTop: statusBarHeight + 'px',
backgroundColor: transparent ? 'transparent' : background, backgroundColor: transparent ? 'transparent' : background,
color: color color: color,
boxSizing: 'border-box',
}" }"
> >
<view class="nav-content"> <view class="nav-content">
<view <view v-if="back" class="back" @tap="goBack" :style="{ color: color }"
v-if="back" ></view
class="back" >
@tap="goBack"
:style="{ color: color }"
></view>
<text class="nav-title" :style="{ color: color }">{{ title }}</text> <text class="nav-title" :style="{ color: color }">{{ title }}</text>
</view> </view>
</view> </view>
@@ -33,7 +31,7 @@
<script setup> <script setup>
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import { getBavBarHeight, getStatusBarHeight } from "@/utils/system"; import { getTitleBarHeight } from "@/utils/system";
const props = defineProps({ const props = defineProps({
title: { title: {
@@ -70,8 +68,9 @@ const navBarHeight = ref(64);
const statusBarHeight = ref(20); const statusBarHeight = ref(20);
onMounted(() => { onMounted(() => {
navBarHeight.value = getBavBarHeight(); const systemInfo = uni.getSystemInfoSync();
statusBarHeight.value = getStatusBarHeight(); statusBarHeight.value = systemInfo.statusBarHeight || 20;
navBarHeight.value = statusBarHeight.value + getTitleBarHeight();
}); });
const goBack = () => { const goBack = () => {

View File

@@ -157,7 +157,11 @@
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app", "navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8", "navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8" "backgroundColor": "#F8F8F8",
"mp-alipay": {
"transparentTitle": "always",
"titlePenetrate": "YES"
}
}, },
"tabBar": { "tabBar": {
"color": "#999999", "color": "#999999",

View File

@@ -2,12 +2,21 @@ const SYSTEM = uni.getSystemInfoSync();
export const getStatusBarHeight = () => SYSTEM.statusBarHeight || 15; export const getStatusBarHeight = () => SYSTEM.statusBarHeight || 15;
export const getTitleBarHeight = () => { export const getTitleBarHeight = () => {
// #ifdef MP-ALIPAY
return 44;
// #endif
if (uni.getMenuButtonBoundingClientRect) { if (uni.getMenuButtonBoundingClientRect) {
const { top, height } = uni.getMenuButtonBoundingClientRect(); try {
return height + (top - getStatusBarHeight()) * 2; const rect = uni.getMenuButtonBoundingClientRect();
} else { if (rect && rect.top && rect.height) {
return 40; return rect.height + (rect.top - getStatusBarHeight()) * 2;
} }
} catch (e) {
console.error(e);
}
}
return 44;
}; };
export const getBavBarHeight = () => getStatusBarHeight() + getTitleBarHeight(); export const getBavBarHeight = () => getStatusBarHeight() + getTitleBarHeight();