ltx d17f43135d feat: 完善多角色赛事服务功能
- 新增参赛者、裁判、检录员角色识别及角色化首页与个人中心
- 新增裁判注册、身份认证提示、赛事执裁报名及报名记录查询
- 新增检录工作台,支持检录任务、轮次状态与运动员检录操作
- 新增赛事成绩查询页面及成绩详情展示
- 封装成绩、检录和裁判报名接口,补充请求参数清理逻辑
- 新增检录 Tab 图标、页面路由及本地开发配置
- 新增 Git 忽略规则,排除依赖、构建缓存、日志和本地工具文件
2026-08-07 11:28:38 +08:00

168 lines
4.3 KiB
JavaScript

const auth = require('../../utils/auth');
const { ROLE, ROLE_META, getProfileRole, updateEventTabBar } = require('../../utils/role');
function normalizeAuthStatus(v) {
if (v == null || v === '') return 0;
const n = Number(v);
return Number.isNaN(n) ? 0 : n;
}
/** 0 未认证 | 1 审核中 | 2 审核通过 | 3 审核失败 | 4 已取消 */
function authStatusText(status) {
const map = {
0: '未认证',
1: '审核中',
2: '审核通过',
3: '审核失败',
4: '已取消'
};
return map[normalizeAuthStatus(status)] || '未认证';
}
function maskPhone(phone) {
if (!phone || phone.length < 7) return phone || '';
return phone.substring(0, 3) + '****' + phone.substring(7);
}
Page({
data: {
loggedIn: false,
profile: {},
maskedPhone: '',
authStatus: 0,
authStatusText: '未认证',
role: ROLE.PARTICIPANT,
roleLabel: ROLE_META.participant.label,
isParticipant: true,
isReferee: false,
isChecker: false
},
onShow() {
const accessToken = wx.getStorageSync('accessToken') || '';
if (!accessToken) {
updateEventTabBar(ROLE.PARTICIPANT);
this.setData({ loggedIn: false, profile: {}, maskedPhone: '', authStatus: 0, authStatusText: '未认证' });
return;
}
this.setData({ loggedIn: true });
this.loadProfile();
},
onPullDownRefresh() {
this.loadProfile().finally(() => wx.stopPullDownRefresh());
},
loadProfile() {
return auth
.fetchMyProfile()
.then((profile) => {
const p = profile || {};
const st = normalizeAuthStatus(p.authStatus != null ? p.authStatus : p.AuthStatus);
const phone = p.mobile || p.phone || '';
const role = getProfileRole(p);
const roleMeta = ROLE_META[role] || ROLE_META.participant;
updateEventTabBar(role);
this.setData({
profile: p,
maskedPhone: maskPhone(phone),
authStatusText: authStatusText(st),
authStatus: st,
role,
roleLabel: roleMeta.label,
isParticipant: role === ROLE.PARTICIPANT,
isReferee: role === ROLE.REFEREE,
isChecker: role === ROLE.CHECKER
});
})
.catch(() => {});
},
goToLogin() {
wx.navigateTo({ url: '/subpackages/mine/login/login' });
},
goToPoints() {
wx.navigateTo({ url: '/subpackages/mine/points/points' });
},
goToCert() {
wx.navigateTo({ url: '/subpackages/mine/cert/cert' });
},
goToRecords() {
wx.navigateTo({ url: '/subpackages/mine/records/records' });
},
goToAuth() {
wx.navigateTo({ url: '/subpackages/mine/auth/auth' });
},
goToOrders() {
wx.navigateTo({ url: '/subpackages/mine/order/order' });
},
goToTeam() {
wx.navigateTo({ url: '/subpackages/mine/team/team' });
},
goToScores() {
wx.navigateTo({ url: '/subpackages/mine/scores/scores' });
},
goToCheckin() {
wx.navigateTo({ url: '/subpackages/mine/checkin/checkin' });
},
onLogout() {
wx.showModal({
title: '提示',
content: '确定要退出登录吗?',
confirmText: '退出',
confirmColor: '#e53935',
success: (res) => {
if (!res.confirm) return;
wx.clearStorageSync();
updateEventTabBar(ROLE.PARTICIPANT);
this.setData({ loggedIn: false, profile: {}, maskedPhone: '', authStatus: 0, authStatusText: '未认证' });
}
});
},
onChooseAvatar(e) {
const tempFilePath = e.detail.avatarUrl;
if (!tempFilePath) return;
// 先展示本地预览
// this.setData({ 'profile.avatar': tempFilePath });
wx.showLoading({ title: '上传中...', mask: true });
auth
.uploadFile(tempFilePath)
.then((url) => {
return auth.updateProfile({ "avatarUrl": url }).then(() => url);
})
.then((url) => {
this.setData({ 'profile.avatar': url });
wx.showToast({ title: '头像更新成功', icon: 'success' });
})
.catch((err) => {
wx.showToast({ title: (err && err.message) || '头像更新失败', icon: 'none' });
// 回滚预览,重新加载 profile
this.loadProfile();
})
.finally(() => {
wx.hideLoading();
});
},
onFetchOpenId() {
wx.login({
success: (res) => {
console.log('res', res);
}
});
}
});