1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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_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);
- wx.setStorageSync('userInfo', validUser);
-
- wx.showToast({
- title: '登录成功',
- icon: 'success'
- });
-
- wx.switchTab({
- url: '/pages/index/index'
- });
- }
- })
|