调用登录接口、注册接口、找回密码接口、短信验证码接口、退出登录接口

master
chen 2022-03-21 14:53:40 +08:00
parent f9330094a1
commit 4ea5a4223c
5 changed files with 122 additions and 72 deletions

View File

@ -72,26 +72,24 @@ const request = (method, url, options) => {
} }
break; break;
} }
let params = {};
if(options!=undefined) params = options;
params.token = uni.getStorageSync('token');
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.request({ uni.request({
url: `${uni.getStorageSync('hostapi')}${url}`, url: `${uni.getStorageSync('hostapi')}${url}`,
method: methods, method: methods,
data: options, data: params,
header: headers, header: headers,
success: res => { success: res => {
console.log(`${url}返的结果===>`,res); console.log(`${url}返的结果===>`,res);
if (res.statusCode == 200) { if (res.statusCode == 200) {
if (res.data.code == 0) {
// 接口调用成功 // 接口调用成功
resolve(res.data); resolve(res.data);
} else { } else {
// 接口返回错误信息 // 接口返回错误信息
checkError(res); checkError(res);
} }
} else {
// 接口返回错误信息
checkError(res);
}
}, },
fail: e => { fail: e => {
// 接口请求错误 // 接口请求错误

View File

@ -1,6 +1,9 @@
<template> <template>
<view class="pad-zy30"> <view class="pad-zy30">
<view class="fon52 bold mar-sx50">忘记密码</view> <status-nav navBarTitle="找回密码" returnColor="#c2c2c2"></status-nav>
<container-subgroup>
<view slot="content" style="margin: 0 -30rpx;">
<view class="fon52 bold mar-sx50">忘记密码 </view>
<view class="fon28"> <view class="fon28">
<view class="forget-title mar-x10">手机号码</view> <view class="forget-title mar-x10">手机号码</view>
<view class="forget-input-box posir"> <view class="forget-input-box posir">
@ -37,6 +40,8 @@
<!-- 立即修改 --> <!-- 立即修改 -->
<view class="forget-btn" @tap="submitEv"></view> <view class="forget-btn" @tap="submitEv"></view>
</view> </view>
</container-subgroup>
</view>
</template> </template>
<script> <script>
@ -54,7 +59,8 @@
ifUnitname:false, ifUnitname:false,
forget_unitname:'', forget_unitname:'',
codeText:'获取验证码' ,// codeText:'获取验证码' ,//
flagCode:true // flagCode:true ,//
countDown:null//
} }
}, },
methods: { methods: {
@ -69,7 +75,12 @@
affiliation: this.forget_unitname ,// affiliation: this.forget_unitname ,//
} }
this.$requst.post('/universal/api.login/password_find',params).then(res=>{ this.$requst.post('/universal/api.login/password_find',params).then(res=>{
if(res.code==1) {
this.$toolAll.tools.showToast('找回成功'); this.$toolAll.tools.showToast('找回成功');
setTimeout(()=>{uni.navigateBack({delta:1})},1000)
} else {
this.$toolAll.tools.showToast(res.msg);
}
}) })
} }
}, },
@ -82,12 +93,12 @@
this.flagCode = false; this.flagCode = false;
let count = 60; let count = 60;
this.codeText = `${count}S重新获取` this.codeText = `${count}S重新获取`
let countDown = setInterval(()=>{ this.countDown = setInterval(()=>{
count--; count--;
count < 10 ? this.codeText = `0${count}S重新获取` : this.codeText = `${count}S重新获取`; count < 10 ? this.codeText = `0${count}S重新获取` : this.codeText = `${count}S重新获取`;
if(count==0) { if(count==0) {
this.codeText = `重新获取`; this.codeText = `重新获取`;
clearInterval(countDown); clearInterval(this.countDown);
this.flagCode = true; this.flagCode = true;
} }
},1000) },1000)
@ -100,6 +111,10 @@
getMessage(phone){ getMessage(phone){
this.$requst.post('/universal/api.login/send_sms',{phone}).then(res=>{ this.$requst.post('/universal/api.login/send_sms',{phone}).then(res=>{
this.$toolAll.tools.showToast(res.msg); this.$toolAll.tools.showToast(res.msg);
if(res.code==0) {
clearInterval(this.countDown);
this.codeText = `获取验证码`
}
}) })
}, },
// //
@ -202,5 +217,5 @@
</script> </script>
<style> <style>
page{background-color: #FFFFFF;}
</style> </style>

View File

@ -82,22 +82,32 @@
methods: { methods: {
// //
submitEv(){ submitEv(){
// if(this.checkEmpty()){ if(this.checkEmpty()){
// let params = { let params = {
// login_type: this.login_type, // mobileaccount login_type: this.login_type, // mobileaccount
// phone: this.login_type == 'mobile' ? this.login_phone : '', // login_type mobile phone: this.login_type == 'mobile' ? this.login_phone : '', // login_type mobile
// password: this.login_password, // login_type account password: this.login_password, // login_type account
// sms_code: this.login_code, // login_type mobile sms_code: this.login_code, // login_type mobile
// username: this.login_type == 'account' ? this.login_phone : '', //login_type account username: this.login_type == 'account' ? this.login_phone : '', //login_type account
// affiliation: this.login_unitName // affiliation: this.login_unitName //
// } }
// this.$requst.post('/universal/api.login/login',params).then(res=>{ this.$requst.post('/universal/api.login/login',params).then(res=>{
// this.$toolAll.tools.showToast(''); console.log(res,95);
// }) if(res.code==1) {
// } this.$toolAll.tools.showToast('登录成功');
// token
uni.setStorageSync('token',res.data.token);
uni.setStorageSync('type_id',res.data.type_id);
setTimeout(()=>{
uni.reLaunch({ uni.reLaunch({
url:'/pages/tabbar/pagehome/pagehome' url:'/pages/tabbar/pagehome/pagehome'
}) })
},2000)
} else {
this.$toolAll.tools.showToast(res.msg);
}
})
}
}, },
// //
getCode(){ getCode(){
@ -126,7 +136,7 @@
getMessage(phone){ getMessage(phone){
this.$requst.post('/universal/api.login/send_sms',{phone}).then(res=>{ this.$requst.post('/universal/api.login/send_sms',{phone}).then(res=>{
this.$toolAll.tools.showToast(res.msg); this.$toolAll.tools.showToast(res.msg);
if(res.data.length==0) { if(res.code==0) {
this.codeText = '获取验证码'; this.codeText = '获取验证码';
clearInterval(this.countDown); clearInterval(this.countDown);
} }

View File

@ -93,7 +93,8 @@
register_unitName:'', // register_unitName:'', //
ifAgreen:false ,// ifAgreen:false ,//
codeText:'获取验证码' ,// codeText:'获取验证码' ,//
flagCode:true // flagCode:true ,//
countDown:null//
} }
}, },
methods: { methods: {
@ -108,9 +109,15 @@
affiliation: this.register_unitName // affiliation: this.register_unitName //
} }
this.$requst.post('/universal/api.login/register',params).then(res=>{ this.$requst.post('/universal/api.login/register',params).then(res=>{
if(res.code==1) {
this.$toolAll.tools.showToast('注册成功'); this.$toolAll.tools.showToast('注册成功');
setTimeout(()=>{
// //
this.goLogin(); this.goLogin();
},1000)
} else {
this.$toolAll.tools.showToast(res.msg);
}
}) })
} }
}, },
@ -123,12 +130,12 @@
this.flagCode = false; this.flagCode = false;
let count = 60; let count = 60;
this.codeText = `${count}S重新获取` this.codeText = `${count}S重新获取`
let countDown = setInterval(()=>{ this.countDown = setInterval(()=>{
count--; count--;
count < 10 ? this.codeText = `0${count}S重新获取` : this.codeText = `${count}S重新获取`; count < 10 ? this.codeText = `0${count}S重新获取` : this.codeText = `${count}S重新获取`;
if(count==0) { if(count==0) {
this.codeText = `重新获取`; this.codeText = `重新获取`;
clearInterval(countDown); clearInterval(this.countDown);
this.flagCode = true; this.flagCode = true;
} }
},1000) },1000)
@ -141,6 +148,11 @@
getMessage(phone){ getMessage(phone){
this.$requst.post('/universal/api.login/send_sms',{phone}).then(res=>{ this.$requst.post('/universal/api.login/send_sms',{phone}).then(res=>{
this.$toolAll.tools.showToast(res.msg); this.$toolAll.tools.showToast(res.msg);
if(res.code==0) {
clearInterval(this.countDown);
this.codeText = `获取验证码`
this.flagCode = true;
}
}) })
}, },
// //

View File

@ -45,7 +45,7 @@
</view> </view>
</view> </view>
<!-- 退出登录 --> <!-- 退出登录 -->
<view class="my-exit-btn">退出登</view> <view class="my-exit-btn" @tap="logOutEv">退</view>
</view> </view>
</view> </view>
<!-- 底部tab --> <!-- 底部tab -->
@ -103,6 +103,21 @@
this.$toolAll.tools.disableShareEv(); this.$toolAll.tools.disableShareEv();
}, },
methods: { methods: {
// 退
logOutEv(){
this.$requst.post('/universal/api.login/signout').then(res=>{
if(res.code==1) {
this.$toolAll.tools.showToast('退出成功');
//
uni.clearStorageSync();
setTimeout(()=>{
uni.reLaunch({
url:'/pages/login/login'
})
},1000)
}
})
},
checkInfo(){ checkInfo(){
this.$requst.post('/api/user/info').then(res=>{ this.$requst.post('/api/user/info').then(res=>{
// console.log('',res); // console.log('',res);