uniapp验证码登录

news/2024/12/4 3:51:32/

<view @click="sendCode" :class="phone.length == 11 ? 'btn2' : ''" class="btn">获取短信验证码</view>
*******************************************************************************************************************************************************
1.调接口获取验证码
2.跳转至输入验证码的页面
3.调接口loginByCode判断验证码是否正确
4.保存用户信息和token到vuex保存token供request使用
5.返回2级页面//发送验证码
return{phone: '',}sendCode() {	const { phone } = this;if (!this.xieyi) {this.toast('请勾选和阅读《Uplay用户协议》《用户隐私政策》');return;}if (phone.length != 11) {this.toast('请输入正确的手机号');return;}getMsgCode({ phone }).then(res => {this.toast('发送成功!注意查收');console.log(res)//{//"msg": "操作成功",//	"code": 200//	}setTimeout(() => {uni.navigateTo({ url: '/pages/login/codeLogin?phone=' + this.phone }); //将手机号带过去}, 1500);});}*********************************************************************************************************************************************************************<view class="box"><view class="content">请输入验证码</view><view class="tip">验证码已发送至<text>{{phone}}</text></view><view class="uni-height"></view><view style="height: 100rpx;"></view><myp-one v-model="test" @finish="finishedOne" class="code_box"></myp-one></view></view>**********************************************************************************************************************************************************************import {  loginByCode,verificationCode ,teacherAuthInfo,loginRtm} from '../../common/apis.js';/*** 验证验证码* @param {Object} data*/export function verificationCode(data) {uni.showLoading()return request({requestType: 'post',method: 'app/user/verificationCode',sendmsg: data,})}/*** 验证码登录* @param {Object} data*/export function loginByCode(data) {uni.showLoading()return request({requestType: 'post',method: 'app/user/loginByCode',sendmsg: data,})}methods:{//校验验证码verificationCode() {const { phone, code } = this;if (code == '') {uni.showToast({title: '请输入验证码',icon: 'none'});return;}verificationCode({phone,msgCode:code}).then(res => {console.log(97,res);this.openUrl(`/pages/login/newPwd?phone=${phone}&code=${code}`)});},finishedOne(val) {console.log(102,val)  //当你输完之后的值this.code = valif(this.type==1){          //忘记密码走这里this.verificationCode()}else{this.login()}},toClear() {this.test = ''this.$refs.hi.clear()},//验证码登录login() {const { phone, code } = this;if (code == '') {uni.showToast({title: '请输入验证码',icon: 'none'});return;}loginByCode({phone,code}).then(res => {console.log(44,res)//{//"msg": "操作成功",//"code": 200,//"data": {//	"id": 98,//	"token": "181e63a3a7e4439a9adfa67cf727fcfa",//		"userAvatar": "common/20210425/head@3x.png",//		"userName": "小U985",// 		"userPhone": "18119685985",//		"userType": 1// 	}// }//老师端if (this.$store.state.environment == 'teacher') {//老师登录if (res.data.userType == 2) {this.toast('登录成功');this.saveUser(res.data);this.saveToken(res.data.token);setTimeout(() => {uni.navigateBack({delta: 2});}, 2000);} else {this.saveUser(res.data);this.saveToken(res.data.token);teacherAuthInfo().then(res => {if (res.data.certificationStatus == -1) {this.openUrlRedirect('/pages/recommend/teacherCert/teacherCert');} else {this.openUrlRedirect('/pages/recommend/certDetail/certDetail?certificationStatus=' + res.data.certificationStatus);}});}} else {this.toast('登录成功',2000,'success');this.saveUser(res.data);this.saveToken(res.data.token);loginRtm()setTimeout(()=>{uni.navigateBack({delta:2})},2000)setTimeout(()=>{uni.$emit('score')},3500)}});},},

 

 


http://www.ppmy.cn/news/521539.html

相关文章

hdu 1869

一个最短路径的变形&#xff0c;解决问题的思路也开阔灵活&#xff0c;其实都是万变不离其宗 六度分离 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 726 Accepted Submission(s): 275 Problem Description …

sgu495

不多提。 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int MAXN100000100; int n,m; double dp[MAXN]; int main() {while(~scanf("%d%d",&n,&m)){double ans1.0;dp[1]1.0;for(int i2;i<m;i)…

UVA1598

思路&#xff1a;每个优先级队列分别存储sell和buy&#xff0c;每个指令后都判断是否产生交易 package test;import java.util.Comparator; import java.util.Iterator; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.…

hdu1698

/* 分析&#xff1a; 线段树水题&#xff0c;成段更新成段查询(总共只查询一次)。 线段树学的太菜了&#xff0c;被这水题虐了&#xff0c;弄了一上午- -I 2012-07-10 */ #include"stdio.h"struct segtree {int l,r;int mid;int val;int flag; }T[300011];void build…

HDU 1598

将边先排序&#xff0c;然后从最小的边开始枚举&#xff0c;当发现需要查找的两个点在一个并查集里面的时候就计算差值&#xff0c;并与min比较。 #include <cstdio> #include <iostream> #include <algorithm> #include <cstring>using namespace std…

UVA1599

题目&#xff1a;https://vjudge.net/problem/UVA-1599 思路&#xff1a;先反向做一次bfs&#xff0c;求出各点到终点经过的最少结点数量。然后正向做一次bfs&#xff0c;每次都选取颜色最小的路径&#xff0c;同时要保证距离的值刚好减1&#xff0c;如果有多条路可以走&#…

UVa1589

/* 题意很简单&#xff0c;就是黑方只剩下一个将&#xff0c;红方还有很多子&#xff0c;而且当前的残局是红方正在将军&#xff0c;判断红方是否已经将死黑方 红方只有四种棋子&#xff0c;帅&#xff0c;车&#xff0c;炮&#xff0c;马&#xff0c;因此按照每个棋子的运算…

hdu1789

/* 分析&#xff1a; 简单贪心&#xff0c;一开始没想到思路。 很直观的&#xff0c;第一步按照score从大到小排序&#xff0c;如果score 相等&#xff0c;则按照deadline从小到大排。 然后开始选择&#xff0c;让当前的课排在其deadline上面&#xff0c;如果 这一天已经被占用…