// pages/profile/index/index.js const app = getApp(); Page({ data: { isLoggedIn: false, userInfo: null, isSubscribed: false }, onLoad() { this.loadUserInfo(); }, onShow() { this.loadUserInfo(); this.checkSubscriptionStatus(); }, /** * 加载用户信息 */ loadUserInfo() { const isLoggedIn = app.isLoggedIn(); const userInfo = app.getUserInfo(); this.setData({ isLoggedIn, userInfo: userInfo || { nickName: '未登录', avatarUrl: '' } }); }, /** * 检查订阅状态 */ checkSubscriptionStatus() { const isSubscribed = app.isSubscribed(); this.setData({ isSubscribed }); }, /** * 点击头部区域 */ handleHeaderTap() { if (!this.data.isLoggedIn) { wx.navigateTo({ url: '/pages/login/login' }); } }, /** * 消息通知设置 */ goToNotificationSettings() { if (!this.data.isLoggedIn) { wx.showModal({ title: '提示', content: '请先登录', confirmText: '去登录', success: res => { if (res.confirm) { wx.navigateTo({ url: '/pages/login/login' }); } } }); return; } wx.showModal({ title: '消息通知', content: '是否开启消息推送通知?开启后可以及时接收设备检验预警提醒', confirmText: '开启', cancelText: '取消', success: async res => { if (res.confirm) { try { await app.subscribeAllMessages(); this.setData({ isSubscribed: true }); wx.showToast({ title: '订阅成功', icon: 'success' }); } catch (error) { console.error('订阅失败', error); wx.showToast({ title: '订阅失败', icon: 'none' }); } } } }); }, /** * 预警设置 */ goToWarningSettings() { wx.navigateTo({ url: '/pages/warning/settings/settings' }); }, /** * 单位管理 */ goToUnitManage() { wx.showToast({ title: '功能开发中', icon: 'none' }); }, /** * 数据导出 */ exportData() { if (!this.data.isLoggedIn) { wx.showModal({ title: '提示', content: '请先登录', confirmText: '去登录', success: res => { if (res.confirm) { wx.navigateTo({ url: '/pages/login/login' }); } } }); return; } wx.showToast({ title: '功能开发中', icon: 'none' }); }, /** * 关于我们 */ goToAbout() { wx.showModal({ title: '关于我们', content: '安全工器具预警小程序\n版本:v1.0.0\n\n专注于施工安全工器具的管理、维保和预警', showCancel: false }); }, /** * 帮助中心 */ goToHelp() { wx.showToast({ title: '功能开发中', icon: 'none' }); }, /** * 退出登录 */ handleLogout() { wx.showModal({ title: '确认退出', content: '确定要退出登录吗?', success: res => { if (res.confirm) { app.logout(); } } }); } });