MrShi
2026-05-22 eb7a808aaf7dd0a6dd2ff70f9ef3f8ce0b1e31d1
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
<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>
                <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>
                <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: {
                    password: '',
                    confirmPassword: ''
                }
            }
        },
        methods: {
            handleSubmit() {
                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 }).then(res => {
                    uni.hideLoading()
                    if (res.code === 200) {
                        uni.showToast({ title: '修改成功', icon: 'success' })
                        setTimeout(() => {
                            this.$store.commit('clearAll')
                            uni.reLaunch({
                                url: '/pages/login/login'
                            })
                        }, 1500)
                    }
                }).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>