import { calcAge } from '../../utils/idCard/index' import type { UserInfo } from '../../api/index' import { leFuService } from '../../lefu/index' /** 页面展示用用户信息 */ interface PageUserInfo { realname: string sex_dictText: string age: number height: number } // pages/my/my.ts Page({ /** * 页面的初始数据 */ data: { // 导航栏背景色,根据滚动位置动态变化 navBgColor: 'rgba(255,255,255,0)', userInfo: null as PageUserInfo | null, }, /** * 生命周期函数--监听页面加载 */ onLoad() { }, // 滚动时导航栏背景渐显 onScroll(e: WechatMiniprogram.ScrollViewScroll) { const scrollTop = e.detail.scrollTop; const opacity = Math.min(Math.max(scrollTop / 300, 0), 1); this.setData({ navBgColor: `rgba(255,255,255,${opacity})`, }); }, onTapPersonalInfo() { wx.navigateTo({ url: '/pages/personalInformation/personalInformation' }) }, onTapHelpCenter() { wx.navigateTo({ url: '/pages/helpCenter/helpCenter' }) }, // 退出登录:清空 lefu 连接与本地信息,回到登录页 onLogout() { wx.showModal({ title: '退出登录', content: '确定要退出登录吗?', confirmText: '退出', cancelText: '取消', success: (res) => { if (!res.confirm) return leFuService.disconnect() leFuService.stopScan() wx.clearStorageSync() wx.reLaunch({ url: '/pages/login/login' }) }, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this._loadUserInfo() }, // 从缓存回显用户信息 _loadUserInfo() { const raw = wx.getStorageSync('userInfo') as UserInfo | null if (!raw?.userId) return this.setData({ userInfo: { realname: raw.realname ?? '', sex_dictText: raw.sex === 1 ? '男' : raw.sex === 2 ? '女' : '', age: calcAge(raw.birthday), height: raw.height ?? 0, }, }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })