pyt
2025-04-03 6d26a6b3397f6433fe070de72381887151950158
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<template>
    <el-dialog :visible.sync="show" :show-close="false" width="500px" :close-on-click-modal="false" append-to-body>
        <div class="content">
            <el-form label-position="left" label-width="120px" ref="form" :model="form" :rules="rules">
                <div class="title">修改密码 | Change Password</div>
                <el-row :gutter="20" class="form-row">
                    <el-col :span="24">
                        <el-form-item label="原密码:" prop="oldPassword">
                            <template #label>
                                <div class="form-label">
                                    <div>原密码</div>
                                    <div class="label-en">Current Password</div>
                                </div>
                            </template>
                            <el-input v-model="form.oldPassword" type="password" placeholder="请输入"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="新密码:" prop="newPassword">
                            <template #label>
                                <div class="form-label">
                                    <div>新密码</div>
                                    <div class="label-en">New Password</div>
                                </div>
                            </template>
                            <el-input v-model="form.newPassword" type="password" placeholder="请输入"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="确认密码:" prop="confirmPassword">
                            <template #label>
                                <div class="form-label">
                                    <div>确认密码</div>
                                    <div class="label-en">Confirm Password</div>
                                </div>
                            </template>
                            <el-input v-model="form.confirmPassword" type="password" placeholder="请输入"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div class="btns">
                <el-button @click="$emit('close')">取消 | Cancel</el-button>
                <el-button type="primary" @click="submit">确定 | Confirm</el-button>
            </div>
        </div>
    </el-dialog>
</template>
 
<script>
import { changePwd } from '@/view/service'
import CryptoJS from 'crypto-js';
 
export default {
    props: ['show'],
    data() {
        return {
            form: {
                oldPassword: '',
                newPassword: '',
                confirmPassword: ''
            },
            rules: {
                oldPassword: [
                    { required: true, message: '请输入原密码', trigger: 'change' }
                ],
                newPassword: [
                    { required: true, message: '请输入新密码', trigger: 'change' },
                    { min: 6, message: '密码长度不能小于6位', trigger: 'change' }
                ],
                confirmPassword: [
                    { required: true, message: '请确认新密码', trigger: 'change' },
                    { validator: this.validateConfirmPassword, trigger: 'change' }
                ]
            }
        }
    },
    methods: {
        validateConfirmPassword(rule, value, callback) {
            if (value !== this.form.newPassword) {
                callback(new Error('两次输入的密码不一致'));
            } else {
                callback();
            }
        },
        submit() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    let params = {
                        extra: localStorage.getItem('extra'),
                        oldPwd: CryptoJS.MD5(this.form.oldPassword).toString(),
                        newPwd: CryptoJS.MD5(this.form.newPassword).toString(),
                    }
 
                    changePwd(params).then(res => {
                        this.$message.success('密码修改成功')
                        this.$emit('close')
                    })
                }
            })
        }
    }
}
</script>
 
<style lang="less" scoped>
.content {
    .title {
        padding: 31px 0;
        text-align: center;
        font-size: 18px;
        font-weight: bold;
        color: #3B3F56;
        line-height: 27px;
    }
 
    .form-row {
        padding: 0 20px;
    }
 
    .btns {
        display: flex;
        justify-content: center;
        margin-top: 32px;
        padding-bottom: 33px;
 
        .el-button {
            width: 190px;
            height: 50px;
            font-size: 20px;
            margin: 0 10px;
        }
 
        .el-button--primary {
            background-color: #014099;
            border-color: #014099;
        }
    }
}
 
/deep/ .el-dialog {
    border-radius: 8px;
 
    .el-dialog__header {
        display: none !important;
    }
 
    .el-dialog__body {
        padding: 0 !important;
    }
}
 
/deep/ .el-form {
    .el-form-item__label {
        font-size: 15px;
        color: #3B3F56;
        font-weight: 500;
        display: flex;
    }
 
    .form-label {
        white-space: normal;
        line-height: 1.2;
        display: flex;
        flex-direction: column;
 
        .label-en {
            font-size: 12px;
            color: #999;
            white-space: nowrap;
        }
    }
}
</style>