qingyiay
2023-11-28 9a63b4c5f5dfcfa14a52fb726a0f5604077bba9c
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
<template>
    <view class="main">
        <u-form :model="modelForm"
            label-position="top"
            :rules="rules"
            ref="uForm"
            label-width="80px">
            <u-form-item prop="password"
                label="密码"
                required
                borderBottom>
                <u-input v-if='inputType==="password"'
                    v-model="modelForm.password"
                    border="surround"
                    placeholder="请输入密码(仅支持数字字母下划线)"
                    :type='inputType' />
                <u-input v-else
                    v-model="modelForm.password"
                    border="surround"
                    placeholder="请输入密码(仅支持数字字母下划线)"
                    :type='inputType' />
            </u-form-item>
            <u-form-item prop="secondPassword"
                label="二次确认"
                required
                borderBottom>
                <u-input v-if='inputType==="password"'
                    v-model="modelForm.secondPassword"
                    border="surround"
                    placeholder="请再次输入密码(仅支持数字字母下划线)"
                    type='password' />
                <u-input v-else
                    v-model="modelForm.secondPassword"
                    border="surround"
                    placeholder="请再次输入密码(仅支持数字字母下划线)"
                    type='text' />
            </u-form-item>
            <u-form-item>
                <view class="process-button">
                    <u-button type="primary"
                        text="确定"
                        :loading="processLoading"
                        @click.stop="process"></u-button>
                </view>
            </u-form-item>
            <u-form-item prop="checkboxValue">
                <u-checkbox-group v-model="checkboxValue"
                    @change="checkChange">
                    <u-checkbox label="显示密码"
                        name="显示"
                        iconSize="32"
                        label-size="32"
                        size="40"
                        shape="circle">
                    </u-checkbox>
                </u-checkbox-group>
            </u-form-item>
        </u-form>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                userInfo: {},
                checkboxValue: [],
                inputType: 'password',
                isFocus: false,
                modelForm: {
                    password: '',
                    secondPassword: ''
                },
                processLoading: false,
                rules: {
                    password: [{
                            type: 'string',
                            required: true,
                            message: '请填写密码',
                            trigger: ['blur', 'change']
                        },
                        {
                            min: 2,
                            max: 10,
                            message: '密码长度应不小于2位,不大于10位  ',
                            trigger: ['blur', 'change']
                        },
                        {
                            pattern: /^[a-zA-Z0-9_]+$/,
                            message: '请输入正确格式的密码',
                            trigger: ['blur', 'change']
                        }
                    ],
                    secondPassword: [{
                            type: 'string',
                            required: true,
                            message: '请填写二次密码',
                            trigger: ['blur', 'change']
                        },
                        {
                            min: 2,
                            max: 10,
                            message: '密码长度应不小于2,不大于10',
                            trigger: ['blur', 'change']
                        }
                    ]
                }
            }
        },
        onLoad(params) {
            this.userInfo = JSON.parse(params.userInfo)
        },
        onReady() {
            this.$refs.uForm.setRules(this.rules)
        },
        methods: {
            checkChange(name) {
                this.inputType = name.length === 0 ? 'password' : ''
                this.isFocus = true
            },
            process() {
                if (this.modelForm.password !== this.modelForm.secondPassword) return uni.$u.toast('密码不一致,请检查')
                this.userInfo.password = this.modelForm.secondPassword;
                this.processLoading = true;
                this.$refs.uForm.validate().then(res => {
                    this.$reqAllJson('appUpdateById', this
                        .userInfo, { method: 'PUT', 'Content-type': 'application/json' }).then(res => {
                        this.processLoading = false;
                        if (res.code === 0) {
                            this.$u.toast('修改成功,即将回到首页')
                            setTimeout(() => {
                                uni.reLaunch({
                                    url: '/pages/login/login'
                                })
                            }, 800)
                        } else {
                            this.$u.toast(res.msg ? res.msg : '修改失败')
                        }
                    })
                }).catch(errors => {
                    uni.$u.toast('校验失败')
                })
            }
        }
    }
</script>
 
<style lang="scss"
    scoped>
    .main {
        width: 94%;
        margin: vww(10) auto;
 
        .process-button {
            margin-top: vww(20);
        }
    }
</style>