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.
92 lines
2.1 KiB
92 lines
2.1 KiB
// pages/login/login.js
|
|
const db = wx.cloud.database();
|
|
|
|
Page({
|
|
data: {
|
|
studentId: '',
|
|
name: ''
|
|
},
|
|
onStudentIdInput: function(e) {
|
|
this.setData({
|
|
studentId: e.detail.value
|
|
});
|
|
},
|
|
onNameInput: function(e) {
|
|
this.setData({
|
|
name: e.detail.value
|
|
});
|
|
},
|
|
onTeacherLogin: function() {
|
|
// 教师登录逻辑
|
|
const { studentId, name } = this.data;
|
|
if (studentId === '520' && name === 'fzu') {
|
|
// 匹配成功,跳转到教师端
|
|
wx.navigateTo({
|
|
url: '/pages/teacherHomePage/teacherHomePage'
|
|
});
|
|
this.setData({
|
|
studentId: '', // 重置学号
|
|
name: '' // 重置姓名
|
|
});
|
|
} else {
|
|
// 匹配失败,提示用户
|
|
wx.showToast({
|
|
title: '无权访问',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
}
|
|
},
|
|
login: function() {
|
|
const { studentId, name } = this.data;
|
|
if (!studentId || !name) {
|
|
wx.showToast({
|
|
title: '学号和姓名不能为空',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
return;
|
|
}
|
|
|
|
// 将输入的学号转换为数字
|
|
const num = Number(studentId);
|
|
if (isNaN(num)) {
|
|
wx.showToast({
|
|
title: '学号必须为数字',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
return;
|
|
}
|
|
|
|
db.collection('users').where({
|
|
num: num,
|
|
name: name
|
|
}).get().then(res => {
|
|
if (res.data.length > 0) {
|
|
// 找到匹配的用户,进行跳转
|
|
wx.navigateTo({
|
|
url: '/pages/studentHomePage/studentHomePage?studentId=' + encodeURIComponent(studentId) + '&name=' + encodeURIComponent(name)
|
|
});
|
|
this.setData({
|
|
studentId: '', // 重置学号
|
|
name: '' // 重置姓名
|
|
});
|
|
} else {
|
|
// 没有找到匹配的用户
|
|
wx.showToast({
|
|
title: '用户不存在或信息错误',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
}
|
|
}).catch(err => {
|
|
console.error('查询失败:', err);
|
|
wx.showToast({
|
|
title: '查询失败',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
});
|
|
}
|
|
}); |