密码校验,参数控制修改密码

This commit is contained in:
faiz 2025-03-24 18:19:52 +08:00
parent e8ae825ba2
commit 6014c75053
2 changed files with 53 additions and 20 deletions
admin/src
layout/components
store/modules

View File

@ -97,8 +97,14 @@
</el-upload>
</el-dialog>
<el-dialog title="修改密码" :visible.sync="dialogPWD">
<el-form :rules="rules" :model="form">
<el-dialog
title="修改密码"
:show-close="isPassword"
:close-on-press-escape="isPassword"
:close-on-click-modal="isPassword"
:visible.sync="dialogPWD"
>
<el-form ref="formName" :rules="rules" :model="form">
<el-form-item label="旧密码" prop="oldpwd">
<el-input v-model="form.oldpwd" autocomplete="off" />
</el-form-item>
@ -107,7 +113,9 @@
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogPWD = false"> </el-button>
<el-button v-if="isPassword" @click="dialogPWD = false"
> </el-button
>
<el-button type="primary" @click="pwd"> </el-button>
</div>
</el-dialog>
@ -201,6 +209,7 @@ import sidebar from "@/layout/components/Sidebar/index.vue";
import avatar from "element-ui/packages/avatar";
import { getQaCityList, getQaList } from "@/api/qa";
import clickoutside from "element-ui/src/utils/clickoutside";
import { Local } from "@/utils/storage";
export default {
directives: { clickoutside },
components: {
@ -228,6 +237,14 @@ export default {
},
// eslint-disable-next-line vue/order-in-Wangeditor
data() {
var validatePassword = (rule, password, callback) => {
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,16}$/;
if (!passwordRegex.test(password)) {
callback(new Error("新密码要求包含字母和数字并且长度在8到16位"));
} else {
callback();
}
};
return {
workstatus: false,
drawer: false,
@ -238,6 +255,7 @@ export default {
imageUrl: false,
QaShow: true,
os: [],
isPassword: true,
getQaCityList: [],
getQaLists: [],
times: [],
@ -260,13 +278,13 @@ export default {
},
],
pwd: [
{ required: true, message: "请输入密码", trigger: "blur" },
{
min: 6,
max: 20,
message: "长度在 6 到 20 个字符",
trigger: "blur",
},
{ required: true, validator: validatePassword, trigger: "blur" },
// {
// min: 6,
// max: 20,
// message: " 6 20 ",
// trigger: "blur",
// },
],
},
};
@ -277,6 +295,12 @@ export default {
this.getQaCityList = res.data;
});
},
mounted() {
if (Local.get("userInfo").change_passwd) {
this.dialogPWD = true;
this.isPassword = false;
}
},
methods: {
color,
toggleSideBar() {
@ -308,15 +332,23 @@ export default {
this.imageUrl = URL.createObjectURL(file.raw);
},
pwd() {
this.$axios
.post("/admin/admin/pwd", this.form)
.then((res) => {
this.dialogPWD = false;
this.form = {};
})
.catch((err) => {
console.log(err);
});
this.$refs["formName"].validate((valid) => {
if (valid) {
this.$axios
.post("/admin/admin/pwd", this.form)
.then((res) => {
this.dialogPWD = false;
this.isPassword = true;
this.form = {};
Local.remove("userInfo");
})
.catch((err) => {
console.log(err);
});
} else {
return false;
}
});
},
saveWork() {
this.$axios

View File

@ -1,7 +1,7 @@
import { login, logout, getInfo } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
import router, { resetRouter } from '@/router'
import { Local } from '@/utils/storage'
const state = {
token: getToken(),
name: '',
@ -45,6 +45,7 @@ const actions = {
const { data } = response
commit('SET_TOKEN', data.token)
setToken(data.token)
Local.set('userInfo', data)
resolve()
}).catch(error => {
reject(error)