| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- // import { models, db } from '../../utils/cloudbase.js'
- import { getDB, getModels, getCommand, getTempFileURLs } from '../../utils/cloudbase.js'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- levelOptions: ['小班', '中班', '大班'],
- selectedLevelIndex: 0,
- xiala: '',
- phone: '',
- gardenList: [], // 这里替换为实际园所名称数组
- gardenIndex: null, // 选中的园所
- contactsname: '',
- selected: {},
- },
- // 监听手机号输入框
- onPhoneInput(e) {
- this.setData({
- phone: e.detail.value
- });
- },
- // 监听姓名输入框
- onContactsInput(e) {
- this.setData({
- contactsname: e.detail.value
- });
- },
- async onLoad(options) {
- this.onScholl();
- const fileIDs = [
- 'cloud://honghgaier-5guiffgcf17a2eea.686f-honghgaier-5guiffgcf17a2eea-1373037829/images/icon/xiala.png',
- ]
- const fileList = await getTempFileURLs(fileIDs)
- this.setData({
- xiala: fileList[0].tempFileURL,
- })
- // // 并发下载多个 fileID
- // Promise.all(
- // fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
- // ).then(results => {
- // // 每个 result 对应一个下载结果
- // const tempFilePaths = results.map(r => r.tempFilePath);
- // console.log('全部下载成功:', tempFilePaths);
- // this.setData({
- // xiala: tempFilePaths[0],
- // });
- // }).catch(err => {
- // console.error('有文件下载失败:', err);
- // });
- },
- // 获取学校数据
- async onScholl() {
- try {
- let allRecords = [];
- let pageNumber = 1;
- const pageSize = 100; // 每次查询 100 条
-
- while (true) {
- const models = await getModels()
- const { data } = await models.wx_school.list({
- filter: {
- where: {}
- },
- pageSize: pageSize,
- pageNumber: pageNumber,
- getCount: true,
- envType: "prod",
- });
-
- if (data.records.length === 0) {
- break; // 没有更多数据,退出循环
- }
-
- allRecords = allRecords.concat(data.records); // 将当前页数据添加到全部数据中
- pageNumber++; // 查询下一页
- }
-
- this.setData({
- gardenList: allRecords // 按实际字段替换
- });
- console.log(this.data.gardenList, 'gardenList');
- } catch (error) {
- console.error('获取数据失败:', error);
- wx.showToast({
- title: '获取数据失败,请稍后再试',
- icon: 'none'
- });
- }
- },
-
- // 选择学校下拉框
- async onGardenChange(e) {
- const index = parseInt(e.detail.value);
- this.setData({
- gardenIndex: index
- });
- const selected = this.data.gardenList[index];
- this.setData({
- selected: selected
- })
- },
- // 注册
- async bindingevents() {
- try {
- // 选中的学校, 姓名, 电话号码
- const { gardenIndex, contactsname, phone } = this.data;
- if (gardenIndex == null) {
- wx.showToast({
- title: '请选择学校',
- icon: 'none'
- });
- return;
- }
- if (!contactsname) {
- wx.showToast({
- title: '请输入姓名',
- icon: 'none'
- });
- return;
- }
- 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('#registorCaptcha');
- const result = childComponent.validCaptcha()
- if (!result.flag) {
- wx.showToast({
- title: result.msg,
- icon: 'none'
- });
- return
- }
- let models = await getModels()
- const { data } = await models.wx_user.get({
- filter: {
- where: {
- $and: [
- {
- delete: {
- $eq: 0, // 推荐传入_id数据标识进行操作
- },
- phone: {
- $eq: this.data.phone,
- }
- },
- ]
- }
- },
- // envType: pre 体验环境, prod 正式环境
- envType: "prod",
- });
-
- // 返回查询到的数据
- console.log(data, '69+++++++++++++');
- if(data && Object.keys(data).length > 0) {
- // 注册成功提示
- wx.showToast({
- title: '账号已存在,跳转登录',
- icon: 'success',
- duration: 1500, // 提示显示 1.5 秒
- });
- setTimeout(() => {
- wx.reLaunch({
- url: `/pages/logins/logins`,
- });
- }, 1500);
- } else {
- const res= await models.wx_user.create({
- data: {
- img: "", // 头像
- gender: 1, // 性别
- teacher_id: "", // 老师id
- user_name: this.data.contactsname, // 用户名
- remark: "", // 备注
- delete: 0, // 逻辑删除
- school_id: this.data.selected._id, // 学校id
- phone: this.data.phone, // 手机号
- grade: this.data.selectedLevelIndex, // 班级
- log_off: "", // 注销原因
- name: this.data.contactsname, // 姓名
- },
- envType: "prod",
- });
-
- // 注册成功提示
- wx.showModal({
- title: '注册成功,去登录',
- icon: 'success',
- duration: 1500, // 提示显示 1.5 秒
- });
-
- // 提示消失后跳转到登录页面,并把手机号带过去
- setTimeout(() => {
- wx.reLaunch({
- url: `/pages/logins/logins?phone=${this.data.phone}`,
- });
- }, 1500);
- }
-
- } catch (error) {
- console.error('注册失败:', error);
- wx.showToast({
- title: '注册失败,请稍后再试',
- icon: 'none',
- });
- }
- }
- })
|