spring
4 天以前 435881d494e2be4ba5ce8bfccb02d6ef49e07314
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
<template>
    <view class="wrap">
        <u-form class="form" :model="model" :rules="rules" ref="uForm">
            <u-form-item label="旧密码" prop="oldPassword" label-width="180">
                <u-input type="password" v-model="model.password" placeholder="请输入旧密码"></u-input>
            </u-form-item>
            <u-form-item label="新密码" prop="newPassword" label-width="180">
                <u-input type="password" v-model="model.newpassword1" placeholder="请输入新密码"></u-input>
            </u-form-item>
            <u-form-item label="确认密码" prop="confirmNewPassword" label-width="180">
                <u-input type="password" v-model="model.newpassword2" placeholder="请确认新密码"></u-input>
            </u-form-item>
        </u-form>
        <view class="form-footer">
            <u-button class="btn" type="primary" @click="submit">提交</u-button>
      <u-button class="btn" type="default" @click="cancel">关闭</u-button>
        </view>
    </view>
</template>
<script>
/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
export default {
    data() {
        return {
            model: {
        password: '',
        newpassword1: '',
        newpassword2: ''
            },
            rules: {
        password: [
                    {
                        required: true,
                        message: '请输入旧密码',
                        trigger: ['change','blur'],
                    }
                ],
        newpassword1: [
                    {
                        required: true,
                        message: '请输入新密码',
                        trigger: ['change','blur'],
                    },
                    {
                        pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+\S{5,12}$/,
                        message: '需同时含有字母和数字,长度在6-12之间',
                        trigger: ['change','blur'],
                    }
                ],
        newpassword2: [
                    {
                        required: true,
                        message: '请重新输入密码',
                        trigger: ['change','blur'],
                    },
                    {
                        validator: (rule, value, callback) => {
                            return value === this.model.newpassword1;
                        },
                        message: '两次输入的密码不相等',
                        trigger: ['change','blur'],
                    }
                ],
            }
        };
    },
    onReady() {
        this.$refs.uForm.setRules(this.rules);
    },
    methods: {
        submit() {
            this.$refs.uForm.validate(valid => {
                if (valid) {
                  //修改密码时携带上userid与username
                    this.$u.api.user.updateUserInfo({
            userId:this.vuex_userId,
            username:this.vuex_username,
            password: this.model.password,
            newpassword1: this.model.newpassword1
                    }).then(res => {
                      let temp = this
                        uni.showModal({
                            title: '提示',
                            content: '修改密码成功,请重新登录.',
                            showCancel: false,
                            success: function () {
                temp.$u.api.logout().then(res => {
                  //清空存储信息
                  temp.$u.vuex('vuex_token', '')
                  temp.$u.vuex('vuex_refresh_token','')
                  temp.$u.vuex('vuex_username', '')
                  temp.$u.vuex('vuex_userId', '')
                  temp.$u.vuex('vuex_client_id', '')
                  temp.$u.vuex('vuex_user',{})
 
                  setTimeout(() => {
                    uni.reLaunch({
                      url: '/pages/sys/login/index'
                    });
                  }, 500);
 
                });
                            }
                        });
                    });
                } else {
                    this.$u.toast('您填写的信息有误,请根据提示修正。');
                }
            });
        },
        cancel() {
            uni.navigateBack();
        }
    }
};
</script>
<style lang="scss">
 
</style>