xwt
2025-06-10 676db89a661ba8af8da04f4503c39b1bc0d2c25e
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
<template>
    <view>
        <uni-base-page :footer="false">
            <view slot="page" class="container">
                <form @submit="formSubmit" @reset="formReset">
                    <view class="form-group">
                        <uni-input-row class="form-input" type="password" title="原密码" v-model="pwd"
                            :focus="passwordFocus" @resetFocus="e=>{passwordFocus=e}" displayable
                            placeholder="请输入密码"></uni-input-row>
                    </view>
                    <view class="form-group">
                        <uni-input-row class="form-input" type="password" title="新密码" v-model="newPwd"
                            :focus="newPasswordFocus" @resetFocus="e=>{newPasswordFocus=e}" displayable
                            placeholder="请输入密码"></uni-input-row>
                    </view>
                    <view class="uni-btn-v">
                        <button type="primary" form-type="submit">提交</button>
                        <button type="default" form-type="reset">重置</button>
                    </view>
                </form>
            </view>
        </uni-base-page>
    </view>
</template>
 
<script>
    import graceChecker from "@/common/graceChecker";
 
    export default {
        data() {
            return {
                passwordFocus: false,
                newPasswordFocus: false,
                pwd: "",
                newPwd: "",
            }
        },
        methods: {
            formSubmit: function(e) {
                let flag = true;
                if (!this.pwd) {
                    uni.showToast({
                        title: "原密码不能为空",
                        icon: "none"
                    });
                    flag = false;
                    return;
                }
                if (!this.newPwd) {
                    uni.showToast({
                        title: "新密码不能为空",
                        icon: "none"
                    });
                    flag = false;
                    return;
                }
                if (this.pwd === this.newPwd) {
                    uni.showToast({
                        title: "原密码不能和新密码一致",
                        icon: "none"
                    });
                    flag = false;
                    return;
                }
                if (this.newPwd.length < 6) {
                    uni.showToast({
                        title: "密码长度不能小于6位",
                        icon: "none"
                    });
                    flag = false;
                    return;
                }
                if (flag) {
                    //发送请求
                    this.$post({
                        //请求的路径
                        url: "/login/resetPassword",
                        //参数
                        data: {
                            name: this.$loginInfo.account,
                            newPwd: this.newPwd,
                            pwd: this.pwd
                        },
                        //指定动画中的文字
                        showLoadingTitle: "核对中",
                    }).then(res => {
                        //返回的结果集
                        if (res.status == 0) {
 
                            uni.showToast({
                                title: "修改成功",
                                icon: "none",
                                success() {
                                    //修改完成后将用户踢回到登录页面
                                    uni.navigateTo({
                                        url: '/pages/BasePages/login' // 重定向到登录页面
                                    });
                                }
                            });
 
                        } else {
                            uni.showToast({
                                title: res.message,
                                icon: "none"
                            });
                        }
                    })
                }
            },
            formReset: function(e) {
                console.log('清空数据')
            }
        }
    }
</script>
 
<style>
    .container {
        padding: 20px;
    }
 
    .form-group {
        margin-bottom: 10px;
    }
 
    .form-label {
        display: inline-block;
        width: 60px;
        font-weight: bold;
    }
 
 
    .form-input {
        padding: 5px 10px;
        border: 1px solid #ccc;
        border-radius: 4px;
    }
 
    .btn-submit {
        padding: 10px;
        background-color: #007bff;
        color: #fff;
        border: none;
        border-radius: 4px;
        cursor: pointer;
    }
</style>