Files
wxapp_companion/pages/me/index.js
T
lik 51b6ef497b feat(attendant): 展示实习/正式身份与实习只读提示
- 角色解析缓存陪诊师阶段与等级,实习仍可进入工作台

- 首页与个人中心展示身份文案,实习期给出不能接单的提示

- 申请页文案说明审核通过后为实习陪诊师、转正后可接单
2026-11-10 12:02:08 +08:00

97 lines
2.1 KiB
JavaScript

// pages/me/index.js
const role = require('../../utils/role.js')
// 性别映射
const SEX_MAP = {
male: '男',
female: '女'
}
Page({
data: {
user: {},
identityText: ''
},
onShow() {
this.loadUser()
this.loadIdentity()
},
/**
* 身份文案:管理员/实习陪诊师/正式陪诊师·等级
*/
loadIdentity() {
role
.ensureRoleSafe()
.then((detail) => {
const attendant = detail.attendant || null
this.setData({
identityText: detail.role === 'admin' ? '管理员' : (attendant ? attendant.text : '')
})
})
.catch(() => {})
},
/**
* 加载当前登录用户信息
*/
loadUser() {
const app = getApp()
app.ensureLogin()
.then(user => {
this.setUser(user)
})
.catch(() => {
wx.showToast({ title: '获取用户信息失败', icon: 'none' })
})
},
/**
* 处理并展示用户信息
*/
setUser(user) {
if (!user) return
const profile = user.profile || {}
const location = user.location || {}
const meta = user.meta || {}
const name = profile.name || '微信用户'
const locationText = [location.province, location.city, location.district]
.filter(Boolean).join(' ')
this.setData({
user: {
avatar: profile.avatar || '',
avatarText: name[0],
name,
mobile: profile.mobile || '',
sexLabel: SEX_MAP[profile.sex] || '未知',
birthText: this.formatDate(profile.birth),
email: profile.email || '',
idnumber: profile.idnumber || '',
locationText,
createText: this.formatDate(meta.createtime)
}
})
},
/**
* 格式化日期为 yyyy-MM-dd
*/
formatDate(dateStr) {
if (!dateStr) return ''
const date = new Date(dateStr)
if (isNaN(date.getTime())) return ''
const pad = (n) => String(n).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
},
onShareAppMessage() {
return {
title: '个人中心',
path: '/pages/me/index'
}
}
})