diff --git a/miniprogram/api/user.ts b/miniprogram/api/user.ts index 0712402..b8a481e 100644 --- a/miniprogram/api/user.ts +++ b/miniprogram/api/user.ts @@ -26,6 +26,8 @@ export interface UserInfo { delFlag: number sn: string | null workNo: string | null + secondDepart: string | null + thirdDepart: string | null remark: string | null relationType: string | null sex_dictText: string diff --git a/miniprogram/pages/personalInformation/personalInformation.ts b/miniprogram/pages/personalInformation/personalInformation.ts index acb186b..adf54bd 100644 --- a/miniprogram/pages/personalInformation/personalInformation.ts +++ b/miniprogram/pages/personalInformation/personalInformation.ts @@ -1,15 +1,43 @@ +import { calcAge } from '../../utils/idCard/index' +import type { UserInfo } from '../../api/index' + // pages/personalInformation/personalInformation.ts Page({ data: { - userInfo: { - name: '狗蛋', - idCard: '4301**********1234', - gender: '男', - age: '45岁', - company: '健康科技公司', - department: '技术部-研发组', - height: '175cm', - weight: '72kg' - } - } + userInfo: null as { + avatar: string + name: string + idCard: string + gender: string + age: string + secondDepart: string + thirdDepart: string + height: string + weight: string + } | null, + }, + + onShow() { + this._loadUserInfo() + }, + + // 从缓存回显用户信息 + _loadUserInfo() { + const raw = wx.getStorageSync('userInfo') as UserInfo | null + if (!raw?.userId) return + const age = calcAge(raw.birthday) + this.setData({ + userInfo: { + avatar: raw.realname?.[0] ?? '', + name: raw.realname ?? '-', + idCard: raw.idCard ?? '-', + gender: raw.sex_dictText || (raw.sex === 1 ? '男' : raw.sex === 2 ? '女' : '-'), + age: age ? `${age}岁` : '-', + secondDepart: raw.secondDepart || '-', + thirdDepart: raw.thirdDepart || '-', + height: raw.height ? `${raw.height}cm` : '-', + weight: raw.weight ? `${raw.weight}kg` : '-', + }, + }) + }, }) diff --git a/miniprogram/pages/personalInformation/personalInformation.wxml b/miniprogram/pages/personalInformation/personalInformation.wxml index ee61d1d..80a5356 100644 --- a/miniprogram/pages/personalInformation/personalInformation.wxml +++ b/miniprogram/pages/personalInformation/personalInformation.wxml @@ -3,8 +3,7 @@ 头像 - - + {{ userInfo.avatar }} @@ -30,12 +29,12 @@ 单位 - {{ userInfo.company }} + {{ userInfo.secondDepart }} 部门 - {{ userInfo.department }} + {{ userInfo.thirdDepart }}