mi-assessment/uniapp/store/app.js
zpc 4387b15de0 feat(mine): 完成我的页面改造
- 实现未登录/已登录两种状态样式
- 添加常用功能入口:我的订单、往期测评、联系我们、邀请新用户
- 添加其他功能入口:关于、用户协议、隐私政策、退出登录
- 实现退出登录二次确认弹窗
- 修复 uni.scss 中 SCSS 导入路径问题
- 整理 .gitignore 文件,移除 unpackage 构建目录
2026-02-10 00:12:01 +08:00

78 lines
1.9 KiB
JavaScript

/**
* 应用状态管理模块
* 管理系统信息、导航栏高度等全局状态
*/
import { defineStore } from 'pinia'
export const useAppStore = defineStore('app', {
state: () => ({
// 状态栏高度
statusBarHeight: 20,
// 导航栏高度(不含状态栏)
navbarHeight: 44,
// 系统信息
systemInfo: {},
// 是否已初始化
initialized: false
}),
getters: {
/**
* 导航栏总高度(状态栏 + 导航栏)
*/
totalNavbarHeight: (state) => state.statusBarHeight + state.navbarHeight,
/**
* 内容区域顶部padding
*/
contentPaddingTop: (state) => state.statusBarHeight + state.navbarHeight,
/**
* 是否是iOS系统
*/
isIOS: (state) => state.systemInfo.platform === 'ios',
/**
* 是否是Android系统
*/
isAndroid: (state) => state.systemInfo.platform === 'android'
},
actions: {
/**
* 初始化系统信息
*/
initSystemInfo() {
if (this.initialized) return
try {
const systemInfo = uni.getSystemInfoSync()
this.systemInfo = systemInfo
this.statusBarHeight = systemInfo.statusBarHeight || 20
// 获取胶囊按钮位置信息(微信小程序)
// #ifdef MP-WEIXIN
const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
if (menuButtonInfo) {
// 导航栏高度 = 胶囊底部距离 - 状态栏高度 + 胶囊与底部的间距
this.navbarHeight = (menuButtonInfo.bottom - this.statusBarHeight) + (menuButtonInfo.top - this.statusBarHeight)
}
// #endif
this.initialized = true
} catch (e) {
console.error('获取系统信息失败:', e)
}
},
/**
* 获取安全区域底部高度
* @returns {number}
*/
getSafeAreaBottom() {
return this.systemInfo.safeAreaInsets?.bottom || 0
}
}
})