提交 c39e90b3 编写于 作者: 芊里

抽离短信发送功能

上级 8238c6fc
......@@ -28,6 +28,13 @@
count: {
type: [String, Number],
default: 60
},
/**
* 手机号码
*/
phone: {
type: [String, Number],
default: ''
}
},
data() {
......@@ -49,10 +56,43 @@
initClick() {
this.start = debounce(() => {
if (this.reverseNumber != 0) return;
this.$emit('getCode', () => {
this.reverseNumber = Number(this.count);
this.sendMsg();
})
},
sendMsg() {
let reg_phone = /^1\d{10}$/;
if(!reg_phone.test(this.phone))return uni.showToast({
title: '手机号格式错误',
icon: 'none'
});
uniCloud.callFunction({
"name": "user-center",
"data": {
"action": "sendSmsCode",
"params": {
"mobile": this.phone,
"type": "login"
}
},
success: (e) => {
uni.showToast({
title: "短信验证码发送成功",
icon: 'none'
});
this.reverseNumber = Number(this.count);
this.getCode();
});
this.$emit('getCode');
},
fail: (err) => {
console.log(err);
uni.showToast({
title: '短信验证码发送失败',
icon: 'none'
});
},
complete: () => {
uni.hideLoading()
}
})
},
getCode() {
......@@ -73,17 +113,19 @@
<style scoped>
.short-code-btn {
width: 200rpx;
height: 85rpx;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
justify-content: center;
align-items: center;
}
.inner-text{
font-size: 28rpx;
}
.inner-text-active{
color: #007aff;
height: 85rpx;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
justify-content: center;
align-items: center;
}
.inner-text {
font-size: 28rpx;
}
.inner-text-active {
color: #007aff;
}
</style>
......@@ -11,7 +11,7 @@
<uni-easyinput type="number" class="phone-input-box" :inputBorder="false"
v-model="formData.code" maxlength="6" placeholder="请输入验证码">
<template slot="right">
<login-short-code ref="shortCode" @getCode="getCode"></login-short-code>
<login-short-code :phone="phoneNumber" ref="shortCode"></login-short-code>
</template>
</uni-easyinput>
</uni-forms-item>
......@@ -70,48 +70,7 @@
onReady() {
this.$refs.shortCode.start();
},
methods: {
/**
* 获取验证码倒计时
* 倒计时期间不会触发该方法
*/
getCode(done) {
if (this.phoneNumber == '') return uni.showToast({
title: '请填写手机号',
icon: 'none'
});
uniCloud.callFunction({
"name": "user-center",
"data": {
"action": "sendSmsCode",
"params": {
"mobile": this.phoneNumber,
"type": "login"
}
},
success: (e) => {
console.log(e);
uni.showToast({
title: "短信验证码发送成功",
icon: 'none'
});
// uni.showModal({
// content: JSON.stringify(e.result),
// showCancel: false,
// confirmText: '知道了'
// });
// 发送成功后开启倒计时
done();
},
fail: (err) => {
console.log(err);
},
complete: () => {
uni.hideLoading()
}
})
},
methods: {
/**
* 完成并提交
*/
......
......@@ -13,7 +13,7 @@
<uni-easyinput type="number" class="phone-input-box" :inputBorder="false"
v-model="formData.code" maxlength="6" placeholder="请输入验证码">
<template slot="right">
<login-short-code ref="shortCode" @getCode="getCode"></login-short-code>
<login-short-code ref="shortCode" :phone="formData.phone"></login-short-code>
</template>
</uni-easyinput>
<uni-easyinput type="password" class="phone-input-box" :inputBorder="false"
......@@ -103,47 +103,7 @@ import mixin from '../../common/loginPage.mixin.js';
this.$refs.shortCode.start();
}
},
methods: {
/**
* 获取验证码倒计时
* 倒计时期间不会触发该方法
*/
getCode(done) {
if (this.formData.phone == '' || this.formData.phone.length!=11) return uni.showToast({
title: '手机号格式不正确',
icon: 'none'
});
uniCloud.callFunction({
"name": "user-center",
"data": {
"action": "sendSmsCode",
"params": {
"mobile": this.formData.phone,
"type": "login"
}
},
success: (e) => {
console.log(e);
uni.showToast({
title: "短信验证码发送成功",
icon: 'none'
});
// uni.showModal({
// content: JSON.stringify(e.result),
// showCancel: false,
// confirmText: '知道了'
// });
// 发送成功后开启倒计时
done();
},
fail: (err) => {
console.log(err);
},
complete: () => {
uni.hideLoading()
}
})
},
methods: {
checkCode(callback){
uniCloud.callFunction({//联网验证登陆
"name": "user-center",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册