import { get } from '../../utils/request/index' import { calcAge } from '../../utils/idCard/index' import type { UserInfo } from '../../api/index' /** 页面展示用用户信息 */ interface PageUserInfo { realname: string sex_dictText: string age: number height: number } /** 将体重数字拆成整数 + 小数字符串 */ const splitWeight = (weight: number): { int: number; decimal: string } => { const str = weight.toFixed(2) const [intPart, decPart] = str.split('.') return { int: Number(intPart), decimal: `.${decPart}` } } Page({ data: { record: null, userInfo: null as PageUserInfo | null, }, 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, }, }) }, onShareAppMessage(): WechatMiniprogram.Page.ICustomShareContent { return { title: '智能蓝牙秤', path: '/pages/home/home', imageUrl: '/images/share/share.jpg', } }, /** 跳转历史数据页 */ onTapHistory() { wx.switchTab({ url: '/pages/data/data' }) }, /** 跳转设备列表页 */ onTapSwitchDevice() { wx.switchTab({ url: '/pages/equipment/equipment' }) }, /** 跳转详细报告页 */ onTapDetailedReport() { wx.navigateTo({ url: '/pages/detailedReport/detailedReport' }) }, })