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

175 lines
4.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const auth = require('../../../utils/auth');
const { ROLE_META } = require('../../../utils/role');
const PHONE_RE = /^1[3456789]\d{9}$/;
Page({
data: {
isReset: false, // true = 重置密码模式,false = 注册模式
mobile: '',
password: '',
password2: '',
verificationCode: '',
nickName: '',
selectedRole: 'participant',
selectedRoleDescription: ROLE_META.participant.description,
roleOptions: [ROLE_META.participant, ROLE_META.referee],
submitting: false,
codeSending: false,
countdown: 0,
statusBarHeight: 0
},
_timer: null,
onLoad(options) {
const { statusBarHeight = 0 } = wx.getSystemInfoSync();
const isReset = options && options.mode === 'reset';
this.setData({ statusBarHeight, isReset });
},
onUnload() {
if (this._timer) {
clearInterval(this._timer);
this._timer = null;
}
},
/** 返回上一页 */
onBack() {
if (getCurrentPages().length > 1) {
wx.navigateBack();
} else {
wx.switchTab({ url: '/pages/mine/mine' });
}
},
onMobileInput(e) {
this.setData({ mobile: (e.detail.value || '').trim() });
},
onPasswordInput(e) {
this.setData({ password: e.detail.value || '' });
},
onPassword2Input(e) {
this.setData({ password2: e.detail.value || '' });
},
onCodeInput(e) {
this.setData({ verificationCode: (e.detail.value || '').trim() });
},
onNickInput(e) {
this.setData({ nickName: (e.detail.value || '').trim() });
},
onRoleTap(e) {
if (this.data.isReset) return;
const role = e.currentTarget.dataset.role;
if (!ROLE_META[role]) return;
this.setData({
selectedRole: role,
selectedRoleDescription: ROLE_META[role].description
});
},
onSendCodeTap() {
const { mobile, countdown, codeSending } = this.data;
if (codeSending || countdown > 0) return;
if (!PHONE_RE.test(mobile)) {
wx.showToast({ title: '请输入正确手机号', icon: 'none' });
return;
}
this.setData({ codeSending: true });
wx.showLoading({ title: '发送中...' });
auth
.sendVerificationCode(mobile)
.then(() => {
wx.showToast({ title: '验证码已发送', icon: 'success' });
this._startCountdown(60);
})
.catch(() => {
wx.showToast({ title: '发送失败', icon: 'none' });
})
.finally(() => {
this.setData({ codeSending: false });
// wx.hideLoading();
});
},
_startCountdown(sec) {
if (this._timer) {
clearInterval(this._timer);
this._timer = null;
}
this.setData({ countdown: sec });
this._timer = setInterval(() => {
const next = this.data.countdown - 1;
if (next <= 0) {
clearInterval(this._timer);
this._timer = null;
this.setData({ countdown: 0 });
} else {
this.setData({ countdown: next });
}
}, 1000);
},
onSubmitTap() {
if (this.data.submitting) return;
const { isReset, mobile, password, password2, verificationCode, nickName, selectedRole } = this.data;
if (!PHONE_RE.test(mobile)) {
wx.showToast({ title: '请输入正确手机号', icon: 'none' });
return;
}
if (!verificationCode) {
wx.showToast({ title: '请输入验证码', icon: 'none' });
return;
}
if (!password || password.length < 6 || password.length > 32) {
wx.showToast({ title: '密码为 6–32 位', icon: 'none' });
return;
}
if (password !== password2) {
wx.showToast({ title: '两次密码不一致', icon: 'none' });
return;
}
this.setData({ submitting: true });
wx.showLoading({ title: '提交中...' });
const apiCall = isReset
? auth.resetPassword({ mobile, password, verificationCode })
: auth.registerWithVerification({ mobile, password, verificationCode, nickName, role: selectedRole });
const successMsg = isReset ? '密码重置成功' : '注册成功';
apiCall
.then(() => {
if (!isReset) wx.setStorageSync('registeredRole', selectedRole);
wx.showToast({ title: successMsg, icon: 'success' });
setTimeout(() => {
if (isReset) {
// 重置密码后返回登录页
// wx.redirectTo({ url: '/subpackages/mine/login/login' });
wx.navigateBack();
} else {
wx.navigateBack();
}
}, 800);
})
.catch((err) => {
const msg = (err && err.errors) || (err && err.message) || (isReset ? '重置失败' : '注册失败');
wx.showToast({ title: msg, icon: 'none' });
})
.finally(() => {
this.setData({ submitting: false });
// wx.hideLoading();
});
}
});