luobisheng
2022-11-24 447a59c76ab12961bce6ae2f9ca6c5cce1905ad8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<template>
    <div class="createUser">
        <main>
            <div class="mainContent">
                <el-form ref="password" label-width="140px" :rules="passwordRules" autoComplete="on" :model="password"
                    label-position="right">
                    <el-form-item class="optionItem" label="当前密码:" prop="oldPassword">
                        <el-input type="password" v-model="password.oldPassword" placeholder="请填写当前密码"></el-input>
                    </el-form-item>
                    <el-form-item class="optionItems" label="新密码:" prop="newPassword">
                        <el-input type="password" v-model="password.newPassword" placeholder="请填写新密码"></el-input>
                    </el-form-item>
                    <el-form-item class="optionItems" label="确定新密码:" prop="confirmPassword">
                        <el-input type="password" v-model="password.confirmPassword" placeholder="请再次填写新密码"></el-input>
                    </el-form-item>
                  <el-form-item class="optionItems">
                    <el-button type="primary" @click="onSubmit">提交</el-button>
                  </el-form-item>
                </el-form>
            </div>
        </main>
    </div>
</template>
<script>
import users from "@/api/users";
 
export default {
    data() {
        return {
          password: {
            oldPassword: null,
            newPassword: null,
            confirmPassword: null
          },
          passwordRules: {
            newPassword: [{ required: true, trigger: 'blur', message: '密码不能为空' }],
            oldPassword: [{ required: true, trigger: 'blur', message: '新密码不能为空' }],
            confirmPassword: [{ required: true, trigger: 'blur', message: '新密码不能为空' }],
          },
        }
    },
    created() {
    },
    methods: {
      onSubmit() {
        this.$refs.password.validate(valid => {
          if (valid) {
            const userName = JSON.parse(sessionStorage.getItem('name'));
            const passwordParams = Object.assign({}, this.password);
            delete passwordParams.confirmPassword;
            users.updatePassword({ username: userName, ...passwordParams })
                .then(() => {
                  this.$message.success('修改密码成功, 即将重新登录');
                  this.logout();
                })
                .catch(err => this.$message.error(err))
          }
        })
      },
      logout() {
        users.logout()
            .then(() => {
              sessionStorage.clear();
            })
            .catch(err => this.$message.error(err))
      }
    },
}
</script>
<style lang="scss" scoped>
.createUser {
    border-radius: 1px;
    background-color: #09152f;
 
    main {
        text-align: left;
        padding: 0 55px;
        background-color: #09152f;
        padding-bottom: 50px;
 
        .mainContent {
            display: flex;
            justify-content: center;
            padding-top: 50px;
 
            .el-form-item__content {
                width: 400px;
 
                .el-select {
                    width: 100%;
                }
            }
 
            .optionHandleSp {
                display: flex;
 
                .areaNumber,
                .moreNumber {
                    flex: 1;
                }
 
                .telNumber {
                    flex: 2;
                }
            }
 
            .optionBtn {
                display: flex;
                margin-top: 20px;
 
                .btn {
                    padding: 12px 50px;
                }
            }
 
        }
    }
 
    &::v-deep .el-textarea__inner {
        background-color: #09152f;
        border: 1px solid #17324c;
    }
 
    ::v-deep .el-form-item__label {
        color: #4b9bb7;
    }
 
    ::v-deep .el-input__inner {
        background-color: #09152f;
        border: 1px solid #17324c;
    }
}
</style>