hailu
2024-12-02 0bbcee731e5259feadd261e8a84c3e27b8387e01
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
<template>
    <view class="container">
        <form @submit.prevent="saveEditPass">
            <!-- 原密码 -->
            <view class="list-cell">
                <text class="cell-tit">原密码</text>
                <input type="password" v-model="editPasswordForm.oldpwd" placeholder="请输入原密码" class="cell-input" />
            </view>
 
            <!-- 新密码 -->
            <view class="list-cell">
                <text class="cell-tit">新密码</text>
                <input type="password" v-model="editPasswordForm.newpwd" placeholder="请输入新密码" class="cell-input" />
            </view>
 
            <!-- 确认密码 -->
            <view class="list-cell">
                <text class="cell-tit">确认密码</text>
                <input type="password" v-model="editPasswordForm.ConfirmPassword" placeholder="请再次输入新密码"
                    class="cell-input" />
            </view>
 
            <!-- 保存按钮 -->
            <button formType="submit" class="save-button" :loading="savePassLoading">保存</button>
        </form>
    </view>
</template>
 
<script>
export default {
    data() {
        return {
            editPasswordForm: {
                Name:'',
                oldpwd: '',
                newpwd: '',
                ConfirmPassword: ''
            },
            savePassLoading: false
        };
    },
    methods: {
        saveEditPass() {
            // 验证原密码
            if (this.editPasswordForm.oldpwd.replace(/\s/g, '').length < 6) {
                this.$msg('原密码输入错误!');
                return false;
            }
            // 验证新密码的复杂度
            const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{6,20}$/;
            if (!passwordRegex.test(this.editPasswordForm.newpwd)) {
                this.$msg('新密码必须为6-20位,包含大小写字母、数字和特殊符号');
                return false;
            }
 
            // 验证确认密码是否与新密码一致
            if (this.editPasswordForm.newpwd !== this.editPasswordForm.ConfirmPassword) {
                this.$msg('两次密码输入不一致!');
                return false;
            }
 
            this.savePassLoading = true;
            let data = this.editPasswordForm;
            this.$http.post('/user/ChangePassword', data).then(res => {
                if (res.Check) {
                    this.$msg('密码修改成功');
                    // 清空输入框
                    this.editPasswordForm.oldpwd = '';
                    this.editPasswordForm.newpwd = '';
                    this.editPasswordForm.ConfirmPassword = '';
                } else {
                    this.$msg('密码修改失败,请重试');
                }
                this.savePassLoading = false;
            }).catch(error => {
                this.savePassLoading = false;
                this.$msg('服务器错误!');
            });
        }
    }
}
</script>
 
<style lang='scss'>
page {
    background: $page-color-base;
}
 
.container {
    padding: 20upx;
}
 
.list-cell {
    display: flex;
    align-items: center;
    padding: 20upx $page-row-spacing;
    line-height: 60upx;
    position: relative;
    background: #fff;
    justify-content: space-between;
 
    &.m-t {
        margin-top: 16upx;
    }
 
    .cell-tit {
        flex: 1;
        font-size: $font-base + 2upx;
        color: $font-color-dark;
        margin-right: 10upx;
    }
 
    .cell-input {
        flex: 1;
        font-size: $font-base + 2upx;
        color: $font-color-dark;
    }
 
    .password-hint {
        font-size: $font-base - 2upx;
        color: #999;
        margin-top: 10upx;
    }
}
 
.save-button {
    width: 100%;
    margin-top: 20upx;
    background-color: #fa436a;
    color: white;
    font-size: $font-base + 2upx;
    border: none;
    border-radius: 8upx;
    padding: 10upx 0;
}
</style>