cashier_wx/stores/navbarStore.js

44 lines
1.6 KiB
JavaScript

import { defineStore } from 'pinia';
export const useNavbarStore = defineStore('navbar', {
state: () => ({
showBack: true,
rightText: '',
showSearch: false,
title: '',
isTransparent: false,
height: 0,
hasPlaceholder: true
}),
actions: {
updateNavbarConfig(config) {
Object.assign(this, config);
},
initNavbarHeight() {
uni.getSystemInfo({
success: (res) => {
const statusBarHeight = res.statusBarHeight;
let navBarHeight;
// 微信小程序的特殊处理
if (res.platform === 'weapp') {
const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
const topGap = menuButtonInfo.top - statusBarHeight;
const bottomGap = statusBarHeight + menuButtonInfo.height + topGap * 2 - (menuButtonInfo.top + menuButtonInfo.height);
navBarHeight = menuButtonInfo.height + topGap + bottomGap;
} else if (uni.getSystemInfoSync().platform === 'ios') {
navBarHeight = 44;
} else {
navBarHeight = 48;
}
this.height = statusBarHeight + navBarHeight;
},
fail: (err) => {
console.error('获取系统信息失败:', err);
this.height = 64; // 失败时设置一个默认高度
}
});
}
}
});