罗广辉
2026-06-18 44dd9c4eb8a2489c63a5eb53fd4254bbb3510e95
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<!-- 修改密码 -->
<template>
    <view class="container">
        <view class="detailBox">
            <div class="detailCon">
                <div class="orderRow">
                    <!-- type="password" :password-icon="passwordIcon" -->
                    <div class="rowTitle">原始密码</div>
                    <input type="password" v-model="passwordForm.oldPassword" placeholder="请输入" class="input-item" />
                </div>
                <div class="orderRow">
                    <div class="rowTitle">新密码</div>
                    <input type="password" v-model="passwordForm.newPassword" placeholder="请输入" class="input-item" />
 
                </div>
                <div class="orderRow">
                    <div class="rowTitle">确认密码</div>
                    <input type="password" v-model="passwordForm.newPassword1" placeholder="请输入" class="input-item" />
                </div>
            </div>
        </view>
        <view class="btngroup">
            <u-button color="#AEAEAE" class="custom-style" shape="circle" @click="reset">重置</u-button>
            <u-button
                :color="submitLoading ? '#AEAEAE' : '#1D6FE9'"
                class="custom-style"
                shape="circle"
                text="提交"
                :loading="submitLoading"
                loading-text="提交中"
                loading-mode="circle"
                :loading-size="13"
                @click="submit"
            />
        </view>
    </view>
</template>
 
<script setup>
    import {
        useUserStore
    } from "@/store/index.js";
    import md5 from "js-md5";
    import {
        getUserInfo,
        updateInfo,
        updatePassword
    } from '@/api/user/index.js';
    const passwordIcon = {
        show: 'fas fa-eye', // 显示密码时的图标
        hide: 'fas fa-eye-slash' // 隐藏密码时的图标
    }
    const userStore = useUserStore();
    const passwordForm = ref({
        oldPassword: '',
        newPassword: '',
        newPassword1: '',
    });
    const submitLoading = ref(false);
    // 校验密码不能包含中文
    const validatePasswordNoChinese = (password) => {
        const chineseRegex = /[\u4e00-\u9fa5]/;
        if (chineseRegex.test(password)) {
 
            uni.showToast({
                title: '密码不能包含中文字符',
                icon: 'none',
                duration: 2000
            });
            return false;
        }
        return true;
    };
    // 校验密码复杂度(长度≥6位,包含字母和数字)
    const validatePasswordStrength = (password) => {
        if (password.length < 6) {
 
            uni.showToast({
                title: '密码长度不能少于6位',
                icon: 'none',
                duration: 2000
            });
            return false;
        }
        return true;
    };
    const clearForm = () => {
        passwordForm.value = {
            oldPassword: '',
            newPassword: '',
            newPassword1: '',
        };
    };
    const reset = () => {
        clearForm();
    };
    const submit = () => {
        if (submitLoading.value) return;
        // 原始密码校验
        if (!passwordForm.value.oldPassword) {
 
            uni.showToast({
                title: '请输入原始密码',
                icon: 'none',
                duration: 2000
            });
            return;
        }
        // 中文校验
        if (!validatePasswordNoChinese(passwordForm.value.newPassword)) return;
        // 新密码校验
        if (!passwordForm.value.newPassword) {
 
            uni.showToast({
                title: '请输入新密码',
                icon: 'none',
                duration: 2000
            });
            return;
        }
        // 确认密码校验
        if (passwordForm.value.newPassword !== passwordForm.value.newPassword1) {
 
            uni.showToast({
                title: '两次输入的新密码不一致',
                icon: 'none',
                duration: 2000
            });
            return;
        }
 
        // 复杂度校验
        if (!validatePasswordStrength(passwordForm.value.newPassword)) return;
        submitLoading.value = true;
        updatePassword(md5(passwordForm.value.oldPassword),
            md5(passwordForm.value.newPassword),
            md5(passwordForm.value.newPassword1)).then(res => {
            if (res.data.code === 200) {
                uni.showToast({
                    title: '修改信息成功',
                    icon: 'none',
                    duration: 1500
                });
                clearForm();
                userStore.setUserInfo(null)
                uni.removeStorageSync('rememberedUser');
                setTimeout(() => {
                    uni.reLaunch({
                        url: '/pages/login/index'
                    })
                }, 1500);
                return
 
            } else {
                uni.showToast({
                    title: res.msg,
                    icon: 'none',
                    duration: 2000
                });
            }
            submitLoading.value = false;
 
        }).catch(() => {
            submitLoading.value = false;
        });
 
    };
    onShow(async () => {
        clearForm();
    });
</script>
 
<style lang="scss" scoped>
    .container {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
 
    .detailBox {
        margin-top: 40rpx;
        width: 702rpx;
 
        min-height: 326rpx;
        background: #FFFFFF;
        border-radius: 12rpx;
        box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
 
        .detailCon {
            padding: 0 24rpx;
        }
 
        .orderRow {
            display: flex;
            justify-content: space-between;
            align-items: center;
            height: 96rpx;
            border-bottom: 2rpx solid #f5f5f5;
            color: #7b7b7b;
 
 
            .rowTitle {
                font-family: Source Han Sans CN, Source Han Sans CN;
                font-weight: 400;
                font-size: 30rpx;
                color: #222324;
                white-space: nowrap;
            }
 
            input.input-item {
                text-align: right;
                border: none !important;
                background: transparent !important;
                box-shadow: none !important;
                padding: 0 !important;
                margin: 0 !important;
                height: auto !important;
 
                outline: none;
                font-size: 30rpx;
                color: #222324;
                font-family: Source Han Sans CN, Source Han Sans CN;
            }
      :deep(.uni-input-placeholder) {
        color: #D5D5D5;
      }
            input.input-item::placeholder {
                font-size: 30rpx;
            }
        }
    }
 
    .btngroup {
        display: flex;
        position: absolute;
        bottom: 150rpx;
    }
 
    :deep(.u-button:first-child) {
        margin-right: 30rpx !important;
    }
 
    .custom-style {
        width: 276rpx;
        height: 76rpx;
    }
    :deep(.u-button){
        width: 276rpx !important;
        height: 76rpx !important;
    }
</style>