quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<template>
    <view class="login-container">
 
        <view class="wechatapp">
            <view class="header">
                <!-- #ifdef MP-WEIXIN -->
                <open-data class="" type="userAvatarUrl"></open-data>
                <!-- #endif -->
            </view>
        </view>
        <view class="auth-title">申请获取以下权限</view>
        <view class="auth-subtitle">获得你的公开信息(昵称、头像等)</view>
        <view class="login-btn">
            <!-- #ifdef MP-WEIXIN -->
            <button class="btn-normal" @click="getUserInfo">授权登录</button>
            <!-- #endif -->
        </view>
        <view class="no-login-btn">
            <button class="btn-normal" @click="onNotLogin">暂不登录</button>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                background: '',
                listData: []
            }
        },
        created() {
            // 获取注册/登录方式 by lyzflash
            this.getRegisterSetting();
        },
        onShow(){
            //wx.login(); //重新登录
        },
        onLoad() {
 
        },
        methods: {
            // 获取注册/登录方式 by lyzflash
            getRegisterSetting: function() {
                let self = this;
                uni.showLoading({
                    title: "正在登录"
                });
                self._get('user.user/registerSetting', {}, function(res) {
                    console.log(res);
                    // 如果是手动注册 by lyzflash
                    if (res.data.register.register_type == 1) {
                        self.gotoPage('/pages/login/minlogin', 'redirect');
                        return false;
                    }
                    self.registerSetting = res.data.register;
                    self.getUserInfo();
                    uni.hideLoading();
                });
            },
            /*改变发送验证码按钮文本*/
            changeMsg() {
                if (this.second > 0) {
                    this.send_btn_txt = this.second + '秒';
                    this.second--;
                    setTimeout(this.changeMsg, 1000);
                } else {
                    this.send_btn_txt = '获取验证码';
                    this.second = 60;
                    this.is_send = false;
                }
            },
            onNotLogin:function(){
                this.gotoPage('/pages/index/index')
            },
            getUserInfo: function() {
                let self = this;
                wx.getUserProfile({
                    lang: 'zh_CN',
                    desc: '用于完善会员资料', 
                    success: (res) => {
                        console.log(res);
                        if (res.errMsg !== 'getUserProfile:ok') {
                            return false;
                        }
                        uni.showLoading({
                            title: "正在登录",
                            mask: true
                        });
                        // 执行微信登录
                        wx.login({
                            success(res_login) {
                                 // 发送用户信息
                                 self._post('user.user/login', {
                                    code: res_login.code,
                                    user_info: res.rawData,
                                    encrypted_data: encodeURIComponent(res.encryptedData),
                                    iv: encodeURIComponent(res.iv),
                                    signature: res.signature,
                                    referee_id: uni.getStorageSync('referee_id'),
                                    source: 'wx'
                                }, result => {
                                    // 记录token user_id
                                    uni.setStorageSync('token', result.data.token);
                                    uni.setStorageSync('user_id', result.data.user_id);
                                    // 执行回调函数
                                    self.gotoWhere();    
                                }, false, () => {
                                    uni.hideLoading();
                                }); 
                            }
                        });
                    }
                });
            },
            gotoWhere: function() {
                let self = this;
                self.jumpPage();
                /* self._get('user.register/userNeed', {
                    }, function(res) {
                        self.needRegister = res.data.needRegister;
                        if (self.needRegister) {
                            self.jumpPage();
                        } else {
                            uni.navigateBack();
                        }
                    }
                ) */
            },
            jumpPage: function() {
                // 获取登录前页面
                let url = '/' + uni.getStorageSync('currentPage');
                if(!uni.getStorageSync('currentPage')){
                    uni.navigateBack();
                }
                let pageOptions = uni.getStorageSync('currentPageOptions');
                if(Object.keys(pageOptions).length > 0){
                    url += '?';
                    for(let i in pageOptions){
                        url += i + '=' + pageOptions[i] + '&';
                    }
                    url = url.substring(0, url.length - 1);
                }
                
                // 执行回调函数
                this.gotoPage(url, 'reLaunch');
            },
        },
    }
</script>
 
<style>
    .login-container {
        padding: 30rpx;
    }
 
    .wechatapp {
        padding: 80rpx 0 48rpx;
        border-bottom: 1rpx solid #e3e3e3;
        margin-bottom: 72rpx;
        text-align: center;
    }
 
    .wechatapp .header {
        width: 190rpx;
        height: 190rpx;
        border: 2px solid #fff;
        margin: 0rpx auto 0;
        border-radius: 50%;
        overflow: hidden;
        box-shadow: 1px 0px 5px rgba(50, 50, 50, 0.3);
    }
 
    .auth-title {
        color: #585858;
        font-size: 34rpx;
        margin-bottom: 40rpx;
    }
 
    .auth-subtitle {
        color: #888;
        margin-bottom: 88rpx;
        font-size: 28rpx;
    }
 
    .login-btn {
        padding: 0 20rpx;
    }
 
    .login-btn button {
        height: 88rpx;
        line-height: 88rpx;
        background: #04be01;
        color: #fff;
        font-size: 30rpx;
        border-radius: 999rpx;
        text-align: center;
    }
 
    .no-login-btn {
        margin-top: 20rpx;
        padding: 0 20rpx;
    }
 
    .no-login-btn button {
        height: 88rpx;
        line-height: 88rpx;
        background: #dfdfdf;
        color: #fff;
        font-size: 30rpx;
        border-radius: 999rpx;
        text-align: center;
    }
</style>