odc.xiaohui
2023-05-12 4b48bacef8646cee8b66f5e10b0ed7124534e93e
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
// index.ts
// 获取应用实例
const app = getApp()
 
Page({
    data: {
        isShow: false,
        userInfo: {},
        hasUserInfo: false,
        canIUse: wx.canIUse('button.open-type.getUserInfo'),
        canIUseGetUserProfile: false,
        canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
    },
    // 事件处理函数
    bindViewTap() {
        wx.navigateTo({
            url: '../logs/logs',
        })
    },
    //    getPhoneNumber: function (e) {
    //         console.log(e.detail.errMsg)
    //         console.log(e.detail.iv)
    //         console.log(e.detail.encryptedData)
    //     },
 
    onLoad() {
        try {
            var value = wx.getStorageSync('token')
            if (value) { // 说明已登录 跳转 页面
                console.log("获取缓存:" + value)
                var role = wx.getStorageSync('role')
                var info = wx.getStorageSync('info')
                console.log("获取缓存:" + role)
                if (role == 0) {
                    wx.switchTab({
                        url: '../user/index'
                    })
                        // wx.redirectTo(
                        //     {
                        //         url: '../user/index'
                        //     }
                        // )
                }
                if (role == 1) {
                    wx.switchTab({
                        url: '../user/index'
                    })
                    // wx.redirectTo(
                    //     {
                    //         url: '../user/index'
                    //     }
                    // )
                }
                wx.switchTab({
                    url: '../user/index'
                })
                // wx.navigateTo({
                //     url: '../user/index'
                // })
            } else {// 未登录 显示 微信授权页面
                this.setData({
                    isShow: true
                })
            }
        } catch (e) {
        }
    },
    getPhoneNumber: function (e) {
        console.log("Pcode", e.detail.code)
        // 用户拒绝授权
        if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
            wx.showToast({
                icon: "none",
                title: '请允许获取手机号,否则功能不可用!',
            })
            return
        }
        console.log("Pcode", e.detail.code)
        wx.login({
            success: (res) => {
                console.log("code", res.code)
                wx.setStorageSync('uesrCode', res.code)
                wx.setStorageSync('userPhoneNumberCode',e.detail.code)
              
                wx.request({
                    url:app.globalData.url+"/wx/checkIdentity",
                    data: {
                        "code": res.code,
                        "phoneNumberCode": e.detail.code
                    },
                    method: "GET",
                    success:(res)=>{
                        wx.setStorageSync('phone', res.data.msg)
                        if (res.data.data==2) {
                            wx.switchTab({
                                url: '../user/index'
                            })
                            // wx.redirectTo(
                            //                         {    url: '../user/index'
                            //                             //   url: '../user/pubulicty/index'
                            //                             // url: '../user/loginInfo/index'
                            //                         }
                            //                     )
                        }else if(res.data.data==0){
                            wx.switchTab({
                                url: '../user/index'
                            })
                            // wx.redirectTo(
                            //     {
                            //         url: '../user/index'
                            //     }
                            // )
                        }else{
                            wx.switchTab({
                                url: '../user/index'
                            })
                            // wx.redirectTo(
                            //     {url: '../user/index'
                            //         // url: '../manager/index'
                            //     }
                            // ) 
                        }
                    }
                })
                // wx.request({
                //     url: app.globalData.url+"/wx/login",
                //     data: {
                //         "code": res.code,
                //         "phoneNumberCode": e.detail.code
                //     },
                //     method: "GET",
                //     success: (res) => {
                //         //  如果用户已经注册直接进入  未注册进入宣传   role == 0用户  1警员
                //         wx.setStorageSync('token', res.data.data.token)
                //         wx.setStorageSync('role', res.data.data.role)
                //         wx.setStorageSync('id', res.data.data.id)
                //         wx.setStorageSync('card',res.data.data.time)
                //         console.log(res.data.data.id)
                //         if (res.data.data.role == 0) {
                //             var info=wx.getStorageSync('card')
                //             if (info) {
                //                 wx.redirectTo(
                //                     {
                //                         url: '../user/index'
                //                     }
                //                 )
                //             } else {
                //                 wx.redirectTo(
                //                     {
                //                           url: '../user/pubulicty/index'
                //                         // url: '../user/loginInfo/index'
                //                     }
                //                 )
                //             }
                //         }
                //         if (res.data.data.role == 1) {
                //             wx.redirectTo(
                //                 {
                //                     url: '../manager/index'
                //                 }
                //             )
                //         }
                //     }
 
                // })
            }
        })
    },
    //   getUserProfile() {
    //     // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
    //     wx.getUserProfile({
    //       desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
    //       success: (res) => {
    //         console.log(res)
    //         this.setData({
    //           userInfo: res.userInfo,
    //           hasUserInfo: true
    //         })
    //         console.log(this.data.userInfo)
    //       }
    //     })
    //   },
    //   getUserInfo(e: any) {
    //     // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
    //     console.log(e)
    //     this.setData({
    //       userInfo: e.detail.userInfo,
    //       hasUserInfo: true
    //     })
 
})