Browse Source

修改密码验证

hella_online_20241205
lijuncheng 2 months ago
parent
commit
8914a51c54
  1. 8
      src/api/httpRequest3.js
  2. 61
      src/pages/login/index.vue
  3. 2
      src/pages/setter/index.vue
  4. 185
      src/pages/setter/loginPwdUpdate.vue

8
src/api/httpRequest3.js

@ -48,10 +48,10 @@ function service(options = {}) {
}) })
} }
// if (res.data.code == 1002000008) { // if (res.data.code == 1002000008) {
// uni.setStorageSync('username',options.data.username) // uni.setStorageSync('username',options.data.username)
// uni.reLaunch({ // uni.reLaunch({
// url: '/pages/setter/loginPwdUpdate' // url: '/pages/setter/loginPwdUpdate'
// }) // })
// } // }
if (res.data.msg) { if (res.data.msg) {
if (res.data.msg.includes('get lock')) { if (res.data.msg.includes('get lock')) {

61
src/pages/login/index.vue

@ -71,7 +71,7 @@
v-model="code" v-model="code"
style="background-color: lightgray;padding-top: 40rpx;padding-bottom: 40rpx;margin-right: 20rpx;" /> style="background-color: lightgray;padding-top: 40rpx;padding-bottom: 40rpx;margin-right: 20rpx;" />
</view> --> </view> -->
<view class="uni-input-wrapper" > <view class="uni-input-wrapper">
<input class="" style="height: 80rpx; background-color: #F7F9FF;margin-right: 20rpx;" <input class="" style="height: 80rpx; background-color: #F7F9FF;margin-right: 20rpx;"
placeholder="请输入验证码" type="number" v-model="code" /> placeholder="请输入验证码" type="number" v-model="code" />
</view> </view>
@ -119,8 +119,8 @@
imageSrc: "", imageSrc: "",
code: "", code: "",
uuid: "", uuid: "",
version: "", version: "",
needCode:false needCode: false
} }
}, },
// computed: mapState(['forcedLogin', 'hasLogin']), // computed: mapState(['forcedLogin', 'hasLogin']),
@ -128,11 +128,11 @@
this.tenantValue = this.tenantArray[0].value this.tenantValue = this.tenantArray[0].value
// uni.clearStorageSync() // uni.clearStorageSync()
// uni.clearStorage(); // // uni.clearStorage(); //
storage.clearStorage() storage.clearStorage()
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
this.username = "admin" this.username = "admin"
this.password = "win123456"; this.password = "CD_win09";
} }
uni.setNavigationBarColor({ uni.setNavigationBarColor({
frontColor: '#ffffff', frontColor: '#ffffff',
@ -157,21 +157,21 @@
} }
}, },
onLoad() { onLoad() {
if(this.needCode){ if (this.needCode) {
getCaptchaImage().then(res => { getCaptchaImage().then(res => {
if (res) { if (res) {
var code = res.data.img; var code = res.data.img;
let base64 = 'data:image/jpeg;base64,' + code let base64 = 'data:image/jpeg;base64,' + code
// console.log("", base64) // console.log("", base64)
this.imageSrc = base64.replace(/[\r\n]/g, "") this.imageSrc = base64.replace(/[\r\n]/g, "")
this.uuid = res.data.uuid this.uuid = res.data.uuid
} }
}).catch(error => { }).catch(error => {
this.showErrorMessage(error); this.showErrorMessage(error);
}) })
} }
this.getAppVersion() this.getAppVersion()
}, },
methods: { methods: {
@ -189,15 +189,13 @@
icon: 'none', icon: 'none',
mask: true mask: true
}) })
} } else if (this.needCode && this.code === '') {
else if (this.needCode&&this.code === '') {
uni.showToast({ uni.showToast({
title: '验证码不能为空', title: '验证码不能为空',
icon: 'none', icon: 'none',
mask: true mask: true
}) })
} } else {
else {
// console.log("", this.username, "", this.password, this.tapstyle, this.smloginmsg) // console.log("", this.username, "", this.password, this.tapstyle, this.smloginmsg)
let logininfo = { let logininfo = {
username: "", username: "",
@ -232,7 +230,7 @@
title: "正在登录", title: "正在登录",
mask: true mask: true
}) })
try{ try {
var result = await this.$store.dispatch('Login', logininfo); var result = await this.$store.dispatch('Login', logininfo);
// await this.$store.dispatch('GetTenantIdInfo', this.tenantName) // await this.$store.dispatch('GetTenantIdInfo', this.tenantName)
console.log(result) console.log(result)
@ -242,11 +240,11 @@
url: '/pages/index/index' url: '/pages/index/index'
}); });
uni.setStorageSync('username', this.username); uni.setStorageSync('username', this.username);
}catch(e){ } catch (e) {
uni.hideLoading() uni.hideLoading()
this.showErrorMessage(e) this.showErrorMessage(e)
} }
}, },
@ -262,7 +260,12 @@
showErrorMessage(message) { showErrorMessage(message) {
this.$refs.comMessage.showErrorMessage(message, res => { this.$refs.comMessage.showErrorMessage(message, res => {
if (res) { if (res) {
if (message.includes("密码策略")) {
uni.setStorageSync('username', this.username);
uni.reLaunch({
url: '/pages/setter/loginPwdUpdate'
})
}
} }
}); });
}, },
@ -275,8 +278,8 @@
this.uuid = res.data.uuid this.uuid = res.data.uuid
} }
}).catch(error => { }).catch(error => {
this.showErrorMessage(error); this.showErrorMessage(error);
}) })
}, },
getAppVersion() { getAppVersion() {
const systemInfo = uni.getSystemInfoSync(); const systemInfo = uni.getSystemInfoSync();

2
src/pages/setter/index.vue

@ -143,7 +143,7 @@
} }
function modifiedPassWord() { function modifiedPassWord() {
uni.navigateTo({ uni.navigateTo({
url:"./passwordpage" url:"./loginPwdUpdate"
}) })
} }

