import { models, db } from '../../utils/cloudbase.js' Page({ data: { phone: '', // 用户输入的手机号码 }, // 监听手机号码输入 onInputPhone(e) { this.setData({ phone: e.detail.value }); }, // 确定按钮点击事件 async onConfirm() { const { phone } = this.data; if (!phone) { wx.showToast({ title: '请输入手机号码', icon: 'none' }); return; } if (!/^1[3-9]\d{9}$/.test(phone)) { wx.showToast({ title: '输入的手机号码有误', icon: 'none' }); return; } const childComponent = this.selectComponent('#loginCaptcha'); const result = childComponent.validCaptcha() if (!result.flag) { wx.showToast({ title: result.msg, icon: 'none' }); return } const { data } = await models.wx_teacher_user.list({ filter: { where: { phone: this.data.phone } }, pageSize: 100, // 分页大小,建议指定,如需设置为其它值,需要和 pageNumber 配合使用,两者同时指定才会生效 pageNumber: 1, // 第几页 getCount: true, // 开启用来获取总数 // envType: pre 体验环境, prod 正式环境 envType: "prod", }); const users = data.records || []; // 如果查不到任何数据 if (users.length === 0) { wx.showToast({ title: '该手机号绑定,请换其他手机号登录', icon: 'none' }); return; } // ✅ 如果查到了,但全部都是 delete === 1,则视为无有效账号 const allDeleted = users.every(user => user.delete === 1); if (allDeleted) { wx.showToast({ title: '该手机号未注册,请换其他手机号登录', icon: 'none' }); return; } // ✅ 只要有一个 delete === 0,就继续登录 const validUser = users.find(user => user.delete === 0); if (validUser.bound === 0) { // 第一次登录去绑定 wx.showToast({ title: '首次登录,请先绑定信息', icon: 'none', duration: 1500 }); setTimeout(() => { wx.navigateTo({ url: `/pages/login/login?phone=${encodeURIComponent(this.data.phone)}` }); }, 1500); // 等提示展示完再跳转 } else { // 登录成功,存储用户信息 wx.setStorageSync('userInfo', validUser); wx.showToast({ title: '登录成功', icon: 'success' }); wx.switchTab({ url: '/pages/index/index' }); } } })