1.关注公众号“码农帮派”,查看更多系列技术文章:
2.微信小程序开发,实现手机号注册的功能模块,去除了网络请求,网络请求的地方可以使用wx提供的网络请求的API完成。
3.[效果展示]
4.[目录结构]
5.[贴代码]
6.register.wxml
viewclass"container"style"height:{{windowHeight}}px"!--第一步--viewwx:if"{{step1}}"id"firstStep_Pad"class"container"style"height:auto;"textclass"grayLineHeng"style"margin-top:55rpx"/viewstyle"width:{{windowWidth}}px;"class"container-hang"textstyle"color:#c9c9c9;margin:33rpx033rpx0;width:460rpx;text-align:center;"国家/地区/texttextclass"grayLineShu"style"height:auto"/texttextstyle"color:#000;width:100%;text-align:center;margin-top:33rpx"{{location}}/text/viewtextclass"grayLineHeng"/viewclass"container-hang"style"width:{{windowWidth}}px;"imagesrc"{{icon_phone}}"style"width:49rpx;height:49rpx;margin:28rpx"/inputid"input_phoneNum"bindchange"input_phoneNum"style"margin:24rpx32rpx00;height:49rpx;"placeholder"请输入电话号码"type"number"//viewtextclass"grayLineHeng"//view!--第二步--viewwx:if"{{step2}}"id"secondStep_Pad"class"container"style"height:auto;align-items:flex-start;"textstyle"margin:44rpx;font-size:30rpx"验证码已经发送到您的手机如长时间没有收到,请点击“重新获取”/texttextclass"grayLineHeng"/viewclass"container-hang"style"width:{{windowWidth}}px;"imagesrc"{{input_icon}}"style"width:49rpx;height:49rpx;margin:28rpx"/inputbindchange"input_identifyCode"style"margin:24rpx32rpx00;height:49rpx;"placeholder"请输入验证码"type"number"//viewtextclass"grayLineHeng"/buttonbindtap"reSendPhoneNum"size"mini"style"margin-top:23rpx;margin-right:23rpx"重新获取({{time}}s)/button/view!--第三步--viewwx:if"{{step3}}"id"thirdStep_Pad"class"container"style"height:auto;margin-top:23rpx"textclass"grayLineHeng"/viewclass"container-hang"style"width:{{windowWidth}}px;"imagesrc"{{icon_password}}"style"width:49rpx;height:49rpx;margin:28rpx"/inputbindchange"input_password"style"margin:24rpx32rpx00;height:49rpx;"placeholder"请输入密码"password//viewtextclass"grayLineHeng"/viewclass"container-hang"style"width:{{windowWidth}}px;"imagesrc"{{icon_password}}"style"width:49rpx;height:49rpx;margin:28rpx"/inputbindchange"input_rePassword"style"margin:24rpx32rpx00;height:49rpx;"placeholder"请再次输入密码"password//viewtextclass"grayLineHeng"//viewbuttonstyle"width:{{nextButtonWidth}}px;margin-top:35rpx"type"primary"size"default"bindtap"nextStep"下一步/button/view7.register.wxss
.container-hang{display:flex;flex-direction:row;background-color:#fff;}8.register.js
varappgetApp()//varstep1//当前操作的stepvarmaxTime60varcurrentTimemaxTime//倒计时的事件(单位:s)varintervalnullvarhintMsgnull//提示varcheckrequire("../../utils/check.js")varwebUtilsrequire("../../utils/registerWebUtil.js")varstep_g1varphoneNumnull,identifyCodenull,passwordnull,rePasswordnull;Page({data:{windowWidth:0,windoeHeight:0,icon_phone:"../../img/icon_phone.png",input_icon:"../../img/input_icon.png",icon_password:"../../img/icon_password.png",location:"中国",nextButtonWidth:0,step:step_g,time:currentTime},onLoad:function(){step_g1varthatthiswx.getSystemInfo({success:function(res){that.setData({windowWidth:res.windowWidth,windowHeight:res.windowHeight,nextButtonWidth:res.windowWidth-20})}})},onUnload:function(){currentTimemaxTimeif(interval!null){clearInterval(interval)}},nextStep:function(){varthatthisif(step_g1){if(firstStep()){step_g2intervalsetInterval(function(){currentTime--;that.setData({time:currentTime})if(currentTime0){clearInterval(interval)currentTime-1}},1000)}}elseif(step_g2){if(secondStep()){step_g3clearInterval(interval)}}else{if(thirdStep()){//完成注册wx.navigateTo({url:'../home/home'})}}if(hintMsg!null){wx.showToast({title:hintMsg,icon:'loading',duration:700})}this.setData({step:step_g})},input_phoneNum:function(e){phoneNume.detail.value},input_identifyCode:function(e){identifyCodee.detail.value},input_password:function(e){passworde.detail.value},input_rePassword:function(e){rePassworde.detail.value},reSendPhoneNum:function(){if(currentTime0){varthatthiscurrentTimemaxTimeintervalsetInterval(function(){currentTime--that.setData({time:currentTime})if(currentTime0){currentTime-1clearInterval(interval)}},1000)}else{wx.showToast({title:'短信已发到您的手机,请稍后重试!',icon:'loading',duration:700})}}})functionfirstStep(){//提交电话号码,获取[验证码]if(!check.checkPhoneNum(phoneNum)){hintMsg"请输入正确的电话号码!"returnfalse}if(webUtils.submitPhoneNum(phoneNum)){hintMsgnullreturntrue}hintMsg"提交错误,请稍后重试!"returnfalse}functionsecondStep(){//提交[验证码]if(!check.checkIsNotNull(identifyCode)){hintMsg"请输入验证码!"returnfalse}if(webUtils.submitIdentifyCode(identifyCode)){hintMsgnullreturntrue}hintMsg"提交错误,请稍后重试!"returnfalse}functionthirdStep(){//提交[密码]和[重新密码]console.log(password+""+rePassword)if(!check.isContentEqual(password,rePassword)){hintMsg"两次密码不一致!"returnfalse}if(webUtils.submitPassword(password)){hintMsg"注册成功"returntrue}hintMsg"提交错误,请稍后重试!"returnfalse}9.register.json
{"navigationBarBackgroundColor":"#000","navigationBarTitleText":"填写手机号码","enablePullDownRefresh":false,"navigationBarTextStyle":"white"}10.check.js
//检测是否有输入functioncheckIsNotNull(content){return(contentcontent!null)}//检测输入内容functioncheckPhoneNum(phoneNum){console.log(phoneNum)if(!checkIsNotNull(phoneNum)){returnfalse}returntrue}//比较两个内容是否相等functionisContentEqual(content_1,content_2){if(!checkIsNotNull(content_1)){returnfalse}if(content_1content_2){returntrue}returnfalse}module.exports{checkIsNotNull:checkIsNotNull,checkPhoneNum:checkPhoneNum,isContentEqual:isContentEqual}11.registerWebUtil.js
//提交[电话号码]functionsubmitPhoneNum(phoneNum){//此处调用wx中的网络请求的API,完成电话号码的提交returntrue}//提交[验证码]functionsubmitIdentifyCode(identifyCode){//此处调用wx中的网络请求的API,完成短信验证码的提交returntrue}//提交[密码],前一步保证两次密码输入相同functionsubmitPassword(password){//此处调用wx中的网络请求的API,完成密码的提交returntrue}module.exports{submitPhoneNum:submitPhoneNum,submitIdentifyCode:submitIdentifyCode,submitPassword:submitPassword}
微信小程序开发-短信注册功能-微信小程序调起手机短信-微信小程序短信验证
浏览量:1231
时间:
来源:百家晓东
版权声明
即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。
最新资讯
-

即速应用,赋能企业玩转微信小程序智慧经营
作为国内领军的智慧商业经营服务商,即速应用始终秉承“让每个企业都拥有自己的智慧店铺”的愿景,持续赋能更多企业玩转智慧经营。即速应用旗下拥有“小程序搭建工具-即速应用”、“私域流量专家-即客云”等产品,帮助商家打通互联网全生态营销闭环。 -

即客云2.0重磅更新,让微信小程序运营更简单!
即客云作为一款基于企业微信的第三方工具,现从多维度提供超过30种功能,自上线以来,已服务多家企业,受到一致好评。近期,我们根据客户反馈和市场调研正式推出升级版 即客云2.0!更新了私域运营SOP,群日历功能,批量拓客,客户雷达,消息推送,个人欢迎语,帮助企业更好运用企业微信;同时提升了社群运营工作标准化,提升运营效率,帮助企业实现客户增长,玩转私域流量。 -

零代码 + AI 双轮驱动|即速应用解锁人工智能小程序开发新范式
无需代码、无需 AI 算法功底,普通人也能快速搭建智能小程序。即速应用将人工智能与零代码开发深度融合,推出 AI 智能生成能力,用户通过自然语言描述需求,AI 自动生成小程序页面、功能模块与后台配置,覆盖商城、预约、同城、社区团购等全场景。平台内置 AI 智能推荐、智能客服、用户画像分析等能力,一键对接微信生态,打通视频号、企业微信、短信跳转,帮企业快速落地 AI 应用,抢占智慧经营先机,让每家企业都拥有 AI 驱动的智慧店铺。










