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

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,22 +72,20 @@ 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 {
// 接口返回错误信息
checkError(res);
}
} else { } else {
// 接口返回错误信息 // 接口返回错误信息
checkError(res); checkError(res);

View File

@ -1,41 +1,46 @@
<template> <template>
<view class="pad-zy30"> <view class="pad-zy30">
<view class="fon52 bold mar-sx50">忘记密码</view> <status-nav navBarTitle="找回密码" returnColor="#c2c2c2"></status-nav>
<view class="fon28"> <container-subgroup>
<view class="forget-title mar-x10">手机号码</view> <view slot="content" style="margin: 0 -30rpx;">
<view class="forget-input-box posir"> <view class="fon52 bold mar-sx50">忘记密码 </view>
<input @blur="inputBlurEv(0)" @focus="inputFocusEv(0)" @input="inputFocusEv(0)" class="fon24" type="number" maxlength="11" v-model="forget_phone" placeholder="请输入您的手机号码" placeholder-style="color:#c8c8c8;" /> <view class="fon28">
<!-- 清除按钮 --> <view class="forget-title mar-x10">手机号码</view>
<view class="clear-box" v-show="ifPhone" @tap="clearInput(0)"><view class="clear-close"><span></span><span></span></view></view> <view class="forget-input-box posir">
<input @blur="inputBlurEv(0)" @focus="inputFocusEv(0)" @input="inputFocusEv(0)" class="fon24" type="number" maxlength="11" v-model="forget_phone" placeholder="请输入您的手机号码" placeholder-style="color:#c8c8c8;" />
<!-- 清除按钮 -->
<view class="clear-box" v-show="ifPhone" @tap="clearInput(0)"><view class="clear-close"><span></span><span></span></view></view>
</view>
<view class="forget-title mar-x10">手机验证码</view>
<view class="forget-input-box posir">
<input @blur="inputBlurEv(1)" @focus="inputFocusEv(1)" @input="inputFocusEv(1)" class="fon24" type="number" maxlength="6" v-model="forget_code" placeholder="请输入手机验证码" placeholder-style="color:#c8c8c8;" />
<view class="forget-obtain-code" @tap="getCode">{{codeText}}</view>
<!-- 清除按钮 -->
<view class="clear-box" v-show="ifCode" @tap="clearInput(1)" style="right: 260rpx;"><view class="clear-close"><span></span><span></span></view></view>
</view>
<view class="forget-title mar-x10">新密码</view>
<view class="forget-input-box posir">
<input @blur="inputBlurEv(2)" @focus="inputFocusEv(2)" @input="inputFocusEv(2)" class="fon24" type="text" password v-model="forget_password" placeholder="请输入新密码" placeholder-style="color:#c8c8c8;" />
<!-- 清除按钮 -->
<view class="clear-box" v-show="ifPassword" @tap="clearInput(2)"><view class="clear-close"><span></span><span></span></view></view>
</view>
<view class="forget-title mar-x10">确认密码</view>
<view class="forget-input-box posir">
<input @blur="inputBlurEv(3)" @focus="inputFocusEv(3)" @input="inputFocusEv(3)" class="fon24" type="text" password v-model="forget_qpassword" placeholder="请再次确认密码" placeholder-style="color:#c8c8c8;" />
<!-- 清除按钮 -->
<view class="clear-box" v-show="ifqpassword" @tap="clearInput(3)"><view class="clear-close"><span></span><span></span></view></view>
</view>
<view class="forget-title mar-x10">单位名称</view>
<view class="forget-input-box posir">
<input @blur="inputBlurEv(4)" @focus="inputFocusEv(4)" @input="inputFocusEv(4)" class="fon24" type="text" v-model="forget_unitname" placeholder="请输入单位名称" placeholder-style="color:#c8c8c8;" />
<!-- 清除按钮 -->
<view class="clear-box" v-show="ifUnitname" @tap="clearInput(4)"><view class="clear-close"><span></span><span></span></view></view>
</view>
</view>
<!-- 立即修改 -->
<view class="forget-btn" @tap="submitEv"></view>
</view> </view>
<view class="forget-title mar-x10">手机验证码</view> </container-subgroup>
<view class="forget-input-box posir">
<input @blur="inputBlurEv(1)" @focus="inputFocusEv(1)" @input="inputFocusEv(1)" class="fon24" type="number" maxlength="6" v-model="forget_code" placeholder="请输入手机验证码" placeholder-style="color:#c8c8c8;" />
<view class="forget-obtain-code" @tap="getCode">{{codeText}}</view>
<!-- 清除按钮 -->
<view class="clear-box" v-show="ifCode" @tap="clearInput(1)" style="right: 260rpx;"><view class="clear-close"><span></span><span></span></view></view>
</view>
<view class="forget-title mar-x10">新密码</view>
<view class="forget-input-box posir">
<input @blur="inputBlurEv(2)" @focus="inputFocusEv(2)" @input="inputFocusEv(2)" class="fon24" type="text" password v-model="forget_password" placeholder="请输入新密码" placeholder-style="color:#c8c8c8;" />
<!-- 清除按钮 -->
<view class="clear-box" v-show="ifPassword" @tap="clearInput(2)"><view class="clear-close"><span></span><span></span></view></view>
</view>
<view class="forget-title mar-x10">确认密码</view>
<view class="forget-input-box posir">
<input @blur="inputBlurEv(3)" @focus="inputFocusEv(3)" @input="inputFocusEv(3)" class="fon24" type="text" password v-model="forget_qpassword" placeholder="请再次确认密码" placeholder-style="color:#c8c8c8;" />
<!-- 清除按钮 -->
<view class="clear-box" v-show="ifqpassword" @tap="clearInput(3)"><view class="clear-close"><span></span><span></span></view></view>
</view>
<view class="forget-title mar-x10">单位名称</view>
<view class="forget-input-box posir">
<input @blur="inputBlurEv(4)" @focus="inputFocusEv(4)" @input="inputFocusEv(4)" class="fon24" type="text" v-model="forget_unitname" placeholder="请输入单位名称" placeholder-style="color:#c8c8c8;" />
<!-- 清除按钮 -->
<view class="clear-box" v-show="ifUnitname" @tap="clearInput(4)"><view class="clear-close"><span></span><span></span></view></view>
</view>
</view>
<!-- 立即修改 -->
<view class="forget-btn" @tap="submitEv"></view>
</view> </view>
</template> </template>
@ -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=>{
this.$toolAll.tools.showToast('找回成功'); if(res.code==1) {
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('登录成功');
uni.reLaunch({ // token
url:'/pages/tabbar/pagehome/pagehome' uni.setStorageSync('token',res.data.token);
}) uni.setStorageSync('type_id',res.data.type_id);
setTimeout(()=>{
uni.reLaunch({
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=>{
this.$toolAll.tools.showToast('注册成功'); if(res.code==1) {
// this.$toolAll.tools.showToast('注册成功');
this.goLogin(); setTimeout(()=>{
//
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);