懒羊羊
2024-01-31 e57a8990ae56f657a59c435a0613c5f7a8728003
提交 | 用户 | 时间
e57a89 1 <template>
2   <el-form ref="form" :model="user" :rules="rules" label-width="80px">
3     <el-form-item label="旧密码" prop="oldPassword">
4       <el-input v-model="user.oldPassword" placeholder="请输入旧密码" type="password" show-password/>
5     </el-form-item>
6     <el-form-item label="新密码" prop="newPassword">
7       <el-input v-model="user.newPassword" placeholder="请输入新密码" type="password" show-password/>
8     </el-form-item>
9     <el-form-item label="确认密码" prop="confirmPassword">
10       <el-input v-model="user.confirmPassword" placeholder="请确认新密码" type="password" show-password/>
11     </el-form-item>
12     <el-form-item>
13       <el-button type="primary" size="mini" @click="submit">保存</el-button>
14       <el-button type="danger" size="mini" @click="close">关闭</el-button>
15     </el-form-item>
16   </el-form>
17 </template>
18
19 <script>
20 import { updateUserPwd } from "@/api/system/user";
21
22 export default {
23   data() {
24     const equalToPassword = (rule, value, callback) => {
25       if (this.user.newPassword !== value) {
26         callback(new Error("两次输入的密码不一致"));
27       } else {
28         callback();
29       }
30     };
31     return {
32       user: {
33         oldPassword: undefined,
34         newPassword: undefined,
35         confirmPassword: undefined
36       },
37       // 表单校验
38       rules: {
39         oldPassword: [
40           { required: true, message: "旧密码不能为空", trigger: "blur" }
41         ],
42         newPassword: [
43           { required: true, message: "新密码不能为空", trigger: "blur" },
44           { min: 6, max: 20, message: "长度在 6 到 20 个字符", trigger: "blur" }
45         ],
46         confirmPassword: [
47           { required: true, message: "确认密码不能为空", trigger: "blur" },
48           { required: true, validator: equalToPassword, trigger: "blur" }
49         ]
50       }
51     };
52   },
53   methods: {
54     submit() {
55       this.$refs["form"].validate(valid => {
56         if (valid) {
57           updateUserPwd(this.user.oldPassword, this.user.newPassword).then(response => {
58             this.$modal.msgSuccess("修改成功");
59           });
60         }
61       });
62     },
63     close() {
64       this.$tab.closePage();
65     }
66   }
67 };
68 </script>