Files
app-govern/pages/user/forget.vue

229 lines
8.0 KiB
Vue
Raw Permalink Normal View History

2023-01-11 16:33:13 +08:00
<template>
<Cn-page :loading="loading">
<view slot="body">
<view class="index">
2023-01-12 10:03:25 +08:00
<uni-forms ref="form" :modelValue="formData" :rules="rules">
<uni-forms-item name="phone">
2023-07-10 20:20:00 +08:00
<uni-easyinput
type="number"
maxlength="11"
v-model="formData.phone"
placeholder="请输入手机号"
/>
2023-01-11 16:33:13 +08:00
</uni-forms-item>
2023-01-12 10:03:25 +08:00
<uni-forms-item name="code">
2023-03-20 08:51:21 +08:00
<view class="login-box-input">
2024-09-02 09:50:59 +08:00
<uni-easyinput
type="text"
v-model="formData.code"
placeholder="请输入验证码"
maxlength="6"
/>
2023-07-10 20:20:00 +08:00
<view
class="ml40"
style="
margin-left: 40rpx;
font-size: 28rpx;
color: #666;
width: 200rpx;
text-align: center;
"
v-if="waitTime > 0"
>{{ waitTime + 's后重新获取' }}</view
>
2023-01-12 10:03:25 +08:00
<button class="login-box-input-btn" v-else @click="getCode" size="mini">获取验证码</button>
</view>
2023-01-11 16:33:13 +08:00
</uni-forms-item>
2023-01-12 10:03:25 +08:00
<uni-forms-item name="password">
2023-07-10 20:20:00 +08:00
<uni-easyinput type="password" v-model="formData.password" placeholder="请输入新的登录密码" />
2023-01-11 16:33:13 +08:00
</uni-forms-item>
2023-01-12 10:03:25 +08:00
<uni-forms-item name="password2">
2023-07-10 20:20:00 +08:00
<uni-easyinput type="password" v-model="formData.password2" placeholder="请再次确认密码" />
2023-01-11 16:33:13 +08:00
</uni-forms-item>
2023-01-12 10:03:25 +08:00
</uni-forms>
2023-01-11 16:33:13 +08:00
<button type="default" class="submit-btn" @click="submit">提交</button>
2023-01-12 10:03:25 +08:00
<view class="login-box-tips">
2023-07-10 20:20:00 +08:00
<view style="color: #999">说明密码长度为6-18</view>
2023-03-20 08:51:21 +08:00
</view>
2023-07-31 09:00:30 +08:00
<!-- <view class="login-box-tips">
2023-07-10 20:20:00 +08:00
<view style="color: #999">点击提交即表示同意</view>
2023-01-13 16:32:56 +08:00
<navigator url="/pages/mine/agreement" hover-class="none">用户协议</navigator>
2024-09-02 09:50:59 +08:00
<navigator url="/pages/mine/policy" hover-class="none">隐私政策</navigator>
2023-07-31 09:00:30 +08:00
</view> -->
2023-01-11 16:33:13 +08:00
</view>
</view>
</Cn-page>
</template>
<script>
2023-07-10 20:20:00 +08:00
import { apiGetYms, apiReSetPsd, gongkey } from '@/common/api/user'
import { sm2, encrypt } from '@/common/js/sm2.js'
import { sm3Digest } from '@/common/js/sm3.js'
2023-01-11 16:33:13 +08:00
export default {
2023-07-10 20:20:00 +08:00
name: 'jiaban',
data() {
2023-01-11 16:33:13 +08:00
return {
loading: false,
2023-01-12 10:03:25 +08:00
waitTime: 0,
2023-01-11 16:33:13 +08:00
// 表单数据
formData: {
2023-01-12 10:03:25 +08:00
phone: '',
code: '',
password: '',
2023-07-10 20:20:00 +08:00
password2: '',
2023-01-11 16:33:13 +08:00
},
rules: {
2023-01-12 10:03:25 +08:00
phone: {
2023-01-11 16:33:13 +08:00
rules: [
{
required: true,
2023-07-10 20:20:00 +08:00
errorMessage: '请填写手机号',
},
],
2023-01-11 16:33:13 +08:00
},
2023-01-12 10:03:25 +08:00
code: {
2023-01-11 16:33:13 +08:00
rules: [
{
required: true,
2023-07-10 20:20:00 +08:00
errorMessage: '请填写验证码',
},
],
2023-01-11 16:33:13 +08:00
},
2023-01-12 10:03:25 +08:00
password: {
2023-01-11 16:33:13 +08:00
rules: [
{
required: true,
2023-07-10 20:20:00 +08:00
errorMessage: '请填写新密码',
},
],
2023-01-11 16:33:13 +08:00
},
2023-01-12 10:03:25 +08:00
password2: {
2023-01-11 16:33:13 +08:00
rules: [
{
required: true,
2023-07-10 20:20:00 +08:00
errorMessage: '请填写确认密码',
},
],
},
},
}
2023-01-11 16:33:13 +08:00
},
2023-07-10 20:20:00 +08:00
onLoad() {},
2023-01-11 16:33:13 +08:00
methods: {
2023-07-10 20:20:00 +08:00
getCode() {
2023-03-20 08:51:21 +08:00
if (!this.formData.phone) {
return this.$util.toast('请输入手机号!')
}
uni.showLoading({
2023-07-10 20:20:00 +08:00
title: '请稍等',
2023-03-20 08:51:21 +08:00
})
apiGetYms({
phone: this.formData.phone,
2023-08-18 14:41:53 +08:00
type: 6,
2023-03-20 08:51:21 +08:00
})
2023-07-10 20:20:00 +08:00
.then((res) => {
uni.hideLoading()
console.log(res)
this.waitTime = 60
this.inter = setInterval(() => {
if (this.waitTime == 0) {
clearInterval(this.inter)
} else {
this.waitTime--
}
}, 1000)
})
.catch((err) => {
uni.hideLoading()
console.log(err)
})
2023-01-12 10:03:25 +08:00
},
2023-07-10 20:20:00 +08:00
submit() {
2023-01-12 10:03:25 +08:00
this.$refs.form.validate((valid) => {
2023-07-10 20:20:00 +08:00
if (this.formData.password != this.formData.password2) {
2023-03-20 08:51:21 +08:00
return this.$util.toast('两次密码不一致')
2023-01-12 10:03:25 +08:00
}
2023-08-23 16:22:08 +08:00
// 密码需要长度为8-16
if (this.formData.password.length < 8 || this.formData.password.length > 16) {
uni.showToast({
title: '密码需要长度为8-16',
icon: 'none',
})
return
2023-07-10 20:20:00 +08:00
}
let loginName = encrypt(this.formData.phone)
gongkey({ loginName }).then((response) => {
let publicKey = response.data
let sm3Pwd = sm3Digest(this.formData.password)
let jiamipassword = sm2(sm3Pwd + '|' + this.formData.password, publicKey, 0)
apiReSetPsd({
phone: this.formData.phone,
code: this.formData.code,
password: jiamipassword,
})
.then((res) => {
this.$util.toast('修改成功!')
setTimeout(() => {
uni.navigateBack()
}, 1000)
})
.catch((err) => {
uni.hideLoading()
console.log(err)
})
2023-03-20 08:51:21 +08:00
})
2023-01-12 10:03:25 +08:00
})
},
2023-07-10 20:20:00 +08:00
},
}
2023-01-11 16:33:13 +08:00
</script>
<style lang="scss">
.index {
2023-02-20 14:19:28 +08:00
padding: 20rpx;
2023-01-11 16:33:13 +08:00
.submit-btn {
2023-08-03 14:51:36 +08:00
background: $uni-theme-color;
2023-01-11 16:33:13 +08:00
color: #fff;
}
2023-01-12 10:03:25 +08:00
.login-box-tips {
margin-top: 60rpx;
display: flex;
justify-content: center;
font-size: 20rpx;
}
.login-box-input {
display: flex;
align-items: center;
border-bottom: 1rpx solid #f0f0f0;
.login-box-input-icon {
width: 40rpx;
margin-right: 40rpx;
}
.login-box-input-main {
font-size: 28rpx;
flex: 1;
height: 100rpx;
line-height: 100rpx;
}
.login-box-input-btn {
2024-09-02 09:50:59 +08:00
padding: 0 40rpx;
2023-01-12 10:03:25 +08:00
margin-left: 40rpx;
2023-08-03 14:51:36 +08:00
background: $uni-theme-color;
2023-01-12 10:03:25 +08:00
color: #fff;
}
.login-box-input-img {
margin-left: 40rpx;
background: skyblue;
height: 80rpx;
width: 200rpx;
}
}
2023-01-11 16:33:13 +08:00
}
</style>