185
src/pages/setter/loginPwdUpdate.vue

@ -1,71 +1,72 @@
<template> <template>
<view class="content passwordpage"> <view class="content passwordpage">
<uni-forms ref="form" :modelValue="formData" :rules="rules"> <uni-forms ref="form" :modelValue="formData" :rules="rules">
<uni-forms-item label="原密码" name="oldPassword" style="margin: 20rpx 0;"> <uni-forms-item label="原密码" name="oldPassword" style="margin: 20rpx 0;">
<uni-easyinput type="password" v-model="formData.oldPassword" placeholder="请输入原来的密码" /> <uni-easyinput type="password" v-model="formData.oldPassword" placeholder="请输入原来的密码" />
</uni-forms-item> </uni-forms-item>
<uni-forms-item label="新密码" name="password" style="border-bottom: 1px solid #eee;"> <uni-forms-item label="新密码" name="password" style="border-bottom: 1px solid #eee;">
<uni-easyinput type="password" v-model="formData.password" placeholder="请输入新密码" /> <uni-easyinput type="password" v-model="formData.password" placeholder="请输入新密码" />
</uni-forms-item> </uni-forms-item>
<uni-forms-item label="确认新密码" name="againPassword"> <uni-forms-item label="确认新密码" name="againPassword">
<uni-easyinput type="password" v-model="formData.againPassword" placeholder="请再次输入密码" /> <uni-easyinput type="password" v-model="formData.againPassword" placeholder="请再次输入密码" />
</uni-forms-item> </uni-forms-item>
</uni-forms> </uni-forms>
<view class="new_btn_bot"> <view class="new_btn_bot">
<button class="new_save_btn" @click="submit">确认修改</button> <button class="new_save_btn" @click="submit">确认修改</button>
</view> </view>
<comMessage ref="comMessage"></comMessage> <comMessage ref="comMessage"></comMessage>
</view> </view>
</template> </template>
<script> <script>
import { loginUpdateUserPwd } from '@/api/request2.js'; import {
loginUpdateUserPwd
} from '@/api/request2.js';
import { import {
navigateBack, navigateBack,
} from '@/common/basic.js'; } from '@/common/basic.js';
export default { export default {
data() { data() {
return { return {
// //
formData: { formData: {
oldPassword: '', oldPassword: '',
password: '', password: '',
againPassword: '' againPassword: ''
}, },
rules: { rules: {
oldPassword: { oldPassword: {
rules: [{ rules: [{
required: true, required: true,
errorMessage: '请输入密码', errorMessage: '请输入原密码',
} }]
] },
}, // name
// name password: {
password: { rules: [{
rules: [{ required: true,
required: true, errorMessage: '请输入新密码',
errorMessage: '请输入密码', }
}, // {
{ // minLength: 6,
minLength: 6, // maxLength: 20,
maxLength: 20, // errorMessage: ' {minLength} {maxLength} ',
errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符', // }
} ]
] },
}, // email
// email againPassword: {
againPassword: { rules: [{
rules: [{ required: true,
required: true, errorMessage: '请输入新密码',
errorMessage: '请输入密码', },
}, // {
{ // minLength: 6,
minLength: 6, // maxLength: 20,
maxLength: 20, // errorMessage: ' {minLength} {maxLength} ',
errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符', // },
},
{ {
validateFunction:function(rule,value,data,callback){ validateFunction: function(rule, value, data, callback) {
console.log(value !== data.againPassword) console.log(value !== data.againPassword)
if (value !== data.againPassword) { if (value !== data.againPassword) {
callback('两次输入不同') callback('两次输入不同')
@ -73,54 +74,56 @@
return true return true
} }
} }
] ]
} }
} }
} }
}, },
methods: { methods: {
/** /**
* 复写 binddata 方法如果只是为了校验无复杂自定义操作可忽略此方法 * 复写 binddata 方法如果只是为了校验无复杂自定义操作可忽略此方法
* @param {String} name 字段名称 * @param {String} name 字段名称
* @param {String} value 表单域的值 * @param {String} value 表单域的值
*/ */
// binddata(name,value){ // binddata(name,value){
// input name // input name
// this.$refs.form.setValue(name, value) // this.$refs.form.setValue(name, value)
// }, // },
// //
submit() { submit() {
this.$refs.form.validate().then(res=>{ this.$refs.form.validate().then(res => {
loginUpdateUserPwd(uni.getStorageSync('username'),res.oldPassword,res.password,res.password).then((ress)=>{ loginUpdateUserPwd(uni.getStorageSync('username'), res.oldPassword, res.password, res.password)
console.log('返回结果:', ress); .then((ress) => {
if(ress.data){ console.log('返回结果:', ress);
this.showCommitSuccessMessage("修改成功") if (ress.data) {
setTimeout(function (){ uni.showToast({
uni.reLaunch({ title: "修改成功"
url: '../login/index' })
}) setTimeout(function() {
},2000) uni.reLaunch({
} url: '../login/index'
}).catch(err =>{ })
this.$refs.comMessage.showErrorMessage(err) }, 500)
}) }
}).catch(err =>{ }).catch(err => {
console.log('表单错误信息:', err); this.$refs.comMessage.showErrorMessage(err)
}) })
}, }).catch(err => {
console.log('表单错误信息:', err);
})
},
showCommitSuccessMessage(hint) { showCommitSuccessMessage(hint) {
this.$refs.comMessage.showSuccessMessage(hint, res => { this.$refs.comMessage.showSuccessMessage(hint, res => {
navigateBack(1)
}) })
}, },
} }
} }
</script> </script>
<style> <style>
.content{ .content {
/* padding: 20rpx; */ /* padding: 20rpx; */
/* background-color: #fff; */ /* background-color: #fff; */
} }
</style>
</style>
Loading…
Cancel
Save