wanshenmean
2025-04-08 ef0a08b828d021bdc7978406e72bbde000097f5e
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
<template>
    <view class="login">
        <view class="login-main">
            <text class="login-main-title">修改密码</text>
            <view class="login-main-subtitle">修改后请保存密码,忘记密码请找管理员修改</view>
            <view class="login-main-body">
                <uni-forms ref="form" :modelValue="formData">
                    <uni-forms-item label="原密码:" required name="yuser">
                        <uni-easyinput v-model="formData.yuser" type="password" focus
                            placeholder="请输入原密码"></uni-easyinput>
                    </uni-forms-item>
                    <uni-forms-item label="新密码:" required name="newpass">
                        <uni-easyinput type="password" v-model="formData.newpass" placeholder="请输入新密码"></uni-easyinput>
                    </uni-forms-item>
                    <uni-forms-item label="确认密码:" required name="qnewpass">
                        <uni-easyinput type="password" v-model="formData.qnewpass" placeholder="请确认新密码"></uni-easyinput>
                    </uni-forms-item>
                    <u-button type="success" size="default" shape="circle" :ripple="true" ripple-bg-color="#909399"
                        @click="login">
                        修改
                    </u-button>
                </uni-forms>
            </view>
        </view>
    </view>
</template>
 
<script>
    import smCrypto from '@/common/smCrypto.js'
    export default {
        data() {
            return {
                formData: {
                    newpass: '',
                    qnewpass: '',
                    yuser: '',
                },
                rules: {
                    newpass: {
                        rules: [{
                            required: true,
                            errorMessage: '请输入新密码',
                        }, ]
                    },
                    qnewpass: {
                        rules: [{
                            required: true,
                            errorMessage: '请再次确认新密码',
                        }, {
                            validateFunction: function(rule, value, data, callback) {
                                console.log(data)
                                if (data.qnewpass != data.newpass) {
                                    callback('两次密码不一致')
                                }
                                return true
                            }
                        }]
                    },
                    yuser: {
                        rules: [{
                            required: true,
                            errorMessage: '请输入原密码',
                        }]
                    }
                }
            }
        },
        onReady() {
            // 需要在onReady中设置规则
            this.$refs.form.setRules(this.rules)
        },
        methods: {
            login(form) {
                this.$refs.form.validate().then(res => {
                    console.log('success', res);
                    this.$t.message.loading('正在修改')
                    let parms = {
                        oldPwd: smCrypto.doSm2Encrypt(res.yuser),
                        newPwd: smCrypto.doSm2Encrypt(res.newpass),
                    }
                let url ="/api/user/modifyPwd?oldPwd=" +this.formData.yuser +"&newPwd=" +this.formData.newpass;
                    this.$u.post(url,{}).then(res => {
                        console.log(res);
                        uni.clearStorage();
                        this.$t.message.toast(res.message)
                        this.$t.message.closeLoading()
                        setTimeout(e => {
                            uni.reLaunch({
                                url: '/pages/login/login'
                            });
                        },1500)
                    }).catch(err => {
                        this.$t.message.toast(res.message)
                        this.$t.message.closeLoading()
                    })
                }).catch(err => {
                    this.$t.message.toast(err)
                })
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .login {
        // font-family: PingFangSC-Regular, PingFang SC;
        // background-color: $color-white;
        height: calc(100vh - var(--window-top));
        width: 100vw;
        box-sizing: border-box;
 
        &-main {
            padding: 112rpx 75rpx 0 75rpx;
            position: relative;
 
            &-title {
                display: flex;
                justify-content: center;
                align-items: center;
                height: 64rpx;
                font-size: 48rpx;
                font-weight: 600;
                // color: $color-text-secondary;
                line-height: 64rpx;
                letter-spacing: 8rpx;
            }
 
            &-subtitle {
                font-size: 28rpx;
                // color: $color-text-thirdly;
                line-height: 40rpx;
                letter-spacing: 12rpx;
                text-align: center;
                margin: 8rpx 0 104rpx;
            }
 
            &-body {
                position: relative;
                box-sizing: border-box;
                width: 600rpx;
                height: 548rpx;
 
                .login-password {
                    position: relative;
                    padding: 40rpx 0 40rpx;
                }
 
                .login-passwordre {
                    position: relative;
                    padding: 0rpx 0 40rpx;
                }
 
                .verCode {
                    position: relative;
                    padding: 0rpx 0 140rpx;
                    display: flex;
                    flex-direction: row;
                    align-items: center;
                    justify-content: center;
                }
            }
        }
 
        &-footer {
            display: flex;
            flex-direction: column;
            width: 100%;
            height: 300rpx;
            text-align: center;
            line-height: 28rpx;
            font-size: 20rpx;
            font-weight: 500;
        }
    }
</style>