MrShi
昨天 e9a7cddce776382916e975402986144a88899ac5
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="change-password-page">
        <view class="change-password-page__form">
            <view class="change-password-page__item">
                <text class="change-password-page__label"><text style="color: red;">*</text>原始密码</text>
                <input v-model="form.oldPassword" class="change-password-page__input" password placeholder="请输入原始密码" placeholder-style="color: #c2c7d0;" />
            </view>
            <view class="change-password-page__item">
                <text class="change-password-page__label"><text style="color: red;">*</text>新密码</text>
                <input v-model="form.password" class="change-password-page__input" password placeholder="请输入新密码" placeholder-style="color: #c2c7d0;" />
            </view>
            <view class="change-password-page__item">
                <text class="change-password-page__label"><text style="color: red;">*</text>确认密码</text>
                <input v-model="form.confirmPassword" class="change-password-page__input" password placeholder="请再次输入新密码" placeholder-style="color: #c2c7d0;" />
            </view>
 
            <text class="change-password-page__rule">密码规则:字母、数字组合,不少于8个字符</text>
        </view>
 
        <button class="change-password-page__submit" hover-class="change-password-page__submit--hover" @click="handleSubmit">确认修改</button>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                form: {
                    oldPassword:'',
                    password: '',
                    confirmPassword: ''
                }
            }
        },
        methods: {
            handleSubmit() {
                if (!this.form.oldPassword) {
                    uni.showToast({ title: '请输入原始密码', icon: 'none' })
                    return
                }
                if (!this.form.password) {
                    uni.showToast({ title: '请输入新密码', icon: 'none' })
                    return
                }
                if (!this.form.confirmPassword) {
                    uni.showToast({ title: '请再次输入新密码', icon: 'none' })
                    return
                }
                if (this.form.password !== this.form.confirmPassword) {
                    uni.showToast({ title: '两次密码输入不一致', icon: 'none' })
                    return
                }
                const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/
                if (!passwordRegex.test(this.form.password)) {
                    uni.showToast({ title: '密码需字母、数字组合,不少于8个字符', icon: 'none' })
                    return
                }
                uni.showLoading({ title: '修改中...' })
                this.$u.api.changePassword({ newPassword: this.form.password,oldPassword:this.form.oldPassword }).then(res => {
                    uni.hideLoading()
                    if (res.code === 200) {
                        uni.showToast({ title: '修改成功,下次登录请使用新密码登录', icon: 'success' })
                    }
                }).catch(err => {
                    uni.hideLoading()
                })
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .change-password-page {
        min-height: 100vh;
        background: #ffffff;
        padding-top: 2rpx;
 
        &__form {
            background: #ffffff;
        }
 
        &__item {
            display: flex;
            align-items: center;
            height: 100rpx;
            padding: 0 30rpx;
            border-bottom: 1rpx solid #eceff4;
        }
 
        &__label {
            width: 150rpx;
            font-size: 32rpx;
            font-weight: 500;
            color: #333333;
            flex-shrink: 0;
        }
 
        &__input {
            flex: 1;
            height: 100rpx;
            text-align: right;
            font-size: 30rpx;
            color: #333333;
            background: transparent;
        }
 
        &__rule {
            display: block;
            padding: 20rpx 30rpx 0;
            font-size: 24rpx;
            line-height: 1.6;
            color: #b3b8c1;
        }
 
        &__submit {
            width: calc(100% - 60rpx);
            height: 78rpx;
            line-height: 78rpx;
            margin: 110rpx auto 0;
            border-radius: 999rpx;
            background: #2476f6;
            font-size: 30rpx;
            font-weight: 500;
            color: #ffffff;
            border: 0;
            padding: 0;
 
            &::after {
                border: 0;
            }
 
            &--hover {
                opacity: 0.92;
            }
        }
    }
</style>