123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- 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'
- });
- }
- }
- })
|