提交 c39e90b3 编写于 作者: 芊里

抽离短信发送功能

上级 8238c6fc
...@@ -28,6 +28,13 @@ ...@@ -28,6 +28,13 @@
count: { count: {
type: [String, Number], type: [String, Number],
default: 60 default: 60
},
/**
* 手机号码
*/
phone: {
type: [String, Number],
default: ''
} }
}, },
data() { data() {
...@@ -49,10 +56,43 @@ ...@@ -49,10 +56,43 @@
initClick() { initClick() {
this.start = debounce(() => { this.start = debounce(() => {
if (this.reverseNumber != 0) return; if (this.reverseNumber != 0) return;
this.$emit('getCode', () => { this.sendMsg();
this.reverseNumber = Number(this.count); })
},
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.getCode();
}); this.$emit('getCode');
},
fail: (err) => {
console.log(err);
uni.showToast({
title: '短信验证码发送失败',
icon: 'none'
});
},
complete: () => {
uni.hideLoading()
}
}) })
}, },
getCode() { getCode() {
...@@ -73,17 +113,19 @@ ...@@ -73,17 +113,19 @@
<style scoped> <style scoped>
.short-code-btn { .short-code-btn {
width: 200rpx; width: 200rpx;
height: 85rpx; height: 85rpx;
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
display: flex; display: flex;
/* #endif */ /* #endif */
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.inner-text{
font-size: 28rpx; .inner-text {
} font-size: 28rpx;
.inner-text-active{ }
color: #007aff;
.inner-text-active {
color: #007aff;
} }
</style> </style>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<uni-easyinput type="number" class="phone-input-box" :inputBorder="false" <uni-easyinput type="number" class="phone-input-box" :inputBorder="false"
v-model="formData.code" maxlength="6" placeholder="请输入验证码"> v-model="formData.code" maxlength="6" placeholder="请输入验证码">
<template slot="right"> <template slot="right">
<login-short-code ref="shortCode" @getCode="getCode"></login-short-code> <login-short-code :phone="phoneNumber" ref="shortCode"></login-short-code>
</template> </template>
</uni-easyinput> </uni-easyinput>
</uni-forms-item> </uni-forms-item>
...@@ -70,48 +70,7 @@ ...@@ -70,48 +70,7 @@
onReady() { onReady() {
this.$refs.shortCode.start(); this.$refs.shortCode.start();
}, },
methods: { 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()
}
})
},
/** /**
* 完成并提交 * 完成并提交
*/ */
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<uni-easyinput type="number" class="phone-input-box" :inputBorder="false" <uni-easyinput type="number" class="phone-input-box" :inputBorder="false"
v-model="formData.code" maxlength="6" placeholder="请输入验证码"> v-model="formData.code" maxlength="6" placeholder="请输入验证码">
<template slot="right"> <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> </template>
</uni-easyinput> </uni-easyinput>
<uni-easyinput type="password" class="phone-input-box" :inputBorder="false" <uni-easyinput type="password" class="phone-input-box" :inputBorder="false"
...@@ -103,47 +103,7 @@ import mixin from '../../common/loginPage.mixin.js'; ...@@ -103,47 +103,7 @@ import mixin from '../../common/loginPage.mixin.js';
this.$refs.shortCode.start(); this.$refs.shortCode.start();
} }
}, },
methods: { 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()
}
})
},
checkCode(callback){ checkCode(callback){
uniCloud.callFunction({//联网验证登陆 uniCloud.callFunction({//联网验证登陆
"name": "user-center", "name": "user-center",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册