提交 385455f0 编写于 作者: M m0_74163447

修改密码改为短信验证

上级 60bc3998
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
<uni-easyinput type="number" :inputBorder="true" v-model="formData.captcha" <uni-easyinput type="number" :inputBorder="true" v-model="formData.captcha"
placeholder="请输入六位验证码"></uni-easyinput> placeholder="请输入六位验证码"></uni-easyinput>
</uni-forms-item> </uni-forms-item>
<button class="captchaButton" @click="sendCaptcha()">发送验证码</button> <!-- <button class="captchaButton" @click="sendCaptcha()">发送验证码</button> -->
<button size="mini" class="captchaButton" :disabled="btnDis" @tap="sendCaptcha">{{btnText}}</button>
</view> </view>
<uni-forms-item name="newPassword" required label="新密码"> <uni-forms-item name="newPassword" required label="新密码">
<uni-easyinput type="password" :inputBorder="true" v-model="formData.newPassword" <uni-easyinput type="password" :inputBorder="true" v-model="formData.newPassword"
...@@ -53,6 +54,8 @@ ...@@ -53,6 +54,8 @@
components: {}, components: {},
data() { data() {
return { return {
btnDis: false,// 发送验证码按钮不禁用
btnText: "发送验证码",// 提示
loading: false, loading: false,
graphicVerifyCode: "", graphicVerifyCode: "",
formData: { formData: {
...@@ -134,6 +137,30 @@ ...@@ -134,6 +137,30 @@
await this.$refs['popupDialog'].open() await this.$refs['popupDialog'].open()
await this.fcaptcha.refresh() await this.fcaptcha.refresh()
}, },
countDown() {
// 初始化定时器
let t = null;
// 倒计时1分钟
let timer = 300;
// 按钮禁用
this.btnDis = true;
// 计时器清零
clearInterval(t);
// 按钮显示时间
this.btnText = `${timer}s`;
t = setInterval(() => {
// 当倒计时完时,显示重新发送,按钮开启
if (timer == 0) {
clearInterval(t);
this.btnText = "重新发送";
this.btnDis = false;
return;
}
// 实现倒计时效果
timer--;
this.btnText = `${timer}s`;
}, 1000)
},
confirm(validateForm) { confirm(validateForm) {
this.$refs[validateForm].validate(valid => { this.$refs[validateForm].validate(valid => {
if (!valid) { if (!valid) {
...@@ -223,6 +250,7 @@ ...@@ -223,6 +250,7 @@
this.code = res.result.code this.code = res.result.code
console.log(this.userId) console.log(this.userId)
}) })
this.countDown();
} }
} }
}, },
......
...@@ -6,25 +6,46 @@ ...@@ -6,25 +6,46 @@
<span class="empty"></span> <span class="empty"></span>
</view> </view>
<view class="content"> <view class="content">
<view class="password"> <view class="text-area">
<span>&ensp;&ensp;码:</span> <uni-forms :modelValue="formData" label-position="left" :labelWidth='90' :rules="confirmRules"
<input placeholder="请输入原密码" @input="bindPassword" type="text" :password="showPassword" ref="form" validate-trigger="bind" err-show-type="undertext">
name="input"></input> <uni-forms-item name="phone" required label="手机号">
<uni-easyinput type="text" :inputBorder="true" v-model="formData.phone"
placeholder="请输入注册使用的手机号"></uni-easyinput>
</uni-forms-item>
<view style="display: flex;flex-flow: row nowrap;">
<uni-forms-item name="captcha" required label="验证码">
<uni-easyinput type="number" :inputBorder="true" v-model="formData.captcha"
placeholder="请输入六位验证码"></uni-easyinput>
</uni-forms-item>
<button size="mini" class="captchaButton" :disabled="btnDis" @tap="sendCaptcha">{{btnText}}</button>
<!-- <button class="captchaButton" @click="sendCaptcha()">发送验证码</button> -->
</view>
<uni-forms-item name="newPassword" required label="新密码">
<uni-easyinput type="password" :inputBorder="true" v-model="formData.newPassword"
placeholder="请输入密码"></uni-easyinput>
</uni-forms-item>
<uni-forms-item name="confirmPassword" required label="确认密码">
<uni-easyinput type="password" :inputBorder="true" v-model="formData.confirmPassword"
placeholder="请确认新密码"></uni-easyinput>
</uni-forms-item>
<uni-forms-item>
<button class="confirmButton" @click="confirm('form')">确认</button>
</uni-forms-item>
</uni-forms>
</view> </view>
<view class="password">
<span>&ensp;&ensp;码:</span>
<input placeholder="请输入新密码" type="text" @input="bindNewPassword" :password="showPassword"
name="input"></input>
</view>
<view class="password">
<span>确认密码:</span>
<input placeholder="请确认密码" type="text" @input="bindConfirmPassword" :password="showPassword"
name="input"></input>
</view>
</view>
<view class="confirm">
<button class="confirm-btn" @click="confirmModification()">确认修改</button>
</view> </view>
<uni-popup ref="popupDialog" type="center">
<view class="mcaptcha">
<view style="padding: 30px 20px;text-align: center;">
<canvas canvas-id="canvas" @click="updateImageCode" class="canvas"></canvas>
<input class="ginput" v-model="graphicVerifyCode" placeholder="请输入验证码" />
<button style="margin-top: 10px;" :loading="loading" @tap="submitFcha" class="btn-big">验证</button>
<view class="text" @click="updateImageCode">获取验证码</view>
</view>
</view>
</uni-popup>
<uni-popup ref="alertDialog" type="dialog"> <uni-popup ref="alertDialog" type="dialog">
<uni-popup-dialog cancelText="取消" confirmText="确定" title="提示" content="确定修改你的密码吗?" <uni-popup-dialog cancelText="取消" confirmText="确定" title="提示" content="确定修改你的密码吗?"
@confirm="dialogConfirm"></uni-popup-dialog> @confirm="dialogConfirm"></uni-popup-dialog>
...@@ -33,115 +54,252 @@ ...@@ -33,115 +54,252 @@
</template> </template>
<script> <script>
let code = 200;
import {
Fcaptcha
} from "@/common/fcaptcha.js"
export default { export default {
name: 'login',
components: {},
data() { data() {
return { return {
showPassword: true, btnDis: false,// 发送验证码按钮不禁用
password: '', btnText: "发送验证码",// 提示
newPassword: '', loading: false,
confirmPassword: '', graphicVerifyCode: "",
formData: {
phone: '',
password: '',
captcha: '',
newPassword: ''
},
confirmRules: {
phone: {
rules: [{
required: true,
errorMessage: '请输入手机号'
}, {
validateFunction: function(rule, value, data, callback) {
if (value === '') {
callback(new Error('手机号不能为空'))
} else {
const reg = /^(13[0-9]|14[0-9]|15[0-9]|166|17[0-9]|18[0-9]|19[8|9])\d{8}$/
if (reg.test(value)) {
this.yzmshow = true
callback()
} else {
callback('请输入正确的手机号')
}
}
}
}]
},
captcha: {
rules: [{
required: true,
errorMessage: '请输入六位验证码'
}, {
validateFunction: function(rule, value, data, callback) {
if (value.length != 6) {
callback('验证码为六位!')
} else {
callback();
}
}
}]
},
newPassword: {
rules: [{
required: true,
errorMessage: '请输入密码'
}, {
validateFunction: function(rule, value, data, callback) {
if (value.length > 20 || value.length < 8) {
callback('密码长度在8-20位!')
} else {
callback();
}
}
}]
},
confirmPassword: {
rules: [{
required: true,
errorMessage: '请确认密码'
}, {
validateFunction: function(rule, value, data, callback) {
if (value.length > 20 || value.length < 8) {
callback('密码长度在8-20位!')
} else if (value != data.newPassword) {
callback('密码不一致')
} else {
callback();
}
}
}]
}
}
} }
}, },
methods: { methods: {
bindPassword(e) { async sendCaptcha() {
this.password = e.detail.value; await this.$refs['popupDialog'].open()
await this.fcaptcha.refresh()
}, },
bindNewPassword(e) { countDown() {
this.newPassword = e.detail.value; // 初始化定时器
let t = null;
// 倒计时1分钟
let timer = 300;
// 按钮禁用
this.btnDis = true;
// 计时器清零
clearInterval(t);
// 按钮显示时间
this.btnText = `${timer}s`;
t = setInterval(() => {
// 当倒计时完时,显示重新发送,按钮开启
if (timer == 0) {
clearInterval(t);
this.btnText = "重新发送";
this.btnDis = false;
return;
}
// 实现倒计时效果
timer--;
this.btnText = `${timer}s`;
}, 1000)
}, },
bindConfirmPassword(e) { confirm(validateForm) {
this.confirmPassword = e.detail.value; this.$refs.alertDialog.open();
}, },
dialogConfirm() { dialogConfirm() {
let that = this; this.$refs[validateForm].validate(valid => {
let password = that.password; if (!valid) {
let newPassword = that.newPassword;
let confirmPassword = that.confirmPassword; this.calluniCloud()
let updata = {}; }
if (!that.isPasswordAvailable(newPassword)) { })
},
async calluniCloud() {
await uniCloud.callFunction({
name: 'fe-retrievePassword',
data: {
phone: this.formData.phone,
password: this.formData.newPassword,
code: this.formData.captcha
}
})
.then(res => {
this.code = res.result.code
console.log(res)
})
await this.showTorM()
},
showTorM() {
if (this.code == 200) {
console.log(this.code, 'this.code1')
uni.showToast({ uni.showToast({
title: '密码长度在8-20位!', title: '修改成功',
icon: 'none',
duration: 2000 duration: 2000
}); });
return; } else if (this.code == 400) {
} else if (!that.isConfirmPasswordAvailable(newPassword, confirmPassword)) {
uni.showToast({ uni.showToast({
title: '两次密码不一致', title: '验证码错误或超时',
icon: 'none', icon: "error",
duration: 2000 duration: 2000
}); });
return; } else {
} else if (that.password == newPassword) {
uni.showToast({ uni.showToast({
title: '与原密码一致', title: '错误',
icon: 'none', icon: "error",
duration: 2000 duration: 2000
}); });
} else {
updata.password = password;
updata.newPassword = newPassword;
this.Upload(updata);
} }
this.$refs.alertDialog.close(); },
goBack() {
uni.navigateBack({
delta: 1, //返回层数,2则上上页
})
}, },
dialogClose() { dialogClose() {
this.$refsalertDialog.close(); this.$refsalertDialog.close();
}, },
confirmModification() {
this.$refs.alertDialog.open(); // 刷新验证码
updateImageCode() {
this.fcaptcha.refresh()
}, },
isPasswordAvailable(newPassword) { // 提交前校验图形验证码
if (newPassword.length > 20 || newPassword.length < 8) { submitFcha() {
return false; if (!this.graphicVerifyCode) {
} else { return uni.showToast({
return true; title: '请输入图形验证码',
icon: 'error'
})
} }
}, let validate = this.fcaptcha.validate(this.graphicVerifyCode)
isConfirmPasswordAvailable(newPassword, confirmPassword) { if (!validate) {
if (newPassword == confirmPassword) { this.updateImageCode();
return true; this.graphicVerifyCode = ''
uni.showToast({
title: '图形验证码错误',
icon: 'error'
})
this.fcaptcha.refresh()
} else { } else {
return false; uni.showToast({
} title: '图形验证码通过'
},
goBack() {
uni.navigateBack({
delta: 1, //返回层数,2则上上页
})
},
Upload(updata) {
uniCloud.callFunction({
name: 'fe-my-resetpassword',
data: {
userId: getApp().globalData.userId,
password: updata.password,
newPassword: updata.newPassword
},
}) })
.then(res => { this.$refs['popupDialog'].close();
uni.showToast({ uniCloud.callFunction({
title: res.result.message, name: 'fe-auth-code',
icon: 'none', data: {
duration: 2000 phone: this.formData.phone
}); }
console.log(res); })
}); .then(res => {
}, this.code = res.result.code
onload() { console.log(this.userId)
plus.navigator.setStatusBarBackground('#EDEEF0'); })
this.countDown();
}
} }
} },
onReady() {
this.fcaptcha = new Fcaptcha({
el: 'canvas',
width: 80,
height: 35,
createCodeImg: ""
});
},
} }
</script> </script>
<style> <style>
.bg {
background-color: #edeef0;
}
.main { .main {
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.content {
/* background-color: #edeef0; */
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
position: absolute;
width: 100%;
height: 100%;
}
.top { .top {
width: 100%; width: 100%;
...@@ -149,7 +307,7 @@ ...@@ -149,7 +307,7 @@
background-color: #EDEEF0; background-color: #EDEEF0;
text-align: center; text-align: center;
} }
.back { .back {
width: 40px; width: 40px;
height: 30px; height: 30px;
...@@ -158,7 +316,7 @@ ...@@ -158,7 +316,7 @@
float: left; float: left;
margin-left: 10px; margin-left: 10px;
} }
.empty { .empty {
width: 40px; width: 40px;
height: 30px; height: 30px;
...@@ -167,7 +325,7 @@ ...@@ -167,7 +325,7 @@
float: right; float: right;
margin-right: 10px; margin-right: 10px;
} }
.title { .title {
font-size: 20px; font-size: 20px;
margin-top: 15px; margin-top: 15px;
...@@ -176,46 +334,65 @@ ...@@ -176,46 +334,65 @@
display: inline-block; display: inline-block;
} }
.content { .returnBack {
height: 55rpx;
width: 80%; width: 55rpx;
margin-top: 50%; margin-top: 60rpx;
margin-left: auto; margin-left: 20rpx;
margin-right: auto; margin-right: auto;
} }
.password { .confirmButton {
background-color: #f1992d;
color: #fff;
border: 0;
border-radius: 20px;
}
margin-top: 50rpx; .confirmButton::after {
height: 20%; border: 0;
display: flex; }
align-items: center;
/* border-bottom: 1px solid #ccc; */ .captchaButton {
background-color: #f1992d;
color: #fff;
width: 90px;
height: 35px;
font-size: 0.7em;
border: 0;
border-radius: 18px;
} }
.password span { .captchaButton::after {
font-size: 35rpx; border: 0;
} }
.password input { .mcaptcha {
border-bottom: 1px solid #ccc; display: flex;
flex-direction: column;
background-color: #fff;
width: 270px;
height: 200px;
border-radius: 10px;
} }
.confirm { .canvas {
height: 20%; margin: auto;
margin-top: 20%; width: 200rpx;
height: 100rpx;
} }
.confirm-btn { .btn-big {
background-color: #F1992D; background-color: #f1992d;
color: #FFFFFF; color: #fff;
width: 70%; border: 0;
height: 85rpx; border-radius: 20px;
line-height: 85rpx; }
margin-top: 100rpx;
margin-left: auto; .text{
margin-right: auto; margin-top: 12px;
border-radius: 20rpx; font-size: 10px;
color: #f1992d;
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册