2026-09-16 15:38:15 +08:00

62 lines
2.1 KiB
JavaScript

const ROLE = {
PARTICIPANT: 'participant',
REFEREE: 'referee',
CHECKER: 'checker'
};
const ROLE_META = {
participant: { value: 'participant', label: '运动员', description: '报名参赛并查询个人成绩' },
referee: { value: 'referee', label: '裁判', description: '完成裁判认证后参与执裁' },
checker: { value: 'checker', label: '检录员', description: '查看检录轮次并完成现场检录' }
};
function normalizeRole(value) {
if (value == null || value === '') return ROLE.PARTICIPANT;
const raw = String(value).toLowerCase();
const map = {
'1': ROLE.PARTICIPANT,
participant: ROLE.PARTICIPANT,
athlete: ROLE.PARTICIPANT,
user: ROLE.PARTICIPANT,
player: ROLE.PARTICIPANT,
'运动员': ROLE.PARTICIPANT,
'2': ROLE.REFEREE,
referee: ROLE.REFEREE,
judge: ROLE.REFEREE,
'裁判': ROLE.REFEREE,
'3': ROLE.CHECKER,
checker: ROLE.CHECKER,
checkin: ROLE.CHECKER,
inspector: ROLE.CHECKER,
'检录员': ROLE.CHECKER
};
return map[raw] || ROLE.PARTICIPANT;
}
function getProfileRole(profile) {
const p = profile && typeof profile === 'object' ? profile : {};
const raw = p.role != null ? p.role
: p.userRole != null ? p.userRole
: p.accountRole != null ? p.accountRole
: p.roleType != null ? p.roleType
: p.RoleType != null ? p.RoleType
: p.userType != null ? p.userType
: p.identityType;
if (raw != null && raw !== '') return normalizeRole(raw);
return normalizeRole(wx.getStorageSync('registeredRole') || ROLE.PARTICIPANT);
}
function updateEventTabBar(role) {
if (typeof wx === 'undefined' || typeof wx.setTabBarItem !== 'function') return;
const isChecker = normalizeRole(role) === ROLE.CHECKER;
wx.setTabBarItem({
index: 0,
text: isChecker ? '检录' : '赛事',
iconPath: isChecker ? 'assets/tab_scan.png' : 'assets/tab_home.png',
selectedIconPath: isChecker ? 'assets/tab_scan_sel.png' : 'assets/tab_home_sel.png',
fail() {}
});
}
module.exports = { ROLE, ROLE_META, normalizeRole, getProfileRole, updateEventTabBar };