289 lines
7.1 KiB
Vue
289 lines
7.1 KiB
Vue
<template>
|
||
<view class="page commonPage">
|
||
<z-nav-bar></z-nav-bar>
|
||
<!-- 公共组件-每个页面必须引入 -->
|
||
<public-module></public-module>
|
||
<view class="title">忘记密码</view>
|
||
<view class="input_box">
|
||
<text class="input_tit">手机号</text>
|
||
<u--input type="text" class="form_input_box" v-model="resetForm.phone" placeholder="请输入手机号" />
|
||
</view>
|
||
<view class="input_box ">
|
||
<text class="input_tit">验证码</text>
|
||
<u--input type="number" class="form_input_box" v-model="resetForm.code" placeholder="请输入验证码"
|
||
placeholder-class="grey" @input="onInput" maxlength="6" />
|
||
<button class="sendCode" @click="getCode" size="mini">{{ codeText }}</button>
|
||
|
||
|
||
</view>
|
||
<view class="input_box">
|
||
<text class="input_tit">密码</text>
|
||
|
||
|
||
<u--input class="form_input_box" type="password" maxlength="8" v-model="resetForm.password" placeholder="请输入密码"
|
||
@input="inputMethod(resetForm.password)" />
|
||
</view>
|
||
<view class="" style="font-size: 28rpx; color: #999;">
|
||
<p v-if="note != ''">{{ note }}</p>
|
||
<p v-html="str2" style="margin-top: 10rpx;"></p>
|
||
</view>
|
||
<view class="input_box">
|
||
<text class="input_tit">确认密码</text>
|
||
<u--input type="password" class="form_input_box" maxlength="8" v-model="resetForm.confirmPassword" placeholder="请确认密码" />
|
||
</view>
|
||
<view class="btn_box"><button @click="onSubmit">提 交</button></view>
|
||
<music-play :playData="playData"></music-play>
|
||
</view>
|
||
</template>
|
||
<script>
|
||
import musicPlay from '@/components/music.vue'
|
||
import md5 from '@/plugins/md5';
|
||
// 密码验证的正则
|
||
//1、密码为八位及以上并且字母数字特殊字符三项都包括
|
||
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
|
||
//2、密码为八位及以上并且字母、数字、特殊字符三项中有两项,强度是中等
|
||
var mediumRegex = new RegExp(
|
||
"^(?=.{8,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[a-z])(?=.*\\W))|((?=.*[0-9])(?=.*\\W))|((?=.*[A-Z])(?=.*\\W))).*$",
|
||
"g");
|
||
|
||
|
||
|
||
|
||
var enoughRegex = new RegExp("(?=.{8,}).*", "g");
|
||
var clear;
|
||
export default {
|
||
data() {
|
||
return {
|
||
resetForm: {},
|
||
playData: {},
|
||
|
||
codeText: '获取验证码',
|
||
//验证码已发
|
||
readonly: false,
|
||
passwordOk: false,
|
||
note: '',
|
||
str2: '',
|
||
urlList: {
|
||
senCode: 'book/user/sms/sendcode',//发送验证码
|
||
setPassword: 'book/user/setPassword',//重置密码
|
||
},
|
||
};
|
||
},
|
||
//第一次加载
|
||
onLoad(e) { },
|
||
//页面显示
|
||
onShow() { },
|
||
components: {
|
||
musicPlay
|
||
|
||
},
|
||
//方法
|
||
methods: {
|
||
// 密码验证
|
||
inputMethod(value) {
|
||
this.passwordOk = false
|
||
// console.log('输入的值为:', value)
|
||
if (strongRegex.test(value)) {
|
||
//console.log('强密码-----',value)
|
||
this.str2 = "<span style='color:#18bc37'>密码强度很不错哦!</span>"
|
||
// this.note = '请至少使用大小写字母、数字、符号两种类型组合的密码,长度至少为8位。'
|
||
this.note = ''
|
||
this.passwordOk = true
|
||
} else if (mediumRegex.test(value)) {
|
||
// console.log('中等密码-----',value)
|
||
this.note = '请至少使用大小写字母、数字、符号两种类型组合的密码,长度为8位。'
|
||
this.str2 = "<span style='color:#2979ff'>密码强度中等!</span>"
|
||
this.passwordOk = true
|
||
} else if (enoughRegex.test(value)) {
|
||
// console.log('弱密码-----',value)
|
||
// this.str2 = "<span style='color:#f3a73f'>密码强度太弱!</span>"
|
||
this.note = '请至少使用大小写字母、数字、符号两种类型组合的密码,长度为8位。'
|
||
}
|
||
else {
|
||
this.passwordOk = false
|
||
this.note = '请至少使用大小写字母、数字、符号两种类型组合的密码,长度为8位。'
|
||
this.str2 = ""
|
||
//console.log('密码-----',value)
|
||
}
|
||
},
|
||
//获取验证码
|
||
async getCode() {
|
||
if (this.readonly) {
|
||
this.$commonJS.showTost('验证码已发送')
|
||
|
||
return;
|
||
}
|
||
if (!this.resetForm.phone) {
|
||
this.$commonJS.showTost('请输入手机号')
|
||
|
||
return;
|
||
}
|
||
if (!this.$base.phoneRegular.test(this.resetForm.phone)) {
|
||
this.$commonJS.showTost('请输入正确的手机号')
|
||
|
||
return;
|
||
}
|
||
await this.$http
|
||
.post(this.urlList.senCode, {
|
||
phone: this.resetForm.phone,
|
||
type: 3000
|
||
})
|
||
.then(res => {
|
||
this.getCodeState();
|
||
});
|
||
},
|
||
//验证码按钮文字状态
|
||
getCodeState() {
|
||
const _this = this;
|
||
this.readonly = true;
|
||
this.codeText = '60S后重新获取';
|
||
var s = 60;
|
||
clear = setInterval(() => {
|
||
s--;
|
||
_this.codeText = s + 'S后重新获取';
|
||
if (s <= 0) {
|
||
clearInterval(clear);
|
||
_this.codeText = '获取验证码';
|
||
_this.readonly = false;
|
||
}
|
||
}, 1000);
|
||
},
|
||
onSubmit() {
|
||
|
||
|
||
if (!this.passwordOk) {
|
||
console.log('不满足密码格式', this.note)
|
||
this.$commonJS.showTost(this.note)
|
||
return
|
||
}
|
||
if (!this.resetForm.phone) {
|
||
this.$commonJS.showTost('请输入手机号')
|
||
|
||
return;
|
||
}
|
||
if (!this.$base.phoneRegular.test(this.resetForm.phone)) {
|
||
this.$commonJS.showTost('请输入正确的手机号')
|
||
|
||
return;
|
||
}
|
||
if (!this.resetForm.code) {
|
||
this.$commonJS.showTost('请输入验证码')
|
||
|
||
return;
|
||
}
|
||
if (!this.resetForm.password) {
|
||
this.$commonJS.showTost('请输入密码')
|
||
|
||
return;
|
||
}
|
||
if (!this.resetForm.confirmPassword) {
|
||
this.$commonJS.showTost('请输入确认密码')
|
||
|
||
return;
|
||
}
|
||
if (this.resetForm.confirmPassword != this.resetForm.password) {
|
||
this.$commonJS.showTost('两次密码不一致')
|
||
|
||
return;
|
||
}
|
||
if (!this.$base.passwordRegular.test(this.resetForm.password)) {
|
||
this.$commonJS.showTost('请输入不少于6位且包含数字和字母的密码')
|
||
|
||
return;
|
||
}
|
||
this.$http
|
||
.post(this.urlList.setPassword, this.resetForm)
|
||
.then(res => {
|
||
uni.showModal({
|
||
title: "提示",
|
||
content: "密码修改成功!",
|
||
showCancel: false,
|
||
success: (res) => {
|
||
uni.navigateBack();
|
||
}
|
||
});
|
||
});
|
||
}
|
||
},
|
||
//页面隐藏
|
||
onHide() { },
|
||
//页面卸载
|
||
onUnload() { },
|
||
//页面下来刷新
|
||
onPullDownRefresh() { },
|
||
//页面上拉触底
|
||
onReachBottom() { },
|
||
//用户点击分享
|
||
onShareAppMessage(e) {
|
||
return this.wxShare();
|
||
}
|
||
};
|
||
</script>
|
||
<style lang="scss" scoped>
|
||
@import '@/style/mixin.scss';
|
||
|
||
.page {
|
||
|
||
|
||
.title {
|
||
padding: 60rpx 0 40rpx 0;
|
||
font-size: 60rpx;
|
||
color: #333333;
|
||
}
|
||
|
||
.input_box {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
height: 100rpx;
|
||
padding-top: 30rpx;
|
||
border-bottom: 1rpx solid #eeeeee;
|
||
align-items: center;
|
||
|
||
text {
|
||
font-size: 30rpx;
|
||
width: 180rpx;
|
||
}
|
||
|
||
input {
|
||
flex: 1;
|
||
height: 70rpx;
|
||
line-height: 70rpx;
|
||
font-size: 30rpx;
|
||
}
|
||
|
||
button {
|
||
height: 78rpx;
|
||
line-height: 78rpx;
|
||
font-size: 30rpx;
|
||
color: $themeColor;
|
||
|
||
&:active {
|
||
background-color: transparent;
|
||
}
|
||
}
|
||
}
|
||
|
||
.btn_box {
|
||
margin-top: 70rpx;
|
||
|
||
button {
|
||
font-size: 32rpx;
|
||
@include theme('btn_bg') color: #fff;
|
||
height: 80rpx;
|
||
line-height: 80rpx;
|
||
border-radius: 50rpx;
|
||
}
|
||
}
|
||
|
||
.protocol {
|
||
font-size: 24rpx;
|
||
color: #999999;
|
||
text-align: center;
|
||
margin-top: 20rpx;
|
||
|
||
text {
|
||
color: $themeColor;
|
||
}
|
||
}
|
||
}
|
||
</style> |