feat(attendant): 展示实习/正式身份与实习只读提示

- 角色解析缓存陪诊师阶段与等级,实习仍可进入工作台

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

- 申请页文案说明审核通过后为实习陪诊师、转正后可接单
This commit is contained in:
lik
2026-11-10 12:02:08 +08:00
parent a8b896846b
commit 51b6ef497b
7 changed files with 104 additions and 12 deletions
+39 -3
View File
@@ -15,6 +15,33 @@ let cachedRole = null
let cachedRoleOk = false
let pending = null
let pendingSafe = null
// 陪诊师阶段/等级快照:仅用于展示身份文案与实习只读提示,不参与权限判定
let cachedAttendant = null
const GRADE_LABELS = { bronze: '青铜', silver: '白银', gold: '黄金', diamond: '钻石' }
/**
* 阶段/等级归一化:后端已归一化,这里兼容旧接口与缺字段的情况
* @param {Object|null} employee 员工档案
* @returns {{stage: string, grade: string, star: number, canAcceptOrder: boolean, text: string}}
*/
function normalizeAttendant(employee) {
const info = (employee && employee.attendantInfo) || {}
const stage = info.stage === 'intern' ? 'intern' : 'certified'
const grade = GRADE_LABELS[info.grade] ? info.grade : 'bronze'
const rawStar = Number(info.star)
const star = grade === 'diamond' && isFinite(rawStar)
? Math.max(0, Math.min(5, Math.floor(rawStar)))
: 0
const gradeText = `${GRADE_LABELS[grade]}${grade === 'diamond' && star ? ' ' + '★'.repeat(star) : ''}`
return {
stage,
grade,
star,
canAcceptOrder: stage === 'certified',
text: stage === 'intern' ? '实习陪诊师' : `正式陪诊师 · ${gradeText}`
}
}
function rolesOf(entry) {
if (!entry) return []
@@ -77,15 +104,21 @@ async function resolveRoleDetail() {
}
if (!user) return { ok: false, role: 'none' }
if (isAdminUser(user)) return { ok: true, role: 'admin' }
if (isAdminUser(user)) {
cachedAttendant = null
return { ok: true, role: 'admin' }
}
try {
const res = await API.employee.getMe()
if (!res || res.code !== 0) return { ok: false, role: 'none' }
const employee = res.data ? res.data.employee : null
// 实习与正式都算陪诊师:实习能进主页面,只是不能接单
if (employee && employee.status === 'active' && employee.role === 'attendant') {
return { ok: true, role: 'attendant' }
cachedAttendant = normalizeAttendant(employee)
return { ok: true, role: 'attendant', attendant: cachedAttendant }
}
cachedAttendant = null
return { ok: true, role: 'none' }
} catch (e) {
// 员工接口异常:解析失败,不据此判定为无身份
@@ -126,7 +159,9 @@ function ensureRole(force) {
* @returns {Promise<{ok: boolean, role: "admin"|"attendant"|"none"}>}
*/
function ensureRoleSafe(force) {
if (!force && cachedRole && cachedRoleOk) return Promise.resolve({ ok: true, role: cachedRole })
if (!force && cachedRole && cachedRoleOk) {
return Promise.resolve({ ok: true, role: cachedRole, attendant: cachedAttendant })
}
if (!force && pendingSafe) return pendingSafe
pendingSafe = resolveRoleDetail()
@@ -157,6 +192,7 @@ function resetRole() {
cachedRoleOk = false
pending = null
pendingSafe = null
cachedAttendant = null
applyAppRole(null)
}