jiangping
2023-09-13 7cce6eae91aab7a6270174085ddc615fabf8f02c
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
<template>
    <view class="change">
        <view class="change_list">
            <view class="change_list_item">
                <view class="label">新密码</view>
                <view class="input">
                    <input type="password" v-if="!isOpen" v-model="password" placeholder="请输入新密码" placeholder-class="placeholder" />
                    <input type="text" v-else v-model="password" placeholder="请输入新密码" placeholder-class="placeholder" />
                    <u-icon name="eye-fill" color="#999999" size="20" v-if="!isOpen" @click="isOpen = true"></u-icon>
                    <u-icon name="eye-off" color="#999999" size="20" v-else @click="isOpen = false"></u-icon>
                </view>
            </view>
            <view class="change_list_item">
                <view class="label">确认密码</view>
                <view class="input">
                    <input type="password" v-if="!isOpen1" v-model="confirmPassword" placeholder="请再次输入新密码" placeholder-class="placeholder" />
                    <input type="text" v-else v-model="confirmPassword" placeholder="请再次输入新密码" placeholder-class="placeholder" />
                    <u-icon name="eye-fill" color="#999999" size="20" v-if="!isOpen1" @click="isOpen1 = true"></u-icon>
                    <u-icon name="eye-off" color="#999999" size="20" v-else @click="isOpen1 = false"></u-icon>
                </view>
            </view>
        </view>
        <view class="change_info">密码规则:字母、数字组合,不少于8个字符</view>
        <view class="change_submit" @click="submit">确认</view>
        <u-toast ref="uToast"></u-toast>
    </view>
</template>
 
<script>
    import { CheckPassWord } from '@/utils/utils.js'
    import { mapState } from 'vuex'
    export default {
        data() {
            return {
                password: '',
                confirmPassword: '',
                isOpen: false,
                isOpen1: false
            };
        },
        computed: {
            ...mapState(['userInfo'])
        },
        methods: {
            submit() {
                if (!this.password) {
                    uni.showToast({
                        title: '新密码不能为空',
                        icon: 'none',
                        duration: 2000
                    });
                    return
                }
                if (!CheckPassWord(this.password)) {
                    uni.showToast({
                        title: '密码必须为字母、数字组合,不少于8个字符',
                        icon: 'none',
                        duration: 2000
                    });
                    return
                }
                if (!this.confirmPassword) {
                    uni.showToast({
                        title: '确认密码不能为空',
                        icon: 'none',
                        duration: 2000
                    });
                    return
                }
                if (this.password !== this.confirmPassword) {
                    uni.showToast({
                        title: '密码不一致',
                        icon: 'none',
                        duration: 2000
                    });
                    return
                }
                this.$u.api.resetPwd({ id: this.userInfo.id, password: this.password })
                    .then(res => {
                        uni.showToast({
                            title: '修改成功',
                            mask: true,
                            icon: 'success',
                            duration: 2000,
                            complete() {
                                setTimeout(() => {
                                    uni.navigateBack({
                                        delta: 1
                                    });
                                }, 2000)
                            }
                        });
                    })
            }
        }
    }
</script>
 
<style lang="scss">
    .change {
        width: 100%;
        padding-top: 20rpx;
        box-sizing: border-box;
        .change_list {
            width: 100%;
            padding: 0 30rpx;
            background-color: #fff;
            box-sizing: border-box;
            .change_list_item {
                width: 100%;
                height: 100%;
                display: flex;
                align-items: center;
                justify-content: space-between;
                border-bottom: 1rpx solid #E5E5E5;
                &:last-child {
                    border: none !important;
                }
                .label {
                    font-size: 30rpx;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #222222;
                    flex-shrink: 0;
                    margin-right: 30rpx;
                }
                .input {
                    flex: 1;
                    height: 100rpx;
                    line-height: 100rpx;
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    .placeholder {
                        font-size: 28rpx;
                        font-family: PingFangSC-Regular, PingFang SC;
                        font-weight: 400;
                        color: #999999;
                    }
                    input {
                        width: 100%;
                        height: 100%;
                        font-size: 28rpx;
                        font-family: PingFangSC-Regular, PingFang SC;
                        font-weight: 400;
                        color: #000000;
                        text-align: right;
                        margin-right: 20rpx;
                    }
                }
            }
        }
        .change_info {
            font-size: 26rpx;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #999999;
            margin-top: 24rpx;
            margin-left: 32rpx;
        }
        .change_submit {
            width: calc(100% - 60rpx);
            margin-left: 30rpx;
            box-sizing: border-box;
            height: 88rpx;
            line-height: 88rpx;
            text-align: center;
            background: #0055FF;
            border-radius: 4rpx;
            font-size: 30rpx;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #FFFFFF;
            margin-top: 100rpx;
        }
    }
</style>