You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
house/fount/views/update-password.vue

158 lines
4.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<!-- 页面根容器 -->
<div>
<!-- 表单组件 -->
<el-form
class="detail-form-content"
ref="ruleForm"
:rules="rules"
:model="ruleForm"
label-width="80px"
>
<!-- 原密码输入项 -->
<el-form-item label="原密码" prop="password">
<el-input v-model="ruleForm.password"></el-input>
</el-form-item>
<!-- 新密码输入项 -->
<el-form-item label="新密码" prop="newpassword">
<el-input v-model="ruleForm.newpassword"></el-input>
</el-form-item>
<!-- 确认密码输入项 -->
<el-form-item label="确认密码" prop="repassword">
<el-input v-model="ruleForm.repassword"></el-input>
</el-form-item>
<!-- 提交按钮区域 -->
<el-form-item>
<el-button type="primary" @click="onUpdateHandler"> </el-button>
</el-form-item>
</el-form>
</div>
</template>
<script>
export default {
data() {
return {
// 控制模态框显示(本页面未使用,但保留)
dialogVisible: false,
// 表单数据模型
ruleForm: {},
// 用户信息对象
user: {},
// 表单验证规则
rules: {
password: [
{
required: true,
message: "密码不能为空",
trigger: "blur"
}
],
newpassword: [
{
required: true,
message: "新密码不能为空",
trigger: "blur"
}
],
repassword: [
{
required: true,
message: "确认密码不能为空",
trigger: "blur"
}
]
}
};
},
mounted() {
// 页面挂载完成后获取当前用户信息
this.$http({
url: `${this.$storage.get("sessionTable")}/session`,
method: "get"
}).then(({ data }) => {
if (data && data.code === 0) {
// 成功获取用户信息
this.user = data.data;
} else {
// 获取失败提示错误信息
this.$message.error(data.msg);
}
});
},
methods: {
// 登出方法
onLogout() {
// 清除 Token
this.$storage.remove("Token");
// 跳转到登录页
this.$router.replace({ name: "login" });
},
// 修改密码方法
onUpdateHandler() {
// 表单验证
this.$refs["ruleForm"].validate(valid => {
if (valid) {
var password = "";
// 判断用户字段是 mima 还是 password兼容不同表结构
if (this.user.mima) {
password = this.user.mima;
} else if (this.user.password) {
password = this.user.password;
}
// 校验原密码是否正确
if (this.ruleForm.password != password) {
this.$message.error("原密码错误");
return;
}
// 校验两次新密码是否一致
if (this.ruleForm.newpassword != this.ruleForm.repassword) {
this.$message.error("两次密码输入不一致");
return;
}
// 更新用户密码字段
this.user.password = this.ruleForm.newpassword;
this.user.mima = this.ruleForm.newpassword;
// 发送修改请求
this.$http({
url: `${this.$storage.get("sessionTable")}/update`,
method: "post",
data: this.user
}).then(({ data }) => {
if (data && data.code === 0) {
// 修改成功提示
this.$message({
message: "修改密码成功,下次登录系统生效",
type: "success",
duration: 1500,
onClose: () => {
// 可选:关闭时操作
}
});
} else {
// 修改失败提示错误信息
this.$message.error(data.msg);
}
});
}
});
}
}
};
</script>
<style lang="scss" scoped>
/* 本页面样式为空,可在此添加自定义样式 */
</style>