From 84ae37a8e238ac81ee08f573854c3a3e3ccdb93d Mon Sep 17 00:00:00 2001 From: p7zwxau5j <904679083@qq.com> Date: Tue, 8 Oct 2024 14:17:17 +0800 Subject: [PATCH] ADD file via upload --- index.js | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..cd56fea --- /dev/null +++ b/index.js @@ -0,0 +1,92 @@ +// 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 + }); + }); + } +}); \ No newline at end of file