You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
4.5 KiB
174 lines
4.5 KiB
Page({
|
|
data: {
|
|
studentName: '',
|
|
studentId: '',
|
|
avatar: '/image/4.png', // 默认头像
|
|
showModal: false, // 控制模态框显示
|
|
score: 0, // 学生积分
|
|
refreshing: false // 控制下拉刷新的状态
|
|
},
|
|
|
|
onLoad(options) {
|
|
const app = getApp();
|
|
const { fromIndex } = options; // 获取参数
|
|
|
|
if (fromIndex) {
|
|
// 清空全局变量和数据
|
|
app.globalData.studentInfo = null;
|
|
this.setData({
|
|
studentName: '',
|
|
studentId: '',
|
|
score: 0,
|
|
avatar: '/image/4.png'
|
|
});
|
|
} else if (app.globalData.studentInfo) {
|
|
const { studentName, studentId, score, avatar } = app.globalData.studentInfo;
|
|
this.setData({ studentName, studentId, score, avatar });
|
|
}
|
|
},
|
|
|
|
onShow() {
|
|
// 页面显示时只更新积分
|
|
this.updateScore();
|
|
},
|
|
|
|
showLoginModal() {
|
|
this.setData({ showModal: true });
|
|
},
|
|
|
|
handleInput(e) {
|
|
const { field } = e.currentTarget.dataset;
|
|
const value = e.detail.value;
|
|
this.setData({ [field]: value });
|
|
},
|
|
|
|
confirmInput() {
|
|
const { studentName, studentId } = this.data;
|
|
|
|
if (!studentName || !studentId) {
|
|
wx.showToast({ title: '请填写完整信息', icon: 'none' });
|
|
return;
|
|
}
|
|
|
|
this.setData({ showModal: false });
|
|
|
|
wx.request({
|
|
url: `http://127.0.0.1:8000/api/get_student_info/${studentId}/`,
|
|
method: 'GET',
|
|
success: (res) => {
|
|
if (res.statusCode === 200) {
|
|
this.setData({
|
|
score: res.data.score,
|
|
avatar: res.data.avatar || this.data.avatar // 更新头像
|
|
});
|
|
|
|
// 将学生信息存入全局变量
|
|
const app = getApp();
|
|
app.globalData.studentInfo = {
|
|
studentName,
|
|
studentId,
|
|
score: res.data.score,
|
|
avatar: this.data.avatar,
|
|
};
|
|
} else {
|
|
wx.showToast({ title: '信息错误,请重试', icon: 'none' });
|
|
}
|
|
},
|
|
fail: (error) => {
|
|
wx.showToast({ title: '无法获取学生信息,请检查网络连接', icon: 'none' });
|
|
}
|
|
});
|
|
},
|
|
|
|
cancelInput() {
|
|
this.setData({ showModal: false });
|
|
},
|
|
|
|
// 下拉刷新功能
|
|
onRefresh() {
|
|
this.setData({ refreshing: true }); // 开始刷新
|
|
this.updateScore(); // 更新积分
|
|
},
|
|
|
|
updateScore() {
|
|
const { studentId } = this.data;
|
|
if (!studentId) {
|
|
// wx.showToast({ title: '学生 ID 丢失', icon: 'none' });
|
|
this.setData({ refreshing: false }); // 刷新结束
|
|
return;
|
|
}
|
|
wx.request({
|
|
url: `http://127.0.0.1:8000/api/get_student_info/${studentId}/`,
|
|
method: 'GET',
|
|
success: (res) => {
|
|
console.log(res.data); // 打印 API 返回的数据
|
|
if (res.statusCode === 200) {
|
|
this.setData({
|
|
score: res.data.score,
|
|
refreshing: false // 刷新结束
|
|
});
|
|
} else {
|
|
wx.showToast({ title: '更新失败', icon: 'none' });
|
|
this.setData({ refreshing: false }); // 刷新结束
|
|
}
|
|
},
|
|
fail: (error) => {
|
|
wx.showToast({ title: '请求失败,请检查网络', icon: 'none' });
|
|
this.setData({ refreshing: false }); // 刷新结束
|
|
}
|
|
});
|
|
},
|
|
|
|
// 上传头像
|
|
uploadAvatar() {
|
|
wx.chooseImage({
|
|
count: 1,
|
|
sizeType: ['compressed'],
|
|
sourceType: ['album', 'camera'],
|
|
success: (res) => {
|
|
const tempFilePath = res.tempFilePaths[0];
|
|
this.setData({ avatar: tempFilePath });
|
|
},
|
|
fail: (error) => {
|
|
wx.showToast({ title: '上传失败,请重试', icon: 'none' });
|
|
}
|
|
});
|
|
},
|
|
|
|
|
|
// 跳转到点名功能
|
|
rollCall() {
|
|
wx.navigateTo({
|
|
// url: '/pages/student/dm/dm?studentId=' + this.data.studentId,
|
|
url: `/pages/student/dm/dm?studentId=${this.data.studentId}&studentName=${this.data.studentName}&score=${this.data.score}`,
|
|
});
|
|
},
|
|
|
|
goBack() {
|
|
wx.navigateTo({
|
|
url: '/pages/index/index',
|
|
});
|
|
},
|
|
|
|
// 跳转到排行榜
|
|
goTorank() {
|
|
console.log('点击了排行榜按钮'); // 添加调试信息
|
|
wx.navigateTo({
|
|
url: '/pages/student/rank/rank',
|
|
});
|
|
},
|
|
// 跳转到典当页面
|
|
goToPledge() {
|
|
console.log('点击了典当按钮'); // 添加调试信息
|
|
wx.navigateTo({
|
|
url: `/pages/student/diandang/dd-yes/dd-yes?studentId=${this.data.studentId}&studentName=${this.data.studentName}`,
|
|
});
|
|
},
|
|
goToguize() {
|
|
console.log('点击了规则按钮'); // 添加调试信息
|
|
wx.navigateTo({
|
|
url: `/pages/student/rules/rule1/rule1`,
|
|
});
|
|
},
|
|
});
|