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.bak

159 lines
4.3 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>