// pages/profile/profile.js const userUtil = require('../../utils/user'); const userApi = require('../../api/user'); Page({ data: { userInfo: null, systemInfo: null, pageHeight: 0 }, onLoad() { this.loadUserInfo(); this.setPageHeight(); }, onShow() { this.loadUserInfo(); }, // 设置页面高度,匹配手机屏幕 setPageHeight() { try { const systemInfo = wx.getSystemInfoSync(); const windowHeight = systemInfo.windowHeight; // 窗口高度(px),已自动减去tabBar高度 const windowWidth = systemInfo.windowWidth; // 窗口宽度(px) // 小程序中,windowHeight已经自动减去了tabBar高度 // 转换为rpx:rpx = px * (750 / 屏幕宽度) const rpxRatio = 750 / windowWidth; const pageHeightRpx = windowHeight * rpxRatio; this.setData({ systemInfo: systemInfo, pageHeight: Math.floor(pageHeightRpx) }); console.log('页面高度设置:', { windowWidth: windowWidth + 'px', windowHeight: windowHeight + 'px', rpxRatio: rpxRatio.toFixed(4), pageHeight: Math.floor(pageHeightRpx) + 'rpx' }); } catch (error) { console.error('设置页面高度失败:', error); // 如果获取系统信息失败,使用默认值 this.setData({ pageHeight: 0 // 使用CSS的100vh作为fallback }); } }, // 加载用户信息 loadUserInfo() { const userInfo = userUtil.getUserInfo(); this.setData({ userInfo }); }, // 退出登录 logout() { wx.showModal({ title: '提示', content: '确定要退出登录吗?', success: (res) => { if (res.confirm) { userUtil.clearUserInfo(); wx.reLaunch({ url: '/pages/login/login' }); } } }); }, // 跳转到书架 goToBookshelf() { wx.switchTab({ url: '/pages/bookshelf/bookshelf' }); }, // 跳转到历史记录 goToHistory() { wx.navigateTo({ url: '/pages/history/history' }); }, // 跳转到AI客服 goToChat() { wx.navigateTo({ url: '/pages/chat/chat' }); }, // 跳转到设置 goToSettings() { wx.navigateTo({ url: '/pages/settings/settings' }); }, // 跳转到我的书籍(第三方) goToMyContent() { wx.navigateTo({ url: '/pages/thirdPartyContent/thirdPartyContent' }); } });