用户模块

This commit is contained in:
仲么了
2023-07-10 20:20:00 +08:00
parent 69063cb241
commit 2104bc0c4c
17 changed files with 4764 additions and 381 deletions

View File

@@ -5,15 +5,32 @@
<template v-if="step == 1">
<uni-forms ref="form" :rules="rules" :modelValue="formData">
<uni-forms-item name="phone">
<uni-easyinput disabled type="text" v-model="formData.phoneShow" placeholder="请输入手机号" />
<uni-easyinput
disabled
type="text"
maxlength="11"
v-model="formData.phoneShow"
placeholder="请输入手机号"
/>
</uni-forms-item>
<uni-forms-item name="code">
<view class="login-box-input">
<uni-easyinput type="number" v-model="formData.code" placeholder="请输入验证码" />
<view class="ml40"
style="margin-left:40rpx;font-size: 28rpx; color: #666; width: 200rpx; text-align: center"
v-if="waitTime > 0">{{ waitTime + 's后重新获取' }}</view>
<button class="login-box-input-btn" v-else @click="getCode(5)" size="mini">获取验证码</button>
<view
class="ml40"
style="
margin-left: 40rpx;
font-size: 28rpx;
color: #666;
width: 200rpx;
text-align: center;
"
v-if="waitTime > 0"
>{{ waitTime + 's后重新获取' }}</view
>
<button class="login-box-input-btn" v-else @click="getCode(5)" size="mini">
获取验证码
</button>
</view>
</uni-forms-item>
</uni-forms>
@@ -22,15 +39,31 @@
<template v-else>
<uni-forms ref="form" :rules="rules" :modelValue="formData">
<uni-forms-item name="phone">
<uni-easyinput type="number" v-model="formData.phone2" placeholder="请输入新手机号" />
<uni-easyinput
maxlength="11"
type="number"
v-model="formData.phone2"
placeholder="请输入新手机号"
/>
</uni-forms-item>
<uni-forms-item name="code">
<view class="login-box-input">
<uni-easyinput type="number" v-model="formData.code2" placeholder="请输入验证码" />
<view class="ml40"
style="margin-left:40rpx;font-size: 28rpx; color: #666; width: 200rpx; text-align: center"
v-if="waitTime > 0">{{ waitTime + 's后重新获取' }}</view>
<button class="login-box-input-btn" v-else @click="getCode(4)" size="mini">获取验证码</button>
<view
class="ml40"
style="
margin-left: 40rpx;
font-size: 28rpx;
color: #666;
width: 200rpx;
text-align: center;
"
v-if="waitTime > 0"
>{{ waitTime + 's后重新获取' }}</view
>
<button class="login-box-input-btn" v-else @click="getCode(4)" size="mini">
获取验证码
</button>
</view>
</uni-forms-item>
</uni-forms>
@@ -43,8 +76,8 @@
<script>
import { apiGetYms, apiComfirmCode, apiRebindPhone } from '@/common/api/user'
export default {
name: "jiaban",
data () {
name: 'jiaban',
data() {
return {
step: 1,
loading: false,
@@ -62,102 +95,108 @@ export default {
rules: [
{
required: true,
errorMessage: "请填写手机号"
}
]
errorMessage: '请填写手机号',
},
],
},
code: {
rules: [
{
required: true,
errorMessage: "请填写验证码"
}
]
errorMessage: '请填写验证码',
},
],
},
phone2: {
rules: [
{
required: true,
errorMessage: "请填写新手机号"
}
]
errorMessage: '请填写新手机号',
},
],
},
code2: {
rules: [
{
required: true,
errorMessage: "请填写验证码"
}
]
}
}
};
errorMessage: '请填写验证码',
},
],
},
},
}
},
onLoad () {
onLoad() {
this.init()
},
methods: {
getCode (type) {
getCode(type) {
if (!this.formData.phone) {
return this.$util.toast('请输入手机号!')
}
uni.showLoading({
title: '请稍等'
title: '请稍等',
})
apiGetYms({
phone: type == 5 ? this.formData.phone : this.formData.phone2,
type,
}).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);
})
.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)
})
},
init () {
this.formData.phone = uni.getStorageSync('userInfo').phone
// 150****0083
this.formData.phoneShow = this.formData.phone.substr(0, 3) + '****' + this.formData.phone.substr(7)
init() {
// 手机号中间四位隐藏
this.formData.phone = uni.getStorageSync('userInfo').user_name
this.formData.phoneShow = this.formData.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
},
firstSubmit () {
firstSubmit() {
apiComfirmCode({
phone: this.formData.phone,
code: this.formData.code,
}).then(res => {
this.step = 2
clearInterval(this.inter)
this.waitTime = 0
}).catch(err => {
console.log(err);
})
.then((res) => {
this.step = 2
clearInterval(this.inter)
this.waitTime = 0
})
.catch((err) => {
console.log(err)
})
},
secondSubmit () {
secondSubmit() {
apiRebindPhone({
phone: this.formData.phone2,
code: this.formData.code2,
}).then(res => {
this.$util.toast('绑定成功')
uni.clearStorageSync();
setTimeout(() => {
uni.redirectTo({
url: '/pages/user/login'
})
}, 1500);
}).catch(err => {
console.log(err);
})
}
}
};
.then((res) => {
this.$util.toast('绑定成功')
uni.clearStorageSync()
setTimeout(() => {
uni.redirectTo({
url: '/pages/user/login',
})
}, 1500)
})
.catch((err) => {
console.log(err)
})
},
},
}
</script>
<style lang="scss">
.index {

View File

@@ -4,105 +4,191 @@
<view class="index">
<uni-forms ref="form" :modelValue="formData" :rules="rules">
<uni-forms-item name="phone">
<uni-easyinput disabled type="text" v-model="formData.phone" placeholder="请输入手机号" />
</uni-forms-item>
<uni-easyinput
maxlength="11"
disabled
type="text"
v-model="formData.showPhone"
placeholder="请输入手机号"
/>
</uni-forms-item>
<uni-forms-item name="code">
<view class="login-box-input mt40">
<view class="login-box-input">
<uni-easyinput type="number" v-model="formData.code" placeholder="请输入手机验证码" />
<view class="ml40"
style="margin-left:40rpx;font-size: 28rpx; color: #666; width: 200rpx; text-align: center"
v-if="waitTime > 0">{{ waitTime + 's后重新获取' }}</view>
<view
class="ml40"
style="
margin-left: 40rpx;
font-size: 28rpx;
color: #666;
width: 200rpx;
text-align: center;
"
v-if="waitTime > 0"
>{{ waitTime + 's后重新获取' }}</view
>
<button class="login-box-input-btn" v-else @click="getCode" size="mini">获取验证码</button>
</view>
</uni-forms-item>
<uni-forms-item name="password">
<uni-easyinput type="text" v-model="formData.password" placeholder="请输入新的登录密码" />
<uni-easyinput type="password" v-model="formData.password" placeholder="请输入新的登录密码" />
</uni-forms-item>
<uni-forms-item name="password2">
<uni-easyinput type="text" v-model="formData.password2" placeholder="请再次确认密码" />
<uni-easyinput type="password" v-model="formData.password2" placeholder="请再次确认密码" />
</uni-forms-item>
</uni-forms>
<button type="default" class="submit-btn" @click="submit">提交</button>
<view class="login-box-tips">
<view style="color:#999">说明密码长度为6-18</view>
<view style="color: #999">说明密码需要包含特殊字符字母数字长度为8-16</view>
</view>
</view>
</view>
</Cn-page>
</template>
<script>
import { apiGetYms, apiModifyPsd, gongkey } from '@/common/api/user'
import { sm2, encrypt } from '@/common/js/sm2.js'
import { sm3Digest } from '@/common/js/sm3.js'
export default {
name: "ChangePWd",
data () {
name: 'ChangePWd',
data() {
return {
loading: false,
waitTime: 0,
// 表单数据
formData: {
phone: '150****0083',
showPhone: '',
phone: '',
code: '',
password: '',
password2: ''
password2: '',
},
rules: {
phone: {
rules: [
{
required: true,
errorMessage: "请填写手机号"
}
]
errorMessage: '请填写手机号',
},
],
},
code: {
rules: [
{
required: true,
errorMessage: "请填写验证码"
}
]
errorMessage: '请填写验证码',
},
],
},
password: {
rules: [
{
required: true,
errorMessage: "请填写新密码"
}
]
errorMessage: '请填写新密码',
},
],
},
password2: {
rules: [
{
required: true,
errorMessage: "请填写确认密码"
}
]
}
}
};
errorMessage: '请填写确认密码',
},
],
},
},
}
},
onLoad () {
onLoad() {
// 手机号中间四位隐藏
this.formData.phone = uni.getStorageSync('userInfo').user_name
this.formData.showPhone = this.formData.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
},
methods: {
getCode () {
this.waitTime = 60
this.inter = setInterval(() => {
if (this.waitTime == 0) {
clearInterval(this.inter)
} else {
this.waitTime--
}
}, 1000)
getCode() {
uni.showLoading({
title: '请稍等',
})
apiGetYms({
phone: this.formData.phone,
type: 2,
})
.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)
})
},
submit () {
submit() {
this.$refs.form.validate((valid) => {
console.log(valid);
console.log(valid)
if (!valid) {
uni.navigateBack({ delta: 1 })
if (this.formData.password != this.formData.password2) {
uni.showToast({
title: '两次密码不一致',
icon: 'none',
})
} else {
// 密码需要包含特殊字符字母数字长度为8-16
if (
!/^(?=.*[a-zA-Z])(?=.*\d)(?=.*[#@!~%^&*])[a-zA-Z\d#@!~%^&*]{8,16}$/.test(
this.formData.password,
)
) {
return this.$util.toast('密码需要包含特殊字符字母数字长度为8-16')
}
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)
// apiPwdLogin({
// username: loginName,
// password: jiamipassword,
// imageCode: '',
// grant_type: 'captcha',
// verifyCode: 0,
// }).then((res) => {
// this.$util.loginSuccess(res.data)
// })
apiModifyPsd({
phone: this.formData.phone,
code: this.formData.code,
password: jiamipassword,
})
.then((res) => {
console.log(res)
uni.showToast({
title: '修改成功',
icon: 'none',
})
setTimeout(() => {
uni.navigateBack({
delta: 1,
})
}, 1000)
})
.catch((err) => {
console.log(err)
})
})
}
}
})
},
}
};
},
}
</script>
<style lang="scss">
.index {

View File

@@ -4,30 +4,44 @@
<view class="index">
<uni-forms ref="form" :modelValue="formData" :rules="rules">
<uni-forms-item name="phone">
<uni-easyinput type="number" v-model="formData.phone" placeholder="请输入手机号" />
<uni-easyinput
type="number"
maxlength="11"
v-model="formData.phone"
placeholder="请输入手机号"
/>
</uni-forms-item>
<uni-forms-item name="code">
<view class="login-box-input">
<uni-easyinput type="number" v-model="formData.code" placeholder="请输入验证码" />
<view class="ml40"
style="margin-left:40rpx;font-size: 28rpx; color: #666; width: 200rpx; text-align: center"
v-if="waitTime > 0">{{ waitTime + 's后重新获取' }}</view>
<view
class="ml40"
style="
margin-left: 40rpx;
font-size: 28rpx;
color: #666;
width: 200rpx;
text-align: center;
"
v-if="waitTime > 0"
>{{ waitTime + 's后重新获取' }}</view
>
<button class="login-box-input-btn" v-else @click="getCode" size="mini">获取验证码</button>
</view>
</uni-forms-item>
<uni-forms-item name="password">
<uni-easyinput type="text" v-model="formData.password" placeholder="请输入新的登录密码" />
<uni-easyinput type="password" v-model="formData.password" placeholder="请输入新的登录密码" />
</uni-forms-item>
<uni-forms-item name="password2">
<uni-easyinput type="text" v-model="formData.password2" placeholder="请再次确认密码" />
<uni-easyinput type="password" v-model="formData.password2" placeholder="请再次确认密码" />
</uni-forms-item>
</uni-forms>
<button type="default" class="submit-btn" @click="submit">提交</button>
<view class="login-box-tips">
<view style="color:#999">说明密码长度为6-18</view>
<view style="color: #999">说明密码长度为6-18</view>
</view>
<view class="login-box-tips">
<view style="color:#999">点击提交即表示同意</view>
<view style="color: #999">点击提交即表示同意</view>
<navigator url="/pages/mine/agreement" hover-class="none">用户协议</navigator>
<navigator url="/pages/mine/policy" hover-class="none">个人信息保护政策</navigator>
</view>
@@ -36,11 +50,12 @@
</Cn-page>
</template>
<script>
import { apiGetYms, apiReSetPsd } from '@/common/api/user'
import { apiGetYms, apiReSetPsd, gongkey } from '@/common/api/user'
import { sm2, encrypt } from '@/common/js/sm2.js'
import { sm3Digest } from '@/common/js/sm3.js'
export default {
name: "jiaban",
data () {
name: 'jiaban',
data() {
return {
loading: false,
waitTime: 0,
@@ -49,102 +64,109 @@ export default {
phone: '',
code: '',
password: '',
password2: ''
password2: '',
},
rules: {
phone: {
rules: [
{
required: true,
errorMessage: "请填写手机号"
}
]
errorMessage: '请填写手机号',
},
],
},
code: {
rules: [
{
required: true,
errorMessage: "请填写验证码"
}
]
errorMessage: '请填写验证码',
},
],
},
password: {
rules: [
{
required: true,
errorMessage: "请填写新密码"
}
]
errorMessage: '请填写新密码',
},
],
},
password2: {
rules: [
{
required: true,
errorMessage: "请填写确认密码"
}
]
}
}
};
},
onLoad () {
errorMessage: '请填写确认密码',
},
],
},
},
}
},
onLoad() {},
methods: {
getCode () {
getCode() {
if (!this.formData.phone) {
return this.$util.toast('请输入手机号!')
}
uni.showLoading({
title: '请稍等'
title: '请稍等',
})
apiGetYms({
phone: this.formData.phone,
type: 3,
}).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);
})
.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)
})
},
submit () {
submit() {
this.$refs.form.validate((valid) => {
if (this.formData.password.length < 6 || this.formData.password.length > 18) {
return this.$util.toast('密码长度为6-18位')
} else if (this.formData.password != this.formData.password2) {
if (this.formData.password != this.formData.password2) {
return this.$util.toast('两次密码不一致')
}
uni.showLoading({
title: '请稍等'
})
apiReSetPsd({
phone: this.formData.phone,
code: this.formData.code,
password: this.formData.password,
}).then(res => {
uni.hideLoading()
console.log(res);
this.$util.toast('修改成功!')
setTimeout(() => {
uni.navigateBack()
}, 1000)
}).catch(err => {
uni.hideLoading()
console.log(err);
// 密码需要包含特殊字符字母数字长度为8-16
if (!/^(?=.*[a-zA-Z])(?=.*\d)(?=.*[#@!~%^&*])[a-zA-Z\d#@!~%^&*]{8,16}$/.test(this.formData.password)) {
return this.$util.toast('密码需要包含特殊字符字母数字长度为8-16')
}
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)
})
})
})
},
}
};
},
}
</script>
<style lang="scss">
.index {

View File

@@ -9,14 +9,19 @@
<image class="login-box-logo" mode="widthFix" src="/static/logo.png"></image>
<template v-if="loginType == 'yzm'">
<view class="login-box-input mt100">
<input class="login-box-input-main" maxlength="11" v-model="yzmForm.phone" placeholder="请输入手机号" />
<input
class="login-box-input-main"
maxlength="11"
v-model="yzmForm.phone"
placeholder="请输入手机号"
/>
</view>
<!-- <view class="login-box-input mt40">
<input class="login-box-input-main" v-model="yzmForm.imgCode" placeholder="图形验证码" />
<view class="login-box-input-img"></view>
</view> -->
<view class="login-box-input mt40">
<input class="login-box-input-main" v-model="yzmForm.code" placeholder="手机验证码" />
<input class="login-box-input-main" v-model="yzmForm.code" placeholder="手机验证码" />
<view
class="ml40"
style="font-size: 28rpx; color: #666; width: 200rpx; text-align: center"
@@ -28,10 +33,15 @@
</template>
<template v-else>
<view class="login-box-input mt100">
<input class="login-box-input-main" v-model="pwdForm.phone" placeholder="请输入账号" />
<input class="login-box-input-main" maxlength="11" v-model="pwdForm.phone" placeholder="请输入账号" />
</view>
<view class="login-box-input mt40">
<input type="password" class="login-box-input-main" v-model="pwdForm.pwd" placeholder="请输入密码" />
<input
type="password"
class="login-box-input-main"
v-model="pwdForm.pwd"
placeholder="请输入密码"
/>
</view>
<!-- <view class="login-box-input mt40">
<view class="login-box-input-icon"></view>
@@ -59,15 +69,18 @@
</Cn-page>
</template>
<script>
import { apiGetYms, apiLogin, apiYsmLogin } from '@/common/api/user'
import { apiGetYms, apiPwdLogin, apiYsmLogin, gongkey } from '@/common/api/user'
import { sm2, encrypt } from '@/common/js/sm2.js'
import { sm3Digest } from '@/common/js/sm3.js'
export default {
data() {
return {
loading: false,
loginType: 'pwd',
pwdForm: {
phone: '',
pwd: '',
phone: '13888888888',
pwd: 'gwo6H8Kb',
imgCode: '',
},
yzmForm: {
@@ -122,15 +135,19 @@ export default {
if (!this.pwdForm.phone && !this.pwdForm.pwd) {
return this.$util.toast('请填写登录信息!')
}
apiLogin({
phone: this.pwdForm.phone,
key: this.pwdForm.pwd,
type: 1,
}).then((res) => {
console.log(res)
uni.setStorageSync('userInfo', res.data)
uni.reLaunch({
url: '/pages/index/index',
let loginName = encrypt(this.pwdForm.phone)
gongkey({ loginName }).then((response) => {
let publicKey = response.data
let sm3Pwd = sm3Digest(this.pwdForm.pwd)
let jiamipassword = sm2(sm3Pwd + '|' + this.pwdForm.pwd, publicKey, 0)
apiPwdLogin({
username: loginName,
password: jiamipassword,
imageCode: '',
grant_type: 'captcha',
verifyCode: 0,
}).then((res) => {
this.$util.loginSuccess(res.data)
})
})
},
@@ -142,21 +159,13 @@ export default {
phone: this.yzmForm.phone,
smsCode: this.yzmForm.code,
}).then((res) => {
console.log(res)
uni.setStorageSync('access_token', res.data.token_type + ' ' + res.data.access_token)
uni.setStorageSync('refresh_token', res.data.refresh_token)
let strings = res.data.access_token.split('.') //截取token获取载体
var userInfo = JSON.parse(decodeURIComponent(escape(window.atob(strings[1].replace(/-/g, '+').replace(/_/g, '/')))))
userInfo.authorities = userInfo.authorities[0]
uni.setStorageSync('userInfo', userInfo)
uni.reLaunch({
url: '/pages/index/index',
})
this.$util.loginSuccess(res.data)
})
},
},
onLoad(o) {
uni.removeStorageSync('engineering')
// 移除所有的缓存
uni.clearStorageSync()
},
}
</script>

View File

@@ -140,7 +140,7 @@ export default {
// this.step = 2
// 直接登录
autoLogin(this.formData.phone).then((res) => {
this.loginSuccess(res.data)
this.$util.loginSuccess(res.data)
})
})
